{"books":{"mt2":[{"n":1,"title":"MT2 preparation and examination plan","sections":[{"title":"Examination schedule and scope","blocks":["<p>The supplied timetable schedules Deep Learning MT2 for <strong>Tuesday, 13 October 2026, 3:00–4:00 pm</strong>, for <strong>10 marks</strong>.</p>","<p><strong>Faculty update received on 12 October:</strong> prepare <strong>Unit 3 (optimization and regularization) and Unit 4 (CNNs)</strong> for theory and numericals. The message highlights possible Unit 3 numericals and two Unit 4 numericals. The 2-mark questions can combine theory and a numerical or be theory only.</p>","<p><strong>Three 3-mark choices, as clarified:</strong> either <strong>Numerical + Numerical + Theory</strong>, or <strong>one mixed Theory-and-Numerical question + one Numerical + one Theory question</strong>. Their exact order and numerical topics are not specified.</p>","<p>The common M2 layout already supplied is <strong>Q1(a,b), 2 marks each, compulsory; answer any two of Q2–Q4, 3 marks each</strong>. Our mocks use this layout. Their exact topic allocation is practice design, not an official prediction.</p>","<p>Maths, losses, gradients and the neuron model remain prerequisite explanations. <strong>RNN is not named in this faculty update and is now kept in the TEE route, outside this focused MT2 reading path.</strong></p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c1-s0","search":"Examination schedule and scope The supplied timetable schedules Deep Learning MT2 for **Tuesday, 13 October 2026, 3:00–4:00 pm**, for **10 marks**.\n\n**Faculty update received on 12 October:** prepare **Unit 3 (optimization and regularization) and Unit 4 (CNNs)** for theory and numericals. The message highlights possible Unit 3 numericals and two Unit 4 numericals. The 2-mark questions can combine theory and a numerical or be theory only.\n\n**Three 3-mark choices, as clarified:** either **Numerical + Numerical + Theory**, or **one mixed Theory-and-Numerical question + one Numerical + one Theory question**. Their exact order and numerical topics are not specified.\n\nThe common M2 layout already supplied is **Q1(a,b), 2 marks each, compulsory; answer any two of Q2–Q4, 3 marks each**. Our mocks use this layout. Their exact topic allocation is practice design, not an official prediction.\n\nMaths, losses, gradients and the neuron model remain prerequisite explanations. **RNN is not named in this faculty update and is now kept in the TEE route, outside this focused MT2 reading path.**\n"},{"title":"Recommended reading order","blocks":["<p>Study <strong>Optimization algorithms → Regularization and generalization → CNN calculations → CNN architectures</strong>. If a symbol or step is unfamiliar, use the Mathematics revision and Neural-network foundations chapters as short prerequisite references, then return to the Unit 3–4 lesson.</p>","<p>For every numerical, reproduce: <strong>Given → To find → formula and why → numbered working → final answer</strong>. For theory, learn the technical definition, mechanism, labelled architecture or relevant formula, advantages/limitations and a concrete example where appropriate.</p>","<p><strong>Hinglish cue:</strong> Unit 3 mein gradient aur update ka order; Unit 4 mein window, shape aur parameter count alag rakho. Theory dono units ki karni hai.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c1-s1","search":"Recommended reading order Study **Optimization algorithms → Regularization and generalization → CNN calculations → CNN architectures**. If a symbol or step is unfamiliar, use the Mathematics revision and Neural-network foundations chapters as short prerequisite references, then return to the Unit 3–4 lesson.\n\nFor every numerical, reproduce: **Given → To find → formula and why → numbered working → final answer**. For theory, learn the technical definition, mechanism, labelled architecture or relevant formula, advantages/limitations and a concrete example where appropriate.\n\n**Hinglish cue:** Unit 3 mein gradient aur update ka order; Unit 4 mein window, shape aur parameter count alag rakho. Theory dono units ki karni hai.\n"},{"title":"Preparation sessions before 13 October","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Session</th><th>What to cover</th><th>What to write on paper</th></tr></thead><tbody><tr><td>1</td><td>Essential prerequisite revision only</td><td>Derivative of the stated loss; meaning of gradient and learning rate; neuron/CNN notation</td></tr><tr><td>2</td><td>GD, batch/SGD/mini-batch, momentum and Nesterov</td><td>Two iterations, update counts, old versus new state, lookahead gradient</td></tr><tr><td>3</td><td>AdaGrad, RMSProp and Adam</td><td>Accumulators, bias correction, sign changes and complete two-step working</td></tr><tr><td>4</td><td>Regularization and generalization</td><td>L1/L2, dropout, early stopping, underfitting/overfitting, training/validation/test; theory and numerical examples</td></tr><tr><td>5</td><td>Convolution, stride, padding and pooling</td><td>Every window product/sum, multi-channel bias, floor and SAME-padding cases, max/min/average pooling</td></tr><tr><td>6</td><td>CNN shapes, parameters and architectures</td><td>Full layer table, flatten/dense count, bottlenecks, residual/concatenation, architecture and transfer-learning theory</td></tr><tr><td>7</td><td>Mock A</td><td>Two Unit 4 numerical choices and Unit 3 theory; full answers directly below each question</td></tr><tr><td>8</td><td>Mock B and final revision</td><td>Mixed Unit 3/4 numerical choices; review both units&#x27; theory and redo incorrect calculations</td></tr></tbody></table></div>","<p>These are short study blocks, not eight full days. The exam is on 13 October; spend the remaining time on the Unit 3–4 blocks you have not completed. Do not spend this MT2 preparation period on the extra RNN material retained in TEE.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c1-s2","search":"Preparation sessions before 13 October | Session | What to cover | What to write on paper |\n| 1 | Essential prerequisite revision only | Derivative of the stated loss; meaning of gradient and learning rate; neuron/CNN notation |\n| 2 | GD, batch/SGD/mini-batch, momentum and Nesterov | Two iterations, update counts, old versus new state, lookahead gradient |\n| 3 | AdaGrad, RMSProp and Adam | Accumulators, bias correction, sign changes and complete two-step working |\n| 4 | Regularization and generalization | L1/L2, dropout, early stopping, underfitting/overfitting, training/validation/test; theory and numerical examples |\n| 5 | Convolution, stride, padding and pooling | Every window product/sum, multi-channel bias, floor and SAME-padding cases, max/min/average pooling |\n| 6 | CNN shapes, parameters and architectures | Full layer table, flatten/dense count, bottlenecks, residual/concatenation, architecture and transfer-learning theory |\n| 7 | Mock A | Two Unit 4 numerical choices and Unit 3 theory; full answers directly below each question |\n| 8 | Mock B and final revision | Mixed Unit 3/4 numerical choices; review both units' theory and redo incorrect calculations |\n\nThese are short study blocks, not eight full days. The exam is on 13 October; spend the remaining time on the Unit 3–4 blocks you have not completed. Do not spend this MT2 preparation period on the extra RNN material retained in TEE.\n"},{"title":"Mock-paper conventions","blocks":["<p>Both practice papers have <strong>60 minutes and 10 attempted marks</strong>. Q1(a,b) contributes 4 compulsory marks; any two 3-mark questions contribute 6 marks. All five answers are provided so every alternative can be studied.</p>","<p>Mock A practises theory-only Q1 plus <strong>Numerical + Numerical + Theory</strong> among Q2–Q4, with both long numericals from Unit 4. Mock B practises a theory/numerical Q1 plus <strong>Theory-and-Numerical mixed + Numerical + Theory</strong> among Q2–Q4. Its mixed question is from Unit 3; the other two questions are from Unit 4. These match the two clarified combinations; exact topic assignment is practice design.</p>","<h3>How the supplied papers ask questions</h3>","<p>Use the Unit 3 and Unit 4 historical questions under <strong>Solved Questions</strong> for longer numerical variations and theory preparation. Historical 5/10-mark questions retain their original marks; they are not predictions of MT2 marks. The new faculty message takes priority over the older provisional course-policy scope inference.</p>","<p>For Unit 3, be ready to differentiate the supplied objective, initialize optimizer state, compute the requested iterations and explain the mechanism. For Unit 4, be ready to compute feature maps, pool them, track tensor dimensions, count parameters, compare computational cost and explain the named architectures. Prepare theory from both units even when practising numericals.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c1-s3","search":"Mock-paper conventions Both practice papers have **60 minutes and 10 attempted marks**. Q1(a,b) contributes 4 compulsory marks; any two 3-mark questions contribute 6 marks. All five answers are provided so every alternative can be studied.\n\nMock A practises theory-only Q1 plus **Numerical + Numerical + Theory** among Q2–Q4, with both long numericals from Unit 4. Mock B practises a theory/numerical Q1 plus **Theory-and-Numerical mixed + Numerical + Theory** among Q2–Q4. Its mixed question is from Unit 3; the other two questions are from Unit 4. These match the two clarified combinations; exact topic assignment is practice design.\n\n### How the supplied papers ask questions\nUse the Unit 3 and Unit 4 historical questions under **Solved Questions** for longer numerical variations and theory preparation. Historical 5/10-mark questions retain their original marks; they are not predictions of MT2 marks. The new faculty message takes priority over the older provisional course-policy scope inference.\n\nFor Unit 3, be ready to differentiate the supplied objective, initialize optimizer state, compute the requested iterations and explain the mechanism. For Unit 4, be ready to compute feature maps, pool them, track tensor dimensions, count parameters, compare computational cost and explain the named architectures. Prepare theory from both units even when practising numericals.\n"},{"title":"Writing technical answers","blocks":["<p>For theory, start with the definition, state the mathematical model or labelled architecture, explain its working, and add the relevant advantage, limitation or comparison. For a numerical, show given values, formula, intermediate states and final result. In iterative algorithms, use one row or clearly labelled block per iteration.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c1-s4","search":"Writing technical answers For theory, start with the definition, state the mathematical model or labelled architecture, explain its working, and add the relevant advantage, limitation or comparison. For a numerical, show given values, formula, intermediate states and final result. In iterative algorithms, use one row or clearly labelled block per iteration.\n"}]},{"n":2,"title":"Mathematics revision","sections":[{"title":"Before maths: what are we trying to learn?","blocks":["<h3>Machine ko ek number do.</h3>","<p>Imagine a tiny machine that estimates a bill. You tell it how many notebooks you bought. This information going INTO the machine is called the INPUT. Abhi bas naam samjho: input = andar diya hua number.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/notebooks_input.png\" aria-label=\"Enlarge diagram: Start at the three notebooks on the left. Their count is the input; the machine turns that quantity into a bill estimate.\"><img src=\"assets/figures/notebooks_input.png\" alt=\"Start at the three notebooks on the left. Their count is the input; the machine turns that quantity into a bill estimate.\" width=\"1672\" height=\"941\" loading=\"lazy\"></button><figcaption>Start at the three notebooks on the left. Their count is the input; the machine turns that quantity into a bill estimate. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Input = 3 notebooks</p>","<h3>Machine se ek answer niklega.</h3>","<p>Suppose the machine says the bill is 30 rupees. This answer coming OUT is called the OUTPUT. Input aur output alag jobs hain: 3 was the quantity; 30 is the predicted bill.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_output.svg\" aria-label=\"Enlarge diagram: Input and output name two different jobs: quantity enters and the estimated bill leaves.\"><img src=\"assets/figures/v_output.svg\" alt=\"Input and output name two different jobs: quantity enters and the estimated bill leaves.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Input and output name two different jobs: quantity enters and the estimated bill leaves. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Input: 3 notebooks → Output: 30 rupees</p>","<h3>Multiply kyun karte hain?</h3>","<p>If each notebook costs 10 rupees, three notebooks cost 10 + 10 + 10 = 30. Multiplication is just the shorter calculation: 3 × 10. In this simple model the multiplying number is called a WEIGHT.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_multiply.svg\" aria-label=\"Enlarge diagram: Point to each Rs 10 notebook contribution, then add the three equal amounts.\"><img src=\"assets/figures/v_multiply.svg\" alt=\"Point to each Rs 10 notebook contribution, then add the three equal amounts.\" width=\"1080\" height=\"490\" loading=\"lazy\"></button><figcaption>Point to each Rs 10 notebook contribution, then add the three equal amounts. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> 3 × 10 = 30</p>","<h3>Weight badla, answer badla.</h3>","<p>Keep the input 3. Change only the weight from 10 to 8. The output becomes 3 × 8 = 24. A weight controls how strongly an input affects the answer. Neural-network weights can also be negative or fractions.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_weight.svg\" aria-label=\"Enlarge diagram: Only the multiplier changes. Compare both outputs while keeping the three notebooks fixed.\"><img src=\"assets/figures/v_weight.svg\" alt=\"Only the multiplier changes. Compare both outputs while keeping the three notebooks fixed.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Only the multiplier changes. Compare both outputs while keeping the three notebooks fixed. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Old: 3 × 10 = 30. New: 3 × 8 = 24.</p>","<h3>Correct answer ko target kehte hain.</h3>","<p>The real bill is 30, but the machine predicted 24. The correct answer supplied for a training example is its TARGET. Our prediction is 6 too small because 30 − 24 = 6.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_target.svg\" aria-label=\"Enlarge diagram: The prediction is the machine’s result. The target is the real bill used to judge that result.\"><img src=\"assets/figures/v_target.svg\" alt=\"The prediction is the machine’s result. The target is the real bill used to judge that result.\" width=\"1080\" height=\"480\" loading=\"lazy\"></button><figcaption>The prediction is the machine’s result. The target is the real bill used to judge that result. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Target = 30. Prediction = 24. Difference = 6.</p>","<h3>Learning ka matlab weight improve karna.</h3>","<p>For this tiny example, changing the weight from 8 to 10 changes the prediction from 24 to the correct 30. Learning means using examples to adjust weights and reduce prediction error. Later, gradient descent will calculate HOW to adjust them.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_learning.svg\" aria-label=\"Enlarge diagram: The weight changes from 8 to 10. The same input now produces a prediction closer to the fixed target.\"><img src=\"assets/figures/v_learning.svg\" alt=\"The weight changes from 8 to 10. The same input now produces a prediction closer to the fixed target.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The weight changes from 8 to 10. The same input now produces a prediction closer to the fixed target. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> 3 × 8 = 24 → adjust weight → 3 × 10 = 30</p>","<h3>Bias ek extra add hone wala number hai.</h3>","<p>Now suppose there is a fixed packing fee of 2 rupees. First calculate the notebook cost: 3 × 10 = 30. Then add 2. That extra adjustable number is called a BIAS. In a neural network, it lets the result shift independently of the input.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bias.svg\" aria-label=\"Enlarge diagram: The packing fee is added after the notebook cost. It is not multiplied by the notebook quantity.\"><img src=\"assets/figures/v_bias.svg\" alt=\"The packing fee is added after the notebook cost. It is not multiplied by the notebook quantity.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The packing fee is added after the notebook cost. It is not multiplied by the notebook quantity. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> 3 × 10 + 2 = 30 + 2 = 32</p>","<h3>Letters numbers ke naam hain.</h3>","<p>Instead of writing input, weight and bias every time, books use short names. x means input; w means weight; b means bias. So x × w + b says exactly the calculation you already did. A letter is a named box holding a number.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_symbols.svg\" aria-label=\"Enlarge diagram: Read each letter as a named box holding a number, then follow the same arithmetic.\"><img src=\"assets/figures/v_symbols.svg\" alt=\"Read each letter as a named box holding a number, then follow the same arithmetic.\" width=\"1080\" height=\"500\" loading=\"lazy\"></button><figcaption>Read each letter as a named box holding a number, then follow the same arithmetic. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> x = 3, w = 10, b = 2 → x × w + b = 32</p>","<h3>Deep learning mein aage kya hoga?</h3>","<p>A neural network connects many small calculating units called neurons. They multiply inputs by weights, add a bias and apply an activation rule. Several layers can learn more complex relationships. First we will learn the small calculation; phir layers jodenge.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_layers.svg\" aria-label=\"Enlarge diagram: Each circle is a small calculation. Outputs from one layer become the next layer’s inputs.\"><img src=\"assets/figures/v_layers.svg\" alt=\"Each circle is a small calculation. Outputs from one layer become the next layer’s inputs.\" width=\"1080\" height=\"650\" loading=\"lazy\"></button><figcaption>Each circle is a small calculation. Outputs from one layer become the next layer’s inputs. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Input → calculations in layers → prediction</p>","<p class=\"inline-question\"><strong>Question.</strong> A toy model has input 4, weight 5 and bias 2. Find its output using input × weight + bias.</p>","<h3>Given</h3>","<p>A toy model has input 4, weight 5 and bias 2.</p>","<h3>To find</h3>","<p>Find the preactivation and the requested neuron output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> multiply input by weight: 4 × 5 = 20.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> add the bias: 20 + 2 = 22. Final output = 22. The bias is added once, after multiplication.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s0","search":"Before maths: what are we trying to learn? \n### Machine ko ek number do.\nImagine a tiny machine that estimates a bill. You tell it how many notebooks you bought. This information going INTO the machine is called the INPUT. Abhi bas naam samjho: input = andar diya hua number.\n\n\n\n**Calculation:** Input = 3 notebooks\n\n### Machine se ek answer niklega.\nSuppose the machine says the bill is 30 rupees. This answer coming OUT is called the OUTPUT. Input aur output alag jobs hain: 3 was the quantity; 30 is the predicted bill.\n\n\n\n**Calculation:** Input: 3 notebooks → Output: 30 rupees\n\n### Multiply kyun karte hain?\nIf each notebook costs 10 rupees, three notebooks cost 10 + 10 + 10 = 30. Multiplication is just the shorter calculation: 3 × 10. In this simple model the multiplying number is called a WEIGHT.\n\n\n\n**Calculation:** 3 × 10 = 30\n\n### Weight badla, answer badla.\nKeep the input 3. Change only the weight from 10 to 8. The output becomes 3 × 8 = 24. A weight controls how strongly an input affects the answer. Neural-network weights can also be negative or fractions.\n\n\n\n**Calculation:** Old: 3 × 10 = 30. New: 3 × 8 = 24.\n\n### Correct answer ko target kehte hain.\nThe real bill is 30, but the machine predicted 24. The correct answer supplied for a training example is its TARGET. Our prediction is 6 too small because 30 − 24 = 6.\n\n\n\n**Calculation:** Target = 30. Prediction = 24. Difference = 6.\n\n### Learning ka matlab weight improve karna.\nFor this tiny example, changing the weight from 8 to 10 changes the prediction from 24 to the correct 30. Learning means using examples to adjust weights and reduce prediction error. Later, gradient descent will calculate HOW to adjust them.\n\n\n\n**Calculation:** 3 × 8 = 24 → adjust weight → 3 × 10 = 30\n\n### Bias ek extra add hone wala number hai.\nNow suppose there is a fixed packing fee of 2 rupees. First calculate the notebook cost: 3 × 10 = 30. Then add 2. That extra adjustable number is called a BIAS. In a neural network, it lets the result shift independently of the input.\n\n\n\n**Calculation:** 3 × 10 + 2 = 30 + 2 = 32\n\n### Letters numbers ke naam hain.\nInstead of writing input, weight and bias every time, books use short names. x means input; w means weight; b means bias. So x × w + b says exactly the calculation you already did. A letter is a named box holding a number.\n\n\n\n**Calculation:** x = 3, w = 10, b = 2 → x × w + b = 32\n\n### Deep learning mein aage kya hoga?\nA neural network connects many small calculating units called neurons. They multiply inputs by weights, add a bias and apply an activation rule. Several layers can learn more complex relationships. First we will learn the small calculation; phir layers jodenge.\n\n\n\n**Calculation:** Input → calculations in layers → prediction\n\n**Question.** A toy model has input 4, weight 5 and bias 2. Find its output using input × weight + bias.\n\n\n\n### Given\n\nA toy model has input 4, weight 5 and bias 2.\n\n### To find\n\nFind the preactivation and the requested neuron output.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** multiply input by weight: 4 × 5 = 20.\n\n*"},{"title":"Negative numbers are direction","blocks":["<h3>1. The minus sign can describe a number</h3>","<p>Zero is the reference point. Positive numbers such as 1, 2 and 3 lie to its right on a number line. Negative numbers such as −1, −2 and −3 lie to its left. The number −3 is three units below zero; it is not an instruction to subtract until another number is supplied.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_negative.svg\" aria-label=\"Enlarge diagram: Read left as smaller and right as larger. Follow one signed movement at a time.\"><img src=\"assets/figures/v_negative.svg\" alt=\"Read left as smaller and right as larger. Follow one signed movement at a time.\" width=\"1080\" height=\"470\" loading=\"lazy\"></button><figcaption>Read left as smaller and right as larger. Follow one signed movement at a time. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>In 5 − 2, the minus sign is an operation: subtract 2 from 5. In 5 + (−2), the sign inside the brackets belongs to the number negative 2. Both expressions finish at 3. Brackets keep the signed number together.</p>","<h3>2. Adding a negative moves left</h3>","<p>Start at 5. Adding positive 2 moves two places right, to 7. Adding negative 2 moves two places left, to 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d25cc2f4afc0b12d.svg\" alt=\"\\begin{aligned}5+2&amp;=7\\\\5+(-2)&amp;=3\\end{aligned}\" width=\"137.13\" height=\"56.20\" style=\"width:137.13px;height:56.20px;aspect-ratio:137.13/56.20\" loading=\"lazy\"></div>","<p>If both numbers are negative, keep moving left. Start at −3 and add −2: the answer is −5.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6f43c9051ebbeef.svg\" alt=\"(-3)+(-2)=-5\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<h3>3. Subtracting reverses that movement</h3>","<p>Subtracting positive 2 moves left. Subtracting negative 2 reverses a leftward movement, so it moves right. A money example is removing a debt of 2: your balance increases by 2.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5db46d4affd9d09b.svg\" alt=\"5-(-2)=5+2=7\" width=\"224.01\" height=\"24.43\" style=\"width:224.01px;height:24.43px;aspect-ratio:224.01/24.43\" loading=\"lazy\"></div>","<p>The shortcut “two negatives make a positive” is not a rule for every calculation. Negative 3 plus negative 2 is still −5. First identify the operation: addition, subtraction, multiplication or division.</p>","<h3>4. Multiplication has its own sign rule</h3>","<p>For multiplication and division, equal signs give a positive result and different signs give a negative result. Calculate the ordinary size, then attach the correct sign.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Signs being multiplied</th><th>Complete calculation</th><th>Result sign</th></tr></thead><tbody><tr><td>Positive × positive</td><td>3 × 2 = 6</td><td>Positive</td></tr><tr><td>Negative × positive</td><td>(−3) × 2 = −6</td><td>Negative</td></tr><tr><td>Positive × negative</td><td>3 × (−2) = −6</td><td>Negative</td></tr><tr><td>Negative × negative</td><td>(−3) × (−2) = 6</td><td>Positive</td></tr></tbody></table></div>","<p>Division uses the same sign pattern: (−6) ÷ 2 = −3 and (−6) ÷ (−2) = 3. The divisor must be nonzero.</p>","<h3>5. Fully worked arithmetic</h3>","<p class=\"inline-question\"><strong>Question.</strong> Calculate −3 + 2, −3 − 2 and −3 − (−2).</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Expressions: −3+2; −3−2; −3−(−2).</p>","<h3>To find</h3>","<p>Evaluate the three signed-number expressions.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the first expression.</strong> start at −3 and move two places right. The answer is −1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e35736ce1cfc9727.svg\" alt=\"-3+2=-1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the second expression.</strong> start at −3 and move two places left. The answer is −5.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/53bef08286131079.svg\" alt=\"-3-2=-5\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: evaluate the third expression.</strong> replace subtract-negative-2 with add-positive-2. The answer is −1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2cc0c9e475076c06.svg\" alt=\"\\begin{aligned}-3-(-2)&amp;=-3+2\\\\&amp;=-1\\end{aligned}\" width=\"217.23\" height=\"56.20\" style=\"width:217.23px;height:56.20px;aspect-ratio:217.23/56.20\" loading=\"lazy\"></div>","<p>Later, a weight update subtracts a correction that can itself be negative. The third expression explains exactly why that update can increase a weight.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s1","search":"Negative numbers are direction ### 1. The minus sign can describe a number\nZero is the reference point. Positive numbers such as 1, 2 and 3 lie to its right on a number line. Negative numbers such as −1, −2 and −3 lie to its left. The number −3 is three units below zero; it is not an instruction to subtract until another number is supplied.\n\nIn 5 − 2, the minus sign is an operation: subtract 2 from 5. In 5 + (−2), the sign inside the brackets belongs to the number negative 2. Both expressions finish at 3. Brackets keep the signed number together.\n### 2. Adding a negative moves left\nStart at 5. Adding positive 2 moves two places right, to 7. Adding negative 2 moves two places left, to 3.\n\nIf both numbers are negative, keep moving left. Start at −3 and add −2: the answer is −5.\n\n### 3. Subtracting reverses that movement\nSubtracting positive 2 moves left. Subtracting negative 2 reverses a leftward movement, so it moves right. A money example is removing a debt of 2: your balance increases by 2.\n\nThe shortcut “two negatives make a positive” is not a rule for every calculation. Negative 3 plus negative 2 is still −5. First identify the operation: addition, subtraction, multiplication or division.\n### 4. Multiplication has its own sign rule\nFor multiplication and division, equal signs give a positive result and different signs give a negative result. Calculate the ordinary size, then attach the correct sign.\n| Signs being multiplied | Complete calculation | Result sign |\n| Positive × positive | 3 × 2 = 6 | Positive |\n| Negative × positive | (−3) × 2 = −6 | Negative |\n| Positive × negative | 3 × (−2) = −6 | Negative |\n| Negative × negative | (−3) × (−2) = 6 | Positive |\nDivision uses the same sign pattern: (−6) ÷ 2 = −3 and (−6) ÷ (−2) = 3. The divisor must be nonzero.\n### 5. Fully worked arithmetic\n**Question.** Calculate −3 + 2, −3 − 2 and −3 − (−2).\n**Answer — step by step.**\n\n\n\n### Given\n\nExpressions: −3+2; −3−2; −3−(−2).\n\n### To find\n\nEvaluate the three signed-number expressions.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n**Step 1: evaluate the first expression.** start at −3 and move two places right. The answer is −1.\n\n**Step 2: evaluate the second expression.** start at −3 and move two places left. The answer is −5.\n\n**Step 3: evaluate the third expression.** replace subtract-negative-2 with add-positive-2. The answer is −1.\n\nLater, a weight update subtracts a correction that can itself be negative. The third expression explains exactly why that update can increase a weight.\n"},{"title":"Fractions decimals and percentages","blocks":["<h3>1. A fraction tells us to divide</h3>","<p>The upper number is the <strong>numerator</strong>. The lower number is the <strong>denominator</strong>. In one-quarter, split one whole into four equal parts and take one part. The fraction bar means division.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13b13c0346dc6e67.svg\" alt=\"\\frac14=1\\div4=0.25\" width=\"185.89\" height=\"49.55\" style=\"width:185.89px;height:49.55px;aspect-ratio:185.89/49.55\" loading=\"lazy\"></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_fractions.svg\" aria-label=\"Enlarge diagram: One shaded part out of four is the same amount as 0.25 or 25 percent.\"><img src=\"assets/figures/v_fractions.svg\" alt=\"One shaded part out of four is the same amount as 0.25 or 25 percent.\" width=\"1080\" height=\"450\" loading=\"lazy\"></button><figcaption>One shaded part out of four is the same amount as 0.25 or 25 percent. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A decimal and a fraction can name the same amount. One-half is 0.5, one-tenth is 0.1, and one-hundredth is 0.01. The denominator cannot be zero: division by zero is undefined.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61c8b62ceed00f18.svg\" alt=\"\\begin{aligned}\\frac12&amp;=0.5\\\\\\frac1{10}&amp;=0.1\\\\\\frac1{100}&amp;=0.01\\end{aligned}\" width=\"123.43\" height=\"164.40\" style=\"width:123.43px;height:164.40px;aspect-ratio:123.43/164.40\" loading=\"lazy\"></div>","<h3>2. Why small decimals become smaller when multiplied</h3>","<p>Multiplying by 0.1 means taking one-tenth. Multiplying by 0.2 means taking two-tenths. For 0.2 × 0.3, express both numbers as fractions. Multiply the numerators and multiply the denominators.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ac4c9d847d5a49fc.svg\" alt=\"\\begin{aligned}0.2\\times0.3&amp;=\\frac2{10}\\times\\frac3{10}\\\\&amp;=\\frac6{100}\\\\&amp;=0.06\\end{aligned}\" width=\"225.15\" height=\"139.28\" style=\"width:225.15px;height:139.28px;aspect-ratio:225.15/139.28\" loading=\"lazy\"></div>","<p>This also explains a calculation used later: 0.1 × (−0.6) is one-tenth of negative 0.6, which is −0.06. The negative sign is kept because the factors have different signs.</p>","<h3>3. Dividing by one-half asks how many halves fit</h3>","<p>Two halves fit inside 1. Four halves fit inside 2. Therefore dividing 2 by one-half gives 4, even though division by a number greater than 1 would make 2 smaller.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e8f8b190ccce77f7.svg\" alt=\"\\begin{aligned}2\\div0.5&amp;=2\\div\\frac12\\\\&amp;=2\\times2\\\\&amp;=4\\end{aligned}\" width=\"170.95\" height=\"113.09\" style=\"width:170.95px;height:113.09px;aspect-ratio:170.95/113.09\" loading=\"lazy\"></div>","<p>The <strong>reciprocal</strong> flips a nonzero fraction: the reciprocal of 1/2 is 2/1. Dividing by a fraction means multiplying by its reciprocal. For decimals, multiplying both the numerator and denominator by the same nonzero number preserves their ratio.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e15debe515ad70bf.svg\" alt=\"\\begin{aligned}\\frac{0.8}{0.5}&amp;=\\frac{0.8\\times10}{0.5\\times10}\\\\&amp;=\\frac85\\\\&amp;=1.6\\end{aligned}\" width=\"170.85\" height=\"139.28\" style=\"width:170.85px;height:139.28px;aspect-ratio:170.85/139.28\" loading=\"lazy\"></div>","<h3>4. Percent means out of one hundred</h3>","<p>To turn a percentage into a decimal, divide by 100. To turn a decimal into a percentage, multiply by 100.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c062ee6009f1f875.svg\" alt=\"\\begin{aligned}20\\%&amp;=\\frac{20}{100}=0.2\\\\50\\%&amp;=\\frac{50}{100}=0.5\\end{aligned}\" width=\"188.59\" height=\"107.51\" style=\"width:188.59px;height:107.51px;aspect-ratio:188.59/107.51\" loading=\"lazy\"></div>","<p>If 20% is removed, 80% remains. As decimals: 1 − 0.2 = 0.8. The number 1 represents the whole amount, or 100%. This same arithmetic will be used for dropout later.</p>","<h3>5. A mean is a fair-share amount</h3>","<p>For 2, 4 and 9, first add all three numbers: 2 + 4 + 9 = 15. Divide by the number of values, which is 3. The mean is 5. Do not divide by 9 just because it is the largest value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d51e471133d25a2.svg\" alt=\"\\text{mean}=\\frac{\\text{sum}}{\\text{count}}\" width=\"160.09\" height=\"44.50\" style=\"width:160.09px;height:44.50px;aspect-ratio:160.09/44.50\" loading=\"lazy\"></div>","<p>Here the sum is 15 and the count is 3. Apply those two quantities to the formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/503bca869d213251.svg\" alt=\"\\begin{aligned}\\text{mean}&amp;=\\frac{2+4+9}{3}\\\\&amp;=\\frac{15}{3}\\\\&amp;=5\\end{aligned}\" width=\"196.73\" height=\"139.55\" style=\"width:196.73px;height:139.55px;aspect-ratio:196.73/139.55\" loading=\"lazy\"></div>","<p>A <strong>weighted mean</strong> gives different shares of importance to the values. With shares 0.9 and 0.1, the first value receives 90% of the importance and the second receives 10%. The shares add to 1.</p>","<p class=\"inline-question\"><strong>Question.</strong> Find the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Find the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.</p>","<h3>To find</h3>","<p>Find the weighted mean.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum.</strong> Multiply each value by its own coefficient and then add. For a weighted mean, divide by the sum of the weights unless that sum is already 1.</p>","<p>xᵢ = value i; aᵢ = its weight. Each input keeps its own matching coefficient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/305c0c88eaed50a3.svg\" alt=\"\\bar x_w=\\frac{\\sum_i a_ix_i}{\\sum_i a_i}\" width=\"152.45\" height=\"61.24\" style=\"width:152.45px;height:61.24px;aspect-ratio:152.45/61.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har number apne weight ke saath multiply; phir sab add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> multiply the first value by its weight: 0.9 × 10 = 9.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> multiply the second value by its weight: 0.1 × 20 = 2.</p>","<p class=\"worked-step\"><strong>Step 3:</strong> add the contributions: 9 + 2 = 11. The weighted mean is <strong>11</strong>. It is closer to 10 because 10 received most of the importance.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eef093497c3c04cc.svg\" alt=\"\\begin{aligned}0.9(10)+0.1(20)&amp;=9+2\\\\&amp;=11\\end{aligned}\" width=\"266.10\" height=\"56.20\" style=\"width:266.10px;height:56.20px;aspect-ratio:266.10/56.20\" loading=\"lazy\"></div>","<p>If importance weights do not sum to 1, divide their weighted sum by the sum of the weights to obtain the weighted mean. A neuron&#x27;s general weighted sum does not require weights to sum to 1 and is not automatically a mean.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s2","search":"Fractions decimals and percentages ### 1. A fraction tells us to divide\nThe upper number is the **numerator**. The lower number is the **denominator**. In one-quarter, split one whole into four equal parts and take one part. The fraction bar means division.\n\n\nA decimal and a fraction can name the same amount. One-half is 0.5, one-tenth is 0.1, and one-hundredth is 0.01. The denominator cannot be zero: division by zero is undefined.\n\n### 2. Why small decimals become smaller when multiplied\nMultiplying by 0.1 means taking one-tenth. Multiplying by 0.2 means taking two-tenths. For 0.2 × 0.3, express both numbers as fractions. Multiply the numerators and multiply the denominators.\n\nThis also explains a calculation used later: 0.1 × (−0.6) is one-tenth of negative 0.6, which is −0.06. The negative sign is kept because the factors have different signs.\n### 3. Dividing by one-half asks how many halves fit\nTwo halves fit inside 1. Four halves fit inside 2. Therefore dividing 2 by one-half gives 4, even though division by a number greater than 1 would make 2 smaller.\n\nThe **reciprocal** flips a nonzero fraction: the reciprocal of 1/2 is 2/1. Dividing by a fraction means multiplying by its reciprocal. For decimals, multiplying both the numerator and denominator by the same nonzero number preserves their ratio.\n\n### 4. Percent means out of one hundred\nTo turn a percentage into a decimal, divide by 100. To turn a decimal into a percentage, multiply by 100.\n\nIf 20% is removed, 80% remains. As decimals: 1 − 0.2 = 0.8. The number 1 represents the whole amount, or 100%. This same arithmetic will be used for dropout later.\n### 5. A mean is a fair-share amount\nFor 2, 4 and 9, first add all three numbers: 2 + 4 + 9 = 15. Divide by the number of values, which is 3. The mean is 5. Do not divide by 9 just because it is the largest value.\n\nHere the sum is 15 and the count is 3. Apply those two quantities to the formula.\n\nA **weighted mean** gives different shares of importance to the values. With shares 0.9 and 0.1, the first value receives 90% of the importance and the second receives 10%. The shares add to 1.\n**Question.** Find the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.\n**Answer — step by step.**\n\n\n\n### Given\n\nFind the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.\n\n### To find\n\nFind the weighted mean.\n\n### Formula — which one and why\n\n**Weighted sum.** Multiply each value by its own coefficient and then add. For a weighted mean, divide by the sum of the weights unless that sum is already 1.\n\nxᵢ = value i; aᵢ = its weight. Each input keeps its own matching coefficient.\n\n\n\n**Yaad rakhne ka cue:** Har number apne weight ke saath multiply; phir sab add.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** multiply the first value by its weight: 0.9 × 10 = 9.\n**Step 2:** multiply the second value by its weight: 0.1 × 20 = 2.\n**Step 3:** add the contributions: 9 + 2 = 11. The weighted mean is **11**. It is closer to 10 because 10 received most of the importance.\n\nIf importance weights do not sum to 1, divide their weighted sum by the sum of the weights to obtain the weighted mean. A neuron's general weighted sum does not require weights to sum to 1 and is not automatically a mean.\n"},{"title":"Brackets before everything else","blocks":["<h3>1. Brackets tell us what must stay together</h3>","<p>An expression is a written calculation. Brackets group part of that calculation. In 1 ÷ (1 + 3), the whole quantity 1 + 3 is the divisor, so calculate it before dividing.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_brackets.svg\" aria-label=\"Enlarge diagram: Follow the bracketed calculation from left to right. The bottom line shows why removing brackets changes the answer.\"><img src=\"assets/figures/v_brackets.svg\" alt=\"Follow the bracketed calculation from left to right. The bottom line shows why removing brackets changes the answer.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow the bracketed calculation from left to right. The bottom line shows why removing brackets changes the answer. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/425b33a05c6633ee.svg\" alt=\"\\frac1{1+3}=\\frac14=0.25\" width=\"196.64\" height=\"51.56\" style=\"width:196.64px;height:51.56px;aspect-ratio:196.64/51.56\" loading=\"lazy\"></div>","<p>Removing the brackets changes the calculation. In 1 ÷ 1 + 3, division comes before addition: 1 ÷ 1 = 1, then 1 + 3 = 4.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1dbb10cc9ab1aacc.svg\" alt=\"1\\div1+3=1+3=4\" width=\"228.09\" height=\"18.54\" style=\"width:228.09px;height:18.54px;aspect-ratio:228.09/18.54\" loading=\"lazy\"></div>","<h3>2. Use this order for the expressions in this course</h3>","<p>First calculate inside brackets. Then evaluate powers and roots. Then do multiplication and division, reading left to right. Finally do addition and subtraction, again reading left to right. Multiplication does not have priority over division; they share a level.</p>","<p>For 8 ÷ 2 × 3, calculate 8 ÷ 2 = 4 and then 4 × 3 = 12. Do not change it into 8 ÷ (2 × 3).</p>","<h3>3. A full example with brackets and a power</h3>","<p class=\"inline-question\"><strong>Question.</strong> Evaluate (2 + 3)² ÷ 5.</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Evaluate (2 + 3)² ÷ 5.</p>","<h3>To find</h3>","<p>Evaluate each expression and state its value.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> finish the brackets: 2 + 3 = 5. The expression becomes 5² ÷ 5.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> square the bracket result: 5² = 25. The expression becomes 25 ÷ 5.</p>","<p class=\"worked-step\"><strong>Step 3:</strong> divide: 25 ÷ 5 = <strong>5</strong>.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/113124579583cb24.svg\" alt=\"\\begin{aligned}\\frac{(2+3)^2}{5}&amp;=\\frac{5^2}{5}\\\\&amp;=\\frac{25}{5}\\\\&amp;=5\\end{aligned}\" width=\"162.51\" height=\"144.21\" style=\"width:162.51px;height:144.21px;aspect-ratio:162.51/144.21\" loading=\"lazy\"></div>","<h3>4. A full example without grouping the addition</h3>","<p class=\"inline-question\"><strong>Question.</strong> Evaluate 2 + 3² × 4.</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Evaluate 2 + 3² × 4.</p>","<h3>To find</h3>","<p>Evaluate each expression and state its value.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> calculate the power: 3² = 9. Keep the other numbers where they are: 2 + 9 × 4.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> multiply: 9 × 4 = 36. The expression becomes 2 + 36.</p>","<p class=\"worked-step\"><strong>Step 3:</strong> add: 2 + 36 = <strong>38</strong>.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef5577a23a205b11.svg\" alt=\"\\begin{aligned}2+3^2\\times4&amp;=2+9\\times4\\\\&amp;=2+36\\\\&amp;=38\\end{aligned}\" width=\"236.03\" height=\"91.24\" style=\"width:236.03px;height:91.24px;aspect-ratio:236.03/91.24\" loading=\"lazy\"></div>","<h3>5. A fraction bar groups the whole denominator</h3>","<p>In a printed fraction, everything below the bar belongs to the denominator. When entering that fraction in a single calculator line, put brackets around the complete denominator. A printed fraction with 1 above and 1 + 3 below must be entered as 1 ÷ (1 + 3).</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s3","search":"Brackets before everything else ### 1. Brackets tell us what must stay together\nAn expression is a written calculation. Brackets group part of that calculation. In 1 ÷ (1 + 3), the whole quantity 1 + 3 is the divisor, so calculate it before dividing.\n\n\nRemoving the brackets changes the calculation. In 1 ÷ 1 + 3, division comes before addition: 1 ÷ 1 = 1, then 1 + 3 = 4.\n\n### 2. Use this order for the expressions in this course\nFirst calculate inside brackets. Then evaluate powers and roots. Then do multiplication and division, reading left to right. Finally do addition and subtraction, again reading left to right. Multiplication does not have priority over division; they share a level.\nFor 8 ÷ 2 × 3, calculate 8 ÷ 2 = 4 and then 4 × 3 = 12. Do not change it into 8 ÷ (2 × 3).\n### 3. A full example with brackets and a power\n**Question.** Evaluate (2 + 3)² ÷ 5.\n**Answer — step by step.**\n\n\n\n### Given\n\nEvaluate (2 + 3)² ÷ 5.\n\n### To find\n\nEvaluate each expression and state its value.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** finish the brackets: 2 + 3 = 5. The expression becomes 5² ÷ 5.\n**Step 2:** square the bracket result: 5² = 25. The expression becomes 25 ÷ 5.\n**Step 3:** divide: 25 ÷ 5 = **5**.\n\n### 4. A full example without grouping the addition\n**Question.** Evaluate 2 + 3² × 4.\n**Answer — step by step.**\n\n\n\n### Given\n\nEvaluate 2 + 3² × 4.\n\n### To find\n\nEvaluate each expression and state its value.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** calculate the power: 3² = 9. Keep the other numbers where they are: 2 + 9 × 4.\n**Step 2:** multiply: 9 × 4 = 36. The expression becomes 2 + 36.\n**Step 3:** add: 2 + 36 = **38**.\n\n### 5. A fraction bar groups the whole denominator\nIn a printed fraction, everything below the bar belongs to the denominator. When entering that fraction in a single calculator line, put brackets around the complete denominator. A printed fraction with 1 above and 1 + 3 below must be entered as 1 ÷ (1 + 3).\n"},{"title":"Powers roots and very small numbers","blocks":["<h3>1. A power counts repeated multiplication</h3>","<p>In 2³, 2 is the <strong>base</strong> and 3 is the <strong>exponent</strong>. For a positive whole-number exponent, multiply that many copies of the base. It does not mean 2 × 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11e21b993b310c0e.svg\" alt=\"2^3=2\\times2\\times2=8\" width=\"196.66\" height=\"23.59\" style=\"width:196.66px;height:23.59px;aspect-ratio:196.66/23.59\" loading=\"lazy\"></div>","<p>The exponent 2 is called a <strong>square</strong>: 3² = 3 × 3 = 9. Three rows of three cells make nine cells.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_powers.svg\" aria-label=\"Enlarge diagram: Count the three rows of three cells. Squaring builds nine; the square root returns three.\"><img src=\"assets/figures/v_powers.svg\" alt=\"Count the three rows of three cells. Squaring builds nine; the square root returns three.\" width=\"1080\" height=\"520\" loading=\"lazy\"></button><figcaption>Count the three rows of three cells. Squaring builds nine; the square root returns three. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>2. A negative number must stay inside its brackets</h3>","<p>Squaring negative 2 means multiplying negative 2 by negative 2. The equal signs of the factors give a positive result.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/756026084f28a30c.svg\" alt=\"(-2)^2=(-2)(-2)=4\" width=\"238.77\" height=\"27.70\" style=\"width:238.77px;height:27.70px;aspect-ratio:238.77/27.70\" loading=\"lazy\"></div>","<p>Without brackets, −2² means first calculate 2², then apply the minus sign: −(4) = −4. Enter brackets when the entire negative number is the base.</p>","<p>For decimals, use the same rule. Negative 0.3 squared is positive 0.09 because 3/10 multiplied by 3/10 is 9/100.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24f2cf37fb12267b.svg\" alt=\"\\begin{aligned}(-0.3)^2&amp;=(-0.3)(-0.3)\\\\&amp;=0.09\\end{aligned}\" width=\"250.99\" height=\"59.48\" style=\"width:250.99px;height:59.48px;aspect-ratio:250.99/59.48\" loading=\"lazy\"></div>","<h3>3. A square root asks which nonnegative number was squared</h3>","<p>Because 3 × 3 = 9, the principal square root of 9 is 3. Although (−3)² also equals 9, the symbol √9 by itself means the nonnegative root, 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2838a7934ce26d9d.svg\" alt=\"\\begin{aligned}\\sqrt9&amp;=3\\\\\\sqrt{0.09}&amp;=0.3\\end{aligned}\" width=\"128.10\" height=\"68.28\" style=\"width:128.10px;height:68.28px;aspect-ratio:128.10/68.28\" loading=\"lazy\"></div>","<p>The <strong>absolute value</strong> of a number is its distance from zero: |−4| = 4 and |4| = 4. Squaring and taking a square root returns this nonnegative size.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bed469d925782c9b.svg\" alt=\"\\sqrt{(-4)^2}=\\sqrt{16}=4\" width=\"208.49\" height=\"45.45\" style=\"width:208.49px;height:45.45px;aspect-ratio:208.49/45.45\" loading=\"lazy\"></div>","<h3>4. Zero and negative exponents follow a pattern</h3>","<p>Start with powers of 10. Each time the exponent decreases by 1, divide the previous value by 10: 1000 → 100 → 10 → 1 → 0.1 → 0.01. This explains both the zero power and the negative powers.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Power</th><th>Calculation</th><th>Value</th></tr></thead><tbody><tr><td>10³</td><td>10 × 10 × 10</td><td>1000</td></tr><tr><td>10²</td><td>1000 ÷ 10</td><td>100</td></tr><tr><td>10¹</td><td>100 ÷ 10</td><td>10</td></tr><tr><td>10⁰</td><td>10 ÷ 10</td><td>1</td></tr><tr><td>10⁻¹</td><td>1 ÷ 10</td><td>0.1</td></tr><tr><td>10⁻²</td><td>0.1 ÷ 10</td><td>0.01</td></tr><tr><td>10⁻³</td><td>0.01 ÷ 10</td><td>0.001</td></tr></tbody></table></div>","<p>For a nonzero base, power zero is 1. A negative exponent means the reciprocal of the corresponding positive power. It does not mean a negative answer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f45c43d6b073f1bb.svg\" alt=\"\\begin{aligned}10^{-3}&amp;=\\frac1{10^3}\\\\&amp;=\\frac1{1000}\\\\&amp;=0.001\\end{aligned}\" width=\"140.75\" height=\"142.64\" style=\"width:140.75px;height:142.64px;aspect-ratio:140.75/142.64\" loading=\"lazy\"></div>","<h3>5. Tiny scientific notation is still an ordinary number</h3>","<p>The notation 1 × 10⁻⁸ equals 0.00000001. Calculators may display it as 1E−8. In optimizer formulas, ε, pronounced “epsilon”, often names a small positive constant added to a denominator. Read its supplied value before calculating.</p>","<p class=\"inline-question\"><strong>Question.</strong> Calculate 1 − 0.9².</p>","<h3>Given</h3>","<p>Expression: 1−0.9².</p>","<h3>To find</h3>","<p>Evaluate the power first, then the subtraction.</p>","<h3>Formula — which one and why</h3>","<p><strong>A square before subtraction.</strong> The exponent applies to 0.9. Squaring is repeated multiplication; perform it before subtracting the result from 1.</p>","<p>q denotes the number being squared. Parentheses would be required to square the whole difference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/12754a3d0dc07c58.svg\" alt=\"q^2=q\\times q\" width=\"108.08\" height=\"26.34\" style=\"width:108.08px;height:26.34px;aspect-ratio:108.08/26.34\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5166132378f964d6.svg\" alt=\"1-q^2=1-(q\\times q)\" width=\"211.26\" height=\"27.70\" style=\"width:211.26px;height:27.70px;aspect-ratio:211.26/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Jis number pe power hai, sirf uska square; subtraction baad mein.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: square only the 0.9.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3338c806844083ae.svg\" alt=\"0.9^2=0.9(0.9)=0.81\" width=\"231.97\" height=\"27.70\" style=\"width:231.97px;height:27.70px;aspect-ratio:231.97/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: subtract the result from 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/41335385ba7e04c7.svg\" alt=\"1-0.81=0.19\" width=\"161.56\" height=\"18.27\" style=\"width:161.56px;height:18.27px;aspect-ratio:161.56/18.27\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 0.19. The square acts on 0.9, not on the entire difference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/df575ab27bdf9309.svg\" alt=\"\\begin{aligned}1-0.9^2&amp;=1-0.81\\\\&amp;=0.19\\end{aligned}\" width=\"202.10\" height=\"59.48\" style=\"width:202.10px;height:59.48px;aspect-ratio:202.10/59.48\" loading=\"lazy\"></div>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s4","search":"Powers roots and very small numbers ### 1. A power counts repeated multiplication\nIn 2³, 2 is the **base** and 3 is the **exponent**. For a positive whole-number exponent, multiply that many copies of the base. It does not mean 2 × 3.\n\nThe exponent 2 is called a **square**: 3² = 3 × 3 = 9. Three rows of three cells make nine cells.\n\n### 2. A negative number must stay inside its brackets\nSquaring negative 2 means multiplying negative 2 by negative 2. The equal signs of the factors give a positive result.\n\nWithout brackets, −2² means first calculate 2², then apply the minus sign: −(4) = −4. Enter brackets when the entire negative number is the base.\nFor decimals, use the same rule. Negative 0.3 squared is positive 0.09 because 3/10 multiplied by 3/10 is 9/100.\n\n### 3. A square root asks which nonnegative number was squared\nBecause 3 × 3 = 9, the principal square root of 9 is 3. Although (−3)² also equals 9, the symbol √9 by itself means the nonnegative root, 3.\n\nThe **absolute value** of a number is its distance from zero: |−4| = 4 and |4| = 4. Squaring and taking a square root returns this nonnegative size.\n\n### 4. Zero and negative exponents follow a pattern\nStart with powers of 10. Each time the exponent decreases by 1, divide the previous value by 10: 1000 → 100 → 10 → 1 → 0.1 → 0.01. This explains both the zero power and the negative powers.\n| Power | Calculation | Value |\n| 10³ | 10 × 10 × 10 | 1000 |\n| 10² | 1000 ÷ 10 | 100 |\n| 10¹ | 100 ÷ 10 | 10 |\n| 10⁰ | 10 ÷ 10 | 1 |\n| 10⁻¹ | 1 ÷ 10 | 0.1 |\n| 10⁻² | 0.1 ÷ 10 | 0.01 |\n| 10⁻³ | 0.01 ÷ 10 | 0.001 |\nFor a nonzero base, power zero is 1. A negative exponent means the reciprocal of the corresponding positive power. It does not mean a negative answer.\n\n### 5. Tiny scientific notation is still an ordinary number\nThe notation 1 × 10⁻⁸ equals 0.00000001. Calculators may display it as 1E−8. In optimizer formulas, ε, pronounced “epsilon”, often names a small positive constant added to a denominator. Read its supplied value before calculating.\n**Question.** Calculate 1 − 0.9².\n\n\n\n### Given\n\nExpression: 1−0.9².\n\n### To find\n\nEvaluate the power first, then the subtraction.\n\n### Formula — which one and why\n\n**A square before subtraction.** The exponent applies to 0.9. Squaring is repeated multiplication; perform it before subtracting the result from 1.\n\nq denotes the number being squared. Parentheses would be required to square the whole difference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Jis number pe power hai, sirf uska square; subtraction baad mein.\n\n### Solution — step by step\n\n\n\n\n**Step 1: square only the 0.9.**\n\n\n\n\n\n\n\n**Step 2: subtract the result from 1.**\n\n\n\n\n\n\n\n**Final answer:** 0.19. The square acts on 0.9, not on the entire difference.\n\n"},{"title":"Variables functions and symbols","blocks":["<p>These notes assume familiarity with algebra and basic calculus. The revision here covers the notation used in neural-network equations and the conventions that affect numerical answers.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Notation</th><th>Technical meaning</th></tr></thead><tbody><tr><td>x, y, ŷ</td><td>Input feature vector, target, model prediction</td></tr><tr><td>W, b, θ</td><td>Weight matrix, bias vector, complete trainable parameter vector</td></tr><tr><td>z, a</td><td>Preactivation (affine input) and activation (layer output)</td></tr><tr><td>L, J</td><td>Per-example loss and aggregate training objective</td></tr><tr><td>∂L/∂w</td><td>Partial derivative with respect to one parameter</td></tr><tr><td>∇θJ</td><td>Gradient: vector of partial derivatives with respect to θ</td></tr><tr><td>η, λ, ε</td><td>Learning rate, regularization coefficient, numerical stabilizer</td></tr><tr><td>Wᵀ, u⊙v</td><td>Transpose and elementwise multiplication</td></tr><tr><td>θₜ, W⁽ˡ⁾</td><td>Update index t and layer index l; neither denotes a power</td></tr></tbody></table></div>","<h3>Conventions used in numerical solutions</h3>","<p>Vectors are columns unless a question specifies otherwise. A weight matrix has one row per receiving neuron and one column per incoming feature. Write matrix dimensions before multiplying. A bias is added once per receiving neuron or output feature map.</p>","<p>Keep at least six significant digits during intermediate calculations and round the final result as requested. The loss reduction matters: a sum, mean and half-sum produce different gradient factors. The location of ε also matters: a denominator √s + ε differs from √(s + ε).</p>","<p>The sign of a gradient belongs to the derivative, not to the loss value. For example, w = 0.4, η = 0.1 and gradient −2 give the update below.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.42px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aab9aaca5264ba06.svg\"><img class=\"math display-math\" src=\"assets/equations/d677f9f3ff8120b5.svg\" alt=\"w_{\\mathrm{new}}=0.4-0.1(-2)=0.6\" width=\"288.23\" height=\"24.43\" style=\"width:288.23px;height:24.43px;aspect-ratio:288.23/24.43\" loading=\"lazy\"></picture></div>","<p>In later calculations, state the optimizer convention, initial state and iteration number before substituting values. This prevents mixing momentum velocity with Adam&#x27;s second-moment accumulator.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s5","search":"Variables functions and symbols These notes assume familiarity with algebra and basic calculus. The revision here covers the notation used in neural-network equations and the conventions that affect numerical answers.\n\n| Notation | Technical meaning |\n| x, y, ŷ | Input feature vector, target, model prediction |\n| W, b, θ | Weight matrix, bias vector, complete trainable parameter vector |\n| z, a | Preactivation (affine input) and activation (layer output) |\n| L, J | Per-example loss and aggregate training objective |\n| ∂L/∂w | Partial derivative with respect to one parameter |\n| ∇θJ | Gradient: vector of partial derivatives with respect to θ |\n| η, λ, ε | Learning rate, regularization coefficient, numerical stabilizer |\n| Wᵀ, u⊙v | Transpose and elementwise multiplication |\n| θₜ, W⁽ˡ⁾ | Update index t and layer index l; neither denotes a power |\n\n### Conventions used in numerical solutions\nVectors are columns unless a question specifies otherwise. A weight matrix has one row per receiving neuron and one column per incoming feature. Write matrix dimensions before multiplying. A bias is added once per receiving neuron or output feature map.\n\nKeep at least six significant digits during intermediate calculations and round the final result as requested. The loss reduction matters: a sum, mean and half-sum produce different gradient factors. The location of ε also matters: a denominator √s + ε differs from √(s + ε).\n\nThe sign of a gradient belongs to the derivative, not to the loss value. For example, w = 0.4, η = 0.1 and gradient −2 give the update below.\n\nIn later calculations, state the optimizer convention, initial state and iteration number before substituting values. This prevents mixing momentum velocity with Adam's second-moment accumulator.\n"},{"title":"Exponentials and natural logarithms","blocks":["<p class=\"definition\"><strong>Definitions.</strong> The exponential function exp(x) = eˣ uses Euler&#x27;s constant e. The natural logarithm ln is its inverse on positive real values. These functions occur in sigmoid, tanh, softmax and cross-entropy.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8726504f24b7b8cc.svg\" alt=\"e^{-x}=\\frac1{e^x},\\qquad\\ln(e^x)=x\" width=\"272.35\" height=\"49.82\" style=\"width:272.35px;height:49.82px;aspect-ratio:272.35/49.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.83px;--narrow-height:106.38px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0f89b5131dee6b2d.svg\"><img class=\"math display-math\" src=\"assets/equations/1cb05479c1668460.svg\" alt=\"e^{\\ln x}=x\\ (x&gt;0),\\qquad\\ln(ab)=\\ln a+\\ln b\\ (a,b&gt;0)\" width=\"532.54\" height=\"28.19\" style=\"width:532.54px;height:28.19px;aspect-ratio:532.54/28.19\" loading=\"lazy\"></picture></div>","<p>For positive constants and valid domains, exponent and log rules simplify expressions before a calculator is needed. For example, e^(−ln 2) = 1/2. Use natural ln for the loss formulas, not the calculator&#x27;s base-10 log.</p>","<h3>Derivatives used in neural networks</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.79px;--narrow-height:120.14px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b8f3afdc22e0eaaf.svg\"><img class=\"math display-math\" src=\"assets/equations/3d8e93cb87192a72.svg\" alt=\"\\frac{d}{dz}e^{-z}=-e^{-z},\\qquad\\frac{d}{dp}[-\\ln p]=-\\frac1p\" width=\"399.72\" height=\"54.97\" style=\"width:399.72px;height:54.97px;aspect-ratio:399.72/54.97\" loading=\"lazy\"></picture></div>","<p>The minus sign in the first expression comes from differentiating the inner function −z. Applying the chain rule correctly here gives the sigmoid derivative derived in the activation section.</p>","<h3>Brief integration and trigonometry reminder</h3>","<p>Integration reverses differentiation up to an additive constant. The basic relevant identities are:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.87px;--narrow-height:97.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/19176aa5b80f6365.svg\"><img class=\"math display-math\" src=\"assets/equations/5b516266e8ee3cea.svg\" alt=\"\\int x^n\\,dx=\\frac{x^{n+1}}{n+1}+C\\quad(n\\ne-1)\" width=\"354.72\" height=\"57.93\" style=\"width:354.72px;height:57.93px;aspect-ratio:354.72/57.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.53px;--narrow-height:123.25px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b17aa54fb4500d95.svg\"><img class=\"math display-math\" src=\"assets/equations/a4a9ce610fff6be4.svg\" alt=\"\\int\\frac1x\\,dx=\\ln|x|+C,\\qquad\\int e^x\\,dx=e^x+C\" width=\"460.92\" height=\"54.29\" style=\"width:460.92px;height:54.29px;aspect-ratio:460.92/54.29\" loading=\"lazy\"></picture></div>","<p>For angles in radians, d(sin x)/dx = cos x and d(cos x)/dx = −sin x. The identity sin²x + cos²x = 1 concerns ordinary trigonometric functions. Hyperbolic tanh is a different function; using tan instead of tanh gives an incorrect recurrent-network answer.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.81px;--narrow-height:119.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/419a6fb08fcd40a6.svg\"><img class=\"math display-math\" src=\"assets/equations/268c7169f8f53160.svg\" alt=\"\\tanh z=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad\\frac{d}{dz}\\tanh z=1-\\tanh^2z\" width=\"502.42\" height=\"54.23\" style=\"width:502.42px;height:54.23px;aspect-ratio:502.42/54.23\" loading=\"lazy\"></picture></div>","<p>The supplied MT2 calculation families mainly require derivatives, matrix products, logarithms and elementary statistics. Extended integration or trigonometric exercises are not needed for those families.</p>","<h3>Calculator values for activation calculations</h3>","<p>At z = 2, sigmoid = 1/(1 + e⁻²) ≈ 0.880797. At z = 1, tanh ≈ 0.761594. Keep unrounded values when a later gradient uses these activations.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s6","search":"Exponentials and natural logarithms **Definitions.** The exponential function exp(x) = eˣ uses Euler's constant e. The natural logarithm ln is its inverse on positive real values. These functions occur in sigmoid, tanh, softmax and cross-entropy.\n\n\nFor positive constants and valid domains, exponent and log rules simplify expressions before a calculator is needed. For example, e^(−ln 2) = 1/2. Use natural ln for the loss formulas, not the calculator's base-10 log.\n\n### Derivatives used in neural networks\n\nThe minus sign in the first expression comes from differentiating the inner function −z. Applying the chain rule correctly here gives the sigmoid derivative derived in the activation section.\n\n### Brief integration and trigonometry reminder\nIntegration reverses differentiation up to an additive constant. The basic relevant identities are:\n\n\nFor angles in radians, d(sin x)/dx = cos x and d(cos x)/dx = −sin x. The identity sin²x + cos²x = 1 concerns ordinary trigonometric functions. Hyperbolic tanh is a different function; using tan instead of tanh gives an incorrect recurrent-network answer.\n\nThe supplied MT2 calculation families mainly require derivatives, matrix products, logarithms and elementary statistics. Extended integration or trigonometric exercises are not needed for those families.\n\n### Calculator values for activation calculations\nAt z = 2, sigmoid = 1/(1 + e⁻²) ≈ 0.880797. At z = 1, tanh ≈ 0.761594. Keep unrounded values when a later gradient uses these activations.\n"},{"title":"Calculator routine","blocks":["<p>You reported a Casio ES-series calculator. The exact model string is not confirmed. The functions below are mathematical entries; use the keys labelled on your model. On fx-991 ES/fx-991 ES PLUS models, eˣ is normally the SHIFT function of ln. Do not confuse eˣ with the × 10ˣ scientific-notation key. Use the function labels on your own calculator for these entries.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_calculator.svg\" aria-label=\"Enlarge diagram: Calculate the exponential, build the full denominator, then take its reciprocal.\"><img src=\"assets/figures/v_calculator.svg\" alt=\"Calculate the exponential, build the full denominator, then take its reciprocal.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Calculate the exponential, build the full denominator, then take its reciprocal. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>1. Use ordinary computation mode. Enter complete brackets around a denominator or negative exponent.</p>","<p>2. For sigmoid at z = 2, enter 1 ÷ (1 + e^(−2)). Result: 0.880797078. Keep the full calculator value; write about six decimals during intermediate work.</p>","<p>3. For tanh at z = 1, use the hyperbolic tanh function if available. A universal alternative is (e² − 1) ÷ (e² + 1), giving 0.761594156. Ordinary tan is a different function; do not use it.</p>","<p>4. For cross-entropy with true probability 0.8, enter −ln(0.8), giving 0.223143551.</p>","<p>5. For softmax [2.3, 4.5, 3.2], subtract 4.5 first, then calculate e⁻²·², 1, e⁻¹·³. Add them, then divide each exponential by the same total.</p>","<p>6. If a result displays as a fraction, use your model’s fraction/decimal conversion key, often S⇔D. Do not reset the calculator unnecessarily.</p>","<p><strong>Five-minute warm-up: </strong> compute sigmoid(0) = 0.5; sigmoid(−2) ≈ 0.119203; tanh(0) = 0; −ln(0.5) ≈ 0.693147; √0.25 = 0.5. A different result signals an entry mistake, not a reason to memorize a wrong value.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s7","search":"Calculator routine You reported a Casio ES-series calculator. The exact model string is not confirmed. The functions below are mathematical entries; use the keys labelled on your model. On fx-991 ES/fx-991 ES PLUS models, eˣ is normally the SHIFT function of ln. Do not confuse eˣ with the × 10ˣ scientific-notation key. Use the function labels on your own calculator for these entries.\n\n\n\n1. Use ordinary computation mode. Enter complete brackets around a denominator or negative exponent.\n2. For sigmoid at z = 2, enter 1 ÷ (1 + e^(−2)). Result: 0.880797078. Keep the full calculator value; write about six decimals during intermediate work.\n3. For tanh at z = 1, use the hyperbolic tanh function if available. A universal alternative is (e² − 1) ÷ (e² + 1), giving 0.761594156. Ordinary tan is a different function; do not use it.\n4. For cross-entropy with true probability 0.8, enter −ln(0.8), giving 0.223143551.\n5. For softmax [2.3, 4.5, 3.2], subtract 4.5 first, then calculate e⁻²·², 1, e⁻¹·³. Add them, then divide each exponential by the same total.\n6. If a result displays as a fraction, use your model’s fraction/decimal conversion key, often S⇔D. Do not reset the calculator unnecessarily.\n**Five-minute warm-up: ** compute sigmoid(0) = 0.5; sigmoid(−2) ≈ 0.119203; tanh(0) = 0; −ln(0.5) ≈ 0.693147; √0.25 = 0.5. A different result signals an entry mistake, not a reason to memorize a wrong value."},{"title":"A complete arithmetic calculation","blocks":["<p>Evaluate 0.4 − 0.1 × (−2). The multiplication has priority over the subtraction.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_arithmetic.svg\" aria-label=\"Enlarge diagram: The negative product stays in brackets until the final subtraction is simplified.\"><img src=\"assets/figures/v_arithmetic.svg\" alt=\"The negative product stays in brackets until the final subtraction is simplified.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The negative product stays in brackets until the final subtraction is simplified. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1:</strong> multiply 0.1 by −2, giving −0.2.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> substitute that entire result, including its sign: 0.4 − (−0.2).</p>","<p class=\"worked-step\"><strong>Step 3:</strong> subtracting a negative means adding its positive value: 0.4 + 0.2 = 0.6.</p>","<p>The answer is <strong>0.6</strong>. This calculation will later appear inside a weight update; the arithmetic is exactly the same.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s8","search":"A complete arithmetic calculation Evaluate 0.4 − 0.1 × (−2). The multiplication has priority over the subtraction.\n\n\n\n**Step 1:** multiply 0.1 by −2, giving −0.2.\n**Step 2:** substitute that entire result, including its sign: 0.4 − (−0.2).\n**Step 3:** subtracting a negative means adding its positive value: 0.4 + 0.2 = 0.6.\nThe answer is **0.6**. This calculation will later appear inside a weight update; the arithmetic is exactly the same.\n"},{"title":"Loss: how one wrong prediction becomes a number","blocks":["<p class=\"definition\"><strong>Definition.</strong> A residual is the signed prediction error. Squared-error objectives aggregate squared residuals; their scaling convention changes both the reported loss and its derivative.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.10px;--narrow-height:275.76px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ae0cc9bf3a93ca00.svg\"><img class=\"math display-math\" src=\"assets/equations/9e6b354fa6fa3c49.svg\" alt=\"e_i=\\hat y_i-y_i,\\qquad \\mathrm{SSE}=\\sum_{i=1}^{n}e_i^2,\\qquad L_{\\mathrm{half}}=\\frac12\\sum_{i=1}^{n}e_i^2,\\qquad \\mathrm{MSE}=\\frac1n\\sum_{i=1}^{n}e_i^2\" width=\"784.05\" height=\"68.62\" style=\"width:784.05px;height:68.62px;aspect-ratio:784.05/68.62\" loading=\"lazy\"></picture></div>","<p>For this definition of n, each i indexes one included scalar prediction. In a multi-output batch, state whether the mean is over examples, output coordinates, or both. Half SSE and MSE happen to agree when n = 2; they are not generally the same objective.</p>","<h3>Derivatives and their scaling</h3>","<p>When differentiating with respect to prediction j, all other prediction terms are constant. The derivative of the j-th square is twice its residual:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:155.75px;--narrow-height:209.30px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3476c309d4e1d90b.svg\"><img class=\"math display-math\" src=\"assets/equations/972f5a96b91fe930.svg\" alt=\"\\frac{\\partial\\mathrm{SSE}}{\\partial\\hat y_j}=2e_j,\\qquad \\frac{\\partial L_{\\mathrm{half}}}{\\partial\\hat y_j}=e_j,\\qquad \\frac{\\partial\\mathrm{MSE}}{\\partial\\hat y_j}=\\frac{2}{n}e_j\" width=\"534.78\" height=\"59.99\" style=\"width:534.78px;height:59.99px;aspect-ratio:534.78/59.99\" loading=\"lazy\"></picture></div>","<p>The factor 1/2 cancels the derivative&#x27;s factor 2. The factor 1/n instead produces 2/n. A weight derivative must also multiply by the derivative of the prediction with respect to that weight.</p>","<p class=\"inline-question\"><strong>Question. Predictions are [0.2, 0.7, 0.4] and targets are [0, 1, 1]. Find SSE, half SSE and MSE, then their gradients with respect to the prediction vector.</strong></p>","<h3>Given</h3>","<p>Predictions = [0.2,0.7,0.4].</p>","<p>Targets = [0,1,1]; n = 3 scalar predictions.</p>","<h3>To find</h3>","<p>Find SSE, half SSE and MSE, then all three prediction-gradient lists.</p>","<h3>Formula — which one and why</h3>","<p><strong>Squared-error objectives.</strong> Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.</p>","<p>ŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle error square; phir question ke hisaab se sum, half ya mean.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the three signed prediction errors.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:300.06px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/23245cd97ea478bc.svg\"><img class=\"math display-math\" src=\"assets/equations/27a2e2729d22f591.svg\" alt=\"e=[0.2-0,\\ 0.7-1,\\ 0.4-1]=[0.2,-0.3,-0.6]\" width=\"511.05\" height=\"24.43\" style=\"width:511.05px;height:24.43px;aspect-ratio:511.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: square every error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fddc4677249bcbb.svg\" alt=\"e\\odot e=[0.04,0.09,0.36]\" width=\"250.87\" height=\"24.43\" style=\"width:250.87px;height:24.43px;aspect-ratio:250.87/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the three squared errors.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4890329b3b657194.svg\"><img class=\"math display-math\" src=\"assets/equations/36128683498bbba3.svg\" alt=\"\\mathrm{SSE}=0.04+0.09+0.36=0.49\" width=\"342.50\" height=\"19.23\" style=\"width:342.50px;height:19.23px;aspect-ratio:342.50/19.23\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: apply the requested loss divisors.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.96px;--narrow-height:153.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/98422634bd86c12f.svg\"><img class=\"math display-math\" src=\"assets/equations/0add52f0daedefdc.svg\" alt=\"L_{\\mathrm{half}}=\\frac{0.49}{2}=0.245,\\qquad \\mathrm{MSE}=\\frac{0.49}{3}\\approx0.163333333\" width=\"583.87\" height=\"50.36\" style=\"width:583.87px;height:50.36px;aspect-ratio:583.87/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: multiply every error by 2 for the SSE gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fec22e50bd202c79.svg\" alt=\"\\nabla_{\\hat y}\\mathrm{SSE}=[0.4,-0.6,-1.2]\" width=\"274.27\" height=\"27.23\" style=\"width:274.27px;height:27.23px;aspect-ratio:274.27/27.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: use each error itself for the half-SSE gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dfa71d7fa81c823c.svg\" alt=\"\\nabla_{\\hat y}L_{\\mathrm{half}}=[0.2,-0.3,-0.6]\" width=\"278.60\" height=\"27.23\" style=\"width:278.60px;height:27.23px;aspect-ratio:278.60/27.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: multiply every error by 2/3 for the MSE gradient.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:297.33px;--narrow-height:131.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a584bba4763cda9f.svg\"><img class=\"math display-math\" src=\"assets/equations/661d59f4a5205fa6.svg\" alt=\"\\nabla_{\\hat y}\\mathrm{MSE}=\\frac23[0.2,-0.3,-0.6]=[0.133333333,-0.2,-0.4]\" width=\"603.39\" height=\"50.09\" style=\"width:603.39px;height:50.09px;aspect-ratio:603.39/50.09\" loading=\"lazy\"></picture></div>","<p>The residual signs survive in the gradients even though the losses are nonnegative. Multiplying a loss by a positive constant leaves its unregularized minimizers unchanged, but scales its gradients and therefore its updates at a fixed learning rate.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c2-s9","search":"Loss: how one wrong prediction becomes a number \n**Definition.** A residual is the signed prediction error. Squared-error objectives aggregate squared residuals; their scaling convention changes both the reported loss and its derivative.\n\nFor this definition of n, each i indexes one included scalar prediction. In a multi-output batch, state whether the mean is over examples, output coordinates, or both. Half SSE and MSE happen to agree when n = 2; they are not generally the same objective.\n\n### Derivatives and their scaling\nWhen differentiating with respect to prediction j, all other prediction terms are constant. The derivative of the j-th square is twice its residual:\n\nThe factor 1/2 cancels the derivative's factor 2. The factor 1/n instead produces 2/n. A weight derivative must also multiply by the derivative of the prediction with respect to that weight.\n\n**Question. Predictions are [0.2, 0.7, 0.4] and targets are [0, 1, 1]. Find SSE, half SSE and MSE, then their gradients with respect to the prediction vector.**\n\n\n\n### Given\n\nPredictions = [0.2,0.7,0.4].\n\nTargets = [0,1,1]; n = 3 scalar predictions.\n\n### To find\n\nFind SSE, half SSE and MSE, then all three prediction-gradient lists.\n\n### Formula — which one and why\n\n**Squared-error objectives.** Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.\n\nŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle error square; phir question ke hisaab se sum, half ya mean.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: calculate the three signed prediction errors.**\n\n\n**Step 2: square every error.**\n\n\n**Step 3: add the three squared errors.**\n\n\n**Step 4: apply the requested loss divisors.**\n\n\n**Step 5: multiply every error by 2 for the SSE gradient.**\n\n\n**Step 6: use each error itself for the half-SSE gradient.**\n\n\n**Step 7: multiply every error by 2/3 for the MSE gradient.**\n\n\nThe residual signs survive in the gradients even though the losses are nonnegative. Multiplying a loss by a positive constant leaves its unregularized minimizers unchanged, but scales its gradients and therefore its updates at a fixed learning rate.\n\n"}]},{"n":3,"title":"The maths behind a network","sections":[{"title":"A vector is a list and a matrix is a table","blocks":["<p>The input [2, 3] is a vector containing two features. A matrix is a rectangle of numbers. “2 by 3” means two rows and three columns. A column vector with two entries has shape 2 by 1. Always write rows before columns.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_matrix.svg\" aria-label=\"Enlarge diagram: Count rows downward and columns across. The shape describes the arrangement of entries.\"><img src=\"assets/figures/v_matrix.svg\" alt=\"Count rows downward and columns across. The shape describes the arrangement of entries.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>Count rows downward and columns across. The shape describes the arrangement of entries. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>In this course, unless a question’s diagram explicitly uses another convention, <strong>each row of a weight matrix belongs to one receiving neuron</strong>. Thus W has shape number of output neurons by number of input features, and the input is a column vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5226c7a9750fc29a.svg\" alt=\"W=\\begin{bmatrix}0.11&amp;0.21\\\\0.12&amp;0.08\\end{bmatrix},\\quad x=\\begin{bmatrix}2\\\\3\\end{bmatrix},\\quad Wx=\\begin{bmatrix}0.11(2)+0.21(3)\\\\0.12(2)+0.08(3)\\end{bmatrix}=\\begin{bmatrix}0.85\\\\0.48\\end{bmatrix}\" width=\"729.52\" height=\"58.64\" style=\"width:729.52px;height:58.64px;aspect-ratio:729.52/58.64\" loading=\"lazy\"></div>","<p><strong>Do it slowly: </strong> row 1 says 0.11 × 2 = 0.22 and 0.21 × 3 = 0.63, so its answer is 0.85. Row 2 says 0.12 × 2 = 0.24 and 0.08 × 3 = 0.24, so its answer is 0.48. Matrix multiplication is several weighted sums written together.</p>","<p><strong>Shape check: </strong> (2 by 2) × (2 by 1) gives (2 by 1). The inside numbers must match; the outside numbers are the answer shape. This check catches many transposed-weight errors before arithmetic begins.</p>","<p>Transpose swaps rows and columns. Elementwise multiplication does not do row-by-column sums: [2, 3] ⊙ [4, 5] = [8, 15]. Dot product does add: [2, 3] · [4, 5] = 8 + 15 = 23. A training dropout mask uses elementwise multiplication, not a dot product.</p>","<p><strong>Practice.</strong> Multiply W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/af9cca7044f770c7.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\3 &amp; 4\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> by x = [2, 1] as a column. Answer: first row 1 × 2 + 2 × 1 = 4; second row 3 × 2 + 4 × 1 = 10. With b = [1, −1], Wx + b = [5, 9].</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s0","search":"A vector is a list and a matrix is a table The input [2, 3] is a vector containing two features. A matrix is a rectangle of numbers. “2 by 3” means two rows and three columns. A column vector with two entries has shape 2 by 1. Always write rows before columns.\n\n\n\nIn this book, unless a question’s diagram explicitly uses another convention, **each row of a weight matrix belongs to one receiving neuron**. Thus W has shape number of output neurons by number of input features, and the input is a column vector.\n\n**Do it slowly: ** row 1 says 0.11 × 2 = 0.22 and 0.21 × 3 = 0.63, so its answer is 0.85. Row 2 says 0.12 × 2 = 0.24 and 0.08 × 3 = 0.24, so its answer is 0.48. Matrix multiplication is several weighted sums written together.\n**Shape check: ** (2 by 2) × (2 by 1) gives (2 by 1). The inside numbers must match; the outside numbers are the answer shape. This check catches many transposed-weight errors before arithmetic begins.\nTranspose swaps rows and columns. Elementwise multiplication does not do row-by-column sums: [2, 3] ⊙ [4, 5] = [8, 15]. Dot product does add: [2, 3] · [4, 5] = 8 + 15 = 23. A training dropout mask uses elementwise multiplication, not a dot product.\n**Practice.** Multiply W =  by x = [2, 1] as a column. Answer: first row 1 × 2 + 2 × 1 = 4; second row 3 × 2 + 4 × 1 = 10. With b = [1, −1], Wx + b = [5, 9]."},{"title":"Matrix multiplication: every row has a job","blocks":["<h3>Row, column, vector and matrix — read these first</h3>","<p>A <strong>row</strong> runs horizontally, from left to right. A <strong>column</strong> runs vertically, from top to bottom. A <strong>matrix</strong> is a rectangular arrangement of numbers in rows and columns. Its size is written rows × columns. A 2 × 3 matrix therefore has two rows and three columns, not six rows.</p>","<p>A <strong>vector</strong> is an ordered list of numbers. Written horizontally it is a row vector, such as [2, 1, 3]. Written vertically it is a column vector. Neural-network equations in these notes usually use column vectors.</p>","<h3>Transpose: rows become columns</h3>","<p>The superscript T means <strong>transpose</strong>, not a power. To obtain Aᵀ, copy row 1 of A as column 1, row 2 as column 2, and so on. Do not reverse the order within a row, change a sign or multiply anything. An m × n matrix becomes n × m.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p>The two indices are positions: i identifies a row and j a column. The rule says “swap the row and column addresses”. For example, the value at row 1, column 3 moves to row 3, column 1.</p>","<p><strong>Yaad rakhne ka cue:</strong> transpose = row ko column bana; number aur sign ko haath mat laga.</p>","<h3>Transpose example 1</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f5189f9c2294a43.svg\" alt=\"A=\\begin{bmatrix}2&amp;1&amp;3\\end{bmatrix}\" width=\"150.01\" height=\"24.43\" style=\"width:150.01px;height:24.43px;aspect-ratio:150.01/24.43\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 1 row(s) and 3 column(s), so its size is 1 × 3.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [2, 1, 3] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dafe6e5e80b48abd.svg\" alt=\"A^T=\\begin{bmatrix}2\\\\1\\\\3\\end{bmatrix}\" width=\"109.91\" height=\"92.85\" style=\"width:109.91px;height:92.85px;aspect-ratio:109.91/92.85\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: state its new size.</strong></p>","<p>The result has 3 row(s) and 1 column(s): 3 × 1.</p>","<p><strong>Final answer:</strong> Aᵀ has size 3 × 1. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 1 rows × 3 columns</div><table class=\"lv-matrix\" aria-label=\"A: 1 rows × 3 columns\"><caption>A: 1 rows × 3 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 3 rows × 1 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 3 rows × 1 columns\"><caption>Aᵀ: 3 rows × 1 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td></tr><tr><td class=\"lv-row-0\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Transpose example 2</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/19f2e9948f5cc39f.svg\" alt=\"A=\\begin{bmatrix}1&amp;2&amp;3\\\\4&amp;5&amp;6\\end{bmatrix}\" width=\"162.24\" height=\"58.64\" style=\"width:162.24px;height:58.64px;aspect-ratio:162.24/58.64\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 2 row(s) and 3 column(s), so its size is 2 × 3.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [1, 2, 3] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: move original row 2 into new column 2.</strong></p>","<p>Copy [4, 5, 6] down column 2, in the same order.</p>","<p class=\"worked-step\"><strong>Step 4: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78bde861f7b64a93.svg\" alt=\"A^T=\\begin{bmatrix}1&amp;4\\\\2&amp;5\\\\3&amp;6\\end{bmatrix}\" width=\"146.57\" height=\"92.85\" style=\"width:146.57px;height:92.85px;aspect-ratio:146.57/92.85\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: state its new size.</strong></p>","<p>The result has 3 row(s) and 2 column(s): 3 × 2.</p>","<p><strong>Final answer:</strong> Aᵀ has size 3 × 2. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 2 rows × 3 columns</div><table class=\"lv-matrix\" aria-label=\"A: 2 rows × 3 columns\"><caption>A: 2 rows × 3 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 3\">3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 5\">5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 3 rows × 2 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 3 rows × 2 columns\"><caption>Aᵀ: 3 rows × 2 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 4\">4</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 5\">5</td></tr><tr><td class=\"lv-row-0\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-1\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 6\">6</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Transpose example 3</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ffb51554b200bfc3.svg\" alt=\"A=\\begin{bmatrix}1&amp;-2\\\\0&amp;3\\end{bmatrix}\" width=\"144.59\" height=\"58.64\" style=\"width:144.59px;height:58.64px;aspect-ratio:144.59/58.64\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 2 row(s) and 2 column(s), so its size is 2 × 2.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [1, -2] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: move original row 2 into new column 2.</strong></p>","<p>Copy [0, 3] down column 2, in the same order.</p>","<p class=\"worked-step\"><strong>Step 4: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3f6121853d314156.svg\" alt=\"A^T=\\begin{bmatrix}1&amp;0\\\\-2&amp;3\\end{bmatrix}\" width=\"158.78\" height=\"58.64\" style=\"width:158.78px;height:58.64px;aspect-ratio:158.78/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: state its new size.</strong></p>","<p>The result has 2 row(s) and 2 column(s): 2 × 2.</p>","<p><strong>Final answer:</strong> Aᵀ has size 2 × 2. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 2 rows × 2 columns</div><table class=\"lv-matrix\" aria-label=\"A: 2 rows × 2 columns\"><caption>A: 2 rows × 2 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 2 rows × 2 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 2 rows × 2 columns\"><caption>Aᵀ: 2 rows × 2 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −2\">−2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Transpose example 4</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b21656f3402af964.svg\" alt=\"A=\\begin{bmatrix}-1\\\\4\\\\2\\end{bmatrix}\" width=\"114.73\" height=\"92.85\" style=\"width:114.73px;height:92.85px;aspect-ratio:114.73/92.85\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 3 row(s) and 1 column(s), so its size is 3 × 1.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [-1] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: move original row 2 into new column 2.</strong></p>","<p>Copy [4] down column 2, in the same order.</p>","<p class=\"worked-step\"><strong>Step 4: move original row 3 into new column 3.</strong></p>","<p>Copy [2] down column 3, in the same order.</p>","<p class=\"worked-step\"><strong>Step 5: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5b69eb45dcd67397.svg\" alt=\"A^T=\\begin{bmatrix}-1&amp;4&amp;2\\end{bmatrix}\" width=\"183.22\" height=\"27.90\" style=\"width:183.22px;height:27.90px;aspect-ratio:183.22/27.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: state its new size.</strong></p>","<p>The result has 1 row(s) and 3 column(s): 1 × 3.</p>","<p><strong>Final answer:</strong> Aᵀ has size 1 × 3. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 3 rows × 1 columns</div><table class=\"lv-matrix\" aria-label=\"A: 3 rows × 1 columns\"><caption>A: 3 rows × 1 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 1 rows × 3 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 1 rows × 3 columns\"><caption>Aᵀ: 1 rows × 3 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: −1\">−1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 4\">4</td><td class=\"lv-row-2\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Dot product: multiply matching entries, then add</h3>","<p>A <strong>dot product</strong> turns two equally long lists into one number. Match first with first, second with second, and so on. It is the weighted sum inside a neuron. If both lists are columns, wᵀ turns the weight column into a row so row × column is allowed.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:213.73px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/97799e8f51bd1031.svg\"><img class=\"math display-math\" src=\"assets/equations/ccb1c24c2967c1fa.svg\" alt=\"w^Tx=w_1x_1+w_2x_2+w_3x_3\" width=\"296.41\" height=\"25.83\" style=\"width:296.41px;height:25.83px;aspect-ratio:296.41/25.83\" loading=\"lazy\"></picture></div>","<p>This formula is the three-input case. With two inputs there are only two products; with d inputs there are d products. A bias is an additional term, added after these products.</p>","<h3>Dot-product example 1</h3>","<p class=\"inline-question\"><strong>Question. For w = [2, 3] and x = [4, 1], calculate wᵀx.</strong></p>","<h3>Given</h3>","<p>Weights w = [2, 3].</p>","<p>Matching inputs x = [4, 1].</p>","<p>Both lists contain 2 numbers.</p>","<h3>To find</h3>","<p>One scalar value wᵀx.</p>","<h3>Formula — which one and why</h3>","<p>A dot product is a sum of matching products. There is no bias in this question.</p>","<p>Σ means add; the index i visits each matching pair.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce95abc5189aaf50.svg\" alt=\"w^Tx=\\sum_i w_ix_i\" width=\"165.06\" height=\"52.35\" style=\"width:165.06px;height:52.35px;aspect-ratio:165.06/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position multiply; sab products add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching pair 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb39ee363580ed9c.svg\" alt=\"(2)(4)=8\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply matching pair 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9934bcd789a00e7d.svg\" alt=\"(3)(1)=3\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b366d83f24fd5dd.svg\" alt=\"w^Tx=(8)+(3)=11\" width=\"227.59\" height=\"27.90\" style=\"width:227.59px;height:27.90px;aspect-ratio:227.59/27.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> wᵀx = 11.</p>","<h3>Dot-product example 2</h3>","<p class=\"inline-question\"><strong>Question. For w = [1, -2] and x = [2, 3], calculate wᵀx.</strong></p>","<h3>Given</h3>","<p>Weights w = [1, -2].</p>","<p>Matching inputs x = [2, 3].</p>","<p>Both lists contain 2 numbers.</p>","<h3>To find</h3>","<p>One scalar value wᵀx.</p>","<h3>Formula — which one and why</h3>","<p>A dot product is a sum of matching products. There is no bias in this question.</p>","<p>Σ means add; the index i visits each matching pair.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce95abc5189aaf50.svg\" alt=\"w^Tx=\\sum_i w_ix_i\" width=\"165.06\" height=\"52.35\" style=\"width:165.06px;height:52.35px;aspect-ratio:165.06/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position multiply; sab products add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching pair 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7259499711e389d2.svg\" alt=\"(1)(2)=2\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply matching pair 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02560299473dc26e.svg\" alt=\"(-2)(3)=-6\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/368a39aeec6c928d.svg\" alt=\"w^Tx=(2)+(-6)=-4\" width=\"253.39\" height=\"27.90\" style=\"width:253.39px;height:27.90px;aspect-ratio:253.39/27.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> wᵀx = -4.</p>","<h3>Dot-product example 3</h3>","<p class=\"inline-question\"><strong>Question. For w = [0.5, 1, -1] and x = [4, 2, 3], calculate wᵀx.</strong></p>","<h3>Given</h3>","<p>Weights w = [0.5, 1, -1].</p>","<p>Matching inputs x = [4, 2, 3].</p>","<p>Both lists contain 3 numbers.</p>","<h3>To find</h3>","<p>One scalar value wᵀx.</p>","<h3>Formula — which one and why</h3>","<p>A dot product is a sum of matching products. There is no bias in this question.</p>","<p>Σ means add; the index i visits each matching pair.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce95abc5189aaf50.svg\" alt=\"w^Tx=\\sum_i w_ix_i\" width=\"165.06\" height=\"52.35\" style=\"width:165.06px;height:52.35px;aspect-ratio:165.06/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position multiply; sab products add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching pair 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3430445c8f6a121.svg\" alt=\"(0.5)(4)=2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply matching pair 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7259499711e389d2.svg\" alt=\"(1)(2)=2\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply matching pair 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c5d478557eb834e1.svg\" alt=\"(-1)(3)=-3\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the products.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.68px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bf7dc79763479e35.svg\"><img class=\"math display-math\" src=\"assets/equations/b85e0c042b7b8396.svg\" alt=\"w^Tx=(2)+(2)+(-3)=1\" width=\"295.48\" height=\"27.90\" style=\"width:295.48px;height:27.90px;aspect-ratio:295.48/27.90\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> wᵀx = 1.</p>","<h3>Matrix multiplication: each row makes one output</h3>","<p>To multiply A of size m × n by B of size n × p, the inner sizes n must match. The result has size m × p. Output entry (i,j) is row i of A dotted with column j of B.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d566b516b84686ee.svg\" alt=\"C_{ij}=\\sum_{k=1}^{n}A_{ik}B_{kj}\" width=\"176.53\" height=\"69.11\" style=\"width:176.53px;height:69.11px;aspect-ratio:176.53/69.11\" loading=\"lazy\"></div>","<p>For a layer receiving two inputs and producing two neuron outputs, W is 2 × 2, x is 2 × 1 and Wx is 2 × 1. Each row of W holds all weights entering one receiving neuron. Its matching bias is added once.</p>","<p><strong>Yaad rakhne ka cue:</strong> multiplication mein andar ke sizes match; answer ka size bahar ke sizes. Har output = ek row × ek column.</p>","<p class=\"definition\"><strong>Definition.</strong> A vector is an ordered collection of scalars; a matrix represents a linear transformation between vector spaces. A neural-network layer combines a linear transformation with an additive bias, giving an affine transformation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28b5d89094e7d00d.svg\" alt=\"z=Wx+b\" width=\"123.89\" height=\"18.96\" style=\"width:123.89px;height:18.96px;aspect-ratio:123.89/18.96\" loading=\"lazy\"></div>","<p>For d input features and m receiving neurons, the dimensions are:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:119.53px;--narrow-height:113.41px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fb325b4580ff43a.svg\"><img class=\"math display-math\" src=\"assets/equations/a38b418b5411afa4.svg\" alt=\"W\\in\\mathbb R^{m\\times d},\\quad x\\in\\mathbb R^{d\\times1},\\quad b,z\\in\\mathbb R^{m\\times1}\" width=\"397.43\" height=\"26.83\" style=\"width:397.43px;height:26.83px;aspect-ratio:397.43/26.83\" loading=\"lazy\"></picture></div>","<p>The inner dimensions must match. Output component j is the dot product of row j of W with x, plus bias bⱼ. Wᵀ reverses the matrix dimensions. The Hadamard product u⊙v multiplies corresponding components and is different from a matrix product.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_matrix.svg\" aria-label=\"Enlarge diagram: Each row of the weight matrix calculates one receiving neuron&#x27;s preactivation.\"><img src=\"assets/figures/v_matrix.svg\" alt=\"Each row of the weight matrix calculates one receiving neuron&#x27;s preactivation.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>Each row of the weight matrix calculates one receiving neuron&#x27;s preactivation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Given W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/aad1d6a46cb2c7f1.svg\" alt=\"\\begin{bmatrix}1 &amp; -2\\\\0.5 &amp; 3\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>, x = [2, 1]ᵀ and b = [0.1, −0.2]ᵀ, calculate z = Wx + b.</p>","<h3>Given</h3>","<p>Weights W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/aad1d6a46cb2c7f1.svg\" alt=\"\\begin{bmatrix}1 &amp; -2\\\\0.5 &amp; 3\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>.</p>","<p>Input column x = [2,1]ᵀ; bias column b = [0.1,−0.2]ᵀ.</p>","<h3>To find</h3>","<p>Find both components of z = Wx+b.</p>","<h3>Formula — which one and why</h3>","<p><strong>Row–column multiplication.</strong> Each receiving neuron uses one weight row. Multiply that row by the input column, add the products, then add that neuron’s bias.</p>","<p>Wⱼᵢ = weight from input i to receiver j; xᵢ = input i; bⱼ = bias of receiver j; zⱼ = its preactivation. A superscript T means transpose: exchange rows and columns.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc40cdac8ad4c81c.svg\" alt=\"z_j=\\sum_i W_{ji}x_i+b_j\" width=\"202.09\" height=\"52.35\" style=\"width:202.09px;height:52.35px;aspect-ratio:202.09/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek row × poora input column = ek receiving neuron ka answer.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: verify compatible dimensions.</strong></p>","<p>W has 2 rows and 2 columns; x has 2 rows and 1 column. The inner dimensions match, and the result has 2 rows and 1 column.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the first receiving row products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07ce1f7a3ced3979.svg\" alt=\"1(2)=2\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28ad4ad477ec80b7.svg\" alt=\"(-2)(1)=-2\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: sum row 1 and add its bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6eacd9d3a609cc.svg\" alt=\"z_1=2+(-2)+0.1=0.1\" width=\"271.85\" height=\"24.43\" style=\"width:271.85px;height:24.43px;aspect-ratio:271.85/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: calculate the second receiving row products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4b945ff5abf26e2.svg\" alt=\"0.5(2)=1\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/464c4958d256b6c8.svg\" alt=\"3(1)=3\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: sum row 2 and add its bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b340e43d0e100bc4.svg\" alt=\"z_2=1+3-0.2=3.8\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.39px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/133f56723bb2a1d8.svg\"><img class=\"math display-math\" src=\"assets/equations/2f3707d9acaff1b9.svg\" alt=\"z_1=1(2)+(-2)(1)+0.1=0.1\" width=\"334.30\" height=\"24.43\" style=\"width:334.30px;height:24.43px;aspect-ratio:334.30/24.43\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-matrix-row\" data-visual=\"matrix-row\"><figcaption class=\"lv-title\">Row 1 produces output component z1</figcaption><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select weight row 1</div><table class=\"lv-matrix\" aria-label=\"1. Select weight row 1\"><caption>1. Select weight row 1</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Use the entire input column</div><table class=\"lv-matrix\" aria-label=\"2. Use the entire input column\"><caption>2. Use the entire input column</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Match and multiply</div><table class=\"lv-matrix\" aria-label=\"3. Match and multiply\"><caption>3. Match and multiply</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr></tbody></table><p class=\"lv-matrix-note\">First × first; second × second.</p></div></div><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sum the products</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias for this row</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">z1</span><strong class=\"lv-value\">0.1</strong></div></div><p class=\"lv-caption\">One receiving neuron corresponds to one row of W and one bias. The other weight row is not used for this component.</p></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.48px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dbd8ceb08ae05e33.svg\"><img class=\"math display-math\" src=\"assets/equations/73b17a005abd5aba.svg\" alt=\"z_2=0.5(2)+3(1)-0.2=3.8\" width=\"315.30\" height=\"24.43\" style=\"width:315.30px;height:24.43px;aspect-ratio:315.30/24.43\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-matrix-row\" data-visual=\"matrix-row\"><figcaption class=\"lv-title\">Row 2 produces output component z2</figcaption><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select weight row 2</div><table class=\"lv-matrix\" aria-label=\"1. Select weight row 2\"><caption>1. Select weight row 2</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Use the entire input column</div><table class=\"lv-matrix\" aria-label=\"2. Use the entire input column\"><caption>2. Use the entire input column</caption><tbody><tr><td class=\"lv-row-1\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Match and multiply</div><table class=\"lv-matrix\" aria-label=\"3. Match and multiply\"><caption>3. Match and multiply</caption><tbody><tr><td class=\"lv-row-1\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">First × first; second × second.</p></div></div><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sum the products</span><strong class=\"lv-value\">4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias for this row</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">z2</span><strong class=\"lv-value\">3.8</strong></div></div><p class=\"lv-caption\">One receiving neuron corresponds to one row of W and one bias. The other weight row is not used for this component.</p></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0bcbcaa175e8ffb8.svg\" alt=\"z=\\begin{bmatrix}0.1\\\\3.8\\end{bmatrix}\" width=\"100.98\" height=\"58.64\" style=\"width:100.98px;height:58.64px;aspect-ratio:100.98/58.64\" loading=\"lazy\"></div>","<p>An activation is applied afterward if the question asks for the layer output. In backpropagation, the input gradient uses Wᵀ because it maps derivatives from m outputs back to d inputs. For a single example, an outer product δxᵀ produces a weight-gradient matrix with exactly the same dimensions as W.</p>","<h3>Two output columns</h3>","<p class=\"inline-question\"><strong>Question. Multiply A = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/af9cca7044f770c7.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\3 &amp; 4\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> by B = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/969e894914a74419.svg\" alt=\"\\begin{bmatrix}2 &amp; 0\\\\1 &amp; 3\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Show all four output entries.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f32200eba37c0ea5.svg\" alt=\"A=\\begin{bmatrix}1&amp;2\\\\3&amp;4\\end{bmatrix}\" width=\"125.58\" height=\"58.64\" style=\"width:125.58px;height:58.64px;aspect-ratio:125.58/58.64\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d45fb6a21c1dc67e.svg\" alt=\"B=\\begin{bmatrix}2&amp;0\\\\1&amp;3\\end{bmatrix}\" width=\"125.80\" height=\"58.64\" style=\"width:125.80px;height:58.64px;aspect-ratio:125.80/58.64\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>The 2 × 2 matrix C = AB.</p>","<h3>Formula — which one and why</h3>","<p>Matrix multiplication pairs one row of A with one column of B for each output. It is not entry-by-entry multiplication.</p>","<p>Cᵢⱼ is the entry in output row i, column j.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46672bbce5b57e87.svg\" alt=\"C_{ij}=\\sum_k A_{ik}B_{kj}\" width=\"176.53\" height=\"52.91\" style=\"width:176.53px;height:52.91px;aspect-ratio:176.53/52.91\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Output ki position dekho: wahi row, wahi column.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: check the dimensions.</strong></p>","<p>(2 × 2)(2 × 2) is valid; output size = 2 × 2.</p>","<p class=\"worked-step\"><strong>Step 2: row 1 with column 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/646952b8a744b648.svg\"><img class=\"math display-math\" src=\"assets/equations/d47e20af5264ff61.svg\" alt=\"C_{11}=1(2)+2(1)=2+2=4\" width=\"317.81\" height=\"24.43\" style=\"width:317.81px;height:24.43px;aspect-ratio:317.81/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: row 1 with column 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2d6dd50233caecfb.svg\"><img class=\"math display-math\" src=\"assets/equations/bf3f58226647b592.svg\" alt=\"C_{12}=1(0)+2(3)=0+6=6\" width=\"317.81\" height=\"24.43\" style=\"width:317.81px;height:24.43px;aspect-ratio:317.81/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: row 2 with column 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c49b369448ab5419.svg\"><img class=\"math display-math\" src=\"assets/equations/ef4f6c3c29a39671.svg\" alt=\"C_{21}=3(2)+4(1)=6+4=10\" width=\"330.03\" height=\"24.43\" style=\"width:330.03px;height:24.43px;aspect-ratio:330.03/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: row 2 with column 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b9ab897087e15f9b.svg\"><img class=\"math display-math\" src=\"assets/equations/c42e9c75451d67af.svg\" alt=\"C_{22}=3(0)+4(3)=0+12=12\" width=\"342.24\" height=\"24.43\" style=\"width:342.24px;height:24.43px;aspect-ratio:342.24/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: assemble the output by position.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/65427879b2654199.svg\" alt=\"C=\\begin{bmatrix}4&amp;6\\\\10&amp;12\\end{bmatrix}\" width=\"150.26\" height=\"58.64\" style=\"width:150.26px;height:58.64px;aspect-ratio:150.26/58.64\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> C = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/6f769fba9b2febe4.svg\" alt=\"\\begin{bmatrix}4 &amp; 6\\\\10 &amp; 12\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>, with size 2 × 2.</p>","<h3>Two products that must not be confused</h3>","<p class=\"inline-question\"><strong>Question. Let a = [2,3]ᵀ and b = [4,5]ᵀ. Find the entry-by-entry product a ⊙ b and the outer product abᵀ.</strong></p>","<h3>Given</h3>","<p>a and b are both 2 × 1 columns: a contains 2,3 and b contains 4,5.</p>","<h3>To find</h3>","<p>The 2 × 1 entry-by-entry product and the 2 × 2 outer product.</p>","<h3>Formula — which one and why</h3>","<p>⊙ multiplies corresponding positions; the outer product combines every value of a with every value of b. Backpropagation uses both operations for different reasons.</p>","<p>⊙ is called the Hadamard or elementwise product. bᵀ is a 1 × 2 row.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/696e2da1033ab6fa.svg\" alt=\"(a\\odot b)_i=a_i b_i\" width=\"152.25\" height=\"24.43\" style=\"width:152.25px;height:24.43px;aspect-ratio:152.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11b839db8ece52c1.svg\" alt=\"(ab^T)_{ij}=a_i b_j\" width=\"144.85\" height=\"28.98\" style=\"width:144.85px;height:28.98px;aspect-ratio:144.85/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> ⊙ mein same jagah; outer product mein har pair.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c69bdb17e45bd1d3.svg\" alt=\"a\\odot b=\\begin{bmatrix}8\\\\15\\end{bmatrix}\" width=\"136.10\" height=\"58.64\" style=\"width:136.10px;height:58.64px;aspect-ratio:136.10/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: transpose b.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a491055be3cc3700.svg\" alt=\"b^T=\\begin{bmatrix}4&amp;5\\end{bmatrix}\" width=\"119.72\" height=\"27.90\" style=\"width:119.72px;height:27.90px;aspect-ratio:119.72/27.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: form row 1 of the outer product.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3e7e9d7e4e1bc080.svg\" alt=\"2(4)=8,\\qquad2(5)=10\" width=\"248.44\" height=\"24.43\" style=\"width:248.44px;height:24.43px;aspect-ratio:248.44/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: form row 2 of the outer product.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/399713a01b02cfa8.svg\" alt=\"3(4)=12,\\qquad3(5)=15\" width=\"260.66\" height=\"24.43\" style=\"width:260.66px;height:24.43px;aspect-ratio:260.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: write both rows.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b24f1f7b777962.svg\" alt=\"ab^T=\\begin{bmatrix}8&amp;10\\\\12&amp;15\\end{bmatrix}\" width=\"169.29\" height=\"58.64\" style=\"width:169.29px;height:58.64px;aspect-ratio:169.29/58.64\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Entry-by-entry result = [8,15]ᵀ. Outer product = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/db73fdbe57c2c901.svg\" alt=\"\\begin{bmatrix}8 &amp; 10\\\\12 &amp; 15\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s1","search":"Matrix multiplication: every row has a job ### Row, column, vector and matrix — read these first\nA **row** runs horizontally, from left to right. A **column** runs vertically, from top to bottom. A **matrix** is a rectangular arrangement of numbers in rows and columns. Its size is written rows × columns. A 2 × 3 matrix therefore has two rows and three columns, not six rows.\n\nA **vector** is an ordered list of numbers. Written horizontally it is a row vector, such as [2, 1, 3]. Written vertically it is a column vector. Neural-network equations in these notes usually use column vectors.\n\n### Transpose: rows become columns\nThe superscript T means **transpose**, not a power. To obtain Aᵀ, copy row 1 of A as column 1, row 2 as column 2, and so on. Do not reverse the order within a row, change a sign or multiply anything. An m × n matrix becomes n × m.\n\nThe two indices are positions: i identifies a row and j a column. The rule says “swap the row and column addresses”. For example, the value at row 1, column 3 moves to row 3, column 1.\n\n**Yaad rakhne ka cue:** transpose = row ko column bana; number aur sign ko haath mat laga.\n\n\n### Transpose example 1\n\n**Question. Find the transpose of the following matrix A and state the size of both matrices.**\n\n\n\n### Given\n\n\n\n\n\n\n\n### To find\n\nAᵀ and both matrix sizes.\n\n### Formula — which one and why\n\nA transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.\n\nA is the original matrix; Aᵀ is its transpose; i and j are row/column positions.\n\n\n\n**Yaad rakhne ka cue:** Row seedha column mein; double transpose se original wapas.\n\n### Solution — step by step\n\n\n\n**Step 1: write the original size.**\n\nA has 1 row(s) and 3 column(s), so its size is 1 × 3.\n\n**Step 2: move original row 1 into new column 1.**\n\nCopy [2, 1, 3] down column 1, in the same order.\n\n**Step 3: write the transposed matrix.**\n\n\n\n\n\n\n\n**Step 4: state its new size.**\n\nThe result has 3 row(s) and 1 column(s): 3 × 1.\n\n**Final answer:** Aᵀ has size 3 × 1. Transposing it again gives the original A.\n\n}]]\n\n\n\n### Transpose example 2\n\n**Question. Find the transpose of the following matrix A and state the size of both matrices.**\n\n\n\n### Given\n\n\n\n\n\n\n\n### To find\n\nAᵀ and both matrix sizes.\n\n### Formula — which one and why\n\nA transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.\n\nA is the original matrix; Aᵀ is its transpose; i and j are row/column positions.\n\n\n\n**Yaad rakhne ka cue:** Row seedha column mein; double transpose se original wapas.\n\n### Solution — step by step\n\n\n\n**Step 1: write the original size.**\n\nA has 2 row(s) and 3 column(s), so its size is 2 × 3.\n\n**Step 2: move original row 1 into new column 1.**\n\nCopy [1, 2, 3] down column 1, in the same order.\n\n**Step 3: move original row 2 into new column 2.**\n\nCopy [4, 5, 6] down column 2, in the same order.\n\n**Step 4: write the transposed matrix.**\n\n\n\n\n\n\n\n**Step 5: state its new size.**\n\nThe result has 3 row(s) and 2 column(s): 3 × 2.\n\n**Final answer:** Aᵀ has size 3 × 2. Transposing it again gives the original A.\n\n}]]\n\n\n\n### Transpose example 3\n\n**Question. Find the transpose of the following matrix A and state the size of both matrices.**\n\n\n\n### Given\n\n\n\n\n\n\n\n### To find\n\nAᵀ and both matrix sizes.\n\n### Formula — which one and why\n\nA transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.\n\nA is the original matrix; Aᵀ is its transpose;"},{"title":"A graph and a slope","blocks":["<p>A graph shows how one value changes with another. Put the weight w on the horizontal axis and the loss L on the vertical axis. A slope is change in height divided by change in horizontal position. If L rises by 6 when w rises by 2, the average slope is 3.</p>","<p>A derivative is the slope for an extremely small change at one location. A positive derivative says increasing the weight initially increases loss. A negative derivative says increasing the weight initially decreases loss. Gradient descent moves against that local slope. <strong>Gradient batata hai loss kis taraf badhega; hum ulte taraf chhota step lete hain.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aab6f621e9833b07.svg\" alt=\"L(w)=w^2,\\qquad \\frac{dL}{dw}=2w\" width=\"276.87\" height=\"50.50\" style=\"width:276.87px;height:50.50px;aspect-ratio:276.87/50.50\" loading=\"lazy\"></div>","<p>At w = 3, slope = 6. With learning rate 0.1, the update is 3 − 0.1 × 6 = 2.4. Loss falls from 9 to 5.76. At w = −3, slope = −6, so the update is −3 − 0.1 × (−6) = −2.4. Both moves approach zero.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gradient.svg\" aria-label=\"Enlarge diagram: A slope tells you the local direction of increasing loss\"><img src=\"assets/figures/gradient.svg\" alt=\"A slope tells you the local direction of increasing loss\" width=\"960\" height=\"390\" loading=\"lazy\"></button><figcaption>A slope tells you the local direction of increasing loss <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s2","search":"A graph and a slope A graph shows how one value changes with another. Put the weight w on the horizontal axis and the loss L on the vertical axis. A slope is change in height divided by change in horizontal position. If L rises by 6 when w rises by 2, the average slope is 3.\nA derivative is the slope for an extremely small change at one location. A positive derivative says increasing the weight initially increases loss. A negative derivative says increasing the weight initially decreases loss. Gradient descent moves against that local slope. **Gradient batata hai loss kis taraf badhega; hum ulte taraf chhota step lete hain.**\n\nAt w = 3, slope = 6. With learning rate 0.1, the update is 3 − 0.1 × 6 = 2.4. Loss falls from 9 to 5.76. At w = −3, slope = −6, so the update is −3 − 0.1 × (−6) = −2.4. Both moves approach zero.\n"},{"title":"Derivatives without a calculus course","blocks":["<p class=\"definition\"><strong>Definition.</strong> A derivative measures the local rate of change of a function. A partial derivative varies one argument while holding the others fixed. The gradient of a scalar-valued function collects its partial derivatives into a vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef6399f58ca20acf.svg\" alt=\"\\nabla_\\theta J=\\begin{bmatrix}\\partial J/\\partial\\theta_1\\\\\\vdots\\\\\\partial J/\\partial\\theta_d\\end{bmatrix}\" width=\"188.95\" height=\"106.29\" style=\"width:188.95px;height:106.29px;aspect-ratio:188.95/106.29\" loading=\"lazy\"></div>","<p>The rules needed for the supplied neural-network numericals are:</p>","<div class=\"table-scroll\"><table><thead><tr><th>Function or operation</th><th>Derivative</th></tr></thead><tbody><tr><td>Constant c</td><td>0</td></tr><tr><td>xⁿ</td><td>nxⁿ⁻¹</td></tr><tr><td>c f(x)</td><td>c f′(x)</td></tr><tr><td>f(x) + g(x)</td><td>f′(x) + g′(x)</td></tr><tr><td>f(x)g(x)</td><td>f′(x)g(x) + f(x)g′(x)</td></tr><tr><td>eˣ</td><td>eˣ</td></tr><tr><td>ln x, x &gt; 0</td><td>1/x</td></tr><tr><td>f(g(x))</td><td>f′(g(x))g′(x)</td></tr></tbody></table></div>","<h3>A parameter derivative is not an input derivative</h3>","<p>For z = wx + b, the variable named in the denominator determines which derivative is required.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:95.43px;--narrow-height:183.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8e90f73571d42f2e.svg\"><img class=\"math display-math\" src=\"assets/equations/b7574a6d14a06a47.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x,\\qquad\\frac{\\partial z}{\\partial x}=w,\\qquad\\frac{\\partial z}{\\partial b}=1\" width=\"377.48\" height=\"51.29\" style=\"width:377.48px;height:51.29px;aspect-ratio:377.48/51.29\" loading=\"lazy\"></picture></div>","<p>At x = 2, w = 3 and b = 1, z = 7, but the three derivatives are 2, 3 and 1 respectively. A function value and its derivative are distinct quantities.</p>","<h3>Gradient direction</h3>","<p>For a small parameter displacement Δθ, first-order Taylor expansion gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:186.14px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9060e5490f15d100.svg\"><img class=\"math display-math\" src=\"assets/equations/2f6a587716d3d081.svg\" alt=\"J(\\theta+\\Delta\\theta)\\approx J(\\theta)+\\nabla J(\\theta)^T\\Delta\\theta\" width=\"328.31\" height=\"27.90\" style=\"width:328.31px;height:27.90px;aspect-ratio:328.31/27.90\" loading=\"lazy\"></picture></div>","<p>The gradient points in the direction of greatest local increase under the Euclidean norm. Choosing Δθ opposite to the gradient gives a local descent direction. This is the mathematical basis of gradient descent; a finite step can still overshoot if the learning rate is too large.</p>","<h3>Differentiate before substituting: 3w^2+5</h3>","<p class=\"inline-question\"><strong>Question. Let J(w) = 3w^2+5. At w = 2, find J and dJ/dw.</strong></p>","<h3>Given</h3>","<p>J(w) = 3w^2+5; w = 2.</p>","<h3>To find</h3>","<p>The function value and its derivative value.</p>","<h3>Formula — which one and why</h3>","<p>The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.</p>","<p>c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/706ea9b2290fe843.svg\" alt=\"\\frac{d(cw^n+k)}{dw}=cnw^{n-1}\" width=\"235.33\" height=\"52.70\" style=\"width:235.33px;height:52.70px;aspect-ratio:235.33/52.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Power neeche multiply; exponent ek kam; constant ka zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the function itself.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b64892fad56f04e4.svg\" alt=\"J(2)=3(2)^2+5=17\" width=\"232.49\" height=\"27.70\" style=\"width:232.49px;height:27.70px;aspect-ratio:232.49/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate symbolically.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f98b439990365e5d.svg\" alt=\"J\\prime(w)=3(2)w^{2-1}+0\" width=\"227.05\" height=\"27.70\" style=\"width:227.05px;height:27.70px;aspect-ratio:227.05/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: put the given w into the derivative.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d4fbd4bd0e97e8fb.svg\" alt=\"J\\prime(2)=3(2)(2)^{1}=12\" width=\"228.36\" height=\"27.70\" style=\"width:228.36px;height:27.70px;aspect-ratio:228.36/27.70\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> J = 17; derivative = 12.</p>","<h3>Differentiate before substituting: 0.7w^3+0</h3>","<p class=\"inline-question\"><strong>Question. Let J(w) = 0.7w^3+0. At w = 1, find J and dJ/dw.</strong></p>","<h3>Given</h3>","<p>J(w) = 0.7w^3+0; w = 1.</p>","<h3>To find</h3>","<p>The function value and its derivative value.</p>","<h3>Formula — which one and why</h3>","<p>The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.</p>","<p>c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/706ea9b2290fe843.svg\" alt=\"\\frac{d(cw^n+k)}{dw}=cnw^{n-1}\" width=\"235.33\" height=\"52.70\" style=\"width:235.33px;height:52.70px;aspect-ratio:235.33/52.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Power neeche multiply; exponent ek kam; constant ka zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the function itself.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5c598d8efe6ecd14.svg\" alt=\"J(1)=0.7(1)^3+0=0.7\" width=\"258.30\" height=\"27.69\" style=\"width:258.30px;height:27.69px;aspect-ratio:258.30/27.69\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate symbolically.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f7d282bf1129194.svg\" alt=\"J\\prime(w)=0.7(3)w^{3-1}+0\" width=\"246.06\" height=\"27.70\" style=\"width:246.06px;height:27.70px;aspect-ratio:246.06/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: put the given w into the derivative.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/38040daaa10cb32e.svg\" alt=\"J\\prime(1)=0.7(3)(1)^{2}=2.1\" width=\"254.16\" height=\"27.70\" style=\"width:254.16px;height:27.70px;aspect-ratio:254.16/27.70\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> J = 0.7; derivative = 2.1.</p>","<h3>Differentiate before substituting: 2w^1+4</h3>","<p class=\"inline-question\"><strong>Question. Let J(w) = 2w^1+4. At w = -1, find J and dJ/dw.</strong></p>","<h3>Given</h3>","<p>J(w) = 2w^1+4; w = -1.</p>","<h3>To find</h3>","<p>The function value and its derivative value.</p>","<h3>Formula — which one and why</h3>","<p>The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.</p>","<p>c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/706ea9b2290fe843.svg\" alt=\"\\frac{d(cw^n+k)}{dw}=cnw^{n-1}\" width=\"235.33\" height=\"52.70\" style=\"width:235.33px;height:52.70px;aspect-ratio:235.33/52.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Power neeche multiply; exponent ek kam; constant ka zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the function itself.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/625a082643eb2a43.svg\" alt=\"J(-1)=2(-1)^1+4=2\" width=\"258.30\" height=\"27.70\" style=\"width:258.30px;height:27.70px;aspect-ratio:258.30/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate symbolically.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/091a2e97f7d74170.svg\" alt=\"J\\prime(w)=2(1)w^{1-1}+0\" width=\"227.05\" height=\"27.70\" style=\"width:227.05px;height:27.70px;aspect-ratio:227.05/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: put the given w into the derivative.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d63d0415964167b7.svg\" alt=\"J\\prime(-1)=2(1)(-1)^{0}=2\" width=\"254.16\" height=\"27.70\" style=\"width:254.16px;height:27.70px;aspect-ratio:254.16/27.70\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> J = 2; derivative = 2.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s3","search":"Derivatives without a calculus course **Definition.** A derivative measures the local rate of change of a function. A partial derivative varies one argument while holding the others fixed. The gradient of a scalar-valued function collects its partial derivatives into a vector.\n\nThe rules needed for the supplied neural-network numericals are:\n\n| Function or operation | Derivative |\n| Constant c | 0 |\n| xⁿ | nxⁿ⁻¹ |\n| c f(x) | c f′(x) |\n| f(x) + g(x) | f′(x) + g′(x) |\n| f(x)g(x) | f′(x)g(x) + f(x)g′(x) |\n| eˣ | eˣ |\n| ln x, x > 0 | 1/x |\n| f(g(x)) | f′(g(x))g′(x) |\n\n### A parameter derivative is not an input derivative\nFor z = wx + b, the variable named in the denominator determines which derivative is required.\n\nAt x = 2, w = 3 and b = 1, z = 7, but the three derivatives are 2, 3 and 1 respectively. A function value and its derivative are distinct quantities.\n\n### Gradient direction\nFor a small parameter displacement Δθ, first-order Taylor expansion gives:\n\nThe gradient points in the direction of greatest local increase under the Euclidean norm. Choosing Δθ opposite to the gradient gives a local descent direction. This is the mathematical basis of gradient descent; a finite step can still overshoot if the learning rate is too large.\n\n\n\n### Differentiate before substituting: 3w^2+5\n\n**Question. Let J(w) = 3w^2+5. At w = 2, find J and dJ/dw.**\n\n\n\n### Given\n\nJ(w) = 3w^2+5; w = 2.\n\n### To find\n\nThe function value and its derivative value.\n\n### Formula — which one and why\n\nThe power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.\n\nc is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.\n\n\n\n**Yaad rakhne ka cue:** Power neeche multiply; exponent ek kam; constant ka zero.\n\n### Solution — step by step\n\n\n\n**Step 1: evaluate the function itself.**\n\n\n\n\n\n\n\n**Step 2: differentiate symbolically.**\n\n\n\n\n\n\n\n**Step 3: put the given w into the derivative.**\n\n\n\n\n\n\n\n**Final answer:** J = 17; derivative = 12.\n\n\n\n### Differentiate before substituting: 0.7w^3+0\n\n**Question. Let J(w) = 0.7w^3+0. At w = 1, find J and dJ/dw.**\n\n\n\n### Given\n\nJ(w) = 0.7w^3+0; w = 1.\n\n### To find\n\nThe function value and its derivative value.\n\n### Formula — which one and why\n\nThe power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.\n\nc is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.\n\n\n\n**Yaad rakhne ka cue:** Power neeche multiply; exponent ek kam; constant ka zero.\n\n### Solution — step by step\n\n\n\n**Step 1: evaluate the function itself.**\n\n\n\n\n\n\n\n**Step 2: differentiate symbolically.**\n\n\n\n\n\n\n\n**Step 3: put the given w into the derivative.**\n\n\n\n\n\n\n\n**Final answer:** J = 0.7; derivative = 2.1.\n\n\n\n### Differentiate before substituting: 2w^1+4\n\n**Question. Let J(w) = 2w^1+4. At w = -1, find J and dJ/dw.**\n\n\n\n### Given\n\nJ(w) = 2w^1+4; w = -1.\n\n### To find\n\nThe function value and its derivative value.\n\n### Formula — which one and why\n\nThe power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.\n\nc is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.\n\n\n\n**Yaad rakhne ka cue:** Power neeche multiply; exponent ek kam; constant ka zero.\n\n### Solution — step by step\n\n\n\n**Step 1: evaluate the function itself.**\n\n\n\n\n\n\n\n**Step 2: differentiate symbolically.**\n\n\n\n\n\n\n\n**S"},{"title":"Derivatives: from an ordinary change to a local slope","blocks":["<h3>1. Function value and change are different numbers</h3>","<p>Let L(w) = w². At w = 3, loss is 9. If we increase w to 4, loss becomes 16. The loss change is 16 − 9 = 7 and the weight change is 4 − 3 = 1. Their ratio is 7. This is an average slope over a whole interval.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_slope_limit.svg\" aria-label=\"Enlarge diagram: Start at weight 3 each time. As the increase becomes smaller, the slope estimate approaches 6.\"><img src=\"assets/figures/v_slope_limit.svg\" alt=\"Start at weight 3 each time. As the increase becomes smaller, the slope estimate approaches 6.\" width=\"1080\" height=\"630\" loading=\"lazy\"></button><figcaption>Start at weight 3 each time. As the increase becomes smaller, the slope estimate approaches 6. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:301.28px;--narrow-height:94.37px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ddbf51217582c207.svg\"><img class=\"math display-math\" src=\"assets/equations/e5eede05db6e20c3.svg\" alt=\"\\text{average slope}=\\frac{\\text{new loss}-\\text{old loss}}{\\text{new weight}-\\text{old weight}}\" width=\"441.29\" height=\"55.27\" style=\"width:441.29px;height:55.27px;aspect-ratio:441.29/55.27\" loading=\"lazy\"></picture></div>","<h3>2. Shrink the interval</h3>","<p>For the same starting weight 3, use an increase of 0.1. The new weight is 3.1 and its square is 9.61. The slope estimate is (9.61 − 9)/0.1 = 6.1. With an increase of 0.01, it is (9.0601 − 9)/0.01 = 6.01. Smaller intervals approach 6.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Increase in w</th><th>New w</th><th>New loss w²</th><th>Change in loss</th><th>Change ratio</th></tr></thead><tbody><tr><td>1</td><td>4</td><td>16</td><td>7</td><td>7</td></tr><tr><td>0.1</td><td>3.1</td><td>9.61</td><td>0.61</td><td>6.1</td></tr><tr><td>0.01</td><td>3.01</td><td>9.0601</td><td>0.0601</td><td>6.01</td></tr></tbody></table></div>","<p>The derivative is the limiting local slope as that interval approaches zero. We do not substitute a literal zero into a division by the interval.</p>","<h3>3. Why the square has derivative 2w</h3>","<p>Call a small nonzero change Δw, read “delta w”. Expanding the new square gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.82px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4e8dd2d8556610b9.svg\"><img class=\"math display-math\" src=\"assets/equations/4203633eb5975d8b.svg\" alt=\"(w+\\Delta w)^2=w^2+2w\\Delta w+(\\Delta w)^2\" width=\"370.46\" height=\"27.70\" style=\"width:370.46px;height:27.70px;aspect-ratio:370.46/27.70\" loading=\"lazy\"></picture></div>","<p>Subtract the old square w² and divide by the change Δw:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.97px;--narrow-height:93.85px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1e547bc2dd023797.svg\"><img class=\"math display-math\" src=\"assets/equations/b33822670f9d55b8.svg\" alt=\"\\frac{(w+\\Delta w)^2-w^2}{\\Delta w}=2w+\\Delta w\" width=\"313.69\" height=\"54.76\" style=\"width:313.69px;height:54.76px;aspect-ratio:313.69/54.76\" loading=\"lazy\"></picture></div>","<p>As Δw approaches zero, this approaches 2w. That is the origin of the rule d(w²)/dw = 2w. At w = 3 it gives 6, matching the table&#x27;s trend.</p>","<h3>4. Reading derivative notation</h3>","<p>In dL/dw, the top names the quantity whose response we study, and the bottom names what we vary. Read it as “the derivative of L with respect to w”. The notation is not asking you to divide the current loss 9 by the current weight 3; that would give 3 and answer a different question.</p>","<p>For a function of several variables, ∂L/∂w is a partial derivative: change w while holding the other independent variables fixed. The gradient groups those partial derivatives for all parameters.</p>","<h3>5. Why subtract the gradient?</h3>","<p>If the derivative is positive, increasing w locally increases loss, so we try a small decrease. If it is negative, increasing w locally decreases loss, so we try a small increase. The subtraction in gradient descent automatically handles both signs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p>This is local information. A very large step can cross a minimum and make loss worse. The learning rate η keeps control of the step; the derivative does not promise that any step size is safe.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s4","search":"Derivatives: from an ordinary change to a local slope ### 1. Function value and change are different numbers\nLet L(w) = w². At w = 3, loss is 9. If we increase w to 4, loss becomes 16. The loss change is 16 − 9 = 7 and the weight change is 4 − 3 = 1. Their ratio is 7. This is an average slope over a whole interval.\n\n\n\n\n### 2. Shrink the interval\nFor the same starting weight 3, use an increase of 0.1. The new weight is 3.1 and its square is 9.61. The slope estimate is (9.61 − 9)/0.1 = 6.1. With an increase of 0.01, it is (9.0601 − 9)/0.01 = 6.01. Smaller intervals approach 6.\n| Increase in w | New w | New loss w² | Change in loss | Change ratio |\n| 1 | 4 | 16 | 7 | 7 |\n| 0.1 | 3.1 | 9.61 | 0.61 | 6.1 |\n| 0.01 | 3.01 | 9.0601 | 0.0601 | 6.01 |\nThe derivative is the limiting local slope as that interval approaches zero. We do not substitute a literal zero into a division by the interval.\n\n### 3. Why the square has derivative 2w\nCall a small nonzero change Δw, read “delta w”. Expanding the new square gives:\n\nSubtract the old square w² and divide by the change Δw:\n\nAs Δw approaches zero, this approaches 2w. That is the origin of the rule d(w²)/dw = 2w. At w = 3 it gives 6, matching the table's trend.\n\n### 4. Reading derivative notation\nIn dL/dw, the top names the quantity whose response we study, and the bottom names what we vary. Read it as “the derivative of L with respect to w”. The notation is not asking you to divide the current loss 9 by the current weight 3; that would give 3 and answer a different question.\nFor a function of several variables, ∂L/∂w is a partial derivative: change w while holding the other independent variables fixed. The gradient groups those partial derivatives for all parameters.\n\n### 5. Why subtract the gradient?\nIf the derivative is positive, increasing w locally increases loss, so we try a small decrease. If it is negative, increasing w locally decreases loss, so we try a small increase. The subtraction in gradient descent automatically handles both signs.\n\nThis is local information. A very large step can cross a minimum and make loss worse. The learning rate η keeps control of the step; the derivative does not promise that any step size is safe.\n"},{"title":"Partial derivatives hold other things still","blocks":["<p>For z = wx + b, the derivative with respect to w is x, because x is held fixed. The derivative with respect to b is 1. The derivative with respect to x is w. This is the entire local maths of a neuron’s weighted sum.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_partial.svg\" aria-label=\"Enlarge diagram: Choose one changing parameter. Everything else is held fixed while you find its effect.\"><img src=\"assets/figures/v_partial.svg\" alt=\"Choose one changing parameter. Everything else is held fixed while you find its effect.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Choose one changing parameter. Everything else is held fixed while you find its effect. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:95.43px;--narrow-height:183.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6437deea893fce68.svg\"><img class=\"math display-math\" src=\"assets/equations/d1922f2b91d23e75.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x,\\qquad \\frac{\\partial z}{\\partial b}=1,\\qquad \\frac{\\partial z}{\\partial x}=w\" width=\"377.48\" height=\"51.29\" style=\"width:377.48px;height:51.29px;aspect-ratio:377.48/51.29\" loading=\"lazy\"></picture></div>","<p class=\"inline-question\"><strong>Question: </strong> z = 3w + b, w = 2, b = 1. Find z, ∂z/∂w and ∂z/∂b.</p>","<h3>Given</h3>","<p>z = 3w+b; w = 2; b = 1.</p>","<h3>To find</h3>","<p>Find z, ∂z/∂w and ∂z/∂b.</p>","<h3>Formula — which one and why</h3>","<p><strong>Partial derivatives.</strong> Differentiate only with respect to the named variable; all other independent inputs and parameters remain fixed.</p>","<p>∂z/∂w reads “rate of change of z when w changes”. For z = wx+b, x is the coefficient of w, while b has coefficient 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c448c09e6087f1d5.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x\" width=\"88.64\" height=\"51.29\" style=\"width:88.64px;height:51.29px;aspect-ratio:88.64/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d2edf1641e728713.svg\" alt=\"\\frac{\\partial z}{\\partial b}=1\" width=\"80.74\" height=\"51.29\" style=\"width:80.74px;height:51.29px;aspect-ratio:80.74/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Neeche jis letter ka naam hai, sirf usko change samjho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the function value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c86ffb173c8d136d.svg\" alt=\"z=3(2)+1=6+1=7\" width=\"261.17\" height=\"24.43\" style=\"width:261.17px;height:24.43px;aspect-ratio:261.17/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate with respect to w while b is fixed.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3ab15e4d1d60b4eb.svg\" alt=\"\\frac{\\partial z}{\\partial w}=3+0=3\" width=\"173.76\" height=\"51.29\" style=\"width:173.76px;height:51.29px;aspect-ratio:173.76/51.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: differentiate with respect to b while w is fixed.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/edaff0abc794c10d.svg\" alt=\"\\frac{\\partial z}{\\partial b}=0+1=1\" width=\"167.64\" height=\"51.29\" style=\"width:167.64px;height:51.29px;aspect-ratio:167.64/51.29\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 7; weight derivative = 3; bias derivative = 1. A function value and its rate of change are different quantities.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s5","search":"Partial derivatives hold other things still For z = wx + b, the derivative with respect to w is x, because x is held fixed. The derivative with respect to b is 1. The derivative with respect to x is w. This is the entire local maths of a neuron’s weighted sum.\n\n\n\n\n**Question: ** z = 3w + b, w = 2, b = 1. Find z, ∂z/∂w and ∂z/∂b.\n\n\n\n### Given\n\nz = 3w+b; w = 2; b = 1.\n\n### To find\n\nFind z, ∂z/∂w and ∂z/∂b.\n\n### Formula — which one and why\n\n**Partial derivatives.** Differentiate only with respect to the named variable; all other independent inputs and parameters remain fixed.\n\n∂z/∂w reads “rate of change of z when w changes”. For z = wx+b, x is the coefficient of w, while b has coefficient 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Neeche jis letter ka naam hai, sirf usko change samjho.\n\n### Solution — step by step\n\n\n\n\n**Step 1: calculate the function value.**\n\n\n\n\n\n\n\n**Step 2: differentiate with respect to w while b is fixed.**\n\n\n\n\n\n\n\n**Step 3: differentiate with respect to b while w is fixed.**\n\n\n\n\n\n\n\n**Final answer:** z = 7; weight derivative = 3; bias derivative = 1. A function value and its rate of change are different quantities."},{"title":"The chain rule is multiplying linked effects","blocks":["<p class=\"definition\"><strong>Definition.</strong> The chain rule finds a rate of change when one quantity depends on another through intermediate calculations. Multiply the local rates along one path. If several paths connect the same starting quantity to the final answer, add their complete contributions.</p>","<h3>First understand why the rates multiply</h3>","<p>Suppose w controls u and u controls v. If each one-unit change in w makes u change by 3 units, and each one-unit change in u makes v change by 2 units, the combined rate is 3 × 2 = 6. Adding 3+2 would describe neither dependency.</p>","<p>The notation du/dw reads “the rate at which u changes when w changes”. A partial derivative ∂L/∂w means the same kind of rate while other independent parameters are held fixed. It is not ordinary division of the values L and w.</p>","<p><strong>Yaad rakhne ka cue:</strong> ek raaste par slopes multiply; alag raaston ke full answers add.</p>","<h3>Chain-rule example 1: two linear links</h3>","<p class=\"inline-question\"><strong>Question. Let u = 3w+1 and v = 2u. At w = 1, find u, v and dv/dw.</strong></p>","<h3>Given</h3>","<p>w = 1; u = 3w+1; v = 2u.</p>","<h3>To find</h3>","<p>The two function values and the rate dv/dw.</p>","<h3>Formula — which one and why</h3>","<p>v depends on w through u. Both links must be included, so multiply the two local derivatives.</p>","<p>du/dw is the slope of 3w+1. dv/du is the slope of 2u.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17086b5a41fb1edf.svg\" alt=\"\\frac{dv}{dw}=\\frac{dv}{du}\\frac{du}{dw}\" width=\"151.92\" height=\"50.50\" style=\"width:151.92px;height:50.50px;aspect-ratio:151.92/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Andar ka slope × bahar ka slope.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the intermediate value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b14c00d5dab41947.svg\" alt=\"u=3(1)+1=4\" width=\"176.89\" height=\"24.43\" style=\"width:176.89px;height:24.43px;aspect-ratio:176.89/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the final value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/396fa5f1dfbfd157.svg\" alt=\"v=2(4)=8\" width=\"132.68\" height=\"24.43\" style=\"width:132.68px;height:24.43px;aspect-ratio:132.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: differentiate the first link.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1379a65c2b33abc7.svg\" alt=\"\\frac{du}{dw}=3\" width=\"85.75\" height=\"50.50\" style=\"width:85.75px;height:50.50px;aspect-ratio:85.75/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: differentiate the second link.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0af363fd8a85c3ab.svg\" alt=\"\\frac{dv}{du}=2\" width=\"82.23\" height=\"50.50\" style=\"width:82.23px;height:50.50px;aspect-ratio:82.23/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: multiply along the path.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/746afadc90e4f6c9.svg\" alt=\"\\frac{dv}{dw}=2(3)=6\" width=\"161.78\" height=\"50.50\" style=\"width:161.78px;height:50.50px;aspect-ratio:161.78/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> u = 4, v = 8 and dv/dw = 6. The function value 8 and its rate 6 are different.</p>","<h3>2. One output: calculate both parameter gradients</h3>","<p class=\"inline-question\"><strong>Question.</strong> A linear neuron has z = wx + b and half squared loss L = ½(z − y)². Given x = 2, y = 4, w = 1 and b = 0, obtain both parameter gradients and perform one gradient-descent update with η = 0.1.</p>","<h3>Given</h3>","<p>Input x = 2; target y = 4.</p>","<p>Old weight w = 1; old bias b = 0.</p>","<p>Linear prediction z = wx+b; loss L = ½(z−y)².</p>","<p>Learning rate η = 0.1; update both parameters once.</p>","<h3>To find</h3>","<p>Find the loss gradient for w and for b, then w_new and b_new. Finally evaluate the changed prediction and loss.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule for a linear neuron.</strong> The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.</p>","<p>z = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/00f49c1127dda70e.svg\" alt=\"z=wx+b\" width=\"115.77\" height=\"18.96\" style=\"width:115.77px;height:18.96px;aspect-ratio:115.77/18.96\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f50d7e1cde6462d5.svg\" alt=\"L=\\frac12(z-y)^2\" width=\"155.08\" height=\"49.55\" style=\"width:155.08px;height:49.55px;aspect-ratio:155.08/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/955c63d58ce8cb9b.svg\" alt=\"g_w=\\frac{\\partial L}{\\partial w}=(z-y)x\" width=\"219.49\" height=\"51.29\" style=\"width:219.49px;height:51.29px;aspect-ratio:219.49/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a5a6192e644e19b.svg\" alt=\"g_b=\\frac{\\partial L}{\\partial b}=z-y\" width=\"180.69\" height=\"51.29\" style=\"width:180.69px;height:51.29px;aspect-ratio:180.69/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33df8d5a70c57c14.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_w\" width=\"167.42\" height=\"19.53\" style=\"width:167.42px;height:19.53px;aspect-ratio:167.42/19.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c2843cb0410cd77b.svg\" alt=\"b_{\\mathrm{new}}=b-\\eta g_b\" width=\"148.44\" height=\"22.24\" style=\"width:148.44px;height:22.24px;aspect-ratio:148.44/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek path mein multiply; alag paths mil rahe hon toh add.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/chain_linear_revision.svg\" aria-label=\"Enlarge diagram: The forward values are z = 2, error = −2 and loss = 2. The backward loss derivative is −2; multiply it by x = 2 for the weight gradient and by 1 for the bias gradient.\"><img src=\"assets/figures/chain_linear_revision.svg\" alt=\"The forward values are z = 2, error = −2 and loss = 2. The backward loss derivative is −2; multiply it by x = 2 for the weight gradient and by 1 for the bias gradient.\" width=\"720\" height=\"635\" loading=\"lazy\"></button><figcaption>The forward values are z = 2, error = −2 and loss = 2. The backward loss derivative is −2; multiply it by x = 2 for the weight gradient and by 1 for the bias gradient. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 — evaluate the original model.</strong> Use the given parameters before applying any update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73aa46b2ed8f2b55.svg\" alt=\"z=wx+b=1(2)+0=2\" width=\"278.68\" height=\"24.43\" style=\"width:278.68px;height:24.43px;aspect-ratio:278.68/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef2733b3de84bfed.svg\" alt=\"e=z-y=2-4=-2\" width=\"247.87\" height=\"21.55\" style=\"width:247.87px;height:21.55px;aspect-ratio:247.87/21.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7adb597b6b18fec3.svg\" alt=\"L=\\frac12e^2=\\frac12(-2)^2=2\" width=\"255.51\" height=\"49.55\" style=\"width:255.51px;height:49.55px;aspect-ratio:255.51/49.55\" loading=\"lazy\"></div>","<figure class=\"learning-visual lv-linear-forward\" data-visual=\"linear-forward\"><figcaption class=\"lv-title\">Forward pass: three distinct quantities</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Prediction z</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">1 × 2 + 0</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Error e</span><strong class=\"lv-value\">−2</strong><span class=\"lv-detail\">Prediction 2 − target 4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Half squared loss</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">½ × (−2)²</span></div></div></figure>","<p>The prediction is 2, the signed error is −2 and the loss is 2. These are three different quantities, even when some numerical values happen to coincide.</p>","<p class=\"worked-step\"><strong>Step 2 — differentiate the loss, keeping the target constant.</strong> First differentiate the square, then the error inside it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba371707e98b2bc9.svg\" alt=\"\\frac{\\partial L}{\\partial e}=\\frac12(2e)=e\" width=\"183.36\" height=\"51.29\" style=\"width:183.36px;height:51.29px;aspect-ratio:183.36/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66db443def7ab596.svg\" alt=\"\\frac{\\partial e}{\\partial z}=\\frac{\\partial(z-y)}{\\partial z}=1\" width=\"210.15\" height=\"52.97\" style=\"width:210.15px;height:52.97px;aspect-ratio:210.15/52.97\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e9802e836c671214.svg\" alt=\"\\delta_z=\\frac{\\partial L}{\\partial z}=e(1)=-2\" width=\"233.72\" height=\"51.29\" style=\"width:233.72px;height:51.29px;aspect-ratio:233.72/51.29\" loading=\"lazy\"></div>","<p>The symbol δ (delta) is a convenient name for the derivative with respect to a neuron&#x27;s preactivation. Delta is not automatically the weight gradient; the weight gradient also depends on the input to that connection.</p>","<p class=\"worked-step\"><strong>Step 3 — differentiate the neuron&#x27;s affine expression.</strong> When differentiating with respect to w, x is a constant coefficient. When differentiating with respect to b, the coefficient of b is 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6badd88b171bea97.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x=2\" width=\"133.43\" height=\"51.29\" style=\"width:133.43px;height:51.29px;aspect-ratio:133.43/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d2edf1641e728713.svg\" alt=\"\\frac{\\partial z}{\\partial b}=1\" width=\"80.74\" height=\"51.29\" style=\"width:80.74px;height:51.29px;aspect-ratio:80.74/51.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4 — multiply along each parameter&#x27;s path.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.29px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b51cdfbc8d705d9a.svg\"><img class=\"math display-math\" src=\"assets/equations/b65d42a6fa860d4a.svg\" alt=\"g_w=\\frac{\\partial L}{\\partial w}=\\delta_z\\frac{\\partial z}{\\partial w}=(-2)(2)=-4\" width=\"374.14\" height=\"51.29\" style=\"width:374.14px;height:51.29px;aspect-ratio:374.14/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:184.33px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a2c0a4ed56c043f.svg\"><img class=\"math display-math\" src=\"assets/equations/f357d7ca8a5a76dc.svg\" alt=\"g_b=\\frac{\\partial L}{\\partial b}=\\delta_z\\frac{\\partial z}{\\partial b}=(-2)(1)=-2\" width=\"362.20\" height=\"51.29\" style=\"width:362.20px;height:51.29px;aspect-ratio:362.20/51.29\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-linear-backward\" data-visual=\"linear-backward\"><figcaption class=\"lv-title\">Backward pass: a separate derivative for each parameter</figcaption><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Shared loss derivative δz</span><strong class=\"lv-value\">−2</strong><span class=\"lv-detail\">Both parameter paths start here.</span></div><div class=\"lv-branch-pair\"><div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weight path: multiply by x = 2</span><strong class=\"lv-value\">−4</strong><span class=\"lv-detail\">∂L/∂w = (−2) × 2</span></div></div><div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias path: multiply by 1</span><strong class=\"lv-value\">−2</strong><span class=\"lv-detail\">∂L/∂b = (−2) × 1</span></div></div></div></figure>","<p>Both derivatives use the original forward-pass values. The weight and bias are different parameters, so keep their gradients separate.</p>","<p class=\"worked-step\"><strong>Step 5 — update both parameters simultaneously.</strong> Gradient descent subtracts the learning rate times the corresponding gradient.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8330219a13690888.svg\"><img class=\"math display-math\" src=\"assets/equations/cb9c6fe7ef91a2db.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_w=1-0.1(-4)=1.4\" width=\"387.37\" height=\"24.43\" style=\"width:387.37px;height:24.43px;aspect-ratio:387.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.24px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d5507ad8ee01624d.svg\"><img class=\"math display-math\" src=\"assets/equations/8186eb873e399f7a.svg\" alt=\"b_{\\mathrm{new}}=b-\\eta g_b=0-0.1(-2)=0.2\" width=\"368.39\" height=\"24.43\" style=\"width:368.39px;height:24.43px;aspect-ratio:368.39/24.43\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-linear-update\" data-visual=\"linear-update\"><figcaption class=\"lv-title\">One simultaneous parameter update</figcaption><div class=\"lv-branch-pair\"><div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weight</span><strong class=\"lv-value\">1 → 1.4</strong><span class=\"lv-detail\">Subtract 0.1 × (−4)</span></div></div><div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias</span><strong class=\"lv-value\">0 → 0.2</strong><span class=\"lv-detail\">Subtract 0.1 × (−2)</span></div></div></div><p class=\"lv-caption\">Both updates use gradients from the same original forward pass. Re-evaluate the model afterward.</p></figure>","<p>Subtracting a negative gradient increases the parameter. Do not recompute the bias gradient using the already changed weight; that would be a different update procedure.</p>","<p class=\"worked-step\"><strong>Step 6 — perform a new forward pass to evaluate the update.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f27e43a3756292cb.svg\" alt=\"z_{\\mathrm{new}}=1.4(2)+0.2=3\" width=\"244.08\" height=\"24.43\" style=\"width:244.08px;height:24.43px;aspect-ratio:244.08/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1762c7935645936f.svg\" alt=\"L_{\\mathrm{new}}=\\frac12(3-4)^2=0.5\" width=\"251.77\" height=\"49.55\" style=\"width:251.77px;height:49.55px;aspect-ratio:251.77/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> weight gradient −4, bias gradient −2; updated weight 1.4 and bias 0.2; new prediction 3 and loss 0.5. If a different question fixes the bias at zero, update only the weight; its new prediction would be 2.8, not 3.</p>","<h3>3. Two outputs: why backward contributions are added</h3>","<p>A shared intermediate value can influence more than one output. The derivative with respect to that shared value must include every output path. Adding paths happens before passing the accumulated derivative further backward.</p>","<p class=\"inline-question\"><strong>Question.</strong> A shared linear hidden value is h = wx + b. Two linear outputs are o₁ = 2h and o₂ = −h; their targets are y₁ = 1 and y₂ = 0. The total loss is L = ½(o₁ − y₁)² + ½(o₂ − y₂)². At x = 2, w = 0.5 and b = 0.1, calculate the loss and the gradients with respect to h, w and b. Treat the output multipliers 2 and −1 as fixed.</p>","<h3>Given</h3>","<p>h = wx+b; outputs o₁ = 2h and o₂ = −h.</p>","<p>x = 2; w = 0.5; b = 0.1; targets = [1,0].</p>","<p>Loss = half the sum of the two squared output errors.</p>","<p>Output multipliers 2 and −1 stay fixed.</p>","<h3>To find</h3>","<p>Find total loss and its derivatives with respect to h, w and b.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule with more than one path.</strong> The shared hidden value affects each output. Multiply derivatives within each path, then add the complete path contributions before continuing to w and b.</p>","<p>oⱼ = output j; yⱼ = its target; h = shared hidden value; ∂oⱼ/∂h is the multiplier on that output path.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e472e733a927b24.svg\" alt=\"\\frac{\\partial L}{\\partial h}=\\sum_j(o_j-y_j)\\frac{\\partial o_j}{\\partial h}\" width=\"245.67\" height=\"68.36\" style=\"width:245.67px;height:68.36px;aspect-ratio:245.67/68.36\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/19ebe8d0b832533d.svg\" alt=\"\\frac{\\partial L}{\\partial w}=\\frac{\\partial L}{\\partial h}x\" width=\"129.86\" height=\"51.29\" style=\"width:129.86px;height:51.29px;aspect-ratio:129.86/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44f3dd28940be744.svg\" alt=\"\\frac{\\partial L}{\\partial b}=\\frac{\\partial L}{\\partial h}\" width=\"115.03\" height=\"51.29\" style=\"width:115.03px;height:51.29px;aspect-ratio:115.03/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har raaste ka effect pehle multiply, junction par sab add.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/chain_branch_revision.svg\" aria-label=\"Enlarge diagram: The shared hidden value affects both losses. The first path contributes 2.4 and the second contributes 1.1, giving a combined derivative of 3.5 before continuing to the weight and bias.\"><img src=\"assets/figures/chain_branch_revision.svg\" alt=\"The shared hidden value affects both losses. The first path contributes 2.4 and the second contributes 1.1, giving a combined derivative of 3.5 before continuing to the weight and bias.\" width=\"720\" height=\"705\" loading=\"lazy\"></button><figcaption>The shared hidden value affects both losses. The first path contributes 2.4 and the second contributes 1.1, giving a combined derivative of 3.5 before continuing to the weight and bias. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 — forward values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c54d1626a0bf10fc.svg\" alt=\"h=0.5(2)+0.1=1.1\" width=\"234.03\" height=\"24.43\" style=\"width:234.03px;height:24.43px;aspect-ratio:234.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.17px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/efc23fa7e963abec.svg\"><img class=\"math display-math\" src=\"assets/equations/a05e20f353481e0c.svg\" alt=\"o_1=2(1.1)=2.2,\\qquad o_2=-(1.1)=-1.1\" width=\"448.28\" height=\"24.43\" style=\"width:448.28px;height:24.43px;aspect-ratio:448.28/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9cca9af1e961da75.svg\" alt=\"L_1=\\frac12(2.2-1)^2=0.72\" width=\"261.88\" height=\"49.55\" style=\"width:261.88px;height:49.55px;aspect-ratio:261.88/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.87px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31043c1e17e75c9f.svg\"><img class=\"math display-math\" src=\"assets/equations/6fa32649e91893bc.svg\" alt=\"L_2=\\frac12(-1.1-0)^2=0.605\" width=\"293.11\" height=\"49.55\" style=\"width:293.11px;height:49.55px;aspect-ratio:293.11/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.74px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/115053bc42452eb3.svg\"><img class=\"math display-math\" src=\"assets/equations/6adf6f563023ced5.svg\" alt=\"L=L_1+L_2=0.72+0.605=1.325\" width=\"383.52\" height=\"20.36\" style=\"width:383.52px;height:20.36px;aspect-ratio:383.52/20.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 — output derivatives.</strong> Each half squared loss differentiates to prediction minus target. The other loss does not depend on this output.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.53px;--narrow-height:93.51px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0cee4ce79f255618.svg\"><img class=\"math display-math\" src=\"assets/equations/cf26e13f912b7730.svg\" alt=\"\\frac{\\partial L}{\\partial o_1}=o_1-y_1=2.2-1=1.2\" width=\"324.42\" height=\"54.41\" style=\"width:324.42px;height:54.41px;aspect-ratio:324.42/54.41\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.54px;--narrow-height:93.51px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1551245d19941245.svg\"><img class=\"math display-math\" src=\"assets/equations/c2e5f710a0148c3f.svg\" alt=\"\\frac{\\partial L}{\\partial o_2}=o_2-y_2=-1.1-0=-1.1\" width=\"362.44\" height=\"54.41\" style=\"width:362.44px;height:54.41px;aspect-ratio:362.44/54.41\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3 — calculate the contribution of each complete path.</strong> The derivative of 2h with respect to h is 2; the derivative of −h is −1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b03138eedef68e56.svg\" alt=\"\\frac{\\partial L_1}{\\partial h}=(1.2)(2)=2.4\" width=\"229.75\" height=\"51.29\" style=\"width:229.75px;height:51.29px;aspect-ratio:229.75/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74549258b69e068b.svg\" alt=\"\\frac{\\partial L_2}{\\partial h}=(-1.1)(-1)=1.1\" width=\"267.76\" height=\"51.29\" style=\"width:267.76px;height:51.29px;aspect-ratio:267.76/51.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4 — add the two contributions at the shared hidden value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4fb627a77ae8284.svg\" alt=\"\\frac{\\partial L}{\\partial h}=\\frac{\\partial L_1}{\\partial h}+\\frac{\\partial L_2}{\\partial h}\" width=\"207.45\" height=\"51.29\" style=\"width:207.45px;height:51.29px;aspect-ratio:207.45/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61ff2149ac92a571.svg\" alt=\"\\frac{\\partial L}{\\partial h}=2.4+1.1=3.5\" width=\"229.94\" height=\"51.29\" style=\"width:229.94px;height:51.29px;aspect-ratio:229.94/51.29\" loading=\"lazy\"></div>","<p>Adding the raw output errors, 1.2 + (−1.1), would omit the output multipliers. Each error must first be multiplied by the local derivative on its own path.</p>","<p class=\"worked-step\"><strong>Step 5 — continue to the hidden weight and bias.</strong> Since h = wx + b, its derivatives with respect to w and b are x and 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/54071389e64f7570.svg\" alt=\"\\frac{\\partial L}{\\partial w}=\\frac{\\partial L}{\\partial h}x=3.5(2)=7\" width=\"269.70\" height=\"51.29\" style=\"width:269.70px;height:51.29px;aspect-ratio:269.70/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/327ca2cf6e5be3c3.svg\" alt=\"\\frac{\\partial L}{\\partial b}=\\frac{\\partial L}{\\partial h}(1)=3.5\" width=\"210.06\" height=\"51.29\" style=\"width:210.06px;height:51.29px;aspect-ratio:210.06/51.29\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> L = 1.325, ∂L/∂h = 3.5, ∂L/∂w = 7 and ∂L/∂b = 3.5. If the hidden value instead includes a nonlinear activation, multiply the accumulated downstream derivative by that activation&#x27;s derivative before multiplying by x. This is the hidden-delta calculation in multilayer backpropagation.</p>","<h3>Chain-rule example 4: a square after a linear link</h3>","<p class=\"inline-question\"><strong>Question. Let z = 3w+1 and L = z². At w = 1, find z, L and dL/dw.</strong></p>","<h3>Given</h3>","<p>w = 1; z = 3w+1; L = z².</p>","<h3>To find</h3>","<p>z, L and the derivative of L with respect to w.</p>","<h3>Formula — which one and why</h3>","<p>The square acts on z, not directly on w. Differentiate the square first and include the change of z with w.</p>","<p>dL/dz = slope of the outer square; dz/dw = slope of the inner linear expression.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/434e48fc84f871b4.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}\" width=\"154.58\" height=\"50.50\" style=\"width:154.58px;height:50.50px;aspect-ratio:154.58/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33825b3d129b23da.svg\" alt=\"\\frac{d(z^2)}{dz}=2z\" width=\"120.66\" height=\"54.76\" style=\"width:120.66px;height:54.76px;aspect-ratio:120.66/54.76\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square ka 2z; andar ka 3; dono multiply.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the inner expression.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8a300d26d67e84f4.svg\" alt=\"z=3(1)+1=4\" width=\"174.28\" height=\"24.43\" style=\"width:174.28px;height:24.43px;aspect-ratio:174.28/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the loss expression.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e7a8c4341fdaf1f8.svg\" alt=\"L=4^2=16\" width=\"129.12\" height=\"23.60\" style=\"width:129.12px;height:23.60px;aspect-ratio:129.12/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: differentiate the square and use z = 4.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3a7684d15448f2e4.svg\" alt=\"\\frac{dL}{dz}=2z=2(4)=8\" width=\"217.09\" height=\"50.50\" style=\"width:217.09px;height:50.50px;aspect-ratio:217.09/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: differentiate the inner expression.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbe8fc0fd6788a9a.svg\" alt=\"\\frac{dz}{dw}=3\" width=\"85.75\" height=\"50.50\" style=\"width:85.75px;height:50.50px;aspect-ratio:85.75/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: multiply, because the changes occur in sequence.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90d0d059a0fe1d53.svg\" alt=\"\\frac{dL}{dw}=8(3)=24\" width=\"174.00\" height=\"50.50\" style=\"width:174.00px;height:50.50px;aspect-ratio:174.00/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 4, L = 16 and dL/dw = 24. The combined operation is multiplication, not 8+3.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s6","search":"The chain rule is multiplying linked effects **Definition.** The chain rule finds a rate of change when one quantity depends on another through intermediate calculations. Multiply the local rates along one path. If several paths connect the same starting quantity to the final answer, add their complete contributions.\n\n### First understand why the rates multiply\nSuppose w controls u and u controls v. If each one-unit change in w makes u change by 3 units, and each one-unit change in u makes v change by 2 units, the combined rate is 3 × 2 = 6. Adding 3+2 would describe neither dependency.\n\nThe notation du/dw reads “the rate at which u changes when w changes”. A partial derivative ∂L/∂w means the same kind of rate while other independent parameters are held fixed. It is not ordinary division of the values L and w.\n\n**Yaad rakhne ka cue:** ek raaste par slopes multiply; alag raaston ke full answers add.\n\n\n### Chain-rule example 1: two linear links\n\n**Question. Let u = 3w+1 and v = 2u. At w = 1, find u, v and dv/dw.**\n\n\n\n### Given\n\nw = 1; u = 3w+1; v = 2u.\n\n### To find\n\nThe two function values and the rate dv/dw.\n\n### Formula — which one and why\n\nv depends on w through u. Both links must be included, so multiply the two local derivatives.\n\ndu/dw is the slope of 3w+1. dv/du is the slope of 2u.\n\n\n\n**Yaad rakhne ka cue:** Andar ka slope × bahar ka slope.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the intermediate value.**\n\n\n\n\n\n\n\n**Step 2: calculate the final value.**\n\n\n\n\n\n\n\n**Step 3: differentiate the first link.**\n\n\n\n\n\n\n\n**Step 4: differentiate the second link.**\n\n\n\n\n\n\n\n**Step 5: multiply along the path.**\n\n\n\n\n\n\n\n**Final answer:** u = 4, v = 8 and dv/dw = 6. The function value 8 and its rate 6 are different.\n\n### 2. One output: calculate both parameter gradients\n**Question.** A linear neuron has z = wx + b and half squared loss L = ½(z − y)². Given x = 2, y = 4, w = 1 and b = 0, obtain both parameter gradients and perform one gradient-descent update with η = 0.1.\n\n\n\n### Given\n\nInput x = 2; target y = 4.\n\nOld weight w = 1; old bias b = 0.\n\nLinear prediction z = wx+b; loss L = ½(z−y)².\n\nLearning rate η = 0.1; update both parameters once.\n\n### To find\n\nFind the loss gradient for w and for b, then w_new and b_new. Finally evaluate the changed prediction and loss.\n\n### Formula — which one and why\n\n**Chain rule for a linear neuron.** The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.\n\nz = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.\n\n\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek path mein multiply; alag paths mil rahe hon toh add.\n\n### Solution — step by step\n\n\n\n\n\n\n\n**Step 1 — evaluate the original model.** Use the given parameters before applying any update.\n\n\n\nThe prediction is 2, the signed error is −2 and the loss is 2. These are three different quantities, even when some numerical values happen to coincide.\n\n**Step 2 — differentiate the loss, keeping the target constant.** First differentiate the square, then the error inside it.\n\n\n\nThe symbol δ (delta) is a convenient name for the derivative with respect to a neuron's preactivation. Delta is not automatically the weight gradient; the weight gradient also depends on the input to that connection.\n\n**Step 3 — differentiate the neuron's "},{"title":"The derivative of prediction error","blocks":["<p>For the half squared loss, use prediction minus target. Let target be y and prediction be ŷ.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_loss_gradient.svg\" aria-label=\"Enlarge diagram: The half and the averaging factor belong to the loss definition, so they also affect its derivative.\"><img src=\"assets/figures/v_loss_gradient.svg\" alt=\"The half and the averaging factor belong to the loss definition, so they also affect its derivative.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The half and the averaging factor belong to the loss definition, so they also affect its derivative. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.48px;--narrow-height:122.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3bd0a5a4ecdf16a4.svg\"><img class=\"math display-math\" src=\"assets/equations/689f9f8b396b9fab.svg\" alt=\"L=\\frac12(\\hat y-y)^2,\\qquad \\frac{\\partial L}{\\partial \\hat y}=\\hat y-y\" width=\"343.04\" height=\"57.81\" style=\"width:343.04px;height:57.81px;aspect-ratio:343.04/57.81\" loading=\"lazy\"></picture></div>","<p>The 2 from differentiating a square cancels the half. Writing the loss as ½(y − ŷ)² gives the same derivative: the derivative of the inside y − ŷ adds a minus sign. This is why “target minus prediction” without the extra minus gives the wrong gradient.</p>","<p>If the question uses plain squared error, its derivative is 2(ŷ − y). If it averages errors over n values, also divide by n. Read the stated loss before using a memorized gradient.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s7","search":"The derivative of prediction error For the half squared loss, use prediction minus target. Let target be y and prediction be ŷ.\n\n\n\n\nThe 2 from differentiating a square cancels the half. Writing the loss as ½(y − ŷ)² gives the same derivative: the derivative of the inside y − ŷ adds a minus sign. This is why “target minus prediction” without the extra minus gives the wrong gradient.\nIf the question uses plain squared error, its derivative is 2(ŷ − y). If it averages errors over n values, also divide by n. Read the stated loss before using a memorized gradient."},{"title":"Loss scaling: derive the gradient instead of guessing a factor","blocks":["<h3>1. One error, three possible objectives</h3>","<p>Let a be a prediction and y a fixed target. The error is a − y. The derivative of that error with respect to a is 1 because y stays fixed. Apply the chain rule to its square:</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_loss_gradient.svg\" aria-label=\"Enlarge diagram: Read the two conventions separately. A derivative for one convention must not be copied into the other unchanged.\"><img src=\"assets/figures/v_loss_gradient.svg\" alt=\"Read the two conventions separately. A derivative for one convention must not be copied into the other unchanged.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Read the two conventions separately. A derivative for one convention must not be copied into the other unchanged. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5f66834fe766593d.svg\" alt=\"\\frac{\\partial (a-y)^2}{\\partial a}=2(a-y)\\times1\" width=\"269.70\" height=\"55.03\" style=\"width:269.70px;height:55.03px;aspect-ratio:269.70/55.03\" loading=\"lazy\"></div>","<p>Multiplying the objective by a constant multiplies its derivative by the same constant. This gives the common loss conventions below.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Stated loss over n outputs</th><th>Derivative with respect to one prediction aⱼ</th></tr></thead><tbody><tr><td>SSE: sum of all squared errors</td><td>2(aⱼ − yⱼ)</td></tr><tr><td>Half SSE: half of that sum</td><td>aⱼ − yⱼ</td></tr><tr><td>MSE: that sum divided by n</td><td>2(aⱼ − yⱼ)/n</td></tr><tr><td>Half MSE: that sum divided by 2n</td><td>(aⱼ − yⱼ)/n</td></tr></tbody></table></div>","<h3>2. Why only the matching output appears</h3>","<p>Suppose three predictions are separate output variables a₁, a₂ and a₃. When differentiating the loss with respect to a₂, the a₁ and a₃ terms are constant with respect to that output variable, so their direct derivatives are zero. The remaining term is the error of output 2, with the correct scaling factor.</p>","<p>Later, a shared hidden weight may influence all three predictions. Backpropagation then combines those separate output contributions through the chain rule. “Differentiate with respect to one output” and “differentiate with respect to a shared weight” are different stages.</p>","<h3>3. The activation contributes another factor</h3>","<p>If a = sigmoid(z), the derivative of a with respect to its input is a(1 − a). For half SSE, the output delta is therefore:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d269ffed64d3f80c.svg\" alt=\"\\delta=\\frac{\\partial L}{\\partial z}=(a-y)a(1-a)\" width=\"277.97\" height=\"51.29\" style=\"width:277.97px;height:51.29px;aspect-ratio:277.97/51.29\" loading=\"lazy\"></div>","<p>For a linear output, the activation derivative is 1. For positive ReLU input it is also 1; for negative ReLU input it is 0. Always use the derivative of the activation actually given in the question.</p>","<h3>4. A numerical comparison</h3>","<p>For a = 0.7 and y = 1, the signed error is −0.3. For half SSE with sigmoid, the activation derivative is 0.7 × 0.3 = 0.21. The output delta is −0.3 × 0.21 = −0.063. With plain SSE it doubles to −0.126. With MSE over three outputs it is −0.126/3 = −0.042.</p>","<p>The forward prediction 0.7 did not change. The loss convention changed the gradient scale. This is why the first line of a backpropagation answer should state the loss being used.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s8","search":"Loss scaling: derive the gradient instead of guessing a factor ### 1. One error, three possible objectives\nLet a be a prediction and y a fixed target. The error is a − y. The derivative of that error with respect to a is 1 because y stays fixed. Apply the chain rule to its square:\n\n\n\n\nMultiplying the objective by a constant multiplies its derivative by the same constant. This gives the common loss conventions below.\n\n| Stated loss over n outputs | Derivative with respect to one prediction aⱼ |\n| SSE: sum of all squared errors | 2(aⱼ − yⱼ) |\n| Half SSE: half of that sum | aⱼ − yⱼ |\n| MSE: that sum divided by n | 2(aⱼ − yⱼ)/n |\n| Half MSE: that sum divided by 2n | (aⱼ − yⱼ)/n |\n\n### 2. Why only the matching output appears\nSuppose three predictions are separate output variables a₁, a₂ and a₃. When differentiating the loss with respect to a₂, the a₁ and a₃ terms are constant with respect to that output variable, so their direct derivatives are zero. The remaining term is the error of output 2, with the correct scaling factor.\nLater, a shared hidden weight may influence all three predictions. Backpropagation then combines those separate output contributions through the chain rule. “Differentiate with respect to one output” and “differentiate with respect to a shared weight” are different stages.\n\n### 3. The activation contributes another factor\nIf a = sigmoid(z), the derivative of a with respect to its input is a(1 − a). For half SSE, the output delta is therefore:\n\nFor a linear output, the activation derivative is 1. For positive ReLU input it is also 1; for negative ReLU input it is 0. Always use the derivative of the activation actually given in the question.\n\n### 4. A numerical comparison\nFor a = 0.7 and y = 1, the signed error is −0.3. For half SSE with sigmoid, the activation derivative is 0.7 × 0.3 = 0.21. The output delta is −0.3 × 0.21 = −0.063. With plain SSE it doubles to −0.126. With MSE over three outputs it is −0.126/3 = −0.042.\nThe forward prediction 0.7 did not change. The loss convention changed the gradient scale. This is why the first line of a backpropagation answer should state the loss being used.\n"},{"title":"Probability mean and variance in plain language","blocks":["<p class=\"definition\"><strong>Definitions.</strong> A probability assigns a value between 0 and 1 to an event. A discrete probability distribution assigns probabilities to mutually exclusive outcomes whose probabilities sum to 1. Expectation is a probability-weighted average. Variance measures expected squared deviation from the mean.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.88px;--narrow-height:119.35px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6a90dd79f192150.svg\"><img class=\"math display-math\" src=\"assets/equations/f1386430c4600e23.svg\" alt=\"\\sum_i p_i=1,\\qquad\\mathbb E[X]=\\sum_i p_i x_i\" width=\"329.05\" height=\"52.35\" style=\"width:329.05px;height:52.35px;aspect-ratio:329.05/52.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.51px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2228ef692c83a513.svg\"><img class=\"math display-math\" src=\"assets/equations/6fbba36f3ebff68d.svg\" alt=\"\\operatorname{Var}(X)=\\mathbb E[(X-\\mu)^2]=\\mathbb E[X^2]-\\mu^2\" width=\"387.99\" height=\"27.70\" style=\"width:387.99px;height:27.70px;aspect-ratio:387.99/27.70\" loading=\"lazy\"></picture></div>","<h3>Conditional probability and classification</h3>","<p>P(A|B) is the probability of A conditional on B, defined when P(B) &gt; 0. Bayes&#x27; rule relates it to the reverse conditional probability.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.33px;--narrow-height:132.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f464138921aade18.svg\"><img class=\"math display-math\" src=\"assets/equations/ca109f70fdd2c998.svg\" alt=\"P(A\\mid B)=\\frac{P(A\\cap B)}{P(B)}=\\frac{P(B\\mid A)P(A)}{P(B)}\" width=\"432.94\" height=\"59.13\" style=\"width:432.94px;height:59.13px;aspect-ratio:432.94/59.13\" loading=\"lazy\"></picture></div>","<p>For classification, the network estimates P(class | input). A softmax output is normalized across mutually exclusive classes. Independent sigmoid outputs are used for multiple labels that can be present together.</p>","<h3>Empirical mean, variance and standardization</h3>","<p>For N observed values, use the stated variance convention. These notes use division by N for the population-style variance in the numerical; an unbiased sample-variance estimate uses N − 1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.26px;--narrow-height:138.50px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/554920a13a606ed9.svg\"><img class=\"math display-math\" src=\"assets/equations/e7193fbf5e735f5d.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i,\\qquad\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"430.15\" height=\"61.92\" style=\"width:430.15px;height:61.92px;aspect-ratio:430.15/61.92\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:141.06px;--narrow-height:96.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f7fcc7ba3415fbf.svg\"><img class=\"math display-math\" src=\"assets/equations/6d0a9fe98061d681.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2},\\qquad x_{\\mathrm{std}}=\\frac{x-\\mu}{\\sigma}\" width=\"296.87\" height=\"47.79\" style=\"width:296.87px;height:47.79px;aspect-ratio:296.87/47.79\" loading=\"lazy\"></picture></div>","<p>For values [3, 3, 7, 7], μ = 5, squared deviations are [4, 4, 4, 4], σ² = 16/4 = 4 and σ = 2. Thus a value 7 standardizes to (7 − 5)/2 = 1: one standard deviation above the mean. For preprocessing, fit μ and σ on training data and reuse them for validation/test data; σ must be nonzero.</p>","<h3>Likelihood and cross-entropy</h3>","<p>If the correct class has predicted probability p, its negative-log loss is −ln p. For p = 0.8, this is approximately 0.223144. For p = 0.1, it is approximately 2.302585. Increasing correct-class probability lowers this loss. Over independent examples, maximizing the product of correct-class probabilities is equivalent to minimizing the sum of negative log probabilities.</p>","<h3>Population mean and spread: [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. For the population [1, 2, 3], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [1, 2, 3]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23a1d761557fba99.svg\" alt=\"1+2+3=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cde1ff63a64aa7ce.svg\" alt=\"(1-2)=-1\" width=\"137.13\" height=\"24.43\" style=\"width:137.13px;height:24.43px;aspect-ratio:137.13/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46782fbf983b8482.svg\" alt=\"(-1)^2=1\" width=\"105.71\" height=\"27.70\" style=\"width:105.71px;height:27.70px;aspect-ratio:105.71/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebe985168f035d36.svg\" alt=\"(3-2)=1\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4b8daac35aec1bc.svg\" alt=\"(1)^2=1\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e913fcfda4146fb6.svg\"><img class=\"math display-math\" src=\"assets/equations/33fa105b83cd3564.svg\" alt=\"\\sigma^2=\\frac{1+0+1}{3}\\approx0.666666667\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c7d94a64e886a59.svg\"><img class=\"math display-math\" src=\"assets/equations/28845fc5f4238747.svg\" alt=\"\\sigma=\\sqrt{0.666666667}\\approx0.816496581\" width=\"357.89\" height=\"26.49\" style=\"width:357.89px;height:26.49px;aspect-ratio:357.89/26.49\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.666666667; σ ≈ 0.816496581.</p>","<h3>Population mean and spread: [2, 2, 2]</h3>","<p class=\"inline-question\"><strong>Question. For the population [2, 2, 2], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [2, 2, 2]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fc38a48a0a6427f.svg\" alt=\"2+2+2=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b0fc9edc8362e2a5.svg\"><img class=\"math display-math\" src=\"assets/equations/f4e20a1682fadce3.svg\" alt=\"\\sigma^2=\\frac{0+0+0}{3}\\approx0.000000000\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.57px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9ee45ab162936835.svg\"><img class=\"math display-math\" src=\"assets/equations/c43ce89c0112ae99.svg\" alt=\"\\sigma=\\sqrt{0.000000000}\\approx0.000000000\" width=\"357.89\" height=\"26.37\" style=\"width:357.89px;height:26.37px;aspect-ratio:357.89/26.37\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.000000000; σ ≈ 0.000000000. Standardization is undefined with this zero standard deviation.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s9","search":"Probability mean and variance in plain language **Definitions.** A probability assigns a value between 0 and 1 to an event. A discrete probability distribution assigns probabilities to mutually exclusive outcomes whose probabilities sum to 1. Expectation is a probability-weighted average. Variance measures expected squared deviation from the mean.\n\n\n\n### Conditional probability and classification\nP(A|B) is the probability of A conditional on B, defined when P(B) > 0. Bayes' rule relates it to the reverse conditional probability.\n\nFor classification, the network estimates P(class | input). A softmax output is normalized across mutually exclusive classes. Independent sigmoid outputs are used for multiple labels that can be present together.\n\n### Empirical mean, variance and standardization\nFor N observed values, use the stated variance convention. These notes use division by N for the population-style variance in the numerical; an unbiased sample-variance estimate uses N − 1.\n\n\nFor values [3, 3, 7, 7], μ = 5, squared deviations are [4, 4, 4, 4], σ² = 16/4 = 4 and σ = 2. Thus a value 7 standardizes to (7 − 5)/2 = 1: one standard deviation above the mean. For preprocessing, fit μ and σ on training data and reuse them for validation/test data; σ must be nonzero.\n\n### Likelihood and cross-entropy\nIf the correct class has predicted probability p, its negative-log loss is −ln p. For p = 0.8, this is approximately 0.223144. For p = 0.1, it is approximately 2.302585. Increasing correct-class probability lowers this loss. Over independent examples, maximizing the product of correct-class probabilities is equivalent to minimizing the sum of negative log probabilities.\n\n### Population mean and spread: [1, 2, 3]\n\n**Question. For the population [1, 2, 3], find mean, population variance and standard deviation.**\n\n\n\n### Given\n\nValues = [1, 2, 3]; N = 3. Use population division by N.\n\n### To find\n\nMean μ, variance σ² and standard deviation σ.\n\n### Formula — which one and why\n\nThe question specifies a population, so use N rather than the N−1 sample-variance divisor.\n\nμ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean, distance, square, mean again, then root.\n\n### Solution — step by step\n\n\n\n**Step 1: add all values.**\n\n\n\n\n\n\n\n**Step 2: divide by the number of values.**\n\n\n\n\n\n\n\n**Step 3: find and square deviation 1.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 4: find and square deviation 2.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 5: find and square deviation 3.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 6: average the squared deviations.**\n\n\n\n\n\n\n\n**Step 7: take the nonnegative square root.**\n\n\n\n\n\n\n\n**Final answer:** μ = 2; σ² ≈ 0.666666667; σ ≈ 0.816496581.\n\n\n\n\n\n### Population mean and spread: [2, 2, 2]\n\n**Question. For the population [2, 2, 2], find mean, population variance and standard deviation.**\n\n\n\n### Given\n\nValues = [2, 2, 2]; N = 3. Use population division by N.\n\n### To find\n\nMean μ, variance σ² and standard deviation σ.\n\n### Formula — which one and why\n\nThe question specifies a population, so use N rather than the N−1 sample-variance divisor.\n\nμ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean, distance, square, mean again, then root.\n\n### Solution — step by step\n\n\n\n**Step 1: add all values.**\n\n\n\n\n\n\n\n**Step 2: divide by the number of values.**\n\n\n\n\n\n\n\n**Step 3: find and square deviation 1.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 4: find and square deviation 2.**\n\n\n"},{"title":"Mean, variance and standard deviation from ordinary arithmetic","blocks":["<p class=\"definition\"><strong>Definition.</strong> The arithmetic mean measures the centre of a numerical dataset. Variance measures the average squared deviation from that mean, and standard deviation expresses dispersion in the original units.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.05px;--narrow-height:209.10px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8b9cec002314f2de.svg\"><img class=\"math display-math\" src=\"assets/equations/9231d9bbf6a6372d.svg\" alt=\"\\mu=\\frac{1}{N}\\sum_{i=1}^{N}x_i,\\qquad \\sigma^2=\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\mu)^2,\\qquad \\sigma=\\sqrt{\\sigma^2}\" width=\"585.96\" height=\"72.79\" style=\"width:585.96px;height:72.79px;aspect-ratio:585.96/72.79\" loading=\"lazy\"></picture></div>","<p>These are population formulas, or empirical moments treating the supplied dataset as the complete reference set. An unbiased sample-variance estimate instead divides the squared-deviation sum by N−1. Use the convention specified by the question; the two denominators are not interchangeable.</p>","<p class=\"inline-question\"><strong>Question. Find the population mean, variance and standard deviation of [3, 3, 7, 7].</strong></p>","<h3>Given</h3>","<p>Observations = [3,3,7,7]; N = 4.</p>","<p>Use population variance (divide by N).</p>","<h3>To find</h3>","<p>Find the population mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p><strong>Mean and spread.</strong> The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.</p>","<p>N = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aa827d67a05a9234.svg\" alt=\"\\mu=\\frac{1}{N}\\sum_{i=1}^{N}x_i\" width=\"145.16\" height=\"72.79\" style=\"width:145.16px;height:72.79px;aspect-ratio:145.16/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a1a03dea0d7cf33e.svg\" alt=\"\\sigma^2=\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\mu)^2\" width=\"225.26\" height=\"72.79\" style=\"width:225.26px;height:72.79px;aspect-ratio:225.26/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean = sabka total ÷ count; variance = squared distances ka mean.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all four observations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b29c1c44847515f7.svg\" alt=\"3+3+7+7=20\" width=\"195.50\" height=\"18.52\" style=\"width:195.50px;height:18.52px;aspect-ratio:195.50/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the count to obtain the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eafa89b652a5378.svg\" alt=\"\\mu=\\frac{20}{4}=5\" width=\"127.31\" height=\"49.55\" style=\"width:127.31px;height:49.55px;aspect-ratio:127.31/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: subtract the mean from each observation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:263.40px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f5609e02cf210acd.svg\"><img class=\"math display-math\" src=\"assets/equations/1c77fe3ea3cb5cf4.svg\" alt=\"[3-5,3-5,7-5,7-5]=[-2,-2,2,2]\" width=\"429.05\" height=\"24.43\" style=\"width:429.05px;height:24.43px;aspect-ratio:429.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: square each deviation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:213.75px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8423c755b10f2fe0.svg\"><img class=\"math display-math\" src=\"assets/equations/54a284752c898da0.svg\" alt=\"[(-2)^2,(-2)^2,2^2,2^2]=[4,4,4,4]\" width=\"341.39\" height=\"27.70\" style=\"width:341.39px;height:27.70px;aspect-ratio:341.39/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the squared deviations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8b51d1e9b84e8106.svg\" alt=\"4+4+4+4=16\" width=\"195.50\" height=\"18.54\" style=\"width:195.50px;height:18.54px;aspect-ratio:195.50/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: divide by four for population variance.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47e0cbf4557b9859.svg\" alt=\"\\sigma^2=\\frac{16}{4}=4\" width=\"137.19\" height=\"49.55\" style=\"width:137.19px;height:49.55px;aspect-ratio:137.19/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a8d993f2bb3889d.svg\" alt=\"\\sigma=\\sqrt4=2\" width=\"124.39\" height=\"26.77\" style=\"width:124.39px;height:26.77px;aspect-ratio:124.39/26.77\" loading=\"lazy\"></div>","<p><strong>Answer:</strong> mean = 5, population variance = 4 and population standard deviation = 2. Variance has squared units; standard deviation has the same units as the observations. With the sample convention, the variance would instead be 16/3.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s10","search":"Mean, variance and standard deviation from ordinary arithmetic \n**Definition.** The arithmetic mean measures the centre of a numerical dataset. Variance measures the average squared deviation from that mean, and standard deviation expresses dispersion in the original units.\n\nThese are population formulas, or empirical moments treating the supplied dataset as the complete reference set. An unbiased sample-variance estimate instead divides the squared-deviation sum by N−1. Use the convention specified by the question; the two denominators are not interchangeable.\n\n**Question. Find the population mean, variance and standard deviation of [3, 3, 7, 7].**\n\n\n\n### Given\n\nObservations = [3,3,7,7]; N = 4.\n\nUse population variance (divide by N).\n\n### To find\n\nFind the population mean μ, variance σ² and standard deviation σ.\n\n### Formula — which one and why\n\n**Mean and spread.** The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.\n\nN = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean = sabka total ÷ count; variance = squared distances ka mean.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: add all four observations.**\n\n\n\n\n\n\n\n**Step 2: divide by the count to obtain the mean.**\n\n\n\n\n\n\n\n**Step 3: subtract the mean from each observation.**\n\n\n\n\n\n\n\n**Step 4: square each deviation.**\n\n\n\n\n\n\n\n**Step 5: add the squared deviations.**\n\n\n\n\n\n\n\n**Step 6: divide by four for population variance.**\n\n\n\n\n\n\n\n**Step 7: take the nonnegative square root.**\n\n\n\n\n\n\n\n**Answer:** mean = 5, population variance = 4 and population standard deviation = 2. Variance has squared units; standard deviation has the same units as the observations. With the sample convention, the variance would instead be 16/3.\n\n"},{"title":"Standardization: what the answer 1 actually means","blocks":["<p class=\"definition\"><strong>Definition.</strong> Standardization is an affine transformation that expresses an observation as its signed distance from a reference mean, measured in reference standard-deviation units.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.64px;--narrow-height:90.47px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/45ffeb13784592e1.svg\"><img class=\"math display-math\" src=\"assets/equations/6f3798eefa1e56a4.svg\" alt=\"z=\\frac{x-\\mu_{\\mathrm{train}}}{\\sigma_{\\mathrm{train}}},\\qquad \\sigma_{\\mathrm{train}}&gt;0\" width=\"308.90\" height=\"51.38\" style=\"width:308.90px;height:51.38px;aspect-ratio:308.90/51.38\" loading=\"lazy\"></picture></div>","<p>Subtracting the mean centres the reference data. Dividing by its standard deviation rescales its spread. The result is dimensionless. A positive z lies above the training mean, a negative z below it, and z = 0 equals it. Standardization does not make an arbitrary distribution Gaussian and does not restrict values to [0,1].</p>","<p class=\"inline-question\"><strong>Question. A feature has training values [3, 3, 7, 7]. Using population standard deviation, standardize the training values and a new observation x = 9.</strong></p>","<h3>Given</h3>","<p>Training observations = [3,3,7,7].</p>","<p>New observation = 9.</p>","<p>Estimate the population standard deviation from the training values.</p>","<h3>To find</h3>","<p>Find the training mean and standard deviation; standardize all four training values and the new observation.</p>","<h3>Formula — which one and why</h3>","<p><strong>Mean and spread.</strong> The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.</p>","<p>N = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aa827d67a05a9234.svg\" alt=\"\\mu=\\frac{1}{N}\\sum_{i=1}^{N}x_i\" width=\"145.16\" height=\"72.79\" style=\"width:145.16px;height:72.79px;aspect-ratio:145.16/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a1a03dea0d7cf33e.svg\" alt=\"\\sigma^2=\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\mu)^2\" width=\"225.26\" height=\"72.79\" style=\"width:225.26px;height:72.79px;aspect-ratio:225.26/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean = sabka total ÷ count; variance = squared distances ka mean.</p>","<p><strong>Standardization.</strong> Subtract the training mean to measure distance from the centre; divide by the training standard deviation to express that distance in standard-deviation units.</p>","<p>x = original value; μ = training mean; σ = training standard deviation, which must be nonzero; z = standardized value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle centre hatao, phir spread se divide karo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all four observations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b29c1c44847515f7.svg\" alt=\"3+3+7+7=20\" width=\"195.50\" height=\"18.52\" style=\"width:195.50px;height:18.52px;aspect-ratio:195.50/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the count to obtain the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eafa89b652a5378.svg\" alt=\"\\mu=\\frac{20}{4}=5\" width=\"127.31\" height=\"49.55\" style=\"width:127.31px;height:49.55px;aspect-ratio:127.31/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: subtract the mean from each observation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:263.40px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f5609e02cf210acd.svg\"><img class=\"math display-math\" src=\"assets/equations/1c77fe3ea3cb5cf4.svg\" alt=\"[3-5,3-5,7-5,7-5]=[-2,-2,2,2]\" width=\"429.05\" height=\"24.43\" style=\"width:429.05px;height:24.43px;aspect-ratio:429.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: square each deviation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:213.75px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8423c755b10f2fe0.svg\"><img class=\"math display-math\" src=\"assets/equations/54a284752c898da0.svg\" alt=\"[(-2)^2,(-2)^2,2^2,2^2]=[4,4,4,4]\" width=\"341.39\" height=\"27.70\" style=\"width:341.39px;height:27.70px;aspect-ratio:341.39/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the squared deviations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8b51d1e9b84e8106.svg\" alt=\"4+4+4+4=16\" width=\"195.50\" height=\"18.54\" style=\"width:195.50px;height:18.54px;aspect-ratio:195.50/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: divide by four for population variance.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47e0cbf4557b9859.svg\" alt=\"\\sigma^2=\\frac{16}{4}=4\" width=\"137.19\" height=\"49.55\" style=\"width:137.19px;height:49.55px;aspect-ratio:137.19/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a8d993f2bb3889d.svg\" alt=\"\\sigma=\\sqrt4=2\" width=\"124.39\" height=\"26.77\" style=\"width:124.39px;height:26.77px;aspect-ratio:124.39/26.77\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: standardize each original training observation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb029ad3b6f0a91a.svg\" alt=\"\\frac{3-5}{2}=-1\" width=\"128.87\" height=\"49.55\" style=\"width:128.87px;height:49.55px;aspect-ratio:128.87/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0a2851f2b573cc2.svg\" alt=\"\\frac{7-5}{2}=1\" width=\"109.86\" height=\"49.80\" style=\"width:109.86px;height:49.80px;aspect-ratio:109.86/49.80\" loading=\"lazy\"></div>","<p>The repeated observations give [-1, −1, 1, 1].</p>","<p class=\"worked-step\"><strong>Step 9: subtract the training mean from the new observation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/116784e6eda9bc25.svg\" alt=\"9-5=4\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 10: divide by the training standard deviation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a563909e15c191b2.svg\" alt=\"z_{\\mathrm{new}}=\\frac42=2\" width=\"143.50\" height=\"49.82\" style=\"width:143.50px;height:49.82px;aspect-ratio:143.50/49.82\" loading=\"lazy\"></div>","<p><strong>Answer:</strong> the new observation is two training standard deviations above the training mean. Do not recompute the mean and standard deviation using the new observation; validation and test data use the training transformation to avoid leakage. A constant feature has zero standard deviation and needs a stated handling policy.</p>","<h3>Standardization with x = 3</h3>","<p class=\"inline-question\"><strong>Question. Training mean is 5 and training standard deviation is 2. Standardize x = 3 and interpret the result.</strong></p>","<h3>Given</h3>","<p>x = 3; training mean μ = 5; training standard deviation σ = 2.</p>","<h3>To find</h3>","<p>Standardized value z and its meaning.</p>","<h3>Formula — which one and why</h3>","<p>Subtract the training centre, then measure that distance in units of the training standard deviation.</p>","<p>A negative z means below the training mean; positive means above it; zero means equal to it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Centre hatao, spread se divide; answer batata hai kitne σ door.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find distance from the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29b71ab0c556c6dc.svg\" alt=\"x-\\mu=3-5=-2\" width=\"209.28\" height=\"21.55\" style=\"width:209.28px;height:21.55px;aspect-ratio:209.28/21.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by one standard-deviation unit.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/679dccde63fa3152.svg\" alt=\"z=\\frac{-2}{2}=-1\" width=\"149.74\" height=\"49.55\" style=\"width:149.74px;height:49.55px;aspect-ratio:149.74/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: interpret sign and size.</strong></p>","<p>The value is 1 standard-deviation unit(s) below the training mean.</p>","<p><strong>Final answer:</strong> z = -1. Use the same training statistics when transforming a new test input.</p>","<h3>Standardization with x = 5</h3>","<p class=\"inline-question\"><strong>Question. Training mean is 5 and training standard deviation is 2. Standardize x = 5 and interpret the result.</strong></p>","<h3>Given</h3>","<p>x = 5; training mean μ = 5; training standard deviation σ = 2.</p>","<h3>To find</h3>","<p>Standardized value z and its meaning.</p>","<h3>Formula — which one and why</h3>","<p>Subtract the training centre, then measure that distance in units of the training standard deviation.</p>","<p>A negative z means below the training mean; positive means above it; zero means equal to it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Centre hatao, spread se divide; answer batata hai kitne σ door.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find distance from the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46cf71d500f243a5.svg\" alt=\"x-\\mu=5-5=0\" width=\"190.27\" height=\"21.55\" style=\"width:190.27px;height:21.55px;aspect-ratio:190.27/21.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by one standard-deviation unit.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8d3a4b4364ff836.svg\" alt=\"z=\\frac{0}{2}=0\" width=\"111.72\" height=\"49.55\" style=\"width:111.72px;height:49.55px;aspect-ratio:111.72/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: interpret sign and size.</strong></p>","<p>The value is 0 standard-deviation unit(s) away from the training mean.</p>","<p><strong>Final answer:</strong> z = 0. Use the same training statistics when transforming a new test input.</p>","<h3>Standardization with x = 9</h3>","<p class=\"inline-question\"><strong>Question. Training mean is 5 and training standard deviation is 2. Standardize x = 9 and interpret the result.</strong></p>","<h3>Given</h3>","<p>x = 9; training mean μ = 5; training standard deviation σ = 2.</p>","<h3>To find</h3>","<p>Standardized value z and its meaning.</p>","<h3>Formula — which one and why</h3>","<p>Subtract the training centre, then measure that distance in units of the training standard deviation.</p>","<p>A negative z means below the training mean; positive means above it; zero means equal to it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Centre hatao, spread se divide; answer batata hai kitne σ door.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find distance from the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/640d8d05be10b7d3.svg\" alt=\"x-\\mu=9-5=4\" width=\"190.27\" height=\"21.82\" style=\"width:190.27px;height:21.82px;aspect-ratio:190.27/21.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by one standard-deviation unit.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b913089938e80c1f.svg\" alt=\"z=\\frac{4}{2}=2\" width=\"111.72\" height=\"49.82\" style=\"width:111.72px;height:49.82px;aspect-ratio:111.72/49.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: interpret sign and size.</strong></p>","<p>The value is 2 standard-deviation unit(s) above the training mean.</p>","<p><strong>Final answer:</strong> z = 2. Use the same training statistics when transforming a new test input.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s11","search":"Standardization: what the answer 1 actually means \n**Definition.** Standardization is an affine transformation that expresses an observation as its signed distance from a reference mean, measured in reference standard-deviation units.\n\nSubtracting the mean centres the reference data. Dividing by its standard deviation rescales its spread. The result is dimensionless. A positive z lies above the training mean, a negative z below it, and z = 0 equals it. Standardization does not make an arbitrary distribution Gaussian and does not restrict values to [0,1].\n\n**Question. A feature has training values [3, 3, 7, 7]. Using population standard deviation, standardize the training values and a new observation x = 9.**\n\n\n\n### Given\n\nTraining observations = [3,3,7,7].\n\nNew observation = 9.\n\nEstimate the population standard deviation from the training values.\n\n### To find\n\nFind the training mean and standard deviation; standardize all four training values and the new observation.\n\n### Formula — which one and why\n\n**Mean and spread.** The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.\n\nN = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean = sabka total ÷ count; variance = squared distances ka mean.\n\n**Standardization.** Subtract the training mean to measure distance from the centre; divide by the training standard deviation to express that distance in standard-deviation units.\n\nx = original value; μ = training mean; σ = training standard deviation, which must be nonzero; z = standardized value.\n\n\n\n**Yaad rakhne ka cue:** Pehle centre hatao, phir spread se divide karo.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: add all four observations.**\n\n\n\n\n\n\n\n**Step 2: divide by the count to obtain the mean.**\n\n\n\n\n\n\n\n**Step 3: subtract the mean from each observation.**\n\n\n\n\n\n\n\n**Step 4: square each deviation.**\n\n\n\n\n\n\n\n**Step 5: add the squared deviations.**\n\n\n\n\n\n\n\n**Step 6: divide by four for population variance.**\n\n\n\n\n\n\n\n**Step 7: take the nonnegative square root.**\n\n\n\n\n\n\n\n**Step 8: standardize each original training observation.**\n\n\n\n\n\n\n\n\n\nThe repeated observations give [-1, −1, 1, 1].\n\n**Step 9: subtract the training mean from the new observation.**\n\n\n\n\n\n\n\n**Step 10: divide by the training standard deviation.**\n\n\n\n\n\n\n\n**Answer:** the new observation is two training standard deviations above the training mean. Do not recompute the mean and standard deviation using the new observation; validation and test data use the training transformation to avoid leakage. A constant feature has zero standard deviation and needs a stated handling policy.\n\n### Standardization with x = 3\n\n**Question. Training mean is 5 and training standard deviation is 2. Standardize x = 3 and interpret the result.**\n\n\n\n### Given\n\nx = 3; training mean μ = 5; training standard deviation σ = 2.\n\n### To find\n\nStandardized value z and its meaning.\n\n### Formula — which one and why\n\nSubtract the training centre, then measure that distance in units of the training standard deviation.\n\nA negative z means below the training mean; positive means above it; zero means equal to it.\n\n\n\n**Yaad rakhne ka cue:** Centre hatao, spread se divide; answer batata hai kitne σ door.\n\n### Solution — step by step\n\n\n\n**Step 1: find distance from the mean.**\n\n\n\n\n\n\n\n**Step 2: divide by one standard-deviation unit.**\n\n\n\n\n\n\n\n"},{"title":"Chain rule: the complete calculation","blocks":["<p>When one value depends on another, a change passes through both calculations. The total derivative multiplies the two local derivatives. It does not add them. Here w is the number being changed, z is an intermediate value, and L is the final value.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_chain_rule.svg\" aria-label=\"Enlarge diagram: Follow w to z to loss. The local slopes on that dependency path multiply.\"><img src=\"assets/figures/v_chain_rule.svg\" alt=\"Follow w to z to loss. The local slopes on that dependency path multiply.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow w to z to loss. The local slopes on that dependency path multiply. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Let z = 3w + 1 and L = z². We will calculate the derivative of L with respect to w at w = 1.</p>","<p class=\"worked-step\"><strong>Step 1: find the intermediate value.</strong> Replace w by 1: z = 3 × 1 + 1 = 4.</p>","<p class=\"worked-step\"><strong>Step 2: differentiate the last calculation.</strong> For L = z², the power rule gives dL/dz = 2z. At z = 4, this is 2 × 4 = 8. This measures how L responds to z.</p>","<p class=\"worked-step\"><strong>Step 3: differentiate the first calculation.</strong> For z = 3w + 1, the derivative of 3w is 3 and the derivative of the constant 1 is 0. Therefore dz/dw = 3. This measures how z responds to w.</p>","<p class=\"worked-step\"><strong>Step 4: connect the two effects.</strong> Multiply 8 by 3. The final derivative is 24.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.31px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f43476deed69b900.svg\"><img class=\"math display-math\" src=\"assets/equations/f69ed1214540da40.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}=(2z)(3)=8\\times3=24\" width=\"404.89\" height=\"50.50\" style=\"width:404.89px;height:50.50px;aspect-ratio:404.89/50.50\" loading=\"lazy\"></picture></div>","<p>The function value is L = 4² = 16. The derivative is 24. These have different meanings: 16 is the current value of L; 24 is its local rate of change per unit change in w.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c3-s12","search":"Chain rule: the complete calculation When one value depends on another, a change passes through both calculations. The total derivative multiplies the two local derivatives. It does not add them. Here w is the number being changed, z is an intermediate value, and L is the final value.\n\n\n\nLet z = 3w + 1 and L = z². We will calculate the derivative of L with respect to w at w = 1.\n**Step 1: find the intermediate value.** Replace w by 1: z = 3 × 1 + 1 = 4.\n**Step 2: differentiate the last calculation.** For L = z², the power rule gives dL/dz = 2z. At z = 4, this is 2 × 4 = 8. This measures how L responds to z.\n**Step 3: differentiate the first calculation.** For z = 3w + 1, the derivative of 3w is 3 and the derivative of the constant 1 is 0. Therefore dz/dw = 3. This measures how z responds to w.\n**Step 4: connect the two effects.** Multiply 8 by 3. The final derivative is 24.\n\nThe function value is L = 4² = 16. The derivative is 24. These have different meanings: 16 is the current value of L; 24 is its local rate of change per unit change in w.\n"}]},{"n":4,"title":"Neural-network foundations","sections":[{"title":"What does learning from data mean","blocks":["<p class=\"definition\"><strong>Definition.</strong> Machine learning develops models from data so that they can perform a task on new examples. A model is a calculation rule with adjustable numbers. Deep learning uses neural networks with multiple trainable layers; each layer transforms the previous layer&#x27;s outputs.</p>","<h3>Start with one complete training example</h3>","<p>A <strong>sample</strong> means one example in the dataset. Suppose one example says: an input number is 2 and the required answer is 4. We write the input as x = 2 and the correct answer, or <strong>target</strong>, as y = 4. These letters are labels for the two numbers.</p>","<p>An <strong>input feature</strong> is one recorded property used to make a prediction. One house might have area, number of rooms and age as three features. The three values together describe one sample. An <strong>input vector</strong> is just an ordered list of those feature values. Order matters: the first model weight must always multiply the first feature.</p>","<p>The model&#x27;s calculated answer is the <strong>prediction</strong>, written ŷ, read “y hat”. The hat helps us distinguish the calculated answer ŷ from the required answer y. A prediction is a probability only when the task and output function give it that interpretation.</p>","<h3>The simplest model: multiply, then add</h3>","<p>In the following model, x is the input, w is a weight and b is a bias. A <strong>weight</strong> multiplies the input. A <strong>bias</strong> is added once after multiplication. Both w and b are adjustable model numbers, called <strong>parameters</strong>.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p>The model first multiplies w and x; then it adds b. For several inputs it uses one matching weight per input, adds their products, and then adds the bias.</p>","<p><strong>Yaad rakhne ka cue:</strong> x diya hua input; y sahi answer; ŷ model ka answer; w aur b training mein badlenge.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: Input numbers are multiplied by weights, their contributions are added with a bias, and an activation gives the neuron output. The next lesson explains each part.\"><img src=\"assets/figures/neuron.svg\" alt=\"Input numbers are multiplied by weights, their contributions are added with a bias, and an activation gives the neuron output. The next lesson explains each part.\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>Input numbers are multiplied by weights, their contributions are added with a bias, and an activation gives the neuron output. The next lesson explains each part. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Model example 1: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 2, w = 1 and b = 0, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 2.</p>","<p>Weight w = 1; bias b = 0.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0690bd581db62ce5.svg\" alt=\"wx=(1)(2)=2\" width=\"171.31\" height=\"24.43\" style=\"width:171.31px;height:24.43px;aspect-ratio:171.31/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31e3d42796c5dd84.svg\" alt=\"\\hat y=2+(0)=2\" width=\"162.67\" height=\"25.90\" style=\"width:162.67px;height:25.90px;aspect-ratio:162.67/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 2. This is a prediction, not a loss or a learned weight.</p>","<h3>Model example 2: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 2, w = 1.5 and b = 1, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 2.</p>","<p>Weight w = 1.5; bias b = 1.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cafd271941bad15.svg\" alt=\"wx=(1.5)(2)=3\" width=\"190.32\" height=\"24.43\" style=\"width:190.32px;height:24.43px;aspect-ratio:190.32/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3a2f92dc89e2b2d2.svg\" alt=\"\\hat y=3+(1)=4\" width=\"162.67\" height=\"25.90\" style=\"width:162.67px;height:25.90px;aspect-ratio:162.67/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 4. This is a prediction, not a loss or a learned weight.</p>","<h3>Model example 3: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 3, w = 1.5 and b = 1, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 3.</p>","<p>Weight w = 1.5; bias b = 1.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b2ec1addfdbb9fd.svg\" alt=\"wx=(1.5)(3)=4.5\" width=\"209.34\" height=\"24.43\" style=\"width:209.34px;height:24.43px;aspect-ratio:209.34/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b28b202a19e96ace.svg\" alt=\"\\hat y=4.5+(1)=5.5\" width=\"200.70\" height=\"25.90\" style=\"width:200.70px;height:25.90px;aspect-ratio:200.70/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 5.5. This is a prediction, not a loss or a learned weight.</p>","<h3>Model example 4: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 2, w = -0.5 and b = 3, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 2.</p>","<p>Weight w = -0.5; bias b = 3.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ee6e60703add42d.svg\" alt=\"wx=(-0.5)(2)=-1\" width=\"228.34\" height=\"24.43\" style=\"width:228.34px;height:24.43px;aspect-ratio:228.34/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2369bf69098b26c.svg\" alt=\"\\hat y=-1+(3)=2\" width=\"181.69\" height=\"25.90\" style=\"width:181.69px;height:25.90px;aspect-ratio:181.69/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 2. This is a prediction, not a loss or a learned weight.</p>","<h3>How the model learns</h3>","<p>An initial model can predict 2 when the target is 4. A <strong>loss function</strong> measures the discrepancy. Training calculates how changing each parameter changes the loss; that rate is a <strong>gradient</strong>. An <strong>optimizer</strong> uses the gradient to adjust the parameters. The learning rate controls the size of this adjustment. The loss, derivative and complete update are explained with full examples in the next lessons.</p>","<p>The learning rate is a <strong>hyperparameter</strong>: a setting chosen for training. A learned weight is a <strong>parameter</strong>: an adjustable number inside the model. During ordinary <strong>inference</strong>, the trained weights stay fixed and the model calculates an output for a new input.</p>","<p>For many training samples, the objective normally averages the individual losses. θ (theta) means the collection of adjustable parameters; N is the number of training examples; Lᵢ is the loss for example i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48f2afe9071bd1c9.svg\" alt=\"J(\\theta)=\\frac1N\\sum_{i=1}^{N}L_i(\\theta)\" width=\"209.50\" height=\"72.79\" style=\"width:209.50px;height:72.79px;aspect-ratio:209.50/72.79\" loading=\"lazy\"></div>","<p>Σ is an instruction to add the listed terms. For three losses it means L₁ + L₂ + L₃, followed by division by 3. Regularization may add a penalty; the regularization chapter explains that separate term.</p>","<h3>Why several layers help</h3>","<p>A <strong>layer</strong> contains several neurons that calculate outputs from the same incoming values. In an image model, earlier layers can respond to simple patterns such as edges; later layers combine earlier responses into more complex features. This hierarchy is learned from data. A deep network is not guaranteed to learn useful features merely because it has many layers; training data, architecture and optimization still matter.</p>","<p><strong>Generalization</strong> means performing well on new examples. Training data adjusts weights; validation data helps choose settings and stopping time; held-out test data evaluates the chosen model. Small training loss alone does not establish good generalization.</p>","<p><strong>Yaad rakhne ka cue:</strong> training = answer nikalo → loss nikalo → gradients nikalo → parameters update karo; inference = trained model se answer nikalo.</p>","<h3>Average training loss</h3>","<p class=\"inline-question\"><strong>Question. Three training examples have losses 2, 0.5 and 0.5. Calculate their mean training loss.</strong></p>","<h3>Given</h3>","<p>L₁ = 2; L₂ = 0.5; L₃ = 0.5; N = 3.</p>","<h3>To find</h3>","<p>The mean loss J.</p>","<h3>Formula — which one and why</h3>","<p>The question asks for the mean, so add all sample losses and divide by the number of samples.</p>","<p>Lᵢ means loss of example i. N counts examples.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3763c395ed6a5c3c.svg\" alt=\"J=\\frac{L_1+L_2+L_3}{N}\" width=\"200.46\" height=\"49.97\" style=\"width:200.46px;height:49.97px;aspect-ratio:200.46/49.97\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean = total loss ÷ examples.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add the losses.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a5dc1556ae91ba13.svg\" alt=\"2+0.5+0.5=3\" width=\"179.22\" height=\"18.27\" style=\"width:179.22px;height:18.27px;aspect-ratio:179.22/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of examples.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ddda757808debff5.svg\" alt=\"J=\\frac33=1\" width=\"115.82\" height=\"50.07\" style=\"width:115.82px;height:50.07px;aspect-ratio:115.82/50.07\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Mean training loss = 1.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s0","search":"What does learning from data mean **Definition.** Machine learning develops models from data so that they can perform a task on new examples. A model is a calculation rule with adjustable numbers. Deep learning uses neural networks with multiple trainable layers; each layer transforms the previous layer's outputs.\n\n### Start with one complete training example\nA **sample** means one example in the dataset. Suppose one example says: an input number is 2 and the required answer is 4. We write the input as x = 2 and the correct answer, or **target**, as y = 4. These letters are labels for the two numbers.\n\nAn **input feature** is one recorded property used to make a prediction. One house might have area, number of rooms and age as three features. The three values together describe one sample. An **input vector** is just an ordered list of those feature values. Order matters: the first model weight must always multiply the first feature.\n\nThe model's calculated answer is the **prediction**, written ŷ, read “y hat”. The hat helps us distinguish the calculated answer ŷ from the required answer y. A prediction is a probability only when the task and output function give it that interpretation.\n\n### The simplest model: multiply, then add\nIn the following model, x is the input, w is a weight and b is a bias. A **weight** multiplies the input. A **bias** is added once after multiplication. Both w and b are adjustable model numbers, called **parameters**.\n\nThe model first multiplies w and x; then it adds b. For several inputs it uses one matching weight per input, adds their products, and then adds the bias.\n\n**Yaad rakhne ka cue:** x diya hua input; y sahi answer; ŷ model ka answer; w aur b training mein badlenge.\n\n\n\n\n### Model example 1: calculate a prediction\n\n**Question. A linear model uses ŷ = wx+b. For x = 2, w = 1 and b = 0, calculate its prediction.**\n\n\n\n### Given\n\nInput x = 2.\n\nWeight w = 1; bias b = 0.\n\nThe output is linear: no extra activation is specified.\n\n### To find\n\nThe predicted value ŷ.\n\n### Formula — which one and why\n\nUse the stated model. The multiplication gives the input contribution; the bias shifts the result.\n\nx is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.\n\n\n\n**Yaad rakhne ka cue:** Pehle input × weight, phir bias add.\n\n### Solution — step by step\n\n\n\n**Step 1: multiply the input by its weight.**\n\n\n\n\n\n\n\n**Step 2: add the bias once.**\n\n\n\n\n\n\n\n**Final answer:** ŷ = 2. This is a prediction, not a loss or a learned weight.\n\n\n\n### Model example 2: calculate a prediction\n\n**Question. A linear model uses ŷ = wx+b. For x = 2, w = 1.5 and b = 1, calculate its prediction.**\n\n\n\n### Given\n\nInput x = 2.\n\nWeight w = 1.5; bias b = 1.\n\nThe output is linear: no extra activation is specified.\n\n### To find\n\nThe predicted value ŷ.\n\n### Formula — which one and why\n\nUse the stated model. The multiplication gives the input contribution; the bias shifts the result.\n\nx is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.\n\n\n\n**Yaad rakhne ka cue:** Pehle input × weight, phir bias add.\n\n### Solution — step by step\n\n\n\n**Step 1: multiply the input by its weight.**\n\n\n\n\n\n\n\n**Step 2: add the bias once.**\n\n\n\n\n\n\n\n**Final answer:** ŷ = 4. This is a prediction, not a loss or a learned weight.\n\n\n\n### Model example 3: calculate a prediction\n\n**Question. A linear model uses ŷ = wx+b. For x = 3, w = 1.5 and b = 1, calculate its prediction.**\n\n\n\n### Given\n\nInput x = 3.\n\nWeight w = 1.5; bias b"},{"title":"Your first complete training step","blocks":["<p class=\"inline-question\"><strong>Question.</strong> A linear model is defined by <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b0668b91b6f454d0.svg\" alt=\"\\hat y=wx\" width=\"59.14\" height=\"19.29\" style=\"width:59.14px;height:19.29px;aspect-ratio:59.14/19.29\" loading=\"lazy\"></span>. For the training example x = 2, y = 4, use initial weight w₀ = 1, learning rate η = 0.1 and half squared loss. Perform two gradient-descent updates and report the prediction and loss after each update.</p>","<h3>Given</h3>","<p>Model: ŷ = wx; bias is absent and is not updated.</p>","<p>x = 2; y = 4; initial w₀ = 1; η = 0.1.</p>","<p>Loss = half squared error; perform two updates.</p>","<h3>To find</h3>","<p>Find the weight, prediction and loss after each update.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule with only a trainable weight.</strong> The weight changes the prediction and the prediction changes the half squared loss. Multiply both rates, then subtract the scaled gradient. The stated model has no bias parameter.</p>","<p>ŷ = prediction; y = target; x = input; w = weight; η = learning rate; g = loss derivative with respect to w.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b0668b91b6f454d0.svg\" alt=\"\\hat y=wx\" width=\"76.03\" height=\"24.80\" style=\"width:76.03px;height:24.80px;aspect-ratio:76.03/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/df5fc0c0a9ad8296.svg\" alt=\"L=\\frac12(\\hat y-y)^2\" width=\"155.68\" height=\"49.55\" style=\"width:155.68px;height:49.55px;aspect-ratio:155.68/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f90a893376d444b0.svg\" alt=\"g=(\\hat y-y)x\" width=\"131.04\" height=\"25.90\" style=\"width:131.04px;height:25.90px;aspect-ratio:131.04/25.90\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Prediction minus target, phir input se multiply; naya weight = purana − ηg.</p>","<h3>Solution — step by step</h3>","<h3>Model, objective and gradient</h3>","<p>The input and target remain fixed; only the weight is trainable. There is no bias parameter in this question.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.48px;--narrow-height:129.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/991254a061f484f9.svg\"><img class=\"math display-math\" src=\"assets/equations/c9459723553604be.svg\" alt=\"\\hat y=wx,\\qquad L(w)=\\frac12(wx-y)^2,\\qquad w_t=w_{t-1}-\\eta g_t\" width=\"575.31\" height=\"49.55\" style=\"width:575.31px;height:49.55px;aspect-ratio:575.31/49.55\" loading=\"lazy\"></picture></div>","<p>Apply the chain rule through the prediction:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.46px;--narrow-height:103.10px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/48779dd96502307c.svg\"><img class=\"math display-math\" src=\"assets/equations/297f87410a0b6ab4.svg\" alt=\"g_t=\\left.\\frac{\\partial L}{\\partial w}\\right|_{w_{t-1}}=\\frac{\\partial L}{\\partial\\hat y}\\frac{\\partial\\hat y}{\\partial w}=(\\hat y-y)x\" width=\"373.84\" height=\"62.54\" style=\"width:373.84px;height:62.54px;aspect-ratio:373.84/62.54\" loading=\"lazy\"></picture></div>","<p>The factor 1/2 in the objective cancels the factor 2 from differentiating the square. The remaining factor x comes from differentiating wx with respect to w.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/first_training.png\" aria-label=\"Enlarge diagram: Forward evaluation, gradient calculation and a parameter update for the same training example.\"><img src=\"assets/figures/first_training.png\" alt=\"Forward evaluation, gradient calculation and a parameter update for the same training example.\" width=\"1536\" height=\"1024\" loading=\"lazy\"></button><figcaption>Forward evaluation, gradient calculation and a parameter update for the same training example. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Iteration 1</h3>","<p class=\"worked-step\"><strong>Step 1: forward evaluation at the current parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.99px;--narrow-height:105.56px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8f7cd4947851e2db.svg\"><img class=\"math display-math\" src=\"assets/equations/396cd8262d595e6d.svg\" alt=\"\\hat y_0=w_0x=1(2)=2,\\qquad e_0=\\hat y_0-y=2-4=-2\" width=\"547.74\" height=\"25.90\" style=\"width:547.74px;height:25.90px;aspect-ratio:547.74/25.90\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6de0a03e9715872f.svg\" alt=\"L_0=\\frac12(-2)^2=2\" width=\"188.57\" height=\"49.55\" style=\"width:188.57px;height:49.55px;aspect-ratio:188.57/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: gradient at the current parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.87px;--narrow-height:64.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eca6d4b6240460b4.svg\"><img class=\"math display-math\" src=\"assets/equations/4b34bd0ab6469482.svg\" alt=\"g_1=(\\hat y_0-y)x=(-2)(2)=-4\" width=\"330.23\" height=\"25.90\" style=\"width:330.23px;height:25.90px;aspect-ratio:330.23/25.90\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: parameter update.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10fc5d59ff5f6fd3.svg\"><img class=\"math display-math\" src=\"assets/equations/32a8eeeef9367ad9.svg\" alt=\"w_1=w_0-\\eta g_1=1-0.1(-4)=1.4\" width=\"373.19\" height=\"24.43\" style=\"width:373.19px;height:24.43px;aspect-ratio:373.19/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: evaluate the updated model.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.29px;--narrow-height:129.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/80c9306a0dfccc42.svg\"><img class=\"math display-math\" src=\"assets/equations/dc92a06893eca5f4.svg\" alt=\"\\hat y_1=1.4(2)=2.8,\\qquad L_1=\\frac12(2.8-4)^2=0.72\" width=\"503.11\" height=\"49.55\" style=\"width:503.11px;height:49.55px;aspect-ratio:503.11/49.55\" loading=\"lazy\"></picture></div>","<h3>Iteration 2</h3>","<p>Use w₁ = 1.4 and recompute the gradient; reusing the previous gradient would not be gradient descent on this objective.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.96px;--narrow-height:64.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a7b033dfd881b35.svg\"><img class=\"math display-math\" src=\"assets/equations/d5601224799e33a1.svg\" alt=\"g_2=(\\hat y_1-y)x=(2.8-4)(2)=-2.4\" width=\"391.34\" height=\"25.90\" style=\"width:391.34px;height:25.90px;aspect-ratio:391.34/25.90\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.06px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ef24d99282ed8b6f.svg\"><img class=\"math display-math\" src=\"assets/equations/1a64bdc673ed180f.svg\" alt=\"w_2=w_1-\\eta g_2=1.4-0.1(-2.4)=1.64\" width=\"423.42\" height=\"24.43\" style=\"width:423.42px;height:24.43px;aspect-ratio:423.42/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.72px;--narrow-height:129.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/09afd5ffebd67c9e.svg\"><img class=\"math display-math\" src=\"assets/equations/cde5a74260a032c4.svg\" alt=\"\\hat y_2=1.64(2)=3.28,\\qquad L_2=\\frac12(3.28-4)^2=0.2592\" width=\"564.19\" height=\"49.55\" style=\"width:564.19px;height:49.55px;aspect-ratio:564.19/49.55\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Model state</th><th>Weight</th><th>Prediction</th><th>Half squared loss</th></tr></thead><tbody><tr><td>Initial</td><td>1</td><td>2</td><td>2</td></tr><tr><td>After update 1</td><td>1.4</td><td>2.8</td><td>0.72</td></tr><tr><td>After update 2</td><td>1.64</td><td>3.28</td><td>0.2592</td></tr></tbody></table></div>","<p><strong>Interpretation.</strong> Both gradients are negative, so the updates increase the weight toward the optimum w = y/x = 2. The loss decreases in these iterations. Gradient descent does not guarantee a decrease for every learning rate; step size matters.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s1","search":"Your first complete training step \n**Question.** A linear model is defined by \\(\\hat y=wx\\). For the training example x = 2, y = 4, use initial weight w₀ = 1, learning rate η = 0.1 and half squared loss. Perform two gradient-descent updates and report the prediction and loss after each update.\n\n\n\n### Given\n\nModel: ŷ = wx; bias is absent and is not updated.\n\nx = 2; y = 4; initial w₀ = 1; η = 0.1.\n\nLoss = half squared error; perform two updates.\n\n### To find\n\nFind the weight, prediction and loss after each update.\n\n### Formula — which one and why\n\n**Chain rule with only a trainable weight.** The weight changes the prediction and the prediction changes the half squared loss. Multiply both rates, then subtract the scaled gradient. The stated model has no bias parameter.\n\nŷ = prediction; y = target; x = input; w = weight; η = learning rate; g = loss derivative with respect to w.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Prediction minus target, phir input se multiply; naya weight = purana − ηg.\n\n### Solution — step by step\n\n\n\n\n\n### Model, objective and gradient\nThe input and target remain fixed; only the weight is trainable. There is no bias parameter in this question.\n\nApply the chain rule through the prediction:\n\nThe factor 1/2 in the objective cancels the factor 2 from differentiating the square. The remaining factor x comes from differentiating wx with respect to w.\n\n\n\n### Iteration 1\n**Step 1: forward evaluation at the current parameter.**\n\n\n**Step 2: gradient at the current parameter.**\n\n**Step 3: parameter update.**\n\n**Step 4: evaluate the updated model.**\n\n\n### Iteration 2\nUse w₁ = 1.4 and recompute the gradient; reusing the previous gradient would not be gradient descent on this objective.\n\n\n\n| Model state | Weight | Prediction | Half squared loss |\n| Initial | 1 | 2 | 2 |\n| After update 1 | 1.4 | 2.8 | 0.72 |\n| After update 2 | 1.64 | 3.28 | 0.2592 |\n**Interpretation.** Both gradients are negative, so the updates increase the weight toward the optimum w = y/x = 2. The loss decreases in these iterations. Gradient descent does not guarantee a decrease for every learning rate; step size matters.\n\n"},{"title":"Classification regression and learning types","blocks":["<p class=\"definition\"><strong>Definition.</strong> A learning problem is specified by its data, desired output and objective. Classification estimates a discrete label or class distribution; regression estimates numerical responses. The supervision type describes the feedback available during training.</p>","<h3>Explanation and working</h3>","<p><strong>Regression</strong> predicts a numerical quantity, such as temperature, price or a continuous rating. <strong>Classification</strong> predicts a category, such as defective/non-defective or cat/dog/bird. Binary classification has two classes. Multiclass classification chooses one of several classes. Multilabel classification can choose several labels together, such as “beach” and “sunset” for the same image.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_tasks.svg\" aria-label=\"Enlarge diagram: Look at the required answer: a numerical quantity is regression; a category is classification.\"><img src=\"assets/figures/v_tasks.svg\" alt=\"Look at the required answer: a numerical quantity is regression; a category is classification.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Look at the required answer: a numerical quantity is regression; a category is classification. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Supervised learning</strong> uses known input–target pairs. Most examination numericals in this course use it. <strong>Unsupervised learning</strong> searches for patterns without supplied target labels, for example grouping similar samples. <strong>Reinforcement learning</strong> learns actions using rewards from an environment. You only need these distinctions as vocabulary here; detailed algorithms from last semester are not prerequisites for this course.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s2","search":"Classification regression and learning types **Definition.** A learning problem is specified by its data, desired output and objective. Classification estimates a discrete label or class distribution; regression estimates numerical responses. The supervision type describes the feedback available during training.\n\n### Explanation and working\n**Regression** predicts a numerical quantity, such as temperature, price or a continuous rating. **Classification** predicts a category, such as defective/non-defective or cat/dog/bird. Binary classification has two classes. Multiclass classification chooses one of several classes. Multilabel classification can choose several labels together, such as “beach” and “sunset” for the same image.\n\n\n\n**Supervised learning** uses known input–target pairs. Most examination numericals in this course use it. **Unsupervised learning** searches for patterns without supplied target labels, for example grouping similar samples. **Reinforcement learning** learns actions using rewards from an environment. You only need these distinctions as vocabulary here; detailed algorithms from last semester are not prerequisites for this book."},{"title":"Training validation and test data","blocks":["<p class=\"definition\"><strong>Definition.</strong> Dataset partitioning separates parameter estimation, model selection and final performance assessment. This separation is essential to evaluate generalization without contaminating the evaluation with selection decisions.</p>","<h3>Explanation and working</h3>","<p>Training data changes the weights. Validation data helps choose settings such as layer size, learning rate and the stopping epoch. Test data is held back for the final estimate of performance on unseen samples. A possible split is 70% training, 15% validation, 15% testing, but the best split depends on the task and dataset size.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_splits.svg\" aria-label=\"Enlarge diagram: The three splits have different jobs. Only the training part is used to fit preprocessing and model parameters.\"><img src=\"assets/figures/v_splits.svg\" alt=\"The three splits have different jobs. Only the training part is used to fit preprocessing and model parameters.\" width=\"1080\" height=\"520\" loading=\"lazy\"></button><figcaption>The three splits have different jobs. Only the training part is used to fit preprocessing and model parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For 1,000 independent samples, this split gives 700 training, 150 validation and 150 testing. Avoid putting duplicates or near-identical views of the same subject across splits. For time series, later observations normally belong after earlier observations rather than being mixed randomly without considering time.</p>","<p><strong>Data leakage</strong> occurs when information that would not be available at prediction time enters training or model selection. Fitting a normalization rule to the whole dataset before splitting can leak information. Estimate preprocessing quantities from training data and apply the same rule to validation and test data.</p>","<p><strong>Normalization example.</strong> To map a training range 0 to 100 into 0 to 1, divide by 100. A value 40 becomes 0.4. Standardization instead subtracts the training mean and divides by the training standard deviation. Scaling can make gradients easier to optimize; it does not create labels or guarantee accuracy.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s3","search":"Training validation and test data **Definition.** Dataset partitioning separates parameter estimation, model selection and final performance assessment. This separation is essential to evaluate generalization without contaminating the evaluation with selection decisions.\n\n### Explanation and working\nTraining data changes the weights. Validation data helps choose settings such as layer size, learning rate and the stopping epoch. Test data is held back for the final estimate of performance on unseen samples. A possible split is 70% training, 15% validation, 15% testing, but the best split depends on the task and dataset size.\n\n\n\nFor 1,000 independent samples, this split gives 700 training, 150 validation and 150 testing. Avoid putting duplicates or near-identical views of the same subject across splits. For time series, later observations normally belong after earlier observations rather than being mixed randomly without considering time.\n**Data leakage** occurs when information that would not be available at prediction time enters training or model selection. Fitting a normalization rule to the whole dataset before splitting can leak information. Estimate preprocessing quantities from training data and apply the same rule to validation and test data.\n**Normalization example.** To map a training range 0 to 100 into 0 to 1, divide by 100. A value 40 becomes 0.4. Standardization instead subtracts the training mean and divides by the training standard deviation. Scaling can make gradients easier to optimize; it does not create labels or guarantee accuracy."},{"title":"Parameters and hyperparameters","blocks":["<p class=\"definition\"><strong>Definition.</strong> Model parameters are quantities estimated during training, whereas hyperparameters specify the architecture or training procedure and are selected separately. Optimizer states are algorithmic accumulators associated with the training procedure.</p>","<h3>Explanation and working</h3>","<p>Weights and biases are parameters learned during training. Learning rate, batch size, number of epochs, network architecture, dropout rate and regularization strength are hyperparameters chosen or tuned using validation performance. Adam’s moving averages are optimizer state: they are updated by the algorithm but are not extra network connection weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters.svg\" aria-label=\"Enlarge diagram: Weights change during training. Settings such as batch size and learning rate are chosen or tuned separately.\"><img src=\"assets/figures/v_parameters.svg\" alt=\"Weights change during training. Settings such as batch size and learning rate are chosen or tuned separately.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Weights change during training. Settings such as batch size and learning rate are chosen or tuned separately. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>An <strong>epoch</strong> is one complete pass through the training dataset. A <strong>batch</strong> is the group used to calculate one update. An <strong>iteration</strong> here means one update. If there are 100 samples and batch size 10, one epoch has 10 updates. One epoch does not generally mean one update.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s4","search":"Parameters and hyperparameters **Definition.** Model parameters are quantities estimated during training, whereas hyperparameters specify the architecture or training procedure and are selected separately. Optimizer states are algorithmic accumulators associated with the training procedure.\n\n### Explanation and working\nWeights and biases are parameters learned during training. Learning rate, batch size, number of epochs, network architecture, dropout rate and regularization strength are hyperparameters chosen or tuned using validation performance. Adam’s moving averages are optimizer state: they are updated by the algorithm but are not extra network connection weights.\n\n\n\nAn **epoch** is one complete pass through the training dataset. A **batch** is the group used to calculate one update. An **iteration** here means one update. If there are 100 samples and batch size 10, one epoch has 10 updates. One epoch does not generally mean one update."},{"title":"What one artificial neuron does","blocks":["<p class=\"definition\"><strong>Definition.</strong> An artificial neuron is a calculation unit that multiplies each input by a matching weight, adds the products and a bias, and applies an activation function to produce its output.</p>","<h3>What goes into a neuron?</h3>","<p>An input is a number supplied to the calculation. With three inputs, x = [2,1,3] simply lists those three numbers in order. The matching weight list tells the neuron which multiplier to use for each input. A negative weight contributes a negative amount when its input is positive.</p>","<p>The <strong>bias</strong> is one extra adjustable number added to the total. The total before activation is called z or <strong>preactivation</strong>. The <strong>activation function</strong> is the final rule applied to z: for example, ReLU replaces a negative z with zero, while sigmoid turns z into a number between 0 and 1. The resulting output is called a or the <strong>activation</strong>.</p>","<p><strong>Yaad rakhne ka cue:</strong> inputs × apne weights → products ka sum → ek bias → activation → output.</p>","<h3>Mathematical model and notation</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.35px;--narrow-height:112.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8032854fc489fa3f.svg\"><img class=\"math display-math\" src=\"assets/equations/28f8b2ebee0ebbf6.svg\" alt=\"z=\\sum_{i=1}^{d}w_ix_i+b=w^Tx+b\" width=\"289.70\" height=\"72.98\" style=\"width:289.70px;height:72.98px;aspect-ratio:289.70/72.98\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<div class=\"table-scroll\"><table><thead><tr><th>Symbol</th><th>Meaning and role</th></tr></thead><tbody><tr><td>xᵢ</td><td>Input component i; the neuron receives d such components</td></tr><tr><td>wᵢ</td><td>Trainable weight multiplying that input component</td></tr><tr><td>b</td><td>Trainable bias added once to this neuron&#x27;s total</td></tr><tr><td>z</td><td>Preactivation: the result before applying the activation function</td></tr><tr><td>f</td><td>Chosen activation function, such as sigmoid or ReLU</td></tr><tr><td>a</td><td>Activation: the neuron&#x27;s output after applying f</td></tr></tbody></table></div>","<p>The dot product wᵀx is a compact notation for the sum of matching weight–input products. A positive weight and a negative weight can make opposite contributions for the same positive input. A larger weight magnitude means a larger contribution for a fixed input; it is not, by itself, a general measure of feature importance across differently scaled inputs.</p>","<h3>Why both a bias and an activation are needed</h3>","<p>The bias changes the preactivation independently of x. In a one-input affine function z = wx + b, it is the intercept. In a classifier with a decision boundary z = 0, a bias allows that boundary to be shifted instead of forcing it through the origin.</p>","<p>The activation determines how z is transformed. Sigmoid produces a value between 0 and 1; ReLU retains positive preactivations and sets negative ones to zero. Nonlinear activations let stacked layers represent nonlinear functions. The preactivation and activation are distinct quantities even when a particular ReLU calculation gives them equal values.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: Read the neuron in order: input contributions → affine sum z → activation function f → output a. Add one bias at the receiving neuron.\"><img src=\"assets/figures/neuron.svg\" alt=\"Read the neuron in order: input contributions → affine sum z → activation function f → output a. Add one bias at the receiving neuron.\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>Read the neuron in order: input contributions → affine sum z → activation function f → output a. Add one bias at the receiving neuron. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Worked numerical</h3>","<p class=\"inline-question\"><strong>Question.</strong> A neuron has x = [2, 1, 3]ᵀ, w = [0.4, −0.2, 0.5]ᵀ and b = 0.1. Calculate its preactivation and sigmoid output.</p>","<h3>Given</h3>","<p>Inputs = [2,1,3]; matching weights = [0.4,−0.2,0.5].</p>","<p>Bias = 0.1; activation = sigmoid.</p>","<h3>To find</h3>","<p>Find the preactivation z, then the sigmoid output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid output.</strong> The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.</p>","<p>z = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Minus-z ki e power, plus one, phir one divided by whole denominator.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/568d8f8a50e883d1.svg\" alt=\"x_1w_1=2(0.4)=0.8\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by weight 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2aecb1c03e00ecf3.svg\" alt=\"x_2w_2=1(-0.2)=-0.2\" width=\"249.67\" height=\"24.43\" style=\"width:249.67px;height:24.43px;aspect-ratio:249.67/24.43\" loading=\"lazy\"></div>","<p>The minus sign belongs to the weight, so the contribution stays negative.</p>","<p class=\"worked-step\"><strong>Step 3: multiply input 3 by weight 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b26c8cde278f5783.svg\" alt=\"x_3w_3=3(0.5)=1.5\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the three contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.48px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/928ca4d8a84ae46e.svg\"><img class=\"math display-math\" src=\"assets/equations/fa72e2cee0620f1c.svg\" alt=\"s=0.8+(-0.2)+1.5=0.6+1.5=2.1\" width=\"424.20\" height=\"24.43\" style=\"width:424.20px;height:24.43px;aspect-ratio:424.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc2fbdf24fc7fcdc.svg\" alt=\"z=s+b=2.1+0.1=2.2\" width=\"284.48\" height=\"18.96\" style=\"width:284.48px;height:18.96px;aspect-ratio:284.48/18.96\" loading=\"lazy\"></div>","<p>This is the preactivation. It is not yet the requested sigmoid output.</p>","<p class=\"worked-step\"><strong>Step 6: negate z for the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6ae6042702919060.svg\" alt=\"-z=-2.2\" width=\"113.19\" height=\"18.27\" style=\"width:113.19px;height:18.27px;aspect-ratio:113.19/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3e8120863f30069.svg\" alt=\"e^{-z}=e^{-2.2}\\approx0.110803158\" width=\"277.96\" height=\"23.60\" style=\"width:277.96px;height:23.60px;aspect-ratio:277.96/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:104.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/417b75e5d36172d1.svg\"><img class=\"math display-math\" src=\"assets/equations/72d833375eab0d1c.svg\" alt=\"1+e^{-z}=1+0.110803158=1.110803158\" width=\"442.16\" height=\"22.17\" style=\"width:442.16px;height:22.17px;aspect-ratio:442.16/22.17\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide one by that denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:155.40px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bc1ac01a29b10b0.svg\"><img class=\"math display-math\" src=\"assets/equations/7567a6adfafdbad0.svg\" alt=\"a=\\frac1{1+e^{-z}}=\\frac1{1.110803158}\\approx0.900249511\" width=\"467.09\" height=\"51.56\" style=\"width:467.09px;height:51.56px;aspect-ratio:467.09/51.56\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> sigmoid output ≈ 0.900249511. It lies between 0 and 1. The raw sum was 2.2, whereas the activated output is approximately 0.90025.</p>","<h3>From one neuron to a layer</h3>","<p>With m receiving neurons and d input components, W has shape m × d. Row j contains the incoming weights of neuron j. The bias vector has m entries, one for each receiving neuron:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/247718acabda6724.svg\" alt=\"z=Wx+b,\\qquad a=f(z)\" width=\"272.94\" height=\"24.43\" style=\"width:272.94px;height:24.43px;aspect-ratio:272.94/24.43\" loading=\"lazy\"></div>","<p>Sigmoid, tanh and ReLU apply independently to each component. Softmax is different: it transforms a whole vector of output logits together.</p>","<h3>Neuron example 2: ReLU output</h3>","<p class=\"inline-question\"><strong>Question. A neuron receives inputs [2], weights [3] and bias 1. Calculate its preactivation and ReLU output.</strong></p>","<h3>Given</h3>","<p>Inputs = [2].</p>","<p>Weights = [3]; bias = 1.</p>","<p>Activation = ReLU.</p>","<h3>To find</h3>","<p>z before activation and a after activation.</p>","<h3>Formula — which one and why</h3>","<p>The weighted sum combines the inputs. The output must then use the activation explicitly requested.</p>","<p>z names the sum; a names the activated result. They are not always equal.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3497cbcbfa494dd1.svg\" alt=\"z=\\sum_i w_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sum alag, activation alag; activation lagana mat bhool.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0789e90228011be2.svg\" alt=\"(2)(3)=6\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the input contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7d688f2957123f9f.svg\" alt=\"s=(6)=6\" width=\"120.07\" height=\"24.43\" style=\"width:120.07px;height:24.43px;aspect-ratio:120.07/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cd7ec47b25d8ce7.svg\" alt=\"z=6+(1)=7\" width=\"162.06\" height=\"24.43\" style=\"width:162.06px;height:24.43px;aspect-ratio:162.06/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply the stated activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a730b8a58ff43cba.svg\" alt=\"a=\\max(0,7)=7\" width=\"190.09\" height=\"24.43\" style=\"width:190.09px;height:24.43px;aspect-ratio:190.09/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 7; a = 7.</p>","<h3>Neuron example 3: ReLU output</h3>","<p class=\"inline-question\"><strong>Question. A neuron receives inputs [2, 1], weights [-1, 0.5] and bias 0.2. Calculate its preactivation and ReLU output.</strong></p>","<h3>Given</h3>","<p>Inputs = [2, 1].</p>","<p>Weights = [-1, 0.5]; bias = 0.2.</p>","<p>Activation = ReLU.</p>","<h3>To find</h3>","<p>z before activation and a after activation.</p>","<h3>Formula — which one and why</h3>","<p>The weighted sum combines the inputs. The output must then use the activation explicitly requested.</p>","<p>z names the sum; a names the activated result. They are not always equal.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3497cbcbfa494dd1.svg\" alt=\"z=\\sum_i w_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sum alag, activation alag; activation lagana mat bhool.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc29fd0da04569d8.svg\" alt=\"(2)(-1)=-2\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47470f92bf2adcc4.svg\" alt=\"(1)(0.5)=0.5\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the input contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2345e5dfa56c33e.svg\" alt=\"s=(-2)+(0.5)=-1.5\" width=\"257.21\" height=\"24.43\" style=\"width:257.21px;height:24.43px;aspect-ratio:257.21/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3c99c8f72adf2141.svg\" alt=\"z=-1.5+(0.2)=-1.3\" width=\"257.12\" height=\"24.43\" style=\"width:257.12px;height:24.43px;aspect-ratio:257.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2503c315df3664fa.svg\" alt=\"a=\\max(0,-1.3)=0\" width=\"228.12\" height=\"24.43\" style=\"width:228.12px;height:24.43px;aspect-ratio:228.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = -1.3; a = 0.</p>","<h3>Neuron example 4: sigmoid output</h3>","<p class=\"inline-question\"><strong>Question. A neuron receives inputs [1, 2], weights [0.2, -0.1] and bias 0. Calculate its preactivation and sigmoid output.</strong></p>","<h3>Given</h3>","<p>Inputs = [1, 2].</p>","<p>Weights = [0.2, -0.1]; bias = 0.</p>","<p>Activation = sigmoid.</p>","<h3>To find</h3>","<p>z before activation and a after activation.</p>","<h3>Formula — which one and why</h3>","<p>The weighted sum combines the inputs. The output must then use the activation explicitly requested.</p>","<p>z names the sum; a names the activated result. They are not always equal.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3497cbcbfa494dd1.svg\" alt=\"z=\\sum_i w_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sum alag, activation alag; activation lagana mat bhool.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5c759a37e815fafb.svg\" alt=\"(1)(0.2)=0.2\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba87aedd127c080a.svg\" alt=\"(2)(-0.1)=-0.2\" width=\"183.30\" height=\"24.43\" style=\"width:183.30px;height:24.43px;aspect-ratio:183.30/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the input contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9a1dc06bff5e31d8.svg\" alt=\"s=(0.2)+(-0.2)=0\" width=\"238.20\" height=\"24.43\" style=\"width:238.20px;height:24.43px;aspect-ratio:238.20/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8d9f0d00314027b.svg\" alt=\"z=0+(0)=0\" width=\"162.06\" height=\"24.43\" style=\"width:162.06px;height:24.43px;aspect-ratio:162.06/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2d7874ea2511447b.svg\" alt=\"a=\\frac1{1+e^{0}}=\\frac1{1+1}=0.5\" width=\"281.86\" height=\"52.39\" style=\"width:281.86px;height:52.39px;aspect-ratio:281.86/52.39\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 0; a = 0.5.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s5","search":"What one artificial neuron does **Definition.** An artificial neuron is a calculation unit that multiplies each input by a matching weight, adds the products and a bias, and applies an activation function to produce its output.\n\n### What goes into a neuron?\nAn input is a number supplied to the calculation. With three inputs, x = [2,1,3] simply lists those three numbers in order. The matching weight list tells the neuron which multiplier to use for each input. A negative weight contributes a negative amount when its input is positive.\n\nThe **bias** is one extra adjustable number added to the total. The total before activation is called z or **preactivation**. The **activation function** is the final rule applied to z: for example, ReLU replaces a negative z with zero, while sigmoid turns z into a number between 0 and 1. The resulting output is called a or the **activation**.\n\n**Yaad rakhne ka cue:** inputs × apne weights → products ka sum → ek bias → activation → output.\n\n### Mathematical model and notation\n\n\n| Symbol | Meaning and role |\n| xᵢ | Input component i; the neuron receives d such components |\n| wᵢ | Trainable weight multiplying that input component |\n| b | Trainable bias added once to this neuron's total |\n| z | Preactivation: the result before applying the activation function |\n| f | Chosen activation function, such as sigmoid or ReLU |\n| a | Activation: the neuron's output after applying f |\n\nThe dot product wᵀx is a compact notation for the sum of matching weight–input products. A positive weight and a negative weight can make opposite contributions for the same positive input. A larger weight magnitude means a larger contribution for a fixed input; it is not, by itself, a general measure of feature importance across differently scaled inputs.\n\n### Why both a bias and an activation are needed\nThe bias changes the preactivation independently of x. In a one-input affine function z = wx + b, it is the intercept. In a classifier with a decision boundary z = 0, a bias allows that boundary to be shifted instead of forcing it through the origin.\n\nThe activation determines how z is transformed. Sigmoid produces a value between 0 and 1; ReLU retains positive preactivations and sets negative ones to zero. Nonlinear activations let stacked layers represent nonlinear functions. The preactivation and activation are distinct quantities even when a particular ReLU calculation gives them equal values.\n\n\n\n### Worked numerical\n**Question.** A neuron has x = [2, 1, 3]ᵀ, w = [0.4, −0.2, 0.5]ᵀ and b = 0.1. Calculate its preactivation and sigmoid output.\n\n\n\n### Given\n\nInputs = [2,1,3]; matching weights = [0.4,−0.2,0.5].\n\nBias = 0.1; activation = sigmoid.\n\n### To find\n\nFind the preactivation z, then the sigmoid output.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**Sigmoid output.** The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.\n\nz = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.\n\n\n\n**Yaad rakhne ka cue:** Minus-z ki e power, plus"},{"title":"Model answer: explain an artificial neuron","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain the structure and working of an artificial neuron. Describe the roles of inputs, weights, bias and activation with a numerical example.</p>"],"answer":["<p>An artificial neuron is a computational unit that applies an activation function to an affine combination of its inputs. Its trainable weights and bias determine the preactivation; its output is passed to subsequent layers.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: Follow each input through its weight, add one bias at the receiving neuron, then apply activation.\"><img src=\"assets/figures/neuron.svg\" alt=\"Follow each input through its weight, add one bias at the receiving neuron, then apply activation.\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>Follow each input through its weight, add one bias at the receiving neuron, then apply activation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Formula and symbols</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.93px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8477fc1ddc03ffc3.svg\"><img class=\"math display-math\" src=\"assets/equations/32a736852ff7774e.svg\" alt=\"z=w_1x_1+w_2x_2+\\cdots+w_nx_n+b,\\qquad a=f(z)\" width=\"513.48\" height=\"24.43\" style=\"width:513.48px;height:24.43px;aspect-ratio:513.48/24.43\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Part</th><th>Meaning</th><th>What it does</th></tr></thead><tbody><tr><td>x₁, x₂, …</td><td>Input features</td><td>Supply the information for this calculation</td></tr><tr><td>w₁, w₂, …</td><td>Weights</td><td>Control the contribution of each matching input</td></tr><tr><td>b</td><td>Bias</td><td>Shifts the weighted sum independently of the inputs</td></tr><tr><td>z</td><td>Net input</td><td>The number before activation</td></tr><tr><td>f</td><td>Activation rule</td><td>Transforms z, often nonlinearly</td></tr><tr><td>a</td><td>Activated output</td><td>The number sent onward</td></tr></tbody></table></div>","<h3>Worked ReLU neuron example</h3>","<p class=\"inline-question\"><strong>Question. An artificial neuron has x₁ = 2, x₂ = 1, w₁ = 0.5, w₂ = −0.2 and b = 0.1. Calculate its preactivation and ReLU output.</strong></p>","<h3>Given</h3>","<p>Inputs = [2,1]; weights = [0.5,−0.2]; bias = 0.1; activation = ReLU.</p>","<h3>To find</h3>","<p>Preactivation z and activated output a.</p>","<h3>Formula — which one and why</h3>","<p>Each input contributes through its own weight. Add one bias after summing the products; ReLU then keeps a positive total.</p>","<p>z means before activation; a means after activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/04168cf0cec0712f.svg\" alt=\"z=w_1x_1+w_2x_2+b\" width=\"219.78\" height=\"20.63\" style=\"width:219.78px;height:20.63px;aspect-ratio:219.78/20.63\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Product, product, sum, bias, phir activation.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the first pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4b945ff5abf26e2.svg\" alt=\"0.5(2)=1\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply the second pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44552ee4afe034fa.svg\" alt=\"(-0.2)(1)=-0.2\" width=\"183.30\" height=\"24.43\" style=\"width:183.30px;height:24.43px;aspect-ratio:183.30/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add both contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d74c1d06c5bc866b.svg\" alt=\"1+(-0.2)=0.8\" width=\"175.14\" height=\"24.43\" style=\"width:175.14px;height:24.43px;aspect-ratio:175.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe5a369324074a4c.svg\" alt=\"z=0.8+0.1=0.9\" width=\"200.08\" height=\"18.27\" style=\"width:200.08px;height:18.27px;aspect-ratio:200.08/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply ReLU.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/abc54eeca8cf7516.svg\" alt=\"a=\\max(0,0.9)=0.9\" width=\"228.12\" height=\"24.43\" style=\"width:228.12px;height:24.43px;aspect-ratio:228.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 0.9 and a = 0.9. ReLU leaves this positive preactivation unchanged.</p>","<p>The weights and bias are learned parameters. During training, their values are adjusted to reduce an objective. The activation function itself is usually chosen as part of the architecture. Adding a bias does not mean adding one bias after every input product; add the receiving neuron&#x27;s bias once.</p>"],"kind":"theory","id":"mt2-c4-s6","search":"Model answer: explain an artificial neuron **Question.** Explain the structure and working of an artificial neuron. Describe the roles of inputs, weights, bias and activation with a numerical example.\n\n**Model answer.**\nAn artificial neuron is a computational unit that applies an activation function to an affine combination of its inputs. Its trainable weights and bias determine the preactivation; its output is passed to subsequent layers.\n\n\n\n\n### Formula and symbols\n\n| Part | Meaning | What it does |\n| x₁, x₂, … | Input features | Supply the information for this calculation |\n| w₁, w₂, … | Weights | Control the contribution of each matching input |\n| b | Bias | Shifts the weighted sum independently of the inputs |\n| z | Net input | The number before activation |\n| f | Activation rule | Transforms z, often nonlinearly |\n| a | Activated output | The number sent onward |\n\n\n\n### Worked ReLU neuron example\n\n**Question. An artificial neuron has x₁ = 2, x₂ = 1, w₁ = 0.5, w₂ = −0.2 and b = 0.1. Calculate its preactivation and ReLU output.**\n\n\n\n### Given\n\nInputs = [2,1]; weights = [0.5,−0.2]; bias = 0.1; activation = ReLU.\n\n### To find\n\nPreactivation z and activated output a.\n\n### Formula — which one and why\n\nEach input contributes through its own weight. Add one bias after summing the products; ReLU then keeps a positive total.\n\nz means before activation; a means after activation.\n\n\n\n\n\n**Yaad rakhne ka cue:** Product, product, sum, bias, phir activation.\n\n### Solution — step by step\n\n\n\n**Step 1: multiply the first pair.**\n\n\n\n\n\n\n\n**Step 2: multiply the second pair.**\n\n\n\n\n\n\n\n**Step 3: add both contributions.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply ReLU.**\n\n\n\n\n\n\n\n**Final answer:** z = 0.9 and a = 0.9. ReLU leaves this positive preactivation unchanged.\n\n\n\nThe weights and bias are learned parameters. During training, their values are adjusted to reduce an objective. The activation function itself is usually chosen as part of the architecture. Adding a bias does not mean adding one bias after every input product; add the receiving neuron's bias once.\n"},{"title":"Activation functions and how to calculate them","blocks":["<h3>What an activation function does, and why it is needed</h3>","<p>A neuron first produces the weighted sum z. The activation function f is a rule that transforms that sum into the output a = f(z). Applying an activation does not change the stored weights; it calculates a new output from the current sum.</p>","<p>If every layer only multiplies and adds, several layers still combine into a single affine transformation. A nonlinear activation lets the network represent more complicated relationships. The output activation must also suit the task: sigmoid for a binary-class probability, softmax for mutually exclusive class probabilities, and often a linear output for unrestricted regression.</p>","<p>The <strong>activation value</strong> says what the neuron outputs. The <strong>activation derivative</strong> says how quickly that output changes when z changes, which is needed during backpropagation. For sigmoid at z = 0, the value is 0.5 but the derivative is 0.25. They serve different purposes.</p>","<p><strong>Yaad rakhne ka cue:</strong> z = activation se pehle ka sum; a = uske baad ka answer; f′ = answer kitni tezi se badlega.</p>","<p class=\"definition\"><strong>Definition.</strong> An activation function maps a neuron&#x27;s preactivation to its output. Nonlinear activations allow a multilayer network to represent nonlinear functions; the output activation also encodes the prediction type. Without a nonlinear activation, a composition of affine layers remains affine.</p>","<h3>Explanation and working</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.01px;--narrow-height:92.09px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b7ede87d0558048.svg\"><img class=\"math display-math\" src=\"assets/equations/7addd035227c8e01.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\quad \\sigma&#x27;(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"427.95\" height=\"51.56\" style=\"width:427.95px;height:51.56px;aspect-ratio:427.95/51.56\" loading=\"lazy\"></picture></div>","<p>Sigmoid converts any finite real input into a value strictly between 0 and 1. At zero it is 0.5. It is useful for a binary-class probability or independent multilabel outputs. At very positive or negative inputs it saturates, so its derivative becomes small. Its derivative is at most 0.25.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_activations.svg\" aria-label=\"Enlarge diagram: Trace the output of each curve as the same raw input moves from negative to positive.\"><img src=\"assets/figures/v_activations.svg\" alt=\"Trace the output of each curve as the same raw input moves from negative to positive.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Trace the output of each curve as the same raw input moves from negative to positive. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.65px;--narrow-height:99.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/151466f4a43db268.svg\"><img class=\"math display-math\" src=\"assets/equations/610c0fbb4970deec.svg\" alt=\"\\tanh(z)=\\frac{e^{2z}-1}{e^{2z}+1},\\quad \\tanh&#x27;(z)=1-\\tanh^2(z)\" width=\"480.72\" height=\"56.48\" style=\"width:480.72px;height:56.48px;aspect-ratio:480.72/56.48\" loading=\"lazy\"></picture></div>","<p>Tanh lies between −1 and +1 and is zero-centered. It is common in recurrent hidden states. It also saturates. “Zero-centered” does not mean “no vanishing gradients”.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8ed42aad8099504b.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z),\\quad f&#x27;(z)=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z&lt;0\\end{cases}\" width=\"455.22\" height=\"58.62\" style=\"width:455.22px;height:58.62px;aspect-ratio:455.22/58.62\" loading=\"lazy\"></div>","<p>ReLU returns the input if positive and zero if negative. It is cheap to compute and has derivative 1 on its positive side. Units can become inactive on all relevant inputs, known as dying ReLU. At z = 0 the mathematical derivative is undefined; a convention such as 0 is used in implementations and this course’s exercises when needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba63451671574a0f.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\az&amp;z&lt;0\\end{cases},\\qquad a=0.01\\ \\text{unless specified}\" width=\"628.12\" height=\"58.62\" style=\"width:628.12px;height:58.62px;aspect-ratio:628.12/58.62\" loading=\"lazy\"></div>","<p>The small negative slope a lets some gradient through for negative inputs. At z = −2 and a = 0.01, output = −0.02. Do not take the absolute value. PReLU learns the negative slope; Leaky ReLU normally fixes it.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:137.99px;--narrow-height:193.56px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ad7e7d9830e70ac.svg\"><img class=\"math display-math\" src=\"assets/equations/50824a322c80361f.svg\" alt=\"p_i=\\frac{e^{z_i}}{\\sum_j e^{z_j}}=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_jz_j\" width=\"434.70\" height=\"63.31\" style=\"width:434.70px;height:63.31px;aspect-ratio:434.70/63.31\" loading=\"lazy\"></picture></div>","<p>Softmax acts on a group of class scores, called logits. All probabilities are positive and sum to 1. Subtracting the same maximum c from all logits leaves the result unchanged and avoids very large exponentials. It is suited to mutually exclusive multiclass output.</p>","<p><strong>Full softmax example.</strong> For [−1, 0, 1], exponentials are [0.367879, 1, 2.718282]. Sum = 4.086161. Divide each by that same sum: [0.090031, 0.244728, 0.665241]. Check their sum is approximately 1. Three separate sigmoids would give [0.268941, 0.5, 0.731059], which are different and do not sum to 1.</p>","<h3>Derivation of the sigmoid derivative</h3>","<p>Write sigmoid as a negative power. The outer derivative contributes −1, and differentiating the inner exponential contributes a second negative sign:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4d8f5baacfd2120.svg\" alt=\"\\sigma(z)=(1+e^{-z})^{-1}\" width=\"197.00\" height=\"27.70\" style=\"width:197.00px;height:27.70px;aspect-ratio:197.00/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.60px;--narrow-height:142.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/25b5ff83cfc93c4e.svg\"><img class=\"math display-math\" src=\"assets/equations/67121a49478eada8.svg\" alt=\"\\sigma&#x27;(z)=-(1+e^{-z})^{-2}(-e^{-z})=\\frac{e^{-z}}{(1+e^{-z})^2}\" width=\"445.69\" height=\"59.16\" style=\"width:445.69px;height:59.16px;aspect-ratio:445.69/59.16\" loading=\"lazy\"></picture></div>","<p>Separate the expression into two factors:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.04px;--narrow-height:133.86px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8342957fe889eca9.svg\"><img class=\"math display-math\" src=\"assets/equations/c3ea50ce5747d8ce.svg\" alt=\"\\sigma&#x27;(z)=\\frac{1}{1+e^{-z}}\\frac{e^{-z}}{1+e^{-z}}=\\sigma(z)[1-\\sigma(z)]\" width=\"436.05\" height=\"54.23\" style=\"width:436.05px;height:54.23px;aspect-ratio:436.05/54.23\" loading=\"lazy\"></picture></div>","<p>The second factor is 1−σ(z) because subtracting 1/(1+e⁻ᶻ) from 1 leaves e⁻ᶻ/(1+e⁻ᶻ). Once a forward pass has supplied σ(z), its derivative requires no further exponential evaluation.</p>","<h3>Derivation of the tanh derivative</h3>","<p>Use the quotient rule on the exponential definition. Here u = e²ᶻ−1 and v = e²ᶻ+1, with u′ = v′ = 2e²ᶻ.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:340.18px;--narrow-height:201.84px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1eaf1c302e07c3ae.svg\"><img class=\"math display-math\" src=\"assets/equations/730661d0a7189944.svg\" alt=\"\\frac{d}{dz}\\tanh z=\\frac{2e^{2z}(e^{2z}+1)-2e^{2z}(e^{2z}-1)}{(e^{2z}+1)^2}=\\frac{4e^{2z}}{(e^{2z}+1)^2}\" width=\"584.52\" height=\"61.42\" style=\"width:584.52px;height:61.42px;aspect-ratio:584.52/61.42\" loading=\"lazy\"></picture></div>","<p>The identity 1−tanh²(z) gives the same expression, since the numerator becomes (e²ᶻ+1)²−(e²ᶻ−1)² = 4e²ᶻ. Therefore the backward-pass factor is 1−a² when a = tanh(z).</p>","<h3>Why nonlinear activations are required</h3>","<p>For two affine layers without a nonlinear activation:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.41px;--narrow-height:104.09px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/886e2a40c2cd8e26.svg\"><img class=\"math display-math\" src=\"assets/equations/dac24947cfd3e2d0.svg\" alt=\"h=W_1x+b_1,\\qquad \\hat y=W_2h+b_2=W_2W_1x+(W_2b_1+b_2)\" width=\"617.32\" height=\"25.90\" style=\"width:617.32px;height:25.90px;aspect-ratio:617.32/25.90\" loading=\"lazy\"></picture></div>","<p>The composition is still one affine transformation. A nonlinear activation between layers changes the family of functions the network can represent. This is the mathematical reason for using nonlinear hidden activations; merely adding affine layers does not provide this expressive advantage.</p>","<h3>sigmoid example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9feed82e056cf24.svg\" alt=\"-z=-(-2)=2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b83d9532e6445b5a.svg\" alt=\"e^{2}\\approx7.389056099\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4026cb0f8944f24f.svg\"><img class=\"math display-math\" src=\"assets/equations/fb7c0cac9ced67f0.svg\" alt=\"1+7.389056099\\approx8.389056099\" width=\"332.60\" height=\"18.52\" style=\"width:332.60px;height:18.52px;aspect-ratio:332.60/18.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f4a3cb96f1098e79.svg\"><img class=\"math display-math\" src=\"assets/equations/b44984dd703daaf9.svg\" alt=\"a=\\frac1{8.389056099}\\approx0.119202922\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/154ffcd0747b53aa.svg\"><img class=\"math display-math\" src=\"assets/equations/61cf4a9551a25fd6.svg\" alt=\"f\\prime(-2)=(0.119202922)(1-0.119202922)\\approx0.104993585\" width=\"602.56\" height=\"24.43\" style=\"width:602.56px;height:24.43px;aspect-ratio:602.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.119202922. Derivative ≈ 0.104993585.</p>","<h3>sigmoid example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17055d0f6bb7d8cb.svg\" alt=\"-z=-(0)=0\" width=\"157.99\" height=\"24.43\" style=\"width:157.99px;height:24.43px;aspect-ratio:157.99/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/88f353ee1ae5e616.svg\"><img class=\"math display-math\" src=\"assets/equations/048aaa762a498d29.svg\" alt=\"1+1.000000000\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55f56d862c8a637f.svg\"><img class=\"math display-math\" src=\"assets/equations/bb9808b4290f77c2.svg\" alt=\"a=\\frac1{2.000000000}\\approx0.500000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5e112d2ee69475de.svg\"><img class=\"math display-math\" src=\"assets/equations/fe0302f0c6aecdca.svg\" alt=\"f\\prime(0)=(0.500000000)(1-0.500000000)\\approx0.250000000\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.500000000. Derivative ≈ 0.250000000.</p>","<h3>sigmoid example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbbb55e23c6ba6a0.svg\" alt=\"-z=-(2)=-2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1264450d54002695.svg\"><img class=\"math display-math\" src=\"assets/equations/21d0f7a7fd447a52.svg\" alt=\"1+0.135335283\\approx1.135335283\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f08d0c34f5e2fdf7.svg\"><img class=\"math display-math\" src=\"assets/equations/6480e62e9ef0f8a2.svg\" alt=\"a=\\frac1{1.135335283}\\approx0.880797078\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278a4098b6b446b4.svg\"><img class=\"math display-math\" src=\"assets/equations/00492ebf856c8aae.svg\" alt=\"f\\prime(2)=(0.880797078)(1-0.880797078)\\approx0.104993585\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.880797078. Derivative ≈ 0.104993585.</p>","<h3>tanh example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ab8a21d8aab882c.svg\" alt=\"2z=2(-2)=-4\" width=\"182.43\" height=\"24.43\" style=\"width:182.43px;height:24.43px;aspect-ratio:182.43/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c3b8c152fd312b9.svg\" alt=\"e^{-4}\\approx0.018315639\" width=\"197.05\" height=\"22.32\" style=\"width:197.05px;height:22.32px;aspect-ratio:197.05/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/782210c69a20fd3b.svg\"><img class=\"math display-math\" src=\"assets/equations/38bd067833181d6c.svg\" alt=\"0.018315639-1\\approx-0.981684361\" width=\"351.62\" height=\"18.54\" style=\"width:351.62px;height:18.54px;aspect-ratio:351.62/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c7713b25655beb72.svg\"><img class=\"math display-math\" src=\"assets/equations/dee5ac5546f1b2f2.svg\" alt=\"0.018315639+1\\approx1.018315639\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.24px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/300fc0089c5516db.svg\"><img class=\"math display-math\" src=\"assets/equations/809bd6f34ad5f6a6.svg\" alt=\"a=\\frac{-0.981684361}{1.018315639}\\approx-0.964027580\" width=\"384.79\" height=\"50.36\" style=\"width:384.79px;height:50.36px;aspect-ratio:384.79/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.52px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bb2d4ce554c14198.svg\"><img class=\"math display-math\" src=\"assets/equations/c4ff92106fa31931.svg\" alt=\"f\\prime(-2)=1-(-0.964027580)^2\\approx0.070650825\" width=\"484.27\" height=\"27.70\" style=\"width:484.27px;height:27.70px;aspect-ratio:484.27/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ -0.964027580. Derivative ≈ 0.070650825.</p>","<h3>tanh example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83fefb855224c584.svg\" alt=\"2z=2(0)=0\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/40327f28206586d2.svg\"><img class=\"math display-math\" src=\"assets/equations/fa618ba26a236aab.svg\" alt=\"1.000000000-1\\approx0.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5e16c3256057084.svg\"><img class=\"math display-math\" src=\"assets/equations/46b371b545cc8bc8.svg\" alt=\"1.000000000+1\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/081512ac7f7a1b51.svg\"><img class=\"math display-math\" src=\"assets/equations/da7a029e0ae3e61f.svg\" alt=\"a=\\frac{0.000000000}{2.000000000}\\approx0.000000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3899b5f76509b8c.svg\"><img class=\"math display-math\" src=\"assets/equations/b3f22ac5fb036f65.svg\" alt=\"f\\prime(0)=1-(0.000000000)^2\\approx1.000000000\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 1.000000000.</p>","<h3>tanh example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28a6e73374f6be65.svg\" alt=\"2z=2(2)=4\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dcc7f746c4400033.svg\" alt=\"e^{4}\\approx54.598150033\" width=\"195.81\" height=\"22.32\" style=\"width:195.81px;height:22.32px;aspect-ratio:195.81/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f63e045301bde055.svg\"><img class=\"math display-math\" src=\"assets/equations/a7f29872524e69fc.svg\" alt=\"54.598150033-1\\approx53.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c86d55c9549cedd.svg\"><img class=\"math display-math\" src=\"assets/equations/1a7460c08ec0eb4e.svg\" alt=\"54.598150033+1\\approx55.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.45px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a5642fac7a0997.svg\"><img class=\"math display-math\" src=\"assets/equations/9d5e297333003136.svg\" alt=\"a=\\frac{53.598150033}{55.598150033}\\approx0.964027580\" width=\"358.99\" height=\"50.09\" style=\"width:358.99px;height:50.09px;aspect-ratio:358.99/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/52d252bd261b679f.svg\"><img class=\"math display-math\" src=\"assets/equations/6f2d0c822236e436.svg\" alt=\"f\\prime(2)=1-(0.964027580)^2\\approx0.070650825\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.964027580. Derivative ≈ 0.070650825.</p>","<h3>ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbc65c947d4ed97f.svg\" alt=\"f\\prime(-2)=0\" width=\"115.19\" height=\"24.43\" style=\"width:115.19px;height:24.43px;aspect-ratio:115.19/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 0.000000000.</p>","<h3>ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>","<h3>Leaky ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24b81e63d794388e.svg\" alt=\"a=-0.2\" width=\"95.75\" height=\"18.27\" style=\"width:95.75px;height:18.27px;aspect-ratio:95.75/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaab86572902924a.svg\" alt=\"f\\prime(-2)=0.1\" width=\"134.21\" height=\"24.43\" style=\"width:134.21px;height:24.43px;aspect-ratio:134.21/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ -0.200000000. Derivative ≈ 0.100000000.</p>","<h3>Leaky ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>Leaky ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>","<h3>Softmax for [0, 0, 0]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [0, 0, 0].</strong></p>","<h3>Given</h3>","<p>Logits = [0, 0, 0]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e35e2c8f440c3bf.svg\" alt=\"z-c=\\begin{bmatrix}0&amp;0&amp;0\\end{bmatrix}\" width=\"183.50\" height=\"24.43\" style=\"width:183.50px;height:24.43px;aspect-ratio:183.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5cbcea061b92c91b.svg\"><img class=\"math display-math\" src=\"assets/equations/77bfb08512787403.svg\" alt=\"D=1.000000000+1.000000000+1.000000000\\approx3.000000000\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/abb38634253b454f.svg\"><img class=\"math display-math\" src=\"assets/equations/aac567888a814ba9.svg\" alt=\"p_1=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6f93f83cf16d42a1.svg\"><img class=\"math display-math\" src=\"assets/equations/4e80a74382faa499.svg\" alt=\"p_2=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd8dca9605ca9fba.svg\"><img class=\"math display-math\" src=\"assets/equations/932805d4a7ff7186.svg\" alt=\"p_3=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.333333333, 0.333333333, 0.333333333]; they sum to 1 within rounding.</p>","<h3>Softmax for [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [1, 2, 3].</strong></p>","<h3>Given</h3>","<p>Logits = [1, 2, 3]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/36a969786afa504d.svg\" alt=\"z-c=\\begin{bmatrix}-2&amp;-1&amp;0\\end{bmatrix}\" width=\"221.52\" height=\"24.43\" style=\"width:221.52px;height:24.43px;aspect-ratio:221.52/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8b081af8baa5f1b.svg\" alt=\"e^{-1}\\approx0.367879441\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff6afad7c399e8cd.svg\"><img class=\"math display-math\" src=\"assets/equations/3e8d536144b8581d.svg\" alt=\"D=0.135335283+0.367879441+1.000000000\\approx1.503214724\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60d7f2c1aed7f3ca.svg\"><img class=\"math display-math\" src=\"assets/equations/806ad5813b3ff8c0.svg\" alt=\"p_1=\\frac{0.135335283}{1.503214724}\\approx0.090030573\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/958d44e6661ca616.svg\"><img class=\"math display-math\" src=\"assets/equations/a839a3e6b8973897.svg\" alt=\"p_2=\\frac{0.367879441}{1.503214724}\\approx0.244728471\" width=\"356.81\" height=\"50.36\" style=\"width:356.81px;height:50.36px;aspect-ratio:356.81/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6153a5efe8276ec2.svg\"><img class=\"math display-math\" src=\"assets/equations/fdcbdba7b8490dd2.svg\" alt=\"p_3=\\frac{1.000000000}{1.503214724}\\approx0.665240956\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.090030573, 0.244728471, 0.665240956]; they sum to 1 within rounding.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s7","search":"Activation functions and how to calculate them \n### What an activation function does, and why it is needed\nA neuron first produces the weighted sum z. The activation function f is a rule that transforms that sum into the output a = f(z). Applying an activation does not change the stored weights; it calculates a new output from the current sum.\n\nIf every layer only multiplies and adds, several layers still combine into a single affine transformation. A nonlinear activation lets the network represent more complicated relationships. The output activation must also suit the task: sigmoid for a binary-class probability, softmax for mutually exclusive class probabilities, and often a linear output for unrestricted regression.\n\nThe **activation value** says what the neuron outputs. The **activation derivative** says how quickly that output changes when z changes, which is needed during backpropagation. For sigmoid at z = 0, the value is 0.5 but the derivative is 0.25. They serve different purposes.\n\n**Yaad rakhne ka cue:** z = activation se pehle ka sum; a = uske baad ka answer; f′ = answer kitni tezi se badlega.\n\n**Definition.** An activation function maps a neuron's preactivation to its output. Nonlinear activations allow a multilayer network to represent nonlinear functions; the output activation also encodes the prediction type. Without a nonlinear activation, a composition of affine layers remains affine.\n\n### Explanation and working\n\nSigmoid converts any finite real input into a value strictly between 0 and 1. At zero it is 0.5. It is useful for a binary-class probability or independent multilabel outputs. At very positive or negative inputs it saturates, so its derivative becomes small. Its derivative is at most 0.25.\n\n\n\n\nTanh lies between −1 and +1 and is zero-centered. It is common in recurrent hidden states. It also saturates. “Zero-centered” does not mean “no vanishing gradients”.\n\nReLU returns the input if positive and zero if negative. It is cheap to compute and has derivative 1 on its positive side. Units can become inactive on all relevant inputs, known as dying ReLU. At z = 0 the mathematical derivative is undefined; a convention such as 0 is used in implementations and this book’s exercises when needed.\n\nThe small negative slope a lets some gradient through for negative inputs. At z = −2 and a = 0.01, output = −0.02. Do not take the absolute value. PReLU learns the negative slope; Leaky ReLU normally fixes it.\n\nSoftmax acts on a group of class scores, called logits. All probabilities are positive and sum to 1. Subtracting the same maximum c from all logits leaves the result unchanged and avoids very large exponentials. It is suited to mutually exclusive multiclass output.\n**Full softmax example.** For [−1, 0, 1], exponentials are [0.367879, 1, 2.718282]. Sum = 4.086161. Divide each by that same sum: [0.090031, 0.244728, 0.665241]. Check their sum is approximately 1. Three separate sigmoids would give [0.268941, 0.5, 0.731059], which are different and do not sum to 1.\n\n### Derivation of the sigmoid derivative\nWrite sigmoid as a negative power. The outer derivative contributes −1, and differentiating the inner exponential contributes a second negative sign:\n\n\nSeparate the expression into two factors:\n\nThe second factor is 1−σ(z) because subtracting 1/(1+e⁻ᶻ) from 1 leaves e⁻ᶻ/(1+e⁻ᶻ). Once a forward pass has supplied σ(z), its derivative requires no further exponential evaluation.\n\n### Derivation of the tanh derivative\nUse the q"},{"title":"Model answer: why a network needs nonlinear activation","question":["<p class=\"inline-question\"><strong>Question.</strong> Why are activation functions required in a multilayer neural network? Compare sigmoid, tanh and ReLU, including their limitations.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum into its output. Nonlinear activations allow successive layers to represent nonlinear relationships. If every layer is only linear or affine, composing those layers still gives one affine transformation; depth alone does not create a nonlinear decision boundary.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nonlinear.svg\" aria-label=\"Enlarge diagram: Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation.\"><img src=\"assets/figures/v_nonlinear.svg\" alt=\"Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Why two linear layers are still linear in the input</h3>","<p>For the first layer let h = 2x + 1. Let the second output be y = 3h + 4. Substitute the first rule into the second:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f54676c512498a38.svg\"><img class=\"math display-math\" src=\"assets/equations/0da4ca75660c25f8.svg\" alt=\"y=3(2x+1)+4=6x+3+4=6x+7\" width=\"429.97\" height=\"24.43\" style=\"width:429.97px;height:24.43px;aspect-ratio:429.97/24.43\" loading=\"lazy\"></picture></div>","<p>This is one straight-line rule. A nonlinear activation between the two calculations changes what the combined model can represent.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Activation</th><th>Output range</th><th>Useful property</th><th>Main limitation</th></tr></thead><tbody><tr><td>Sigmoid</td><td>Strictly between 0 and 1</td><td>Useful as a binary-class probability output</td><td>Saturates at large positive or negative inputs; gradients become small</td></tr><tr><td>Tanh</td><td>Strictly between −1 and 1</td><td>Can represent signed, zero-centered activations</td><td>Also saturates and can contribute to vanishing gradients</td></tr><tr><td>ReLU</td><td>From 0 upward</td><td>Simple; derivative is 1 for positive inputs</td><td>A unit that stays on the negative side receives zero local gradient</td></tr></tbody></table></div>","<p>Sigmoid and tanh do not return negative and positive versions of the same scale: their ranges differ. ReLU is not restricted to values below 1. For multiclass output, softmax normalizes a group of class scores so the probabilities sum to 1; it acts on the score vector rather than independently applying sigmoid to each score.</p>","<p><strong>Exam conclusion:</strong> select the activation according to the layer&#x27;s job and task. Hidden layers need useful nonlinear transformations; the output activation must match the meaning of the desired prediction.</p>"],"kind":"theory","id":"mt2-c4-s8","search":"Model answer: why a network needs nonlinear activation **Question.** Why are activation functions required in a multilayer neural network? Compare sigmoid, tanh and ReLU, including their limitations.\n\n**Model answer.**\nAn activation function transforms a neuron's weighted sum into its output. Nonlinear activations allow successive layers to represent nonlinear relationships. If every layer is only linear or affine, composing those layers still gives one affine transformation; depth alone does not create a nonlinear decision boundary.\n\n\n\n\n### Why two linear layers are still linear in the input\nFor the first layer let h = 2x + 1. Let the second output be y = 3h + 4. Substitute the first rule into the second:\n\nThis is one straight-line rule. A nonlinear activation between the two calculations changes what the combined model can represent.\n\n| Activation | Output range | Useful property | Main limitation |\n| Sigmoid | Strictly between 0 and 1 | Useful as a binary-class probability output | Saturates at large positive or negative inputs; gradients become small |\n| Tanh | Strictly between −1 and 1 | Can represent signed, zero-centered activations | Also saturates and can contribute to vanishing gradients |\n| ReLU | From 0 upward | Simple; derivative is 1 for positive inputs | A unit that stays on the negative side receives zero local gradient |\n\nSigmoid and tanh do not return negative and positive versions of the same scale: their ranges differ. ReLU is not restricted to values below 1. For multiclass output, softmax normalizes a group of class scores so the probabilities sum to 1; it acts on the score vector rather than independently applying sigmoid to each score.\n\n**Exam conclusion:** select the activation according to the layer's job and task. Hidden layers need useful nonlinear transformations; the output activation must match the meaning of the desired prediction.\n"},{"title":"Choosing a loss","blocks":["<p class=\"definition\"><strong>Definition.</strong> A loss function quantifies the discrepancy between a prediction and its target. The training objective aggregates per-example losses and may add regularization. The loss must be compatible with the task and output parameterization.</p>","<h3>Explanation and working</h3>","<p>Activation produces the prediction. Loss measures how wrong that prediction is. An optimizer uses gradients to update parameters. These are three different roles.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_loss_choice.svg\" aria-label=\"Enlarge diagram: First identify what the prediction means. Then choose the loss paired with that task and output.\"><img src=\"assets/figures/v_loss_choice.svg\" alt=\"First identify what the prediction means. Then choose the loss paired with that task and output.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>First identify what the prediction means. Then choose the loss paired with that task and output. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.25px;--narrow-height:151.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46872a64dc44481e.svg\"><img class=\"math display-math\" src=\"assets/equations/52f47ec283865e9e.svg\" alt=\"\\operatorname{MSE}=\\frac1n\\sum_{i=1}^n(\\hat y_i-y_i)^2,\\qquad \\operatorname{MAE}=\\frac1n\\sum_{i=1}^n|\\hat y_i-y_i|\" width=\"551.36\" height=\"68.62\" style=\"width:551.36px;height:68.62px;aspect-ratio:551.36/68.62\" loading=\"lazy\"></picture></div>","<p class=\"inline-question\"><strong>Question.</strong> Targets are [2, 4], predictions are [1, 6]. Find MSE and MAE.</p>","<h3>Given</h3>","<p>Targets = [2,4]; predictions = [1,6]; n = 2.</p>","<h3>To find</h3>","<p>Find mean squared error and mean absolute error.</p>","<h3>Formula — which one and why</h3>","<p><strong>Squared-error objectives.</strong> Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.</p>","<p>ŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle error square; phir question ke hisaab se sum, half ya mean.</p>","<p><strong>Mean absolute error.</strong> Absolute value removes the sign of each prediction error without squaring its magnitude. Average those magnitudes.</p>","<p>n = number of predictions. |e| means the nonnegative magnitude of error e.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/da84fa0919b7d150.svg\" alt=\"\\mathrm{MAE}=\\frac1n\\sum_i|\\hat y_i-y_i|\" width=\"242.18\" height=\"61.92\" style=\"width:242.18px;height:61.92px;aspect-ratio:242.18/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MAE mein magnitude; MSE mein square.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate prediction minus target.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dba84d8eacba9175.svg\" alt=\"e_1=1-2=-1\" width=\"172.76\" height=\"19.94\" style=\"width:172.76px;height:19.94px;aspect-ratio:172.76/19.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7004e5d2962bc876.svg\" alt=\"e_2=6-4=2\" width=\"153.75\" height=\"20.21\" style=\"width:153.75px;height:20.21px;aspect-ratio:153.75/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square both errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/725d81fce4be12d0.svg\" alt=\"e_1^2=(-1)^2=1\" width=\"160.35\" height=\"27.70\" style=\"width:160.35px;height:27.70px;aspect-ratio:160.35/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4282b80c2e07509.svg\" alt=\"e_2^2=2^2=4\" width=\"122.32\" height=\"27.64\" style=\"width:122.32px;height:27.64px;aspect-ratio:122.32/27.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add squares and divide by two observations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9258cd0363de1324.svg\" alt=\"\\mathrm{MSE}=\\frac{1+4}{2}=2.5\" width=\"214.09\" height=\"49.82\" style=\"width:214.09px;height:49.82px;aspect-ratio:214.09/49.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: take the absolute value of each original error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a8f4cb66d218e6f.svg\" alt=\"|-1|=1,\\qquad |2|=2\" width=\"230.82\" height=\"24.41\" style=\"width:230.82px;height:24.41px;aspect-ratio:230.82/24.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add absolute errors and divide by two.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2d85cc8a7db473e8.svg\" alt=\"\\mathrm{MAE}=\\frac{1+2}{2}=1.5\" width=\"218.82\" height=\"49.55\" style=\"width:218.82px;height:49.55px;aspect-ratio:218.82/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> MSE = 2.5; MAE = 1.5. Squaring gives larger errors more influence; MAE is not differentiable at zero error.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:325.53px;--narrow-height:131.10px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9ec44fbf24f3156c.svg\"><img class=\"math display-math\" src=\"assets/equations/ceba44b43aaab755.svg\" alt=\"L_{\\mathrm{BCE}}=-[y\\ln p+(1-y)\\ln(1-p)],\\qquad L_{\\mathrm{CCE}}=-\\sum_k y_k\\ln p_k\" width=\"658.88\" height=\"52.91\" style=\"width:658.88px;height:52.91px;aspect-ratio:658.88/52.91\" loading=\"lazy\"></picture></div>","<p>For binary y = 1, BCE becomes −ln(p). For y = 0, it becomes −ln(1 − p). For one-hot multiclass labels, CCE is simply minus the natural log of the predicted probability assigned to the correct class.</p>","<p class=\"inline-question\"><strong>Question.</strong> True class is Mild, encoded [0,1,0], and probabilities are [0.1,0.8,0.1]. Find CCE.</p>","<h3>Given</h3>","<p>True class = Mild; one-hot target = [0,1,0].</p>","<p>Predicted probabilities = [0.1,0.8,0.1].</p>","<h3>To find</h3>","<p>Find the categorical cross-entropy.</p>","<h3>Formula — which one and why</h3>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write one weighted log term for each class.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6cc766252350138b.svg\" alt=\"L=-[0\\ln(0.1)+1\\ln(0.8)+0\\ln(0.1)]\" width=\"402.28\" height=\"24.43\" style=\"width:402.28px;height:24.43px;aspect-ratio:402.28/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: remove terms with zero target weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17a83c5bb645a7c5.svg\" alt=\"L=-\\ln(0.8)\" width=\"142.93\" height=\"24.43\" style=\"width:142.93px;height:24.43px;aspect-ratio:142.93/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: evaluate the natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply the outer minus sign.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b71a143e9ddc291e.svg\"><img class=\"math display-math\" src=\"assets/equations/8076883238c541d3.svg\" alt=\"L\\approx-(-0.223143551)=0.223143551\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> CCE ≈ 0.223144. Only the correct-class probability contributes for this one-hot target.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Task</th><th>Typical output</th><th>Typical loss</th></tr></thead><tbody><tr><td>Unbounded numerical regression</td><td>One linear output</td><td>MSE or MAE</td></tr><tr><td>Binary classification</td><td>One sigmoid output</td><td>Binary cross-entropy</td></tr><tr><td>Exactly one of K classes</td><td>K softmax outputs</td><td>Categorical cross-entropy</td></tr><tr><td>Several independent labels</td><td>K sigmoid outputs</td><td>Binary cross-entropy per label</td></tr></tbody></table></div>","<p>A continuous rating restricted to 0–10 can use a linear output with a stated range policy, or 10 × sigmoid with an appropriate regression loss. If ratings are treated as discrete ordered categories, modelling choices differ. State the interpretation instead of selecting a loss merely from the number 10.</p>","<h3>Squared-error scaling in backpropagation</h3>","<p>For n included scalar predictions, let eᵢ = ŷᵢ−yᵢ. Three frequently used objectives are:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.10px;--narrow-height:205.50px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90823ff8e0467213.svg\"><img class=\"math display-math\" src=\"assets/equations/74a2e5af6d9c93b2.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2,\\qquad L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2,\\qquad \\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"602.56\" height=\"61.92\" style=\"width:602.56px;height:61.92px;aspect-ratio:602.56/61.92\" loading=\"lazy\"></picture></div>","<p>Differentiating with respect to one prediction produces different factors:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:154.58px;--narrow-height:202.76px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1bf294550797614e.svg\"><img class=\"math display-math\" src=\"assets/equations/9c169d2ae1cd10a3.svg\" alt=\"\\frac{\\partial\\mathrm{SSE}}{\\partial\\hat y_i}=2e_i,\\quad \\frac{\\partial L_{\\mathrm{half}}}{\\partial\\hat y_i}=e_i,\\quad \\frac{\\partial\\mathrm{MSE}}{\\partial\\hat y_i}=\\frac2n e_i\" width=\"482.44\" height=\"57.81\" style=\"width:482.44px;height:57.81px;aspect-ratio:482.44/57.81\" loading=\"lazy\"></picture></div>","<p>Use the exact objective in the question. The teacher&#x27;s two-output backpropagation example uses half SSE. Do not automatically insert the MSE factor into that example.</p>","<h3>Why cross-entropy uses the negative logarithm</h3>","<p>For a one-hot target, the likelihood of the observed class is the probability assigned to it. Maximizing that likelihood is equivalent to minimizing its negative logarithm. For independent training examples, multiplying probabilities becomes adding their logarithms. A low correct-class probability therefore produces a large loss.</p>","<h3>Sigmoid with binary cross-entropy: output delta</h3>","<p>Let p = σ(z). First differentiate the loss with respect to p, holding y constant:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.86px;--narrow-height:124.37px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc392cea6dae6dda.svg\"><img class=\"math display-math\" src=\"assets/equations/a1bc86d47cf16a06.svg\" alt=\"\\frac{\\partial L}{\\partial p}=-\\frac yp+\\frac{1-y}{1-p}=\\frac{p-y}{p(1-p)}\" width=\"339.87\" height=\"57.45\" style=\"width:339.87px;height:57.45px;aspect-ratio:339.87/57.45\" loading=\"lazy\"></picture></div>","<p>Then multiply by the sigmoid derivative:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.69px;--narrow-height:163.47px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6d9c2d8649b6476d.svg\"><img class=\"math display-math\" src=\"assets/equations/88355caa5908a259.svg\" alt=\"\\frac{\\partial L}{\\partial z}=\\frac{\\partial L}{\\partial p}\\frac{\\partial p}{\\partial z}=\\frac{p-y}{p(1-p)}p(1-p)=p-y\" width=\"453.31\" height=\"57.45\" style=\"width:453.31px;height:57.45px;aspect-ratio:453.31/57.45\" loading=\"lazy\"></picture></div>","<p>Thus the logit delta is p−y for this paired output and loss. With sigmoid and half squared error it is instead (p−y)p(1−p). Confusing these two cases changes every subsequent gradient.</p>","<h3>Softmax with categorical cross-entropy: output delta</h3>","<p>For a normalized target vector, the derivative of softmax component pᵢ with respect to logit zⱼ is pᵢ times (δᵢⱼ−pⱼ), where δᵢⱼ is 1 if i = j and 0 otherwise. Therefore:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:242.60px;--narrow-height:236.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/add665e2f73a094d.svg\"><img class=\"math display-math\" src=\"assets/equations/630851ea15af9c6b.svg\" alt=\"\\frac{\\partial L}{\\partial z_j}=-\\sum_i\\frac{y_i}{p_i}p_i(\\delta_{ij}-p_j)=-y_j+p_j\\sum_i y_i=p_j-y_j\" width=\"580.11\" height=\"63.12\" style=\"width:580.11px;height:63.12px;aspect-ratio:580.11/63.12\" loading=\"lazy\"></picture></div>","<p>This result assumes the target components sum to 1. For a mean loss over a batch, include the corresponding averaging factor as well.</p>","<h3>Three squared-error conventions: [1, 3]</h3>","<p class=\"inline-question\"><strong>Question. Predictions are [1, 3] and targets are [2, 3]. Find SSE, half SSE and MSE.</strong></p>","<h3>Given</h3>","<p>Predictions = [1, 3].</p>","<p>Targets = [2, 3].</p>","<p>Number of scalar predictions n = 2.</p>","<h3>To find</h3>","<p>SSE, half SSE and MSE separately.</p>","<h3>Formula — which one and why</h3>","<p>All three use the same squared errors but divide the sum differently. The question explicitly asks for each convention.</p>","<p>ŷᵢ is a prediction; yᵢ its target; n counts predictions, not network layers.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square sab mein; half mein 2, mean mein n se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dba84d8eacba9175.svg\" alt=\"e_1=1-2=-1\" width=\"172.76\" height=\"19.94\" style=\"width:172.76px;height:19.94px;aspect-ratio:172.76/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/725d81fce4be12d0.svg\" alt=\"e_1^2=(-1)^2=1\" width=\"160.35\" height=\"27.70\" style=\"width:160.35px;height:27.70px;aspect-ratio:160.35/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/168d50f2de11bd29.svg\" alt=\"e_2=3-3=0\" width=\"153.75\" height=\"19.94\" style=\"width:153.75px;height:19.94px;aspect-ratio:153.75/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: square error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/760944c761b54733.svg\" alt=\"e_2^2=(0)^2=0\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add squared errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d7eadaf7257dae1.svg\" alt=\"\\mathrm{SSE}=1+0=1\" width=\"175.50\" height=\"19.23\" style=\"width:175.50px;height:19.23px;aspect-ratio:175.50/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: divide by 2 for half SSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6b038fb864ecaa7.svg\" alt=\"L_{\\mathrm{half}}=\\frac{1}{2}=0.5\" width=\"167.51\" height=\"49.55\" style=\"width:167.51px;height:49.55px;aspect-ratio:167.51/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: divide by the number of predictions for MSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89fe10c4fdc1b2d9.svg\" alt=\"\\mathrm{MSE}=\\frac{1}{2}\\approx0.500000000\" width=\"269.73\" height=\"49.55\" style=\"width:269.73px;height:49.55px;aspect-ratio:269.73/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> SSE = 1; half SSE = 0.5; MSE ≈ 0.500000000.</p>","<h3>Three squared-error conventions: [2, 5, 1]</h3>","<p class=\"inline-question\"><strong>Question. Predictions are [2, 5, 1] and targets are [1, 3, 2]. Find SSE, half SSE and MSE.</strong></p>","<h3>Given</h3>","<p>Predictions = [2, 5, 1].</p>","<p>Targets = [1, 3, 2].</p>","<p>Number of scalar predictions n = 3.</p>","<h3>To find</h3>","<p>SSE, half SSE and MSE separately.</p>","<h3>Formula — which one and why</h3>","<p>All three use the same squared errors but divide the sum differently. The question explicitly asks for each convention.</p>","<p>ŷᵢ is a prediction; yᵢ its target; n counts predictions, not network layers.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square sab mein; half mein 2, mean mein n se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b0c87b502c9af9cc.svg\" alt=\"e_1=2-1=1\" width=\"153.75\" height=\"19.94\" style=\"width:153.75px;height:19.94px;aspect-ratio:153.75/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/527befb1696e696d.svg\" alt=\"e_1^2=(1)^2=1\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/776a0d96be6de464.svg\" alt=\"e_2=5-3=2\" width=\"153.75\" height=\"19.94\" style=\"width:153.75px;height:19.94px;aspect-ratio:153.75/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: square error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c723f0acd2a3070.svg\" alt=\"e_2^2=(2)^2=4\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate error 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b685cf877781a273.svg\" alt=\"e_3=1-2=-1\" width=\"172.76\" height=\"20.31\" style=\"width:172.76px;height:20.31px;aspect-ratio:172.76/20.31\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: square error 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1212dd80c80f5b96.svg\" alt=\"e_3^2=(-1)^2=1\" width=\"160.35\" height=\"28.02\" style=\"width:160.35px;height:28.02px;aspect-ratio:160.35/28.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: add squared errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8252220326cba08a.svg\" alt=\"\\mathrm{SSE}=1+4+1=6\" width=\"217.59\" height=\"19.23\" style=\"width:217.59px;height:19.23px;aspect-ratio:217.59/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: divide by 2 for half SSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5e41d17ab2e98c3d.svg\" alt=\"L_{\\mathrm{half}}=\\frac{6}{2}=3\" width=\"148.50\" height=\"49.55\" style=\"width:148.50px;height:49.55px;aspect-ratio:148.50/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 9: divide by the number of predictions for MSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4955c778fd95a4f.svg\" alt=\"\\mathrm{MSE}=\\frac{6}{3}\\approx2.000000000\" width=\"269.73\" height=\"50.09\" style=\"width:269.73px;height:50.09px;aspect-ratio:269.73/50.09\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> SSE = 6; half SSE = 3; MSE ≈ 2.000000000.</p>","<h3>Three squared-error conventions: [4]</h3>","<p class=\"inline-question\"><strong>Question. Predictions are [4] and targets are [1]. Find SSE, half SSE and MSE.</strong></p>","<h3>Given</h3>","<p>Predictions = [4].</p>","<p>Targets = [1].</p>","<p>Number of scalar predictions n = 1.</p>","<h3>To find</h3>","<p>SSE, half SSE and MSE separately.</p>","<h3>Formula — which one and why</h3>","<p>All three use the same squared errors but divide the sum differently. The question explicitly asks for each convention.</p>","<p>ŷᵢ is a prediction; yᵢ its target; n counts predictions, not network layers.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square sab mein; half mein 2, mean mein n se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35c4c4ba3ef807a6.svg\" alt=\"e_1=4-1=3\" width=\"153.75\" height=\"20.21\" style=\"width:153.75px;height:20.21px;aspect-ratio:153.75/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1c1774a6ed0f013e.svg\" alt=\"e_1^2=(3)^2=9\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add squared errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3acb15eecc0c073c.svg\" alt=\"\\mathrm{SSE}=9=9\" width=\"133.41\" height=\"19.23\" style=\"width:133.41px;height:19.23px;aspect-ratio:133.41/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide by 2 for half SSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6c789702092108e1.svg\" alt=\"L_{\\mathrm{half}}=\\frac{9}{2}=4.5\" width=\"167.51\" height=\"49.55\" style=\"width:167.51px;height:49.55px;aspect-ratio:167.51/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: divide by the number of predictions for MSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1fcd30496290844.svg\" alt=\"\\mathrm{MSE}=\\frac{9}{1}\\approx9.000000000\" width=\"269.73\" height=\"49.55\" style=\"width:269.73px;height:49.55px;aspect-ratio:269.73/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> SSE = 9; half SSE = 4.5; MSE ≈ 9.000000000.</p>","<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fcb072c6f4519069.svg\" alt=\"p=0.8\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65af868a518fd08e.svg\"><img class=\"math display-math\" src=\"assets/equations/710d02f73efd4006.svg\" alt=\"L=-(-0.223143551)=0.223143551\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.223143551 nats.</p>","<h3>Binary cross-entropy: target 0, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 0. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 0; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/438398f064595bb7.svg\" alt=\"1-p=1-0.8=0.2\" width=\"224.09\" height=\"21.02\" style=\"width:224.09px;height:21.02px;aspect-ratio:224.09/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a82bb66e18d1bf7c.svg\" alt=\"\\ln(0.2)\\approx-1.609437912\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe3e4a4ff07bc0e0.svg\"><img class=\"math display-math\" src=\"assets/equations/8a78ffe2df23393c.svg\" alt=\"L=-(-1.609437912)=1.609437912\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 1.609437912 nats.</p>","<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.5</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.5. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.5; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c8d4b00d7d4788e.svg\" alt=\"p=0.5\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89c211e38f586f86.svg\" alt=\"\\ln(0.5)\\approx-0.693147181\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e0e8fd22135c9d7b.svg\"><img class=\"math display-math\" src=\"assets/equations/4bf6a8c1047d0f4a.svg\" alt=\"L=-(-0.693147181)=0.693147181\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.693147181 nats.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=1</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 1. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 1; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55554414edc61afc.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-1}{0.16}=-1.25\" width=\"251.78\" height=\"54.97\" style=\"width:251.78px;height:54.97px;aspect-ratio:251.78/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.60px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/352e50cd272ef421.svg\"><img class=\"math display-math\" src=\"assets/equations/b564b0f8f85410b8.svg\" alt=\"\\frac{dL}{dz}=(-1.25)(0.16)=-0.2\" width=\"299.42\" height=\"50.50\" style=\"width:299.42px;height:50.50px;aspect-ratio:299.42/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> dL/dz = -0.2. No further sigmoid derivative is needed.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=0</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 0. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 0; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcb217487ddffdd.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-0}{0.16}=5\" width=\"201.55\" height=\"54.97\" style=\"width:201.55px;height:54.97px;aspect-ratio:201.55/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86de3ab6d9deb754.svg\" alt=\"\\frac{dL}{dz}=(5)(0.16)=0.8\" width=\"230.17\" height=\"50.50\" style=\"width:230.17px;height:50.50px;aspect-ratio:230.17/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> dL/dz = 0.8. No further sigmoid derivative is needed.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s9","search":"Choosing a loss **Definition.** A loss function quantifies the discrepancy between a prediction and its target. The training objective aggregates per-example losses and may add regularization. The loss must be compatible with the task and output parameterization.\n\n### Explanation and working\nActivation produces the prediction. Loss measures how wrong that prediction is. An optimizer uses gradients to update parameters. These are three different roles.\n\n\n\n\n**Question.** Targets are [2, 4], predictions are [1, 6]. Find MSE and MAE.\n\n\n\n### Given\n\nTargets = [2,4]; predictions = [1,6]; n = 2.\n\n### To find\n\nFind mean squared error and mean absolute error.\n\n### Formula — which one and why\n\n**Squared-error objectives.** Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.\n\nŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle error square; phir question ke hisaab se sum, half ya mean.\n\n**Mean absolute error.** Absolute value removes the sign of each prediction error without squaring its magnitude. Average those magnitudes.\n\nn = number of predictions. |e| means the nonnegative magnitude of error e.\n\n\n\n**Yaad rakhne ka cue:** MAE mein magnitude; MSE mein square.\n\n### Solution — step by step\n\n\n\n\n**Step 1: calculate prediction minus target.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 2: square both errors.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 3: add squares and divide by two observations.**\n\n\n\n\n\n\n\n**Step 4: take the absolute value of each original error.**\n\n\n\n\n\n\n\n**Step 5: add absolute errors and divide by two.**\n\n\n\n\n\n\n\n**Final answer:** MSE = 2.5; MAE = 1.5. Squaring gives larger errors more influence; MAE is not differentiable at zero error.\n\nFor binary y = 1, BCE becomes −ln(p). For y = 0, it becomes −ln(1 − p). For one-hot multiclass labels, CCE is simply minus the natural log of the predicted probability assigned to the correct class.\n**Question.** True class is Mild, encoded [0,1,0], and probabilities are [0.1,0.8,0.1]. Find CCE.\n\n\n\n### Given\n\nTrue class = Mild; one-hot target = [0,1,0].\n\nPredicted probabilities = [0.1,0.8,0.1].\n\n### To find\n\nFind the categorical cross-entropy.\n\n### Formula — which one and why\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n**Step 1: write one weighted log term for each class.**\n\n\n\n\n\n\n\n**Step 2: remove terms with zero target weight.**\n\n\n\n\n\n\n\n**Step 3: evaluate the natural logarithm.**\n\n\n\n\n\n\n\n**Step 4: apply the outer minus sign.**\n\n\n\n\n\n\n\n**Final answer:** CCE ≈ 0.223144. Only the correct-class probability contributes for this one-hot target.\n| Task | Typical output | Typical loss |\n| Unbounded numerical regression | One linear output | MSE or MAE |\n| Binary classification | One sigmoid output | Binary cross-entropy |\n| Exactly one of K classes | K softmax outputs | Categorical cross-entropy |\n| Several independent labels | K sigmoid outputs | Binary cross-entropy per label |\nA continuous rating restricted to 0–10 can us"},{"title":"Forward propagation through multiple neurons","blocks":["<p class=\"definition\"><strong>Definitions.</strong> A feedforward neural network has a directed acyclic computation graph: information moves from inputs toward outputs without recurrent feedback connections. A multilayer perceptron (MLP) is a feedforward network built from fully connected layers, with one or more hidden layers and nonlinear hidden activations.</p>","<h3>Input, hidden and output layers</h3>","<p>The <strong>input layer</strong> supplies the feature vector. A <strong>hidden layer</strong> learns an intermediate representation; its outputs are computed from preceding activations, not supplied as target labels. The <strong>output layer</strong> produces the prediction in the form needed by the task.</p>","<p>In a dense connection between two layers, every receiving neuron has a weight for every preceding activation. Each receiving neuron also normally has its own bias. An ANN is the broader family containing feedforward and recurrent models. A CNN can be feedforward without being an MLP, because convolution uses local shared connections.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/network.svg\" aria-label=\"Enlarge diagram: A feedforward network calculates each hidden representation before using it to calculate the next layer.\"><img src=\"assets/figures/network.svg\" alt=\"A feedforward network calculates each hidden representation before using it to calculate the next layer.\" width=\"960\" height=\"440\" loading=\"lazy\"></button><figcaption>A feedforward network calculates each hidden representation before using it to calculate the next layer. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>General layer equations and dimensions</h3>","<p>Let a⁽⁰⁾ = x. For layer l:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/87472012ebbb4a9d.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)}\" width=\"228.73\" height=\"25.06\" style=\"width:228.73px;height:25.06px;aspect-ratio:228.73/25.06\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/da3b4bdac78b839b.svg\" alt=\"a^{(l)}=f^{(l)}(z^{(l)})\" width=\"152.47\" height=\"29.16\" style=\"width:152.47px;height:29.16px;aspect-ratio:152.47/29.16\" loading=\"lazy\"></div>","<p>If the preceding layer has n inputs and the current layer has m neurons, W has m rows and n columns. The vectors z, a and b have m components. Row j of W contains the incoming weights of neuron j.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.15px;--narrow-height:72.98px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bb1ec5bee5b7117c.svg\"><img class=\"math display-math\" src=\"assets/equations/6213a7d0a0d572f3.svg\" alt=\"W^{(l)}\\in\\mathbb R^{m\\times n},\\qquad b^{(l)},z^{(l)},a^{(l)}\\in\\mathbb R^{m\\times1}\" width=\"400.98\" height=\"27.79\" style=\"width:400.98px;height:27.79px;aspect-ratio:400.98/27.79\" loading=\"lazy\"></picture></div>","<p>For one hidden layer, these computations compose to give:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ff7d7b3e6546d64.svg\" alt=\"h=f^{(1)}(W^{(1)}x+b^{(1)})\" width=\"234.01\" height=\"29.16\" style=\"width:234.01px;height:29.16px;aspect-ratio:234.01/29.16\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb13b3127fe27394.svg\" alt=\"\\hat y=f^{(2)}(W^{(2)}h+b^{(2)})\" width=\"232.01\" height=\"29.16\" style=\"width:232.01px;height:29.16px;aspect-ratio:232.01/29.16\" loading=\"lazy\"></div>","<p>The hidden activation must be nonlinear to obtain nonlinear representational power. Stacking affine layers alone still gives one affine mapping. A single threshold perceptron cannot separate XOR; a hidden nonlinear representation can make the two classes separable for the output layer.</p>","<h3>Forward propagation versus training</h3>","<p>Forward propagation evaluates these layer equations using the current parameters. Training additionally evaluates a loss, uses backpropagation to calculate gradients, and applies an optimizer update. The architecture specifies connections; backpropagation is a differentiation algorithm used to train that architecture.</p>","<h3>Complete two-layer numerical</h3>","<p class=\"inline-question\"><strong>Question. A feedforward network receives x = [1, 0]ᵀ. Its hidden-layer weights are W¹ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/59303f63a5ad2b9b.svg\" alt=\"\\begin{bmatrix}0.2 &amp; 0.4\\\\0.3 &amp; 0.7\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span> and biases are b¹ = [0.1, 0.2]ᵀ. The output weights are W² = [0.5, 0.6] and output bias is b² = 0.1. Use ReLU in both layers and one row per receiving neuron. Calculate every preactivation and the final output.</strong></p>","<h3>Given</h3>","<p>A feedforward network receives x = [1, 0]ᵀ.</p>","<p>Its hidden-layer weights are W¹ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/59303f63a5ad2b9b.svg\" alt=\"\\begin{bmatrix}0.2 &amp; 0.4\\\\0.3 &amp; 0.7\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span> and biases are b¹ = [0.1, 0.2]ᵀ.</p>","<p>The output weights are W² = [0.5, 0.6] and output bias is b² = 0.1.</p>","<p>Use ReLU in both layers and one row per receiving neuron.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the requested activation values and slopes.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_5f379b367f.svg\" aria-label=\"Enlarge diagram: The given weights use rows for receiving neurons. There are two hidden neurons and one output neuron.\"><img src=\"assets/figures/given_5f379b367f.svg\" alt=\"The given weights use rows for receiving neurons. There are two hidden neurons and one output neuron.\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>The given weights use rows for receiving neurons. There are two hidden neurons and one output neuron. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1: identify the matrix dimensions.</strong> W¹ is 2 × 2 and x is 2 × 1, so the hidden preactivation has two entries. W² is 1 × 2, so it takes those two activations and produces one output.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the first hidden preactivation.</strong> Multiply the first row by x, then add the first hidden bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:72.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f1a7c307bfbc37e.svg\"><img class=\"math display-math\" src=\"assets/equations/2aa7feda8e9b9e38.svg\" alt=\"z^{(1)}_1=0.2(1)+0.4(0)+0.1=0.3\" width=\"347.74\" height=\"33.18\" style=\"width:347.74px;height:33.18px;aspect-ratio:347.74/33.18\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the second hidden preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:72.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee1bd9d85fa15d84.svg\"><img class=\"math display-math\" src=\"assets/equations/8b6a4f4bbfa44dae.svg\" alt=\"z^{(1)}_2=0.3(1)+0.7(0)+0.2=0.5\" width=\"347.74\" height=\"33.18\" style=\"width:347.74px;height:33.18px;aspect-ratio:347.74/33.18\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: activate the hidden layer.</strong> Both values are positive, so ReLU retains them.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0b16aa9984127202.svg\" alt=\"a^{(1)}_1=\\max(0,0.3)=0.3\" width=\"252.22\" height=\"33.18\" style=\"width:252.22px;height:33.18px;aspect-ratio:252.22/33.18\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6263aed38871ad59.svg\" alt=\"a^{(1)}_2=\\max(0,0.5)=0.5\" width=\"252.22\" height=\"33.18\" style=\"width:252.22px;height:33.18px;aspect-ratio:252.22/33.18\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/368b9c59527b8200.svg\" alt=\"a^{(1)}=\\begin{bmatrix}0.3\\\\0.5\\end{bmatrix}\" width=\"126.65\" height=\"58.64\" style=\"width:126.65px;height:58.64px;aspect-ratio:126.65/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the output preactivation.</strong> Use the activated hidden values as this layer&#x27;s inputs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.43px;--narrow-height:68.26px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f3fff5a6e4a523e4.svg\"><img class=\"math display-math\" src=\"assets/equations/3480e69d1dd395dc.svg\" alt=\"z^{(2)}=0.5(0.3)+0.6(0.5)+0.1\" width=\"321.95\" height=\"29.16\" style=\"width:321.95px;height:29.16px;aspect-ratio:321.95/29.16\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:184.81px;--narrow-height:68.26px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2fda741950753a37.svg\"><img class=\"math display-math\" src=\"assets/equations/ccbd4dc810f4e3fd.svg\" alt=\"z^{(2)}=0.15+0.30+0.10=0.55\" width=\"334.15\" height=\"25.06\" style=\"width:334.15px;height:25.06px;aspect-ratio:334.15/25.06\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the output activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc763b55540917.svg\" alt=\"\\hat y=\\max(0,0.55)=0.55\" width=\"251.60\" height=\"25.90\" style=\"width:251.60px;height:25.90px;aspect-ratio:251.60/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> hidden preactivations and activations are [0.3, 0.5]ᵀ; output preactivation and prediction are both 0.55. They coincide here because every ReLU input is positive. No parameter has been updated during this forward pass.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s10","search":"Forward propagation through multiple neurons **Definitions.** A feedforward neural network has a directed acyclic computation graph: information moves from inputs toward outputs without recurrent feedback connections. A multilayer perceptron (MLP) is a feedforward network built from fully connected layers, with one or more hidden layers and nonlinear hidden activations.\n\n### Input, hidden and output layers\nThe **input layer** supplies the feature vector. A **hidden layer** learns an intermediate representation; its outputs are computed from preceding activations, not supplied as target labels. The **output layer** produces the prediction in the form needed by the task.\n\nIn a dense connection between two layers, every receiving neuron has a weight for every preceding activation. Each receiving neuron also normally has its own bias. An ANN is the broader family containing feedforward and recurrent models. A CNN can be feedforward without being an MLP, because convolution uses local shared connections.\n\n\n\n### General layer equations and dimensions\nLet a⁽⁰⁾ = x. For layer l:\n\n\nIf the preceding layer has n inputs and the current layer has m neurons, W has m rows and n columns. The vectors z, a and b have m components. Row j of W contains the incoming weights of neuron j.\n\nFor one hidden layer, these computations compose to give:\n\n\nThe hidden activation must be nonlinear to obtain nonlinear representational power. Stacking affine layers alone still gives one affine mapping. A single threshold perceptron cannot separate XOR; a hidden nonlinear representation can make the two classes separable for the output layer.\n\n### Forward propagation versus training\nForward propagation evaluates these layer equations using the current parameters. Training additionally evaluates a loss, uses backpropagation to calculate gradients, and applies an optimizer update. The architecture specifies connections; backpropagation is a differentiation algorithm used to train that architecture.\n\n### Complete two-layer numerical\n**Question. A feedforward network receives x = [1, 0]ᵀ. Its hidden-layer weights are W¹ =  and biases are b¹ = [0.1, 0.2]ᵀ. The output weights are W² = [0.5, 0.6] and output bias is b² = 0.1. Use ReLU in both layers and one row per receiving neuron. Calculate every preactivation and the final output.**\n\n\n\n### Given\n\nA feedforward network receives x = [1, 0]ᵀ.\n\nIts hidden-layer weights are W¹ =  and biases are b¹ = [0.1, 0.2]ᵀ.\n\nThe output weights are W² = [0.5, 0.6] and output bias is b² = 0.1.\n\nUse ReLU in both layers and one row per receiving neuron.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the requested activation values and slopes.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota"},{"title":"Backpropagation with one hidden neuron","blocks":["<p class=\"definition\"><strong>Definition.</strong> Backpropagation computes the derivatives of a scalar objective with respect to network parameters by applying the chain rule in reverse through the computational graph. An optimizer then uses these derivatives to update the parameters.</p>","<h3>Network equations and the meaning of delta</h3>","<p>Consider one input, one hidden neuron and one output neuron:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:155.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3f2141c2576fb066.svg\"><img class=\"math display-math\" src=\"assets/equations/3c0624453c85b214.svg\" alt=\"z_h=w_1x+b_1,\\qquad h=f(z_h)\" width=\"311.27\" height=\"24.43\" style=\"width:311.27px;height:24.43px;aspect-ratio:311.27/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:154.41px;--narrow-height:64.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b90638b5849c176.svg\"><img class=\"math display-math\" src=\"assets/equations/60f589c099da8571.svg\" alt=\"z_o=w_2h+b_2,\\qquad\\hat y=g(z_o)\" width=\"304.33\" height=\"25.90\" style=\"width:304.33px;height:25.90px;aspect-ratio:304.33/25.90\" loading=\"lazy\"></picture></div>","<p>For the half squared loss used in this example:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/df5fc0c0a9ad8296.svg\" alt=\"L=\\frac12(\\hat y-y)^2\" width=\"155.68\" height=\"49.55\" style=\"width:155.68px;height:49.55px;aspect-ratio:155.68/49.55\" loading=\"lazy\"></div>","<p>Define a neuron&#x27;s delta as the derivative of the loss with respect to its <strong>preactivation</strong>, not with respect to its output:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6215ea243129f507.svg\" alt=\"\\delta_o=\\frac{\\partial L}{\\partial z_o}=(\\hat y-y)g&#x27;(z_o)\" width=\"264.82\" height=\"54.60\" style=\"width:264.82px;height:54.60px;aspect-ratio:264.82/54.60\" loading=\"lazy\"></div>","<p>The output-weight derivative contains the hidden activation because zₒ = w₂h + b₂:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/338a3082f0298cb5.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=\\delta_o h,\\qquad\\frac{\\partial L}{\\partial b_2}=\\delta_o\" width=\"279.97\" height=\"54.41\" style=\"width:279.97px;height:54.41px;aspect-ratio:279.97/54.41\" loading=\"lazy\"></div>","<p>To reach the hidden neuron, continue backwards through the old output weight and the hidden activation:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6409774c2652b14e.svg\" alt=\"\\delta_h=\\delta_o w_2 f&#x27;(z_h)\" width=\"168.70\" height=\"25.88\" style=\"width:168.70px;height:25.88px;aspect-ratio:168.70/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/675e596602704d40.svg\" alt=\"\\frac{\\partial L}{\\partial w_1}=\\delta_h x,\\qquad\\frac{\\partial L}{\\partial b_1}=\\delta_h\" width=\"283.01\" height=\"54.41\" style=\"width:283.01px;height:54.41px;aspect-ratio:283.01/54.41\" loading=\"lazy\"></div>","<p>The bias derivative equals the corresponding delta because the derivative of z with respect to its additive bias is 1. All these derivatives belong to the same forward pass; an updated weight must not be used partway through this backward pass.</p>","<h3>Complete worked numerical</h3>","<p class=\"inline-question\"><strong>Question.</strong> x = 2, y = 1; w₁ = 0.5, b₁ = 0.1; w₂ = 0.8, b₂ = 0.2. Both neurons use ReLU. Use half squared loss. Find the output and all four parameter gradients, then update all four parameters using η = 0.1.</p>","<h3>Given</h3>","<p>x = 2, y = 1.</p>","<p>w₁ = 0.5, b₁ = 0.1.</p>","<p>w₂ = 0.8, b₂ = 0.2.</p>","<p>Both neurons use ReLU.</p>","<p>Use half squared loss.</p>","<p>Find the output and all four parameter gradients, then update all four parameters using η = 0.1.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_single_backprop.svg\" aria-label=\"Enlarge diagram: The forward pass evaluates hidden and output activations. The backward pass multiplies local derivatives through the same, unchanged weights.\"><img src=\"assets/figures/v_single_backprop.svg\" alt=\"The forward pass evaluates hidden and output activations. The backward pass multiplies local derivatives through the same, unchanged weights.\" width=\"1080\" height=\"690\" loading=\"lazy\"></button><figcaption>The forward pass evaluates hidden and output activations. The backward pass multiplies local derivatives through the same, unchanged weights. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1: forward propagation through the hidden neuron.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5613b3868c5f8d85.svg\" alt=\"z_h=0.5(2)+0.1=1.1\" width=\"243.29\" height=\"24.43\" style=\"width:243.29px;height:24.43px;aspect-ratio:243.29/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5206a5b2ac9abfe4.svg\" alt=\"h=\\operatorname{ReLU}(1.1)=1.1\" width=\"223.14\" height=\"24.43\" style=\"width:223.14px;height:24.43px;aspect-ratio:223.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: forward propagation through the output neuron.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a7535982ea7d2cd.svg\" alt=\"z_o=0.8(1.1)+0.2=1.08\" width=\"272.95\" height=\"24.43\" style=\"width:272.95px;height:24.43px;aspect-ratio:272.95/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8a3b4bb2871113ef.svg\" alt=\"\\hat y=\\operatorname{ReLU}(1.08)=1.08\" width=\"245.47\" height=\"25.90\" style=\"width:245.47px;height:25.90px;aspect-ratio:245.47/25.90\" loading=\"lazy\"></div>","<p>ReLU is not bounded above by 1, so this output is valid. It is not being interpreted as a probability here.</p>","<p class=\"worked-step\"><strong>Step 3: calculate the loss and output delta.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e51ef56449f25818.svg\" alt=\"L=\\frac12(1.08-1)^2=0.0032\" width=\"287.86\" height=\"49.55\" style=\"width:287.86px;height:49.55px;aspect-ratio:287.86/49.55\" loading=\"lazy\"></div>","<p>Both preactivations are positive, so both ReLU derivatives are 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ead62e2abd6d370.svg\" alt=\"\\delta_o=(1.08-1)(1)=0.08\" width=\"265.64\" height=\"24.43\" style=\"width:265.64px;height:24.43px;aspect-ratio:265.64/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: calculate the output-layer parameter gradients.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/20d536b8c74dbceb.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=0.08(1.1)=0.088\" width=\"267.26\" height=\"54.41\" style=\"width:267.26px;height:54.41px;aspect-ratio:267.26/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57f3bbde46d88ee8.svg\" alt=\"\\frac{\\partial L}{\\partial b_2}=0.08\" width=\"121.76\" height=\"54.41\" style=\"width:121.76px;height:54.41px;aspect-ratio:121.76/54.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: propagate the derivative to the hidden neuron.</strong></p>","<p>Use w₂ = 0.8, its value during the forward pass:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cf97525165cb969.svg\" alt=\"\\delta_h=0.08(0.8)(1)=0.064\" width=\"268.56\" height=\"24.43\" style=\"width:268.56px;height:24.43px;aspect-ratio:268.56/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a31fd300551ec8e1.svg\" alt=\"\\frac{\\partial L}{\\partial w_1}=0.064(2)=0.128\" width=\"260.46\" height=\"54.41\" style=\"width:260.46px;height:54.41px;aspect-ratio:260.46/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc73ac9e8421c88b.svg\" alt=\"\\frac{\\partial L}{\\partial b_1}=0.064\" width=\"133.97\" height=\"54.41\" style=\"width:133.97px;height:54.41px;aspect-ratio:133.97/54.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: update each parameter using its own gradient.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a6ad843a78157c3.svg\"><img class=\"math display-math\" src=\"assets/equations/d781e32010d9fb09.svg\" alt=\"w_{1,\\mathrm{new}}=0.5-0.1(0.128)=0.4872\" width=\"362.76\" height=\"25.35\" style=\"width:362.76px;height:25.35px;aspect-ratio:362.76/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.28px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d766af9fb7ee76f0.svg\"><img class=\"math display-math\" src=\"assets/equations/33bdb6cbe9ce338c.svg\" alt=\"b_{1,\\mathrm{new}}=0.1-0.1(0.064)=0.0936\" width=\"355.75\" height=\"25.35\" style=\"width:355.75px;height:25.35px;aspect-ratio:355.75/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2a2db66205fe592.svg\"><img class=\"math display-math\" src=\"assets/equations/1d57ae029d4adfac.svg\" alt=\"w_{2,\\mathrm{new}}=0.8-0.1(0.088)=0.7912\" width=\"362.76\" height=\"25.35\" style=\"width:362.76px;height:25.35px;aspect-ratio:362.76/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:243.06px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4678bc376cf0d02b.svg\"><img class=\"math display-math\" src=\"assets/equations/55b6e2f442ea2fb4.svg\" alt=\"b_{2,\\mathrm{new}}=0.2-0.1(0.08)=0.192\" width=\"331.31\" height=\"25.35\" style=\"width:331.31px;height:25.35px;aspect-ratio:331.31/25.35\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Parameter</th><th>Gradient from the original forward pass</th><th>Updated value</th></tr></thead><tbody><tr><td>w₁</td><td>0.128</td><td>0.4872</td></tr><tr><td>b₁</td><td>0.064</td><td>0.0936</td></tr><tr><td>w₂</td><td>0.088</td><td>0.7912</td></tr><tr><td>b₂</td><td>0.08</td><td>0.192</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> the original prediction is 1.08 and its loss is 0.0032. The table contains all requested gradients and updated parameters. A new forward pass would use all four new parameters together.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s11","search":"Backpropagation with one hidden neuron \n**Definition.** Backpropagation computes the derivatives of a scalar objective with respect to network parameters by applying the chain rule in reverse through the computational graph. An optimizer then uses these derivatives to update the parameters.\n\n### Network equations and the meaning of delta\nConsider one input, one hidden neuron and one output neuron:\n\n\nFor the half squared loss used in this example:\n\nDefine a neuron's delta as the derivative of the loss with respect to its **preactivation**, not with respect to its output:\n\nThe output-weight derivative contains the hidden activation because zₒ = w₂h + b₂:\n\nTo reach the hidden neuron, continue backwards through the old output weight and the hidden activation:\n\n\nThe bias derivative equals the corresponding delta because the derivative of z with respect to its additive bias is 1. All these derivatives belong to the same forward pass; an updated weight must not be used partway through this backward pass.\n\n### Complete worked numerical\n**Question.** x = 2, y = 1; w₁ = 0.5, b₁ = 0.1; w₂ = 0.8, b₂ = 0.2. Both neurons use ReLU. Use half squared loss. Find the output and all four parameter gradients, then update all four parameters using η = 0.1.\n\n\n\n### Given\n\nx = 2, y = 1.\n\nw₁ = 0.5, b₁ = 0.1.\n\nw₂ = 0.8, b₂ = 0.2.\n\nBoth neurons use ReLU.\n\nUse half squared loss.\n\nFind the output and all four parameter gradients, then update all four parameters using η = 0.1.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n\n\n**Step 1: forward propagation through the hidden neuron.**\n\n\n\n**Step 2: forward propagation through the output neuron.**\n\n\nReLU is not bounded above by 1, so this output is valid. It is not being interpreted as a probability here.\n\n**Step 3: calculate the loss and output delta.**\n\nBoth preactivations are positive, so bot"},{"title":"More outputs and vectorized backpropagation","blocks":["<p class=\"definition\"><strong>Definition.</strong> Vectorized backpropagation expresses the chain rule using matrix products and elementwise derivatives. When a hidden activation affects several outputs, its derivative contains the sum of the contributions from every downstream path.</p>","<h3>Why the hidden derivative is a sum</h3>","<p>If hidden activation hⱼ connects to output preactivations zₒ₁ and zₒ₂, changing hⱼ changes both outputs. The multivariable chain rule gives:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf829204c0f41f49.svg\" alt=\"\\frac{\\partial L}{\\partial h_j}=W_{2,1j}\\delta_{o_1}+W_{2,2j}\\delta_{o_2}\" width=\"276.44\" height=\"57.94\" style=\"width:276.44px;height:57.94px;aspect-ratio:276.44/57.94\" loading=\"lazy\"></div>","<p>For any number of connected outputs, sum their contributions and then differentiate the hidden activation:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:264.69px;--narrow-height:115.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f94e1705f6027563.svg\"><img class=\"math display-math\" src=\"assets/equations/08fe50471952c690.svg\" alt=\"\\delta_{h_j}=\\left(\\sum_k W_{2,kj}\\delta_{o_k}\\right)f&#x27;(z_{h_j})\" width=\"293.99\" height=\"73.28\" style=\"width:293.99px;height:73.28px;aspect-ratio:293.99/73.28\" loading=\"lazy\"></picture></div>","<p>Use the connecting weights from the original forward pass. Adding only the contribution of the first output would omit a dependency of the loss.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_branch_gradient.svg\" aria-label=\"Enlarge diagram: The outgoing paths both contribute to the hidden derivative. Add the weighted output deltas, then apply the hidden activation derivative.\"><img src=\"assets/figures/v_branch_gradient.svg\" alt=\"The outgoing paths both contribute to the hidden derivative. Add the weighted output deltas, then apply the hidden activation derivative.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>The outgoing paths both contribute to the hidden derivative. Add the weighted output deltas, then apply the hidden activation derivative. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Matrix equations for one training sample</h3>","<p>Use column vectors throughout. Let W₁ map d inputs to m hidden units and W₂ map those units to k outputs. The following output-delta formula assumes <strong>half sum of squared errors</strong> and an elementwise output activation f₂:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3370e1f71500a0e.svg\" alt=\"L=\\frac12\\sum_{j=1}^{k}(\\hat y_j-y_j)^2\" width=\"213.33\" height=\"75.08\" style=\"width:213.33px;height:75.08px;aspect-ratio:213.33/75.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07eda20c3b7d69f3.svg\" alt=\"\\delta_2=(\\hat y-y)\\odot f_2&#x27;(z_2)\" width=\"220.47\" height=\"25.90\" style=\"width:220.47px;height:25.90px;aspect-ratio:220.47/25.90\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.33px;--narrow-height:123.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7401adc017e3686d.svg\"><img class=\"math display-math\" src=\"assets/equations/b217a2191f391cf2.svg\" alt=\"\\frac{\\partial L}{\\partial W_2}=\\delta_2a_1^T,\\qquad\\frac{\\partial L}{\\partial b_2}=\\delta_2\" width=\"299.10\" height=\"54.41\" style=\"width:299.10px;height:54.41px;aspect-ratio:299.10/54.41\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9b8719d9f5e5e0f.svg\" alt=\"\\delta_1=(W_2^T\\delta_2)\\odot f_1&#x27;(z_1)\" width=\"229.33\" height=\"27.90\" style=\"width:229.33px;height:27.90px;aspect-ratio:229.33/27.90\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:147.38px;--narrow-height:123.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/88df80b8a0e03820.svg\"><img class=\"math display-math\" src=\"assets/equations/ae5ad96746c9621d.svg\" alt=\"\\frac{\\partial L}{\\partial W_1}=\\delta_1x^T,\\qquad\\frac{\\partial L}{\\partial b_1}=\\delta_1\" width=\"300.14\" height=\"54.41\" style=\"width:300.14px;height:54.41px;aspect-ratio:300.14/54.41\" loading=\"lazy\"></picture></div>","<p>Here ⊙ means elementwise multiplication. The product δ₂a₁ᵀ is an <strong>outer product</strong>: every receiving delta is multiplied by every sending activation.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Quantity</th><th>Shape</th><th>Reason</th></tr></thead><tbody><tr><td>W₁ and its gradient</td><td>m × d</td><td>m receiving hidden neurons, d inputs</td></tr><tr><td>W₂ and its gradient</td><td>k × m</td><td>k receiving output neurons, m hidden activations</td></tr><tr><td>δ₂</td><td>k × 1</td><td>One derivative per output preactivation</td></tr><tr><td>W₂ᵀδ₂</td><td>m × 1</td><td>The summed downstream derivative for each hidden unit</td></tr><tr><td>δ₂a₁ᵀ</td><td>(k × 1)(1 × m) = k × m</td><td>The output-weight gradient has the same shape as W₂</td></tr></tbody></table></div>","<h3>How the loss changes the output delta</h3>","<p>For MSE averaged over k output components, the squared-error derivative has the factor 2/k. For sigmoid with binary cross-entropy, or softmax with categorical cross-entropy and a normalized target, the paired derivative simplifies to prediction minus target:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d69b7fe4a0f11cd.svg\" alt=\"\\delta_{\\mathrm{output}}=\\hat y-y\" width=\"150.17\" height=\"26.81\" style=\"width:150.17px;height:26.81px;aspect-ratio:150.17/26.81\" loading=\"lazy\"></div>","<p>That simplification already includes differentiation of the paired activation and loss. Multiplying by a sigmoid derivative again would be incorrect. For sigmoid with half squared error, the sigmoid derivative is still required.</p>","<p>For a batch, sum per-example parameter gradients; divide by the batch size only if the objective is a batch mean. State the output reduction and batch reduction separately when both appear in a question.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s12","search":"More outputs and vectorized backpropagation \n**Definition.** Vectorized backpropagation expresses the chain rule using matrix products and elementwise derivatives. When a hidden activation affects several outputs, its derivative contains the sum of the contributions from every downstream path.\n\n### Why the hidden derivative is a sum\nIf hidden activation hⱼ connects to output preactivations zₒ₁ and zₒ₂, changing hⱼ changes both outputs. The multivariable chain rule gives:\n\nFor any number of connected outputs, sum their contributions and then differentiate the hidden activation:\n\nUse the connecting weights from the original forward pass. Adding only the contribution of the first output would omit a dependency of the loss.\n\n\n\n### Matrix equations for one training sample\nUse column vectors throughout. Let W₁ map d inputs to m hidden units and W₂ map those units to k outputs. The following output-delta formula assumes **half sum of squared errors** and an elementwise output activation f₂:\n\n\n\n\n\nHere ⊙ means elementwise multiplication. The product δ₂a₁ᵀ is an **outer product**: every receiving delta is multiplied by every sending activation.\n\n| Quantity | Shape | Reason |\n| W₁ and its gradient | m × d | m receiving hidden neurons, d inputs |\n| W₂ and its gradient | k × m | k receiving output neurons, m hidden activations |\n| δ₂ | k × 1 | One derivative per output preactivation |\n| W₂ᵀδ₂ | m × 1 | The summed downstream derivative for each hidden unit |\n| δ₂a₁ᵀ | (k × 1)(1 × m) = k × m | The output-weight gradient has the same shape as W₂ |\n\n### How the loss changes the output delta\nFor MSE averaged over k output components, the squared-error derivative has the factor 2/k. For sigmoid with binary cross-entropy, or softmax with categorical cross-entropy and a normalized target, the paired derivative simplifies to prediction minus target:\n\nThat simplification already includes differentiation of the paired activation and loss. Multiplying by a sigmoid derivative again would be incorrect. For sigmoid with half squared error, the sigmoid derivative is still required.\n\nFor a batch, sum per-example parameter gradients; divide by the batch size only if the objective is a batch mean. State the output reduction and batch reduction separately when both appear in a question.\n\n"},{"title":"Model answer: forward propagation, backpropagation and updating","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain how a feedforward neural network learns using forward propagation, a loss function, backpropagation and gradient descent. State the order of operations.</p>"],"answer":["<p>Training repeatedly uses labeled examples to improve a network&#x27;s weights and biases. The four operations have different jobs.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_training_loop.svg\" aria-label=\"Enlarge diagram: Four different jobs: calculate the prediction, measure the mistake, calculate gradients, and update parameters.\"><img src=\"assets/figures/v_training_loop.svg\" alt=\"Four different jobs: calculate the prediction, measure the mistake, calculate gradients, and update parameters.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Four different jobs: calculate the prediction, measure the mistake, calculate gradients, and update parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Operation</th><th>Direction or action</th><th>Result</th></tr></thead><tbody><tr><td>Forward propagation</td><td>Inputs move through successive layers</td><td>Predictions and intermediate activations</td></tr><tr><td>Loss calculation</td><td>Compare predictions with targets</td><td>A scalar objective for the example or batch</td></tr><tr><td>Backpropagation</td><td>Apply the chain rule from the loss toward earlier layers</td><td>Gradients of the objective with respect to parameters</td></tr><tr><td>Optimizer update</td><td>Use those gradients to change parameters</td><td>A new set of weights and biases</td></tr></tbody></table></div>","<h3>1. Forward propagation</h3>","<p>At each layer, calculate its weighted sums and activations. Retain these values because derivatives such as the sigmoid derivative depend on them. Complete a whole layer before calculating the next.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:72.98px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2845b5af7a9f9056.svg\"><img class=\"math display-math\" src=\"assets/equations/4698521353358290.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)},\\qquad a^{(l)}=f(z^{(l)})\" width=\"419.03\" height=\"29.16\" style=\"width:419.03px;height:29.16px;aspect-ratio:419.03/29.16\" loading=\"lazy\"></picture></div>","<h3>2. Loss</h3>","<p>Use the loss specified by the task. For one regression output, half squared loss is one possible choice:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b45e01da7c114be3.svg\" alt=\"L=\\frac12(a-y)^2\" width=\"156.64\" height=\"49.55\" style=\"width:156.64px;height:49.55px;aspect-ratio:156.64/49.55\" loading=\"lazy\"></div>","<p>Here a is the prediction and y is the target. Other stated losses produce different derivatives.</p>","<h3>3. Backpropagation</h3>","<p>Multiply local derivatives along each dependency path. If a hidden unit influences several outputs, add the contributions from those branches. For a connection, the weight gradient is the receiving neuron&#x27;s net-input derivative multiplied by the sending activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c4e0f7ded9389700.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i\" width=\"130.68\" height=\"57.94\" style=\"width:130.68px;height:57.94px;aspect-ratio:130.68/57.94\" loading=\"lazy\"></div>","<p>Here δⱼ means the derivative of loss with respect to the receiving neuron&#x27;s weighted sum. It is not automatically equal to raw prediction error; the activation and loss determine it.</p>","<h3>4. Update and repeat</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/116cb3cc8bb58606.svg\" alt=\"w_{\\mathrm{new}}=w_{\\mathrm{old}}-\\eta\\frac{\\partial L}{\\partial w}\" width=\"208.53\" height=\"51.29\" style=\"width:208.53px;height:51.29px;aspect-ratio:208.53/51.29\" loading=\"lazy\"></div>","<p>Compute all gradients using the same pre-update weights. Then update the requested parameters. Run another forward pass to calculate the new loss. Backpropagation calculates gradients; gradient descent uses them. Those are related, separate operations.</p>"],"kind":"theory","id":"mt2-c4-s13","search":"Model answer: forward propagation, backpropagation and updating **Question.** Explain how a feedforward neural network learns using forward propagation, a loss function, backpropagation and gradient descent. State the order of operations.\n\n**Model answer.**\nTraining repeatedly uses labeled examples to improve a network's weights and biases. The four operations have different jobs.\n\n\n\n\n| Operation | Direction or action | Result |\n| Forward propagation | Inputs move through successive layers | Predictions and intermediate activations |\n| Loss calculation | Compare predictions with targets | A scalar objective for the example or batch |\n| Backpropagation | Apply the chain rule from the loss toward earlier layers | Gradients of the objective with respect to parameters |\n| Optimizer update | Use those gradients to change parameters | A new set of weights and biases |\n\n### 1. Forward propagation\nAt each layer, calculate its weighted sums and activations. Retain these values because derivatives such as the sigmoid derivative depend on them. Complete a whole layer before calculating the next.\n\n### 2. Loss\nUse the loss specified by the task. For one regression output, half squared loss is one possible choice:\n\nHere a is the prediction and y is the target. Other stated losses produce different derivatives.\n### 3. Backpropagation\nMultiply local derivatives along each dependency path. If a hidden unit influences several outputs, add the contributions from those branches. For a connection, the weight gradient is the receiving neuron's net-input derivative multiplied by the sending activation.\n\nHere δⱼ means the derivative of loss with respect to the receiving neuron's weighted sum. It is not automatically equal to raw prediction error; the activation and loss determine it.\n### 4. Update and repeat\n\nCompute all gradients using the same pre-update weights. Then update the requested parameters. Run another forward pass to calculate the new loss. Backpropagation calculates gradients; gradient descent uses them. Those are related, separate operations.\n"},{"title":"Counting parameters in a dense network","blocks":["<p class=\"definition\"><strong>Definition.</strong> A dense layer connects every input component to every receiving neuron. Its trainable parameters are these connection weights and the receiving neurons&#x27; independently trainable biases.</p>","<h3>Deriving the parameter count</h3>","<p>For m inputs and n receiving neurons, each receiver needs m weights. There are therefore mn weights. With one bias per receiver, there are n additional parameters:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e846c0a1de0fb579.svg\"><img class=\"math display-math\" src=\"assets/equations/b9cd556f84e19c2e.svg\" alt=\"P_{\\mathrm{dense}}=mn+n=(m+1)n\" width=\"302.10\" height=\"24.43\" style=\"width:302.10px;height:24.43px;aspect-ratio:302.10/24.43\" loading=\"lazy\"></picture></div>","<p>Activation values are computed from data and parameters; they are not additional trainable parameters. The input layer supplies data and does not acquire an extra bias merely because it appears in a diagram.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dense_count.svg\" aria-label=\"Enlarge diagram: Count all input-to-neuron connections and then one bias per receiving neuron.\"><img src=\"assets/figures/v_dense_count.svg\" alt=\"Count all input-to-neuron connections and then one bias per receiving neuron.\" width=\"1080\" height=\"575\" loading=\"lazy\"></button><figcaption>Count all input-to-neuron connections and then one bias per receiving neuron. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical</h3>","<p class=\"inline-question\"><strong>Question.</strong> A network has 10 input features, three hidden layers with 5 neurons each, and 4 outputs. Every receiving neuron has a bias. Count its trainable parameters.</p>","<h3>Given</h3>","<p>Layer sizes: 10 inputs → 5 hidden → 5 hidden → 5 hidden → 4 outputs.</p>","<p>Every hidden/output neuron has one bias.</p>","<h3>To find</h3>","<p>Count weights and biases at each receiving layer, then the total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Dense-layer parameters.</strong> Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.</p>","<p>n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/494312d0893d20d2.svg\" alt=\"P=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"184.79\" height=\"24.43\" style=\"width:184.79px;height:24.43px;aspect-ratio:184.79/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output ke liye saare inputs plus ek bias.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the consecutive layer widths.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/68fe56c651575649.svg\" alt=\"10\\longrightarrow5\\longrightarrow5\\longrightarrow5\\longrightarrow4\" width=\"287.70\" height=\"17.07\" style=\"width:287.70px;height:17.07px;aspect-ratio:287.70/17.07\" loading=\"lazy\"></div>","<p>There are four trainable dense transformations. A connection between two hidden layers is counted once, as part of the receiving layer&#x27;s parameters.</p>","<p class=\"worked-step\"><strong>Step 2: count weights and biases for each transformation.</strong></p>","<div class=\"table-scroll\"><table><thead><tr><th>Transformation</th><th>Weights</th><th>Biases</th><th>Layer total</th></tr></thead><tbody><tr><td>Input → hidden 1</td><td>10 × 5 = 50</td><td>5</td><td>55</td></tr><tr><td>Hidden 1 → hidden 2</td><td>5 × 5 = 25</td><td>5</td><td>30</td></tr><tr><td>Hidden 2 → hidden 3</td><td>5 × 5 = 25</td><td>5</td><td>30</td></tr><tr><td>Hidden 3 → output</td><td>5 × 4 = 20</td><td>4</td><td>24</td></tr></tbody></table></div>","<p class=\"worked-step\"><strong>Step 3: add the layer totals.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.28px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1c0d23dc90da3211.svg\"><img class=\"math display-math\" src=\"assets/equations/e55d02bddb539fc5.svg\" alt=\"P=55+30+30+24=139\" width=\"307.52\" height=\"18.69\" style=\"width:307.52px;height:18.69px;aspect-ratio:307.52/18.69\" loading=\"lazy\"></picture></div>","<p>Equivalently, the network has 120 weights and 19 biases, so 120 + 19 = 139.</p>","<p><strong>Final answer: 139 trainable parameters.</strong> If a question explicitly removes biases, count only the 120 weights. Optimizer states such as Adam&#x27;s moments are extra training storage, not extra parameters in this predictive network.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s14","search":"Counting parameters in a dense network \n**Definition.** A dense layer connects every input component to every receiving neuron. Its trainable parameters are these connection weights and the receiving neurons' independently trainable biases.\n\n### Deriving the parameter count\nFor m inputs and n receiving neurons, each receiver needs m weights. There are therefore mn weights. With one bias per receiver, there are n additional parameters:\n\nActivation values are computed from data and parameters; they are not additional trainable parameters. The input layer supplies data and does not acquire an extra bias merely because it appears in a diagram.\n\n\n\n### Complete numerical\n**Question.** A network has 10 input features, three hidden layers with 5 neurons each, and 4 outputs. Every receiving neuron has a bias. Count its trainable parameters.\n\n\n\n### Given\n\nLayer sizes: 10 inputs → 5 hidden → 5 hidden → 5 hidden → 4 outputs.\n\nEvery hidden/output neuron has one bias.\n\n### To find\n\nCount weights and biases at each receiving layer, then the total.\n\n### Formula — which one and why\n\n**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\nn_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.\n\n\n\n**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: identify the consecutive layer widths.**\n\nThere are four trainable dense transformations. A connection between two hidden layers is counted once, as part of the receiving layer's parameters.\n\n**Step 2: count weights and biases for each transformation.**\n| Transformation | Weights | Biases | Layer total |\n| Input → hidden 1 | 10 × 5 = 50 | 5 | 55 |\n| Hidden 1 → hidden 2 | 5 × 5 = 25 | 5 | 30 |\n| Hidden 2 → hidden 3 | 5 × 5 = 25 | 5 | 30 |\n| Hidden 3 → output | 5 × 4 = 20 | 4 | 24 |\n\n**Step 3: add the layer totals.**\n\nEquivalently, the network has 120 weights and 19 biases, so 120 + 19 = 139.\n\n**Final answer: 139 trainable parameters.** If a question explicitly removes biases, count only the 120 weights. Optimizer states such as Adam's moments are extra training storage, not extra parameters in this predictive network.\n\n"},{"title":"What you should understand before optimization","blocks":["<p>You should be able to explain why a target and prediction differ, compute a weighted sum, choose an activation, measure a loss, find a one-neuron gradient and update a weight. If these steps are weak, repeat the first training example and the ReLU backprop example. They contain the entire calculation pattern that the next chapters extend.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_training_loop.svg\" aria-label=\"Enlarge diagram: These four operations form the training loop used by the optimizers in the next chapter.\"><img src=\"assets/figures/v_training_loop.svg\" alt=\"These four operations form the training loop used by the optimizers in the next chapter.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>These four operations form the training loop used by the optimizers in the next chapter. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s15","search":"What you should understand before optimization You should be able to explain why a target and prediction differ, compute a weighted sum, choose an activation, measure a loss, find a one-neuron gradient and update a weight. If these steps are weak, repeat the first training example and the ReLU backprop example. They contain the entire calculation pattern that the next chapters extend.\n\n\n\n\n"},{"title":"Complete sigmoid training example","blocks":["<p class=\"inline-question\"><strong>Question.</strong> A sigmoid neuron has input 2, weight 0, bias 0, target 1 and half squared loss. Will gradient descent increase or decrease the weight? Use learning rate 0.1 and calculate the exact update.</p>","<h3>Given</h3>","<p>x = 2; w = 0; b = 0; y = 1.</p>","<p>Sigmoid output; half squared loss; η = 0.1.</p>","<h3>To find</h3>","<p>Find the weight-gradient sign, exact weight update and resulting weight.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 forward:</strong> net = 0(2) + 0 = 0; sigmoid output = 0.5.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_sigmoid_training.svg\" aria-label=\"Enlarge diagram: The diagram uses the same input, weight, bias and target as the question. Follow prediction, activation slope, delta and update in order.\"><img src=\"assets/figures/v_sigmoid_training.svg\" alt=\"The diagram uses the same input, weight, bias and target as the question. Follow prediction, activation slope, delta and update in order.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>The diagram uses the same input, weight, bias and target as the question. Follow prediction, activation slope, delta and update in order. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 2 backward:</strong> prediction minus target = 0.5 − 1 = −0.5. Sigmoid slope = 0.5(1 − 0.5) = 0.25. Delta = −0.5 × 0.25 = −0.125.</p>","<p class=\"worked-step\"><strong>Step 3 gradients and update:</strong> weight gradient = −0.125 × 2 = −0.25. New weight = 0 − 0.1(−0.25) = 0.025. Bias gradient = −0.125; new bias = 0.0125. Both increase. With positive input, these changes initially raise the prediction toward the target. Your intuition and arithmetic now agree.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s16","search":"Complete sigmoid training example **Question.** A sigmoid neuron has input 2, weight 0, bias 0, target 1 and half squared loss. Will gradient descent increase or decrease the weight? Use learning rate 0.1 and calculate the exact update.\n\n\n\n### Given\n\nx = 2; w = 0; b = 0; y = 1.\n\nSigmoid output; half squared loss; η = 0.1.\n\n### To find\n\nFind the weight-gradient sign, exact weight update and resulting weight.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**Step 1 forward:** net = 0(2) + 0 = 0; sigmoid output = 0.5.\n\n\n\n**Step 2 backward:** prediction minus target = 0.5 − 1 = −0.5. Sigmoid slope = 0.5(1 − 0.5) = 0.25. Delta = −0.5 × 0.25 = −0.125.\n**Step 3 gradients and update:** weight gradient = −0.125 × 2 = −0.25. New weight = 0 − 0.1(−0.25) = 0.025. Bias gradient = −0.125; new bias = 0.0125. Both increase. With positive input, these changes initially raise the prediction toward the target. Your intuition and arithmetic now agree.\n"},{"title":"Cross-entropy for probability distributions","blocks":["<p class=\"definition\"><strong>Definition.</strong> For a discrete target distribution p and a predicted distribution q over the same classes, cross-entropy is the target-weighted negative logarithm of the predicted probabilities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ca68a6ddd1ac17cc.svg\" alt=\"H(p,q)=-\\sum_{i=1}^{K}p_i\\log q_i\" width=\"248.66\" height=\"72.79\" style=\"width:248.66px;height:72.79px;aspect-ratio:248.66/72.79\" loading=\"lazy\"></div>","<p>Here pᵢ and qᵢ refer to the same class i, and each distribution sums to 1. The target supplies the weights outside the logarithm; the prediction goes inside it. If the target is one-hot, only the correct-class term remains. For a soft target with several nonzero entries, include all its nonzero terms.</p>","<h3>Logarithm base and units</h3>","<p>Natural logarithms produce <strong>nats</strong>; base-2 logarithms produce <strong>bits</strong>. These notes use ln unless a question states another base. On a calculator with ln, use the change-of-base rule for base 2:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/85b0a11172f30b61.svg\" alt=\"\\log_2 q=\\frac{\\ln q}{\\ln 2}\" width=\"137.21\" height=\"50.24\" style=\"width:137.21px;height:50.24px;aspect-ratio:137.21/50.24\" loading=\"lazy\"></div>","<p>For a target entry pᵢ = 0, its contribution is defined as zero. If pᵢ &gt; 0 but qᵢ = 0, the loss is infinite. For numerical stability, software normally calculates cross-entropy from logits or carefully handles boundary probabilities.</p>","<h3>A target distribution with two nonzero entries</h3>","<p class=\"inline-question\"><strong>Question. A two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5]. Calculate cross-entropy using natural logarithms and using base-2 logarithms.</strong></p>","<h3>Given</h3>","<p>A two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5].</p>","<p>Calculate cross-entropy using natural logarithms and using base-2 logarithms.</p>","<h3>To find</h3>","<p>Find cross-entropy in the requested units.</p>","<h3>Formula — which one and why</h3>","<p><strong>Cross-entropy between distributions.</strong> Weight each negative log prediction by the target probability. Unlike one-hot targets, several terms can contribute.</p>","<p>pᵢ = target-distribution probability; qᵢ = predicted probability. Natural logs give nats; base-2 logs give bits.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/feb21e9c89a912d7.svg\" alt=\"H(p,q)=-\\sum_i p_i\\ln q_i\" width=\"237.82\" height=\"52.35\" style=\"width:237.82px;height:52.35px;aspect-ratio:237.82/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f4684a5e966eb42a.svg\" alt=\"H_2(p,q)=\\frac{H(p,q)}{\\ln2}\" width=\"202.81\" height=\"52.43\" style=\"width:202.81px;height:52.43px;aspect-ratio:202.81/52.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Target probability batati hai kis log-loss ka kitna hissa lena hai.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the two terms.</strong> Both target entries are nonzero, so neither term can be discarded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:331.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcc9ac503722bcd6.svg\"><img class=\"math display-math\" src=\"assets/equations/3a2a7c8cae7d7ea4.svg\" alt=\"H(p,q)=-[0.75\\ln(0.5)+0.25\\ln(0.5)]\" width=\"406.41\" height=\"24.43\" style=\"width:406.41px;height:24.43px;aspect-ratio:406.41/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the logarithms.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89c211e38f586f86.svg\" alt=\"\\ln(0.5)\\approx-0.693147181\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: weight each negative logarithm by its target probability.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ba03d4ba50c7c4e4.svg\"><img class=\"math display-math\" src=\"assets/equations/c34f15079f0e23f0.svg\" alt=\"-0.75\\ln(0.5)\\approx0.519860385\" width=\"298.70\" height=\"24.43\" style=\"width:298.70px;height:24.43px;aspect-ratio:298.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7dbaf11af5ca2bb7.svg\"><img class=\"math display-math\" src=\"assets/equations/ca2ff9da024bd22a.svg\" alt=\"-0.25\\ln(0.5)\\approx0.173286795\" width=\"298.70\" height=\"24.43\" style=\"width:298.70px;height:24.43px;aspect-ratio:298.70/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: add the contributions, retaining calculator precision.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.65px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/77f2dae5c0c0431a.svg\"><img class=\"math display-math\" src=\"assets/equations/2b18f4e26d74ffd0.svg\" alt=\"H(p,q)\\approx0.519860385+0.173286795\\approx0.693147181\\ \\text{nats}\" width=\"608.08\" height=\"24.43\" style=\"width:608.08px;height:24.43px;aspect-ratio:608.08/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: repeat with base 2.</strong> Since 2⁻¹ = 0.5, log₂(0.5) = −1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:282.41px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cf0bfa788dbc4b07.svg\"><img class=\"math display-math\" src=\"assets/equations/ef4d3bcee474b612.svg\" alt=\"H_2(p,q)=-[0.75(-1)+0.25(-1)]=1\\ \\text{bit}\" width=\"447.58\" height=\"24.43\" style=\"width:447.58px;height:24.43px;aspect-ratio:447.58/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> 0.693147 nats or 1 bit. The distributions are unchanged; the logarithm base changes the unit and the numerical scale.</p>","<h3>Cross-entropy, entropy and relative entropy</h3>","<p>These names are related but do not denote the same quantity. Entropy uses the target distribution in both positions. Relative entropy, also called KL divergence, measures their difference through a probability ratio.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ac39baa15925718.svg\" alt=\"H(p)=-\\sum_i p_i\\ln p_i\" width=\"217.10\" height=\"52.35\" style=\"width:217.10px;height:52.35px;aspect-ratio:217.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.03px;--narrow-height:95.55px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8933903c2570cd47.svg\"><img class=\"math display-math\" src=\"assets/equations/5174a1ccffce0c30.svg\" alt=\"D_{\\mathrm{KL}}(p\\Vert q)=\\sum_i p_i\\ln\\frac{p_i}{q_i}=H(p,q)-H(p)\" width=\"443.59\" height=\"56.45\" style=\"width:443.59px;height:56.45px;aspect-ratio:443.59/56.45\" loading=\"lazy\"></picture></div>","<p>For fixed p, H(p) is constant with respect to the model parameters, so minimizing cross-entropy also minimizes this KL divergence. KL is clarified here to distinguish the terminology; it is not a separately named unit in the official syllabus.</p>","<p class=\"inline-question\"><strong>Question. For the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.</strong></p>","<h3>Given</h3>","<p>For the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.</p>","<h3>To find</h3>","<p>Find entropy and KL divergence in nats.</p>","<h3>Formula — which one and why</h3>","<p><strong>Entropy and relative entropy.</strong> Entropy measures the target distribution’s uncertainty. Relative entropy measures the extra cross-entropy when q is used instead of p.</p>","<p>p = target distribution; q = model distribution; H(p) = entropy; DKL = Kullback–Leibler divergence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ac39baa15925718.svg\" alt=\"H(p)=-\\sum_i p_i\\ln p_i\" width=\"217.10\" height=\"52.35\" style=\"width:217.10px;height:52.35px;aspect-ratio:217.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.95px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1dc0b474b12a2bf8.svg\"><img class=\"math display-math\" src=\"assets/equations/636a195581e18582.svg\" alt=\"D_{\\mathrm{KL}}(p\\Vert q)=H(p,q)-H(p)\" width=\"291.82\" height=\"24.43\" style=\"width:291.82px;height:24.43px;aspect-ratio:291.82/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> KL = cross-entropy minus target ki own entropy.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the target entropy.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78338077753f61a2.svg\" alt=\"H(p)=-[0.75\\ln(0.75)+0.25\\ln(0.25)]\" width=\"408.75\" height=\"24.43\" style=\"width:408.75px;height:24.43px;aspect-ratio:408.75/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.35px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c8cc7ed1293c1673.svg\"><img class=\"math display-math\" src=\"assets/equations/a0496aac07524e4b.svg\" alt=\"\\ln(0.75)\\approx-0.287682072,\\qquad\\ln(0.25)\\approx-1.386294361\" width=\"586.52\" height=\"24.43\" style=\"width:586.52px;height:24.43px;aspect-ratio:586.52/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.55px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b8c34bbe332a549f.svg\"><img class=\"math display-math\" src=\"assets/equations/1669c0167b94fcff.svg\" alt=\"H(p)\\approx0.215761554+0.346573590=0.562335145\" width=\"534.93\" height=\"24.43\" style=\"width:534.93px;height:24.43px;aspect-ratio:534.93/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: subtract target entropy from cross-entropy.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a763ffee09c5ad1.svg\"><img class=\"math display-math\" src=\"assets/equations/45d882f13b18b109.svg\" alt=\"D_{\\mathrm{KL}}(p\\Vert q)\\approx0.693147181-0.562335145=0.130812036\" width=\"583.19\" height=\"24.43\" style=\"width:583.19px;height:24.43px;aspect-ratio:583.19/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> H(p) ≈ 0.562335 nats and DKL(p ∥ q) ≈ 0.130812 nats. For a one-hot target H(p) = 0, so cross-entropy and this KL divergence coincide; for this soft target they differ.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c4-s17","search":"Cross-entropy for probability distributions **Definition.** For a discrete target distribution p and a predicted distribution q over the same classes, cross-entropy is the target-weighted negative logarithm of the predicted probabilities.\n\nHere pᵢ and qᵢ refer to the same class i, and each distribution sums to 1. The target supplies the weights outside the logarithm; the prediction goes inside it. If the target is one-hot, only the correct-class term remains. For a soft target with several nonzero entries, include all its nonzero terms.\n\n### Logarithm base and units\nNatural logarithms produce **nats**; base-2 logarithms produce **bits**. These notes use ln unless a question states another base. On a calculator with ln, use the change-of-base rule for base 2:\n\nFor a target entry pᵢ = 0, its contribution is defined as zero. If pᵢ > 0 but qᵢ = 0, the loss is infinite. For numerical stability, software normally calculates cross-entropy from logits or carefully handles boundary probabilities.\n\n### A target distribution with two nonzero entries\n**Question. A two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5]. Calculate cross-entropy using natural logarithms and using base-2 logarithms.**\n\n\n\n### Given\n\nA two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5].\n\nCalculate cross-entropy using natural logarithms and using base-2 logarithms.\n\n### To find\n\nFind cross-entropy in the requested units.\n\n### Formula — which one and why\n\n**Cross-entropy between distributions.** Weight each negative log prediction by the target probability. Unlike one-hot targets, several terms can contribute.\n\npᵢ = target-distribution probability; qᵢ = predicted probability. Natural logs give nats; base-2 logs give bits.\n\n\n\n\n\n**Yaad rakhne ka cue:** Target probability batati hai kis log-loss ka kitna hissa lena hai.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: write the two terms.** Both target entries are nonzero, so neither term can be discarded.\n\n\n**Step 2: calculate the logarithms.**\n\n\n**Step 3: weight each negative logarithm by its target probability.**\n\n\n\n**Step 4: add the contributions, retaining calculator precision.**\n\n\n**Step 5: repeat with base 2.** Since 2⁻¹ = 0.5, log₂(0.5) = −1.\n\n**Final answer:** 0.693147 nats or 1 bit. The distributions are unchanged; the logarithm base changes the unit and the numerical scale.\n\n### Cross-entropy, entropy and relative entropy\nThese names are related but do not denote the same quantity. Entropy uses the target distribution in both positions. Relative entropy, also called KL divergence, measures their difference through a probability ratio.\n\n\nFor fixed p, H(p) is constant with respect to the model parameters, so minimizing cross-entropy also minimizes this KL divergence. KL is clarified here to distinguish the terminology; it is not a separately named unit in the official syllabus.\n\n**Question. For the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.**\n\n\n\n### Given\n\nFor the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.\n\n### To find\n\nFind entropy and KL divergence in nats.\n\n### Formula — which one and why\n\n**Entropy and relative entropy.** Entropy measures the target distribution’s uncertainty. Relative entropy measures the extra cross-entropy when q is used instead of p.\n\np = target distribution; q = model distribution; H(p) = entropy; DKL = Kullback–Leibler divergence.\n\n\n\n\n\n**Yaad rakhne ka cue:** KL"}]},{"n":5,"title":"Optimization algorithms","sections":[{"title":"Reading an optimizer formula without getting lost","blocks":["<p>An optimizer updates the numbers the model is allowed to learn. Usually these are weights and biases. The letter θ is a convenient name for whichever parameter is currently being updated.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_optimizer_notation.svg\" aria-label=\"Enlarge diagram: Old value, current gradient and new value belong to different moments in the update.\"><img src=\"assets/figures/v_optimizer_notation.svg\" alt=\"Old value, current gradient and new value belong to different moments in the update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Old value, current gradient and new value belong to different moments in the update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Old, current and new</h3>","<p>At update t, θₜ₋₁ is the value before the update and θₜ is the value after it. The symbol gₜ is the loss gradient used in that update. If a question already supplies gₜ, use it. If it supplies a loss J(θ), differentiate J and evaluate the derivative at the stated position.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p>η, read eta, is the learning rate. It multiplies the gradient to determine the basic correction. A positive gradient is subtracted; a negative gradient makes the new value larger because subtracting a negative is addition.</p>","<h3>What a stored state means</h3>","<p>An optimizer may retain a number from its previous update. This number is called its state or memory. It is an ordinary calculated number, not an additional neuron. Momentum stores movement; AdaGrad stores a sum of squared gradients; RMSProp stores a moving average of squares; Adam stores a moving average of gradients and another of squares.</p>","<h3>A weighted average from ordinary arithmetic</h3>","<p>If the old state is 4, the new squared gradient is 9 and the decay is 0.9, retain 90% of the old state and add 10% of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0d4d3672b448c16a.svg\"><img class=\"math display-math\" src=\"assets/equations/722eae46e0545987.svg\" alt=\"0.9\\times4=3.6,\\qquad(1-0.9)\\times9=0.9\" width=\"395.09\" height=\"24.43\" style=\"width:395.09px;height:24.43px;aspect-ratio:395.09/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4044336c67492dab.svg\" alt=\"s_{\\mathrm{new}}=3.6+0.9=4.5\" width=\"231.96\" height=\"20.40\" style=\"width:231.96px;height:20.40px;aspect-ratio:231.96/20.40\" loading=\"lazy\"></div>","<p>The coefficients 0.9 and 0.1 add to 1. As updates continue, a past contribution gets multiplied by 0.9 again, so its influence fades. AdaGrad instead gives 4 + 9 = 13 because it retains the full old sum.</p>","<h3>Squared memory and signed direction</h3>","<p>For gradient −3, the square is 9. The stored scale is positive, but the update still needs the negative gradient to determine direction. Do not replace every occurrence of g with g².</p>","<h3>Epsilon and hats</h3>","<p>ε, read epsilon, is a small positive number that prevents an exactly zero denominator. A hat in Adam, such as m with a hat, labels a bias-corrected average. A hat does not mean squaring. The power βᵗ uses the update number t, so its value changes from the first update to the second.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s0","search":"Reading an optimizer formula without getting lost An optimizer updates the numbers the model is allowed to learn. Usually these are weights and biases. The letter θ is a convenient name for whichever parameter is currently being updated.\n\n\n\n### Old, current and new\nAt update t, θₜ₋₁ is the value before the update and θₜ is the value after it. The symbol gₜ is the loss gradient used in that update. If a question already supplies gₜ, use it. If it supplies a loss J(θ), differentiate J and evaluate the derivative at the stated position.\n\nη, read eta, is the learning rate. It multiplies the gradient to determine the basic correction. A positive gradient is subtracted; a negative gradient makes the new value larger because subtracting a negative is addition.\n### What a stored state means\nAn optimizer may retain a number from its previous update. This number is called its state or memory. It is an ordinary calculated number, not an additional neuron. Momentum stores movement; AdaGrad stores a sum of squared gradients; RMSProp stores a moving average of squares; Adam stores a moving average of gradients and another of squares.\n### A weighted average from ordinary arithmetic\nIf the old state is 4, the new squared gradient is 9 and the decay is 0.9, retain 90% of the old state and add 10% of the new square.\n\n\nThe coefficients 0.9 and 0.1 add to 1. As updates continue, a past contribution gets multiplied by 0.9 again, so its influence fades. AdaGrad instead gives 4 + 9 = 13 because it retains the full old sum.\n### Squared memory and signed direction\nFor gradient −3, the square is 9. The stored scale is positive, but the update still needs the negative gradient to determine direction. Do not replace every occurrence of g with g².\n### Epsilon and hats\nε, read epsilon, is a small positive number that prevents an exactly zero denominator. A hat in Adam, such as m with a hat, labels a bias-corrected average. A hat does not mean squaring. The power βᵗ uses the update number t, so its value changes from the first update to the second.\n"},{"title":"Optimizer notation: old value, memory, new value","blocks":["<h3>1. A parameter and a stored state are different</h3>","<p>θ is the parameter we want to learn. A memory such as v, s or m helps an optimizer decide how to change θ; it is not a second prediction. Each trainable parameter usually has its own corresponding memory entries.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_optimizer_notation.svg\" aria-label=\"Enlarge diagram: The time label tells you which value to use. Carry the previous memory into the current update.\"><img src=\"assets/figures/v_optimizer_notation.svg\" alt=\"The time label tells you which value to use. Carry the previous memory into the current update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The time label tells you which value to use. Carry the previous memory into the current update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At time t = 0, the problem supplies starting values. At update t = 1, read the old values, calculate the current gradient and new memory, then calculate the new parameter. At update t = 2, use the results of update 1 as the old values.</p>","<h3>2. A supplied gradient versus a supplied objective</h3>","<p>If the question says gradients are 2 and −1, use those values in order. If it instead gives J(θ) = θ², first differentiate to get g(θ) = 2θ. Recalculate g using the current parameter at each iteration. Nesterov evaluates at its lookahead point instead.</p>","<p>For θ₀ = 1 and η = 0.1 with ordinary GD, g₁ = 2 and θ₁ = 0.8. The next gradient is 2 × 0.8 = 1.6, not the old value 2. Therefore θ₂ = 0.8 − 0.1 × 1.6 = 0.64.</p>","<h3>3. A squared gradient keeps size and loses sign</h3>","<p>Both 2² and (−2)² equal 4. Squared-gradient memory tells us about scale. The signed numerator still decides the update direction. Never replace the gradient in every part of an optimizer by its square.</p>","<h3>4. Square root and epsilon belong to the denominator</h3>","<p>If s = 4 and ε = 0.01, the denominator √s + ε is 2 + 0.01 = 2.01. It is different from √(s + ε), which is √4.01. Use the placement specified by the formula. Small ε keeps a zero accumulator from causing division by zero.</p>","<h3>5. A table prevents mixing iterations</h3>","<p>Write one row per iteration. Ordinary GD needs current θ, gradient and new θ. Momentum adds old and new velocity. Adam adds both memories and their corrected values. Complete a row before starting the next; otherwise a new value from iteration 2 may accidentally be used inside iteration 1.</p>","<p>The worked examples below use this exact order, with every state shown.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s1","search":"Optimizer notation: old value, memory, new value ### 1. A parameter and a stored state are different\nθ is the parameter we want to learn. A memory such as v, s or m helps an optimizer decide how to change θ; it is not a second prediction. Each trainable parameter usually has its own corresponding memory entries.\n\n\n\nAt time t = 0, the problem supplies starting values. At update t = 1, read the old values, calculate the current gradient and new memory, then calculate the new parameter. At update t = 2, use the results of update 1 as the old values.\n\n### 2. A supplied gradient versus a supplied objective\nIf the question says gradients are 2 and −1, use those values in order. If it instead gives J(θ) = θ², first differentiate to get g(θ) = 2θ. Recalculate g using the current parameter at each iteration. Nesterov evaluates at its lookahead point instead.\nFor θ₀ = 1 and η = 0.1 with ordinary GD, g₁ = 2 and θ₁ = 0.8. The next gradient is 2 × 0.8 = 1.6, not the old value 2. Therefore θ₂ = 0.8 − 0.1 × 1.6 = 0.64.\n\n### 3. A squared gradient keeps size and loses sign\nBoth 2² and (−2)² equal 4. Squared-gradient memory tells us about scale. The signed numerator still decides the update direction. Never replace the gradient in every part of an optimizer by its square.\n\n### 4. Square root and epsilon belong to the denominator\nIf s = 4 and ε = 0.01, the denominator √s + ε is 2 + 0.01 = 2.01. It is different from √(s + ε), which is √4.01. Use the placement specified by the formula. Small ε keeps a zero accumulator from causing division by zero.\n\n### 5. A table prevents mixing iterations\nWrite one row per iteration. Ordinary GD needs current θ, gradient and new θ. Momentum adds old and new velocity. Adam adds both memories and their corrected values. Complete a row before starting the next; otherwise a new value from iteration 2 may accidentally be used inside iteration 1.\nThe worked examples below use this exact order, with every state shown.\n"},{"title":"What an optimizer is trying to do","blocks":["<p class=\"definition\"><strong>Definition.</strong> Optimization is the process of selecting model parameters to minimize a scalar objective. In neural-network training, a gradient-based optimizer updates weights and biases using derivatives of the training objective.</p>","<h3>Objective and gradient</h3>","<p>For empirical risk with an optional regularizer:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.50px;--narrow-height:111.88px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e8f2cd5bb532bd92.svg\"><img class=\"math display-math\" src=\"assets/equations/b7857d96c4edb1c7.svg\" alt=\"J(\\theta)=\\frac1N\\sum_{i=1}^{N}L_i(\\theta)+\\lambda\\Omega(\\theta)\" width=\"301.72\" height=\"72.79\" style=\"width:301.72px;height:72.79px;aspect-ratio:301.72/72.79\" loading=\"lazy\"></picture></div>","<p>The loss value indicates the current objective. Its gradient indicates local sensitivity to parameters. Backpropagation computes this gradient efficiently; the optimizer determines how the parameters are updated from it. A gradient and a loss value cannot be interchanged in the update equation.</p>","<h3>Why gradient descent subtracts the gradient</h3>","<p>For a small displacement Δθ, first-order Taylor expansion approximates the objective by:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:186.14px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9060e5490f15d100.svg\"><img class=\"math display-math\" src=\"assets/equations/2f6a587716d3d081.svg\" alt=\"J(\\theta+\\Delta\\theta)\\approx J(\\theta)+\\nabla J(\\theta)^T\\Delta\\theta\" width=\"328.31\" height=\"27.90\" style=\"width:328.31px;height:27.90px;aspect-ratio:328.31/27.90\" loading=\"lazy\"></picture></div>","<p>Choose Δθ = −η∇J(θ), with η &gt; 0. Substitution gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.29px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f0fe0e6b83fb6f66.svg\"><img class=\"math display-math\" src=\"assets/equations/6c50025de1d032a9.svg\" alt=\"J(\\theta-\\eta\\nabla J)\\approx J(\\theta)-\\eta\\|\\nabla J\\|_2^2\" width=\"315.23\" height=\"27.70\" style=\"width:315.23px;height:27.70px;aspect-ratio:315.23/27.70\" loading=\"lazy\"></picture></div>","<p>The squared norm is nonnegative. Therefore the negative-gradient direction is locally a descent direction when the gradient is nonzero. The approximation explains the sign; it does not guarantee that an arbitrarily large finite step decreases loss.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_gd.svg\" aria-label=\"Enlarge diagram: A gradient specifies a local direction; the learning rate determines the finite parameter step.\"><img src=\"assets/figures/v_gd.svg\" alt=\"A gradient specifies a local direction; the learning rate determines the finite parameter step.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>A gradient specifies a local direction; the learning rate determines the finite parameter step. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Local minima, global minima and saddle points</h3>","<p>A local minimum has objective value no larger than nearby points. A global minimum is minimal over the whole feasible domain. At a saddle point, the objective increases in some directions and decreases in others. A small gradient alone does not establish a minimum: a stationary point can also be a maximum or saddle.</p>","<p>Neural-network objectives are generally nonconvex. Training can encounter flat regions, ill-conditioned valleys, noisy gradient estimates and poor step sizes. Momentum modifies the update direction using previous steps; adaptive methods rescale parameter-specific updates. These methods improve particular optimization behavior, without guaranteeing the global optimum or best test performance.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s2","search":"What an optimizer is trying to do **Definition.** Optimization is the process of selecting model parameters to minimize a scalar objective. In neural-network training, a gradient-based optimizer updates weights and biases using derivatives of the training objective.\n\n### Objective and gradient\nFor empirical risk with an optional regularizer:\n\nThe loss value indicates the current objective. Its gradient indicates local sensitivity to parameters. Backpropagation computes this gradient efficiently; the optimizer determines how the parameters are updated from it. A gradient and a loss value cannot be interchanged in the update equation.\n\n### Why gradient descent subtracts the gradient\nFor a small displacement Δθ, first-order Taylor expansion approximates the objective by:\n\nChoose Δθ = −η∇J(θ), with η > 0. Substitution gives:\n\nThe squared norm is nonnegative. Therefore the negative-gradient direction is locally a descent direction when the gradient is nonzero. The approximation explains the sign; it does not guarantee that an arbitrarily large finite step decreases loss.\n\n\n\n### Local minima, global minima and saddle points\nA local minimum has objective value no larger than nearby points. A global minimum is minimal over the whole feasible domain. At a saddle point, the objective increases in some directions and decreases in others. A small gradient alone does not establish a minimum: a stationary point can also be a maximum or saddle.\n\nNeural-network objectives are generally nonconvex. Training can encounter flat regions, ill-conditioned valleys, noisy gradient estimates and poor step sizes. Momentum modifies the update direction using previous steps; adaptive methods rescale parameter-specific updates. These methods improve particular optimization behavior, without guaranteeing the global optimum or best test performance.\n"},{"title":"The ordinary gradient descent update","blocks":["<p class=\"definition\"><strong>Definition.</strong> Gradient descent is an iterative first-order optimization algorithm that updates parameters in the negative direction of the current objective gradient, scaled by a positive learning rate.</p>","<h3>Explanation and working</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p>Here update numbers start at t = 1: calculate g₁ at θ₀, obtain θ₁, then calculate g₂ at θ₁. The subscript counts completed updates; it is not an exponent.</p>","<p>Read it aloud: “new parameter equals old parameter minus learning rate times current gradient.” The old parameter is where you are. The gradient gives the local uphill direction. The learning rate controls how far you move in the opposite direction.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_gd.svg\" aria-label=\"Enlarge diagram: Calculate the slope first, multiply it by the learning rate, then subtract that correction.\"><img src=\"assets/figures/v_gd.svg\" alt=\"Calculate the slope first, multiply it by the learning rate, then subtract that correction.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>Calculate the slope first, multiply it by the learning rate, then subtract that correction. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> J(θ) = 0.7 θ³; θ₀ = 1; η = 0.1. Perform two iterations.</p>","<h3>Given</h3>","<p>J(θ) = 0.7θ³; initial θ₀ = 1; η = 0.1.</p>","<h3>To find</h3>","<p>Differentiate J and perform two gradient-descent iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1. Differentiate.</strong> g(θ) = 0.7 × 3 × θ² = 2.1 θ².</p>","<p class=\"worked-step\"><strong>Step 2. First update.</strong> g₁ = 2.1(1)² = 2.1. θ₁ = 1 − 0.1(2.1) = 0.79.</p>","<p class=\"worked-step\"><strong>Step 3. Second gradient.</strong> Square the new value: 0.79² = 0.6241. Multiply: g₂ = 2.1 × 0.6241 = 1.31061.</p>","<p class=\"worked-step\"><strong>Step 4. Second update.</strong> θ₂ = 0.79 − 0.1(1.31061) = 0.79 − 0.131061 = <strong>0.658939</strong>.</p>","<p>The paper calls this SGD. With only a scalar objective supplied, no sample selection is specified; the arithmetic is the stated gradient-descent update. Also, this cubic is not bounded below over all real values. Do not claim these two steps prove convergence to a global minimum.</p>","<p><strong>Common error: </strong> using the loss J itself instead of its derivative g. Another error is repeatedly using θ₀ to calculate later gradients.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s3","search":"The ordinary gradient descent update **Definition.** Gradient descent is an iterative first-order optimization algorithm that updates parameters in the negative direction of the current objective gradient, scaled by a positive learning rate.\n\n### Explanation and working\n\n\nHere update numbers start at t = 1: calculate g₁ at θ₀, obtain θ₁, then calculate g₂ at θ₁. The subscript counts completed updates; it is not an exponent.\nRead it aloud: “new parameter equals old parameter minus learning rate times current gradient.” The old parameter is where you are. The gradient gives the local uphill direction. The learning rate controls how far you move in the opposite direction.\n\n\n\n**Question.** J(θ) = 0.7 θ³; θ₀ = 1; η = 0.1. Perform two iterations.\n\n\n\n### Given\n\nJ(θ) = 0.7θ³; initial θ₀ = 1; η = 0.1.\n\n### To find\n\nDifferentiate J and perform two gradient-descent iterations.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n**Step 1. Differentiate.** g(θ) = 0.7 × 3 × θ² = 2.1 θ².\n**Step 2. First update.** g₁ = 2.1(1)² = 2.1. θ₁ = 1 − 0.1(2.1) = 0.79.\n**Step 3. Second gradient.** Square the new value: 0.79² = 0.6241. Multiply: g₂ = 2.1 × 0.6241 = 1.31061.\n**Step 4. Second update.** θ₂ = 0.79 − 0.1(1.31061) = 0.79 − 0.131061 = **0.658939**.\nThe paper calls this SGD. With only a scalar objective supplied, no sample selection is specified; the arithmetic is the stated gradient-descent update. Also, this cubic is not bounded below over all real values. Do not claim these two steps prove convergence to a global minimum.\n**Common error: ** using the loss J itself instead of its derivative g. Another error is repeatedly using θ₀ to calculate later gradients."},{"title":"Batch stochastic and mini batch gradient descent","blocks":["<p class=\"definition\"><strong>Definition.</strong> Batch, stochastic and mini-batch gradient descent differ in the subset of training examples used to estimate the gradient for each parameter update. Their update equation is the same; their gradient estimates and update frequency differ.</p>","<h3>Explanation and working</h3>","<p>All three use the same update idea. They differ in how much data contributes to one gradient.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_batches.svg\" aria-label=\"Enlarge diagram: Count outlined groups, not individual cells, to count gradient updates in one epoch.\"><img src=\"assets/figures/v_batches.svg\" alt=\"Count outlined groups, not individual cells, to count gradient updates in one epoch.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Count outlined groups, not individual cells, to count gradient updates in one epoch. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>Data for one update</th><th>Updates in one epoch with N samples</th><th>Typical behaviour</th></tr></thead><tbody><tr><td>Batch GD</td><td>All N samples</td><td>1</td><td>Stable full-data gradient; costly updates</td></tr><tr><td>Stochastic GD</td><td>One sample</td><td>N</td><td>Frequent noisy updates</td></tr><tr><td>Mini-batch GD</td><td>B samples</td><td>Ceiling of N/B if final partial batch is retained</td><td>Efficient parallel calculation with moderate noise</td></tr></tbody></table></div>","<p class=\"inline-question\"><strong>Question.</strong> N = 1,000 and B = 100. Find updates per epoch.</p>","<h3>Given</h3>","<p>N = 1,000 examples; mini-batch size B = 100; one epoch.</p>","<h3>To find</h3>","<p>Count full-batch, stochastic and mini-batch updates per epoch.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count full-batch updates.</strong></p>","<p>All 1,000 samples form one group, so one epoch has 1 update.</p>","<p class=\"worked-step\"><strong>Step 2: count stochastic updates.</strong></p>","<p>One sample per update gives 1,000 updates per epoch.</p>","<p class=\"worked-step\"><strong>Step 3: count mini-batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/044096791068cfc7.svg\" alt=\"\\frac{N}{B}=\\frac{1000}{100}=10\" width=\"181.68\" height=\"50.50\" style=\"width:181.68px;height:50.50px;aspect-ratio:181.68/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> batch = 1; SGD = 1,000; mini-batch = 10 updates per epoch.</p>","<h3>Mini-batch calculation with a remainder</h3>","<p class=\"inline-question\"><strong>Question. A dataset contains 105 samples and the mini-batch size is 20. Keeping the incomplete last batch, find the updates per epoch.</strong></p>","<h3>Given</h3>","<p>N = 105; B = 20; retain the final incomplete batch.</p>","<h3>To find</h3>","<p>The number of updates per epoch.</p>","<h3>Formula — which one and why</h3>","<p>Every processed group causes one update. A remaining nonempty group also counts.</p>","<p>The ceiling symbol rounds upward to the next integer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a73af57990a3f346.svg\" alt=\"U=\\lceil N/B\\rceil\" width=\"125.49\" height=\"24.43\" style=\"width:125.49px;height:24.43px;aspect-ratio:125.49/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bacha hua batch process kiya toh ek aur update.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count complete batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/165b56a31834874f.svg\" alt=\"5(20)=100\" width=\"124.90\" height=\"24.43\" style=\"width:124.90px;height:24.43px;aspect-ratio:124.90/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count remaining examples.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/018ad701e47e6473.svg\" alt=\"105-100=5\" width=\"147.97\" height=\"18.27\" style=\"width:147.97px;height:18.27px;aspect-ratio:147.97/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: include the nonempty last batch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/298ed637938b4bf6.svg\" alt=\"U=5+1=6\" width=\"150.43\" height=\"18.69\" style=\"width:150.43px;height:18.69px;aspect-ratio:150.43/18.69\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 6 updates. If a question explicitly drops the final incomplete batch, it instead gives 5.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s4","search":"Batch stochastic and mini batch gradient descent **Definition.** Batch, stochastic and mini-batch gradient descent differ in the subset of training examples used to estimate the gradient for each parameter update. Their update equation is the same; their gradient estimates and update frequency differ.\n\n### Explanation and working\nAll three use the same update idea. They differ in how much data contributes to one gradient.\n\n\n\n| Method | Data for one update | Updates in one epoch with N samples | Typical behaviour |\n| Batch GD | All N samples | 1 | Stable full-data gradient; costly updates |\n| Stochastic GD | One sample | N | Frequent noisy updates |\n| Mini-batch GD | B samples | Ceiling of N/B if final partial batch is retained | Efficient parallel calculation with moderate noise |\n**Question.** N = 1,000 and B = 100. Find updates per epoch.\n\n\n\n### Given\n\nN = 1,000 examples; mini-batch size B = 100; one epoch.\n\n### To find\n\nCount full-batch, stochastic and mini-batch updates per epoch.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n### Solution — step by step\n\n\n\n\n**Step 1: count full-batch updates.**\n\nAll 1,000 samples form one group, so one epoch has 1 update.\n\n**Step 2: count stochastic updates.**\n\nOne sample per update gives 1,000 updates per epoch.\n\n**Step 3: count mini-batches.**\n\n\n\n\n\n\n\n**Final answer:** batch = 1; SGD = 1,000; mini-batch = 10 updates per epoch.\n\n\n### Mini-batch calculation with a remainder\n\n**Question. A dataset contains 105 samples and the mini-batch size is 20. Keeping the incomplete last batch, find the updates per epoch.**\n\n\n\n### Given\n\nN = 105; B = 20; retain the final incomplete batch.\n\n### To find\n\nThe number of updates per epoch.\n\n### Formula — which one and why\n\nEvery processed group causes one update. A remaining nonempty group also counts.\n\nThe ceiling symbol rounds upward to the next integer.\n\n\n\n**Yaad rakhne ka cue:** Bacha hua batch process kiya toh ek aur update.\n\n### Solution — step by step\n\n\n\n**Step 1: count complete batches.**\n\n\n\n\n\n\n\n**Step 2: count remaining examples.**\n\n\n\n\n\n\n\n**Step 3: include the nonempty last batch.**\n\n\n\n\n\n\n\n**Final answer:** 6 updates. If a question explicitly drops the final incomplete batch, it instead gives 5.\n\n"},{"title":"Model answer: batch, stochastic and mini-batch training","question":["<p class=\"inline-question\"><strong>Question.</strong> Differentiate batch gradient descent, stochastic gradient descent and mini-batch gradient descent. Explain an epoch, a batch and an iteration.</p>"],"answer":["<p>All three methods update model parameters using gradients. Their difference is the number of training examples used to estimate the gradient for one update.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_batches.svg\" aria-label=\"Enlarge diagram: All methods visit the same six examples. Their grouping determines how often they update.\"><img src=\"assets/figures/v_batches.svg\" alt=\"All methods visit the same six examples. Their grouping determines how often they update.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>All methods visit the same six examples. Their grouping determines how often they update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A <strong>batch</strong> is the group of examples used together for an update. An <strong>iteration</strong>, in this context, is one optimizer update. An <strong>epoch</strong> is one complete pass through the chosen training dataset. One epoch usually contains several iterations.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Basis</th><th>Batch GD</th><th>Stochastic GD</th><th>Mini-batch GD</th></tr></thead><tbody><tr><td>Examples in one gradient</td><td>Entire training dataset</td><td>One example</td><td>A smaller group of B examples</td></tr><tr><td>Updates per epoch</td><td>One</td><td>N</td><td>Ceiling of N/B if the remainder is retained</td></tr><tr><td>Gradient behavior</td><td>Full-data gradient</td><td>Noisy sample gradient</td><td>Intermediate averaging</td></tr><tr><td>Practical implication</td><td>Updates can be expensive on large datasets</td><td>Many small, sequential updates</td><td>Common compromise for vectorized computation</td></tr></tbody></table></div>","<h3>Example to distinguish the three counts</h3>","<p>With 105 examples and batch size 20, five batches use 100 examples and a sixth uses the remaining 5. Therefore one epoch has 6 mini-batch updates. Three epochs give 18 updates. It would be 5 updates per epoch only if the problem explicitly discarded the incomplete batch.</p>","<p>The basic parameter update is unchanged:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8a6ef020e7632784.svg\" alt=\"\\theta_{\\mathrm{new}}=\\theta_{\\mathrm{old}}-\\eta g\" width=\"166.03\" height=\"22.51\" style=\"width:166.03px;height:22.51px;aspect-ratio:166.03/22.51\" loading=\"lazy\"></div>","<p>For batch or mini-batch training, g normally represents the gradient of the stated aggregate loss over that group. For sequential SGD, update after each example and use the new parameter for the next example. Consequently, one SGD epoch need not equal one batch update even when both use the same examples.</p>"],"kind":"theory","id":"mt2-c5-s5","search":"Model answer: batch, stochastic and mini-batch training **Question.** Differentiate batch gradient descent, stochastic gradient descent and mini-batch gradient descent. Explain an epoch, a batch and an iteration.\n\n**Model answer.**\nAll three methods update model parameters using gradients. Their difference is the number of training examples used to estimate the gradient for one update.\n\n\n\n\nA **batch** is the group of examples used together for an update. An **iteration**, in this context, is one optimizer update. An **epoch** is one complete pass through the chosen training dataset. One epoch usually contains several iterations.\n\n| Basis | Batch GD | Stochastic GD | Mini-batch GD |\n| Examples in one gradient | Entire training dataset | One example | A smaller group of B examples |\n| Updates per epoch | One | N | Ceiling of N/B if the remainder is retained |\n| Gradient behavior | Full-data gradient | Noisy sample gradient | Intermediate averaging |\n| Practical implication | Updates can be expensive on large datasets | Many small, sequential updates | Common compromise for vectorized computation |\n\n### Example to distinguish the three counts\nWith 105 examples and batch size 20, five batches use 100 examples and a sixth uses the remaining 5. Therefore one epoch has 6 mini-batch updates. Three epochs give 18 updates. It would be 5 updates per epoch only if the problem explicitly discarded the incomplete batch.\n\nThe basic parameter update is unchanged:\n\nFor batch or mini-batch training, g normally represents the gradient of the stated aggregate loss over that group. For sequential SGD, update after each example and use the new parameter for the next example. Consequently, one SGD epoch need not equal one batch update even when both use the same examples.\n"},{"title":"A tiny dataset shows why the methods differ","blocks":["<p class=\"inline-question\"><strong>Question.</strong> Train ŷ = wx on samples (1,2) and (2,4), starting at w = 1, with η = 0.1 and mean half squared loss. Compare one batch update with one SGD epoch in the listed order.</p>","<h3>Given</h3>","<p>Model ŷ = wx; initial w = 1; η = 0.1.</p>","<p>Samples in order: (1,2), (2,4).</p>","<p>Mean half squared loss for the batch.</p>","<h3>To find</h3>","<p>Compare one batch update with a sequential SGD epoch.</p>","<h3>Formula — which one and why</h3>","<p><strong>Batch mean versus sequential SGD.</strong> A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.</p>","<p>B = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/657f63b5043d3907.svg\" alt=\"g_{\\mathrm{batch}}=\\frac1B\\sum_i g_i\" width=\"180.88\" height=\"61.92\" style=\"width:180.88px;height:61.92px;aspect-ratio:180.88/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0b4939a48933eb0a.svg\" alt=\"g_i=(wx_i-y_i)x_i\" width=\"182.50\" height=\"24.43\" style=\"width:182.50px;height:24.43px;aspect-ratio:182.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Batch: same old weight par average; SGD: har sample ke baad weight change.</p>","<h3>Solution — step by step</h3>","<h3>One batch update</h3>","<p class=\"worked-step\"><strong>Step 1: predict sample 1 with the original weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d19c8d7124e25bc5.svg\" alt=\"\\hat y_1=1(1)=1\" width=\"143.47\" height=\"25.90\" style=\"width:143.47px;height:25.90px;aspect-ratio:143.47/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate its error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dba84d8eacba9175.svg\" alt=\"e_1=1-2=-1\" width=\"172.76\" height=\"19.94\" style=\"width:172.76px;height:19.94px;aspect-ratio:172.76/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply its error by its input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fdbcda3ad0050efb.svg\" alt=\"g_1=(-1)(1)=-1\" width=\"200.18\" height=\"24.43\" style=\"width:200.18px;height:24.43px;aspect-ratio:200.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: predict sample 2 with the same original weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7be604573d864f92.svg\" alt=\"\\hat y_2=1(2)=2\" width=\"143.47\" height=\"25.90\" style=\"width:143.47px;height:25.90px;aspect-ratio:143.47/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate its error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55c62638d290dff9.svg\" alt=\"e_2=2-4=-2\" width=\"172.76\" height=\"20.21\" style=\"width:172.76px;height:20.21px;aspect-ratio:172.76/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: multiply its error by its input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f6d46df3c042284.svg\" alt=\"g_2=(-2)(2)=-4\" width=\"200.18\" height=\"24.43\" style=\"width:200.18px;height:24.43px;aspect-ratio:200.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: average the two gradients.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8cfa6ee1614fe8e3.svg\" alt=\"g=\\frac{-1+(-4)}2=-2.5\" width=\"249.15\" height=\"52.43\" style=\"width:249.15px;height:52.43px;aspect-ratio:249.15/52.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: update once.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.42px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f263219d999d6318.svg\"><img class=\"math display-math\" src=\"assets/equations/9fb7a46ddd37e16c.svg\" alt=\"w_{\\mathrm{new}}=1-0.1(-2.5)=1.25\" width=\"300.45\" height=\"24.43\" style=\"width:300.45px;height:24.43px;aspect-ratio:300.45/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_batches.svg\" aria-label=\"Enlarge diagram: This grouping sketch explains the difference. The worked dataset below supplies its own values for the actual gradient calculation.\"><img src=\"assets/figures/v_batches.svg\" alt=\"This grouping sketch explains the difference. The worked dataset below supplies its own values for the actual gradient calculation.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>This grouping sketch explains the difference. The worked dataset below supplies its own values for the actual gradient calculation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>One sequential SGD epoch</h3>","<p class=\"worked-step\"><strong>Step 1: use the first sample gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a43ae4bf3e05e38.svg\" alt=\"g_1=-1\" width=\"86.13\" height=\"21.29\" style=\"width:86.13px;height:21.29px;aspect-ratio:86.13/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: update after the first sample.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2a537796fbcbe31.svg\" alt=\"w_1=1-0.1(-1)=1.1\" width=\"248.11\" height=\"24.43\" style=\"width:248.11px;height:24.43px;aspect-ratio:248.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: predict sample 2 using the changed weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b434bd09ecf3d6fa.svg\" alt=\"\\hat y_2=1.1(2)=2.2\" width=\"181.49\" height=\"25.90\" style=\"width:181.49px;height:25.90px;aspect-ratio:181.49/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find sample 2 error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbcb5d7c79c1f6bd.svg\" alt=\"e_2=2.2-4=-1.8\" width=\"210.77\" height=\"20.21\" style=\"width:210.77px;height:20.21px;aspect-ratio:210.77/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find the new sample 2 gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/352a3c332b7e819d.svg\" alt=\"g_2=(-1.8)(2)=-3.6\" width=\"238.20\" height=\"24.43\" style=\"width:238.20px;height:24.43px;aspect-ratio:238.20/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: update after sample 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.32px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/337ee1d4f3248df4.svg\"><img class=\"math display-math\" src=\"assets/equations/93143771f8225850.svg\" alt=\"w_2=1.1-0.1(-3.6)=1.46\" width=\"298.35\" height=\"24.43\" style=\"width:298.35px;height:24.43px;aspect-ratio:298.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> batch weight = 1.25; sequential SGD weight = 1.46. SGD changes the weight between samples.</p>","<p>Larger mini-batches use more memory and often make better use of parallel hardware. Smaller batches provide noisier gradient estimates and more updates per epoch. Wall-clock speed and generalization depend on the implementation and problem, so “SGD always converges fastest” is not a safe claim.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s6","search":"A tiny dataset shows why the methods differ **Question.** Train ŷ = wx on samples (1,2) and (2,4), starting at w = 1, with η = 0.1 and mean half squared loss. Compare one batch update with one SGD epoch in the listed order.\n\n\n\n### Given\n\nModel ŷ = wx; initial w = 1; η = 0.1.\n\nSamples in order: (1,2), (2,4).\n\nMean half squared loss for the batch.\n\n### To find\n\nCompare one batch update with a sequential SGD epoch.\n\n### Formula — which one and why\n\n**Batch mean versus sequential SGD.** A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.\n\nB = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Batch: same old weight par average; SGD: har sample ke baad weight change.\n\n### Solution — step by step\n\n\n\n\n### One batch update\n\n**Step 1: predict sample 1 with the original weight.**\n\n\n\n\n\n\n\n**Step 2: calculate its error.**\n\n\n\n\n\n\n\n**Step 3: multiply its error by its input.**\n\n\n\n\n\n\n\n**Step 4: predict sample 2 with the same original weight.**\n\n\n\n\n\n\n\n**Step 5: calculate its error.**\n\n\n\n\n\n\n\n**Step 6: multiply its error by its input.**\n\n\n\n\n\n\n\n**Step 7: average the two gradients.**\n\n\n\n\n\n\n\n**Step 8: update once.**\n\n\n\n\n\n\n\n\n\n\n\n### One sequential SGD epoch\n\n**Step 1: use the first sample gradient.**\n\n\n\n\n\n\n\n**Step 2: update after the first sample.**\n\n\n\n\n\n\n\n**Step 3: predict sample 2 using the changed weight.**\n\n\n\n\n\n\n\n**Step 4: find sample 2 error.**\n\n\n\n\n\n\n\n**Step 5: find the new sample 2 gradient.**\n\n\n\n\n\n\n\n**Step 6: update after sample 2.**\n\n\n\n\n\n\n\n**Final answer:** batch weight = 1.25; sequential SGD weight = 1.46. SGD changes the weight between samples.\nLarger mini-batches use more memory and often make better use of parallel hardware. Smaller batches provide noisier gradient estimates and more updates per epoch. Wall-clock speed and generalization depend on the implementation and problem, so “SGD always converges fastest” is not a safe claim."},{"title":"Learning rate and common training problems","blocks":["<p class=\"definition\"><strong>Definition.</strong> The learning rate is a hyperparameter controlling the scale of a gradient-based update. It affects convergence speed and stability; it is not the gradient and is not the magnitude of the loss.</p>","<h3>Explanation and working</h3>","<p>A very small rate can make progress slow. A very large rate can overshoot, oscillate or diverge. A suitable rate permits progress without uncontrolled jumps. Feature scaling can reduce long zig-zag paths. A noisy curve alone is not proof of failure; individual mini-batch losses fluctuate.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative loss traces show why smoothness and progress are different\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative loss traces show why smoothness and progress are different\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative loss traces show why smoothness and progress are different <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Observation</th><th>Possible reason</th><th>Sensible first action</th></tr></thead><tbody><tr><td>Loss barely changes</td><td>Very small rate, saturated/dead units, wrong implementation</td><td>Check gradients and data; then tune rate or activation</td></tr><tr><td>Loss jumps wildly</td><td>Rate too high or exploding gradients</td><td>Reduce rate; inspect gradient size; clip if appropriate</td></tr><tr><td>Noisy but decreasing loss</td><td>Small-batch sampling noise</td><td>Compare a smoothed trend; consider larger batches or momentum</td></tr><tr><td>Training improves but validation worsens</td><td>Overfitting</td><td>Use regularization, augmentation or early stopping</td></tr><tr><td>All identical hidden neurons learn alike</td><td>Symmetric initialization</td><td>Use suitable nonidentical initial weights</td></tr></tbody></table></div>","<p>Convergence means updates or the objective are settling under a criterion. A zero gradient can also occur at a saddle point or in a saturated region; it is not proof of a global optimum.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s7","search":"Learning rate and common training problems **Definition.** The learning rate is a hyperparameter controlling the scale of a gradient-based update. It affects convergence speed and stability; it is not the gradient and is not the magnitude of the loss.\n\n### Explanation and working\nA very small rate can make progress slow. A very large rate can overshoot, oscillate or diverge. A suitable rate permits progress without uncontrolled jumps. Feature scaling can reduce long zig-zag paths. A noisy curve alone is not proof of failure; individual mini-batch losses fluctuate.\n\n| Observation | Possible reason | Sensible first action |\n| Loss barely changes | Very small rate, saturated/dead units, wrong implementation | Check gradients and data; then tune rate or activation |\n| Loss jumps wildly | Rate too high or exploding gradients | Reduce rate; inspect gradient size; clip if appropriate |\n| Noisy but decreasing loss | Small-batch sampling noise | Compare a smoothed trend; consider larger batches or momentum |\n| Training improves but validation worsens | Overfitting | Use regularization, augmentation or early stopping |\n| All identical hidden neurons learn alike | Symmetric initialization | Use suitable nonidentical initial weights |\nConvergence means updates or the objective are settling under a criterion. A zero gradient can also occur at a saddle point or in a saturated region; it is not proof of a global optimum."},{"title":"A moving average remembers the recent past","blocks":["<p class=\"definition\"><strong>Definition.</strong> An exponentially weighted moving average (EWMA) is a recursively updated estimate in which older observations receive exponentially decreasing weights. Optimizers use it to summarize recent gradients or squared gradients.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:131.51px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278e38d8879b5e28.svg\"><img class=\"math display-math\" src=\"assets/equations/9d6a2ee32d9c0644.svg\" alt=\"m_t=\\beta m_{t-1}+(1-\\beta)g_t,\\qquad0\\le\\beta&lt;1\" width=\"415.82\" height=\"24.43\" style=\"width:415.82px;height:24.43px;aspect-ratio:415.82/24.43\" loading=\"lazy\"></picture></div>","<p>For m₀ = 0, expanding the recurrence gives:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3400900697b48b50.svg\" alt=\"m_t=(1-\\beta)\\sum_{k=1}^{t}\\beta^{t-k}g_k\" width=\"247.88\" height=\"72.28\" style=\"width:247.88px;height:72.28px;aspect-ratio:247.88/72.28\" loading=\"lazy\"></div>","<p>The most recent gradient has coefficient 1 − β; a gradient k steps older is discounted by an additional factor βᵏ. Larger β smooths more strongly but responds more slowly to a change in direction. The heuristic averaging horizon is approximately 1/(1 − β); it is not a hard cutoff in the stored history.</p>","<h3>Signed gradients versus squared gradients</h3>","<p>An average of g contains directional information: positive and negative contributions can cancel. An average of g² estimates the scale through an uncentered second moment and cannot become negative when initialized nonnegatively. Adam tracks both quantities. RMSProp tracks a squared-gradient average in its basic form.</p>","<p class=\"inline-question\"><strong>Question.</strong> Let β = 0.9, m₀ = 0 and gradients g₁ = 2, g₂ = −1. Find m₁ and m₂.</p>","<h3>Given</h3>","<p>β = 0.9; initial m₀ = 0.</p>","<p>Gradients in order: g₁ = 2, g₂ = −1.</p>","<h3>To find</h3>","<p>Find m₁ and m₂, preserving the sign of each gradient.</p>","<h3>Formula — which one and why</h3>","<p><strong>Exponential moving average.</strong> Keep the specified fraction of the old state and add the complementary fraction of the new gradient. This tracks signed direction, so negative gradients can reduce the state.</p>","<p>β (beta) = retained fraction; m = stored average; g = current gradient. m₀ is the initial state.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7999b979f742c872.svg\" alt=\"m_t=\\beta m_{t-1}+(1-\\beta)g_t\" width=\"252.64\" height=\"24.43\" style=\"width:252.64px;height:24.43px;aspect-ratio:252.64/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Beta purani memory rakhta hai; 1−beta naya gradient leta hai.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find the recent-gradient coefficient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1d3a9c6b5c275e6a.svg\" alt=\"1-0.9=0.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the old memory for step 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4351a4e3442a023e.svg\" alt=\"0.9(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: weight the first gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/687125898d5f60b7.svg\" alt=\"0.1(2)=0.2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add to obtain the first memory.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/624684fe1c8cf03d.svg\" alt=\"m_1=0+0.2=0.2\" width=\"201.83\" height=\"19.94\" style=\"width:201.83px;height:19.94px;aspect-ratio:201.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: retain the first memory for step 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/30b407cc303a0e19.svg\" alt=\"0.9(0.2)=0.18\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: weight the second gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/995079ed548eec78.svg\" alt=\"0.1(-1)=-0.1\" width=\"164.29\" height=\"24.43\" style=\"width:164.29px;height:24.43px;aspect-ratio:164.29/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: add to obtain the second memory.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0e62fb9876ad9dac.svg\" alt=\"m_2=0.18+(-0.1)=0.08\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> m₁ = 0.2; m₂ = 0.08.</p>","<p>The second average remains positive although the latest gradient is negative because the previous positive contribution still has weight. If the recurrence is applied to the squared gradients instead, the second state is 0.9(0.4) + 0.1(1) = 0.46. These states have different meanings and are not interchangeable.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s8","search":"A moving average remembers the recent past **Definition.** An exponentially weighted moving average (EWMA) is a recursively updated estimate in which older observations receive exponentially decreasing weights. Optimizers use it to summarize recent gradients or squared gradients.\n\nFor m₀ = 0, expanding the recurrence gives:\n\nThe most recent gradient has coefficient 1 − β; a gradient k steps older is discounted by an additional factor βᵏ. Larger β smooths more strongly but responds more slowly to a change in direction. The heuristic averaging horizon is approximately 1/(1 − β); it is not a hard cutoff in the stored history.\n\n### Signed gradients versus squared gradients\nAn average of g contains directional information: positive and negative contributions can cancel. An average of g² estimates the scale through an uncentered second moment and cannot become negative when initialized nonnegatively. Adam tracks both quantities. RMSProp tracks a squared-gradient average in its basic form.\n\n**Question.** Let β = 0.9, m₀ = 0 and gradients g₁ = 2, g₂ = −1. Find m₁ and m₂.\n\n\n\n### Given\n\nβ = 0.9; initial m₀ = 0.\n\nGradients in order: g₁ = 2, g₂ = −1.\n\n### To find\n\nFind m₁ and m₂, preserving the sign of each gradient.\n\n### Formula — which one and why\n\n**Exponential moving average.** Keep the specified fraction of the old state and add the complementary fraction of the new gradient. This tracks signed direction, so negative gradients can reduce the state.\n\nβ (beta) = retained fraction; m = stored average; g = current gradient. m₀ is the initial state.\n\n\n\n**Yaad rakhne ka cue:** Beta purani memory rakhta hai; 1−beta naya gradient leta hai.\n\n### Solution — step by step\n\n\n\n\n**Step 1: find the recent-gradient coefficient.**\n\n\n\n\n\n\n\n**Step 2: retain the old memory for step 1.**\n\n\n\n\n\n\n\n**Step 3: weight the first gradient.**\n\n\n\n\n\n\n\n**Step 4: add to obtain the first memory.**\n\n\n\n\n\n\n\n**Step 5: retain the first memory for step 2.**\n\n\n\n\n\n\n\n**Step 6: weight the second gradient.**\n\n\n\n\n\n\n\n**Step 7: add to obtain the second memory.**\n\n\n\n\n\n\n\n**Final answer:** m₁ = 0.2; m₂ = 0.08.\nThe second average remains positive although the latest gradient is negative because the previous positive contribution still has weight. If the recurrence is applied to the squared gradients instead, the second state is 0.9(0.4) + 0.1(1) = 0.46. These states have different meanings and are not interchangeable.\n"},{"title":"Momentum remembers movement","blocks":["<p class=\"definition\"><strong>Definition.</strong> Momentum is a gradient-based optimization method that combines the current gradient correction with a fraction of the previous parameter displacement. It can accumulate movement along persistent directions and damp some oscillations across alternating directions.</p>","<h3>Update equations and convention</h3>","<p>This course uses <strong>signed displacement velocity</strong> v. It already includes the learning rate, and the parameter update adds it to the old parameter:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c19372684b38c7e4.svg\" alt=\"g_t=J&#x27;(\\theta_{t-1})\" width=\"136.88\" height=\"25.88\" style=\"width:136.88px;height:25.88px;aspect-ratio:136.88/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p>θ is the parameter, η is the learning rate and β controls how much previous displacement is retained, normally with 0 ≤ β &lt; 1. A negative v moves θ in the negative direction. Every parameter has its own velocity; this optimizer state is distinct from the network&#x27;s trainable parameters.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_momentum.svg\" aria-label=\"Enlarge diagram: Combine the retained displacement with the current gradient correction, then apply the resulting velocity to the old parameter.\"><img src=\"assets/figures/v_momentum.svg\" alt=\"Combine the retained displacement with the current gradient correction, then apply the resulting velocity to the old parameter.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Combine the retained displacement with the current gradient correction, then apply the resulting velocity to the old parameter. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two iterations</h3>","<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1, β = 0.9. Find two iterations using signed displacement velocity.</p>","<h3>Given</h3>","<p>J(θ) = ½θ²; θ₀ = 1; v₀ = 0.</p>","<p>η = 0.1; β = 0.9; signed-displacement velocity.</p>","<h3>To find</h3>","<p>Find the gradient, velocity and actual parameter after each of two iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<p><strong>Derivative used:</strong> differentiating J gives J′(θ) = θ. The gradient must therefore be reevaluated at the current θ on each iteration.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1: gradient, velocity, parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9e80b135dd68a0a3.svg\" alt=\"g_1=J&#x27;(1)=1\" width=\"154.49\" height=\"25.88\" style=\"width:154.49px;height:25.88px;aspect-ratio:154.49/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2: use θ₁ and v₁.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14dc30bcccfa9d0f.svg\" alt=\"g_2=J&#x27;(0.9)=0.9\" width=\"192.52\" height=\"25.88\" style=\"width:192.52px;height:25.88px;aspect-ratio:192.52/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.38px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0143acec3cdc1b06.svg\"><img class=\"math display-math\" src=\"assets/equations/9d76f7ff1692b41e.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.9)=-0.18\" width=\"361.95\" height=\"24.43\" style=\"width:361.95px;height:24.43px;aspect-ratio:361.95/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<div class=\"table-scroll\"><table><thead><tr><th>Iteration</th><th>Parameter where gradient is evaluated</th><th>Gradient</th><th>New velocity</th><th>New parameter</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>1</td><td>−0.1</td><td>0.9</td></tr><tr><td>2</td><td>0.9</td><td>0.9</td><td>−0.18</td><td>0.72</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ = 0.72. At iteration 2, the retained displacement contributes −0.09 and the new gradient correction contributes another −0.09. Their sum explains the larger displacement despite the smaller current gradient.</p>","<h3>Properties and alternative notation</h3>","<p>Momentum can improve progress through long, poorly scaled valleys, but excessive learning rate or momentum can overshoot. It does not guarantee a global minimum for a general neural-network objective.</p>","<p>Some texts store a positive gradient accumulator u instead:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:169.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcab484ef321b3b2.svg\"><img class=\"math display-math\" src=\"assets/equations/0f57b8541207a6df.svg\" alt=\"u_t=\\beta u_{t-1}+g_t,\\qquad\\theta_t=\\theta_{t-1}-\\eta u_t\" width=\"380.87\" height=\"22.51\" style=\"width:380.87px;height:22.51px;aspect-ratio:380.87/22.51\" loading=\"lazy\"></picture></div>","<p>With constant η and consistent initialization, this corresponds to vₜ = −ηuₜ. A normalized moving average containing (1−β)gₜ is a different scaling convention. Use the exact recurrence stated in the question instead of combining pieces of different conventions.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s9","search":"Momentum remembers movement \n**Definition.** Momentum is a gradient-based optimization method that combines the current gradient correction with a fraction of the previous parameter displacement. It can accumulate movement along persistent directions and damp some oscillations across alternating directions.\n\n### Update equations and convention\nThis course uses **signed displacement velocity** v. It already includes the learning rate, and the parameter update adds it to the old parameter:\n\n\n\nθ is the parameter, η is the learning rate and β controls how much previous displacement is retained, normally with 0 ≤ β < 1. A negative v moves θ in the negative direction. Every parameter has its own velocity; this optimizer state is distinct from the network's trainable parameters.\n\n\n\n### Complete numerical: two iterations\n**Question.** J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1, β = 0.9. Find two iterations using signed displacement velocity.\n\n\n\n### Given\n\nJ(θ) = ½θ²; θ₀ = 1; v₀ = 0.\n\nη = 0.1; β = 0.9; signed-displacement velocity.\n\n### To find\n\nFind the gradient, velocity and actual parameter after each of two iterations.\n\n### Formula — which one and why\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n**Derivative used:** differentiating J gives J′(θ) = θ. The gradient must therefore be reevaluated at the current θ on each iteration.\n\n**Step 1: Iteration 1: gradient, velocity, parameter.**\n\n\n\n\n**Step 2: Iteration 2: use θ₁ and v₁.**\n\n\n\n\n| Iteration | Parameter where gradient is evaluated | Gradient | New velocity | New parameter |\n| 1 | 1 | 1 | −0.1 | 0.9 |\n| 2 | 0.9 | 0.9 | −0.18 | 0.72 |\n\n**Final answer:** θ₁ = 0.9 and θ₂ = 0.72. At iteration 2, the retained displacement contributes −0.09 and the new gradient correction contributes another −0.09. Their sum explains the larger displacement despite the smaller current gradient.\n\n### Properties and alternative notation\nMomentum can improve progress through long, poorly scaled valleys, but excessive learning rate or momentum can overshoot. It does not guarantee a global minimum for a general neural-network objective.\n\nSome texts store a positive gradient accumulator u instead:\n\nWith constant η and consistent initialization, this corresponds to vₜ = −ηuₜ. A normalized moving average containing (1−β)gₜ is a different scaling convention. Use the exact recurrence stated in the question instead of combining pieces of different conventions.\n\n"},{"title":"Nesterov looks before correcting","blocks":["<p class=\"definition\"><strong>Definition.</strong> Nesterov accelerated gradient is a momentum-based method that evaluates the gradient at a lookahead parameter, formed using the previous velocity, before calculating the new velocity and actual parameter update.</p>","<h3>What changes relative to momentum</h3>","<p>Ordinary momentum evaluates J′ at θₜ₋₁. Nesterov evaluates it after the anticipated displacement βvₜ₋₁. This changes the point where the objective&#x27;s slope is measured:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64563c533a276a7d.svg\" alt=\"\\theta_{\\mathrm{look},t}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"216.02\" height=\"24.25\" style=\"width:216.02px;height:24.25px;aspect-ratio:216.02/24.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ec7b790dfa7e622.svg\" alt=\"g_t=J&#x27;(\\theta_{\\mathrm{look},t})\" width=\"150.81\" height=\"26.78\" style=\"width:150.81px;height:26.78px;aspect-ratio:150.81/26.78\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p>The lookahead point is an auxiliary evaluation point, not the new actual parameter. In this signed-displacement convention, the new velocity is added to θₜ₋₁.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nesterov.svg\" aria-label=\"Enlarge diagram: Locate the lookahead point using the old velocity; measure the gradient there; use that gradient to calculate the actual update.\"><img src=\"assets/figures/v_nesterov.svg\" alt=\"Locate the lookahead point using the old velocity; measure the gradient there; use that gradient to calculate the actual update.\" width=\"1080\" height=\"530\" loading=\"lazy\"></button><figcaption>Locate the lookahead point using the old velocity; measure the gradient there; use that gradient to calculate the actual update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two iterations</h3>","<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1 and β = 0.9. Perform two Nesterov updates using signed displacement velocity.</p>","<h3>Given</h3>","<p>J(θ) = ½θ²; θ₀ = 1; v₀ = 0.</p>","<p>η = 0.1; β = 0.9; signed-displacement velocity.</p>","<h3>To find</h3>","<p>Find the gradient, velocity and actual parameter after each of two iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Nesterov lookahead.</strong> First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.</p>","<p>θ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d83df079bf260cc.svg\" alt=\"g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"138.39\" height=\"24.43\" style=\"width:138.39px;height:24.43px;aspect-ratio:138.39/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle look ahead; gradient wahan; update original position se.</p>","<h3>Solution — step by step</h3>","<p>The derivative is J′(θ) = θ. Therefore the gradient equals the lookahead value in this particular objective.</p>","<p><strong>Iteration 1 — step 1: locate the lookahead point.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0abe86d8e2a6e122.svg\" alt=\"\\theta_{\\mathrm{look},1}=1+0.9(0)=1\" width=\"240.06\" height=\"25.35\" style=\"width:240.06px;height:25.35px;aspect-ratio:240.06/25.35\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the gradient there.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9e80b135dd68a0a3.svg\" alt=\"g_1=J&#x27;(1)=1\" width=\"154.49\" height=\"25.88\" style=\"width:154.49px;height:25.88px;aspect-ratio:154.49/25.88\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the new velocity and actual parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p><strong>Iteration 2 — step 1: use the previous actual parameter and velocity.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.29px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/25448224eab650c3.svg\"><img class=\"math display-math\" src=\"assets/equations/ba38208dd4ceff26.svg\" alt=\"\\theta_{\\mathrm{look},2}=0.9+0.9(-0.1)=0.81\" width=\"328.32\" height=\"25.35\" style=\"width:328.32px;height:25.35px;aspect-ratio:328.32/25.35\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the gradient at 0.81, not at 0.9.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e8429bc60dff5c5c.svg\" alt=\"g_2=J&#x27;(0.81)=0.81\" width=\"216.95\" height=\"25.88\" style=\"width:216.95px;height:25.88px;aspect-ratio:216.95/25.88\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the new velocity.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35f06a75a728a22a.svg\"><img class=\"math display-math\" src=\"assets/equations/e92dee4c49c58b06.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.81)=-0.171\" width=\"386.38\" height=\"24.43\" style=\"width:386.38px;height:24.43px;aspect-ratio:386.38/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: update the old actual parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b7b6422b337bab9.svg\"><img class=\"math display-math\" src=\"assets/equations/2c96483424ef8929.svg\" alt=\"\\theta_2=0.9+(-0.171)=0.729\" width=\"297.73\" height=\"24.43\" style=\"width:297.73px;height:24.43px;aspect-ratio:297.73/24.43\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Iteration</th><th>Old actual θ</th><th>Lookahead θ</th><th>Gradient</th><th>New v</th><th>New actual θ</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>1</td><td>1</td><td>−0.1</td><td>0.9</td></tr><tr><td>2</td><td>0.9</td><td>0.81</td><td>0.81</td><td>−0.171</td><td>0.729</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ = 0.729. The first update matches ordinary momentum because v₀ = 0. At the second update, ordinary momentum would use gradient 0.9 and produce θ₂ = 0.72. Adding v₂ to 0.81 instead of 0.9 would count the old momentum contribution twice.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s10","search":"Nesterov looks before correcting \n**Definition.** Nesterov accelerated gradient is a momentum-based method that evaluates the gradient at a lookahead parameter, formed using the previous velocity, before calculating the new velocity and actual parameter update.\n\n### What changes relative to momentum\nOrdinary momentum evaluates J′ at θₜ₋₁. Nesterov evaluates it after the anticipated displacement βvₜ₋₁. This changes the point where the objective's slope is measured:\n\n\n\n\nThe lookahead point is an auxiliary evaluation point, not the new actual parameter. In this signed-displacement convention, the new velocity is added to θₜ₋₁.\n\n\n\n### Complete numerical: two iterations\n**Question.** J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1 and β = 0.9. Perform two Nesterov updates using signed displacement velocity.\n\n\n\n### Given\n\nJ(θ) = ½θ²; θ₀ = 1; v₀ = 0.\n\nη = 0.1; β = 0.9; signed-displacement velocity.\n\n### To find\n\nFind the gradient, velocity and actual parameter after each of two iterations.\n\n### Formula — which one and why\n\n**Nesterov lookahead.** First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.\n\nθ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle look ahead; gradient wahan; update original position se.\n\n### Solution — step by step\n\n\n\n\n\nThe derivative is J′(θ) = θ. Therefore the gradient equals the lookahead value in this particular objective.\n\n**Iteration 1 — step 1: locate the lookahead point.**\n\n**Step 2: evaluate the gradient there.**\n\n**Step 3: calculate the new velocity and actual parameter.**\n\n\n\n**Iteration 2 — step 1: use the previous actual parameter and velocity.**\n\n**Step 2: evaluate the gradient at 0.81, not at 0.9.**\n\n**Step 3: calculate the new velocity.**\n\n**Step 4: update the old actual parameter.**\n\n\n| Iteration | Old actual θ | Lookahead θ | Gradient | New v | New actual θ |\n| 1 | 1 | 1 | 1 | −0.1 | 0.9 |\n| 2 | 0.9 | 0.81 | 0.81 | −0.171 | 0.729 |\n\n**Final answer:** θ₁ = 0.9 and θ₂ = 0.729. The first update matches ordinary momentum because v₀ = 0. At the second update, ordinary momentum would use gradient 0.9 and produce θ₂ = 0.72. Adding v₂ to 0.81 instead of 0.9 would count the old momentum contribution twice.\n\n"},{"title":"Model answer: momentum and Nesterov","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain momentum and Nesterov accelerated gradient. How does the point at which the gradient is measured differ?</p>"],"answer":["<p>Momentum retains a fraction of the previous movement and combines it with the current gradient correction. Movement in a persistent direction can build up, while alternating directions can partially cancel. This can reduce zig-zagging and improve progress through poorly scaled regions.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nesterov.svg\" aria-label=\"Enlarge diagram: Nesterov changes where the gradient is measured: at the look-ahead point implied by momentum.\"><img src=\"assets/figures/v_nesterov.svg\" alt=\"Nesterov changes where the gradient is measured: at the look-ahead point implied by momentum.\" width=\"1080\" height=\"530\" loading=\"lazy\"></button><figcaption>Nesterov changes where the gradient is measured: at the look-ahead point implied by momentum. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Momentum formulas</h3>","<p>This answer uses signed displacement velocity v: a negative velocity moves the parameter left. η is learning rate and β is the fraction of previous velocity retained.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c19372684b38c7e4.svg\" alt=\"g_t=J&#x27;(\\theta_{t-1})\" width=\"136.88\" height=\"25.88\" style=\"width:136.88px;height:25.88px;aspect-ratio:136.88/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<h3>Nesterov&#x27;s change</h3>","<p>Nesterov first forms a lookahead position using the old momentum. It measures the gradient there, then computes a new velocity and updates the actual old parameter.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88dc28f2501b464e.svg\" alt=\"g_t=J&#x27;(\\theta_{\\mathrm{look}})\" width=\"139.77\" height=\"25.88\" style=\"width:139.77px;height:25.88px;aspect-ratio:139.77/25.88\" loading=\"lazy\"></div>","<p>The velocity and parameter update formulas remain as displayed above. Add the new velocity to θ at the previous iteration, not to the lookahead point.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Basis</th><th>Momentum</th><th>Nesterov</th></tr></thead><tbody><tr><td>Gradient evaluated at</td><td>Current parameter</td><td>Lookahead parameter</td></tr><tr><td>Information retained</td><td>Previous velocity</td><td>Previous velocity</td></tr><tr><td>Intuition</td><td>Continue useful movement</td><td>Inspect the slope where old momentum points</td></tr><tr><td>Initial zero velocity</td><td>No movement contribution yet</td><td>First lookahead equals current parameter</td></tr></tbody></table></div>","<p>Both require suitable learning rate and momentum settings. Neither guarantees the global minimum of a general neural-network objective. Different books use different definitions of stored velocity, so the definition and update must be used together consistently.</p>"],"kind":"theory","id":"mt2-c5-s11","search":"Model answer: momentum and Nesterov **Question.** Explain momentum and Nesterov accelerated gradient. How does the point at which the gradient is measured differ?\n\n**Model answer.**\nMomentum retains a fraction of the previous movement and combines it with the current gradient correction. Movement in a persistent direction can build up, while alternating directions can partially cancel. This can reduce zig-zagging and improve progress through poorly scaled regions.\n\n\n\n\n### Momentum formulas\nThis answer uses signed displacement velocity v: a negative velocity moves the parameter left. η is learning rate and β is the fraction of previous velocity retained.\n\n\n\n### Nesterov's change\nNesterov first forms a lookahead position using the old momentum. It measures the gradient there, then computes a new velocity and updates the actual old parameter.\n\n\nThe velocity and parameter update formulas remain as displayed above. Add the new velocity to θ at the previous iteration, not to the lookahead point.\n\n| Basis | Momentum | Nesterov |\n| Gradient evaluated at | Current parameter | Lookahead parameter |\n| Information retained | Previous velocity | Previous velocity |\n| Intuition | Continue useful movement | Inspect the slope where old momentum points |\n| Initial zero velocity | No movement contribution yet | First lookahead equals current parameter |\n\nBoth require suitable learning rate and momentum settings. Neither guarantees the global minimum of a general neural-network objective. Different books use different definitions of stored velocity, so the definition and update must be used together consistently.\n"},{"title":"AdaGrad adds every squared gradient","blocks":["<p class=\"definition\"><strong>Definition.</strong> AdaGrad is an adaptive first-order optimizer that scales each parameter&#x27;s update using the inverse square root of the sum of its previous and current squared gradients. Each parameter maintains its own accumulator.</p>","<h3>State, effective learning rate and update</h3>","<p>For one parameter θ, let gₜ be its current gradient and s₀ = 0:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/32f05266b341eaa2.svg\" alt=\"s_t=s_{t-1}+g_t^2\" width=\"146.31\" height=\"27.82\" style=\"width:146.31px;height:27.82px;aspect-ratio:146.31/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5cf38c4d809aeefb.svg\" alt=\"\\eta_{\\mathrm{effective},t}=\\frac{\\eta}{\\sqrt{s_t}+\\varepsilon}\" width=\"212.27\" height=\"52.24\" style=\"width:212.27px;height:52.24px;aspect-ratio:212.27/52.24\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52438222ad8d94df.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta_{\\mathrm{effective},t}g_t\" width=\"231.02\" height=\"24.25\" style=\"width:231.02px;height:24.25px;aspect-ratio:231.02/24.25\" loading=\"lazy\"></div>","<p>s stores squared-gradient history. Both positive and negative gradients increase this nonnegative sum after squaring. The effective learning rate is the coefficient multiplying the signed gradient; the actual displacement also depends on that gradient&#x27;s magnitude and sign.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad.svg\" aria-label=\"Enlarge diagram: The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients.\"><img src=\"assets/figures/v_adagrad.svg\" alt=\"The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: supplied gradients</h3>","<p class=\"inline-question\"><strong>Question.</strong> Start θ₀ = 1, s₀ = 0, η = 0.1. Given gradients g₁ = 2 and g₂ = 1, perform two AdaGrad updates. Ignore epsilon only for this hand calculation because neither denominator is zero.</p>","<h3>Given</h3>","<p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p>","<p>Supplied gradients g₁ = 2, g₂ = 1.</p>","<p>ε = 0 for this hand calculation.</p>","<h3>To find</h3>","<p>Calculate all required states and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p>","<p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p>","<h3>Solution — step by step</h3>","<p>The gradients are supplied by the question. They are not computed from an assumed objective, and g₂ is not replaced by the updated parameter.</p>","<p><strong>Iteration 1 — step 1: update the accumulator.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18b84cdbfe918936.svg\" alt=\"s_1=0+2^2=4\" width=\"164.48\" height=\"25.26\" style=\"width:164.48px;height:25.26px;aspect-ratio:164.48/25.26\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the effective learning rate.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8acc57815fd4951a.svg\" alt=\"\\eta_{\\mathrm{effective},1}=\\frac{0.1}{\\sqrt4}=0.05\" width=\"241.94\" height=\"57.72\" style=\"width:241.94px;height:57.72px;aspect-ratio:241.94/57.72\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the signed gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8aa23a9e3a9c5875.svg\" alt=\"\\theta_1=1-0.05(2)=0.9\" width=\"235.28\" height=\"24.43\" style=\"width:235.28px;height:24.43px;aspect-ratio:235.28/24.43\" loading=\"lazy\"></div>","<p><strong>Iteration 2 — step 1: retain s₁ and add the new squared gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1e29c54438050499.svg\" alt=\"s_2=4+1^2=5\" width=\"164.48\" height=\"25.26\" style=\"width:164.48px;height:25.26px;aspect-ratio:164.48/25.26\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the new coefficient.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:165.92px;--narrow-height:96.81px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d33a28de17065dc.svg\"><img class=\"math display-math\" src=\"assets/equations/3d6533ca9b2ac114.svg\" alt=\"\\eta_{\\mathrm{effective},2}=\\frac{0.1}{\\sqrt5}\\approx0.044721360\" width=\"327.47\" height=\"57.72\" style=\"width:327.47px;height:57.72px;aspect-ratio:327.47/57.72\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update from θ₁.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.01px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81f6101b82b353cb.svg\"><img class=\"math display-math\" src=\"assets/equations/f835d09c27f0313a.svg\" alt=\"\\theta_2=0.9-\\frac{0.1(1)}{\\sqrt5}\\approx0.855278640\" width=\"350.57\" height=\"60.60\" style=\"width:350.57px;height:60.60px;aspect-ratio:350.57/60.60\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ ≈ 0.855279, with accumulators s₁ = 4 and s₂ = 5.</p>","<h3>Advantage, limitation and epsilon convention</h3>","<p>Coordinate-specific scaling can be useful when some features or gradients occur infrequently. Because s never decreases, its effective learning rate is nonincreasing when η and ε are fixed, and can become too small during prolonged training. The actual displacement magnitude need not decrease monotonically because gₜ also changes.</p>","<p>ε is normally a small positive stabilizer. These notes place it outside the square root. If a question places it inside, use that specified denominator consistently; the two placements are not numerically identical.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s12","search":"AdaGrad adds every squared gradient \n**Definition.** AdaGrad is an adaptive first-order optimizer that scales each parameter's update using the inverse square root of the sum of its previous and current squared gradients. Each parameter maintains its own accumulator.\n\n### State, effective learning rate and update\nFor one parameter θ, let gₜ be its current gradient and s₀ = 0:\n\n\n\ns stores squared-gradient history. Both positive and negative gradients increase this nonnegative sum after squaring. The effective learning rate is the coefficient multiplying the signed gradient; the actual displacement also depends on that gradient's magnitude and sign.\n\n\n\n### Complete numerical: supplied gradients\n**Question.** Start θ₀ = 1, s₀ = 0, η = 0.1. Given gradients g₁ = 2 and g₂ = 1, perform two AdaGrad updates. Ignore epsilon only for this hand calculation because neither denominator is zero.\n\n\n\n### Given\n\nθ₀ = 1; initial state(s) = 0; η = 0.1.\n\nSupplied gradients g₁ = 2, g₂ = 1.\n\nε = 0 for this hand calculation.\n\n### To find\n\nCalculate all required states and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**AdaGrad.** Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.\n\nG = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.\n\n\n\n\n\n**Yaad rakhne ka cue:** Square karo, purane sum mein jodo, root se scale karo.\n\n### Solution — step by step\n\n\n\n\n\nThe gradients are supplied by the question. They are not computed from an assumed objective, and g₂ is not replaced by the updated parameter.\n\n**Iteration 1 — step 1: update the accumulator.**\n\n**Step 2: calculate the effective learning rate.**\n\n**Step 3: apply the signed gradient.**\n\n\n**Iteration 2 — step 1: retain s₁ and add the new squared gradient.**\n\n**Step 2: calculate the new coefficient.**\n\n**Step 3: update from θ₁.**\n\n\n**Final answer:** θ₁ = 0.9 and θ₂ ≈ 0.855279, with accumulators s₁ = 4 and s₂ = 5.\n\n### Advantage, limitation and epsilon convention\nCoordinate-specific scaling can be useful when some features or gradients occur infrequently. Because s never decreases, its effective learning rate is nonincreasing when η and ε are fixed, and can become too small during prolonged training. The actual displacement magnitude need not decrease monotonically because gₜ also changes.\n\nε is normally a small positive stabilizer. These notes place it outside the square root. If a question places it inside, use that specified denominator consistently; the two placements are not numerically identical.\n\n"},{"title":"RMSProp remembers recent squared gradients","blocks":["<p class=\"definition\"><strong>Definition.</strong> RMSProp is an adaptive optimizer that normalizes the current gradient by the root of an exponentially weighted moving average of squared gradients. Its decaying history addresses AdaGrad&#x27;s permanently growing accumulator.</p>","<h3>Recurrence and interpretation</h3>","<p>Using decay β and zero initial state:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b2de5dc1fbe8c99.svg\" alt=\"s_t=\\beta s_{t-1}+(1-\\beta)g_t^2\" width=\"235.06\" height=\"27.82\" style=\"width:235.06px;height:27.82px;aspect-ratio:235.06/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>β is the fraction of the previous squared-gradient average retained, not a signed velocity. Some papers use ρ for this same decay. The square is applied to the gradient before averaging; the square root is applied to the resulting average in the update.</p>","<p>If recent squared gradients are smaller than the old average, s can decrease. Thus older large gradients do not remain in the denominator with their original weight forever.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rmsprop.svg\" aria-label=\"Enlarge diagram: Retain part of the old squared-gradient average and add the weighted square of the current gradient.\"><img src=\"assets/figures/v_rmsprop.svg\" alt=\"Retain part of the old squared-gradient average and add the weighted square of the current gradient.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Retain part of the old squared-gradient average and add the weighted square of the current gradient. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two iterations</h3>","<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, s₀ = 0, η = 0.1, β = 0.9; supplied gradients are 2 then 1. Perform two RMSProp updates, with ε = 0 for this hand calculation.</p>","<h3>Given</h3>","<p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p>","<p>Supplied gradients g₁ = 2, g₂ = 1.</p>","<p>ε = 0 for this hand calculation.</p>","<p>β = 0.9.</p>","<h3>To find</h3>","<p>Calculate all required states and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p>","<p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p>","<h3>Solution — step by step</h3>","<p><strong>Iteration 1 — step 1: calculate the squared-gradient average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea96f08ec1d03a73.svg\" alt=\"s_1=0.9(0)+0.1(2^2)=0.4\" width=\"283.96\" height=\"27.70\" style=\"width:283.96px;height:27.70px;aspect-ratio:283.96/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the denominator and signed correction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d388f002971175a6.svg\"><img class=\"math display-math\" src=\"assets/equations/73269d6fb6447a99.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.4}\\approx0.632455532\" width=\"289.17\" height=\"30.34\" style=\"width:289.17px;height:30.34px;aspect-ratio:289.17/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/91debda43e9c7015.svg\"><img class=\"math display-math\" src=\"assets/equations/918a6ff758f0307c.svg\" alt=\"\\frac{\\eta g_1}{\\sqrt{s_1}}=\\frac{0.1(2)}{\\sqrt{0.4}}\\approx0.316227766\" width=\"321.06\" height=\"60.60\" style=\"width:321.06px;height:60.60px;aspect-ratio:321.06/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update the parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.76px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46ce5315f0e4b144.svg\"><img class=\"math display-math\" src=\"assets/equations/67ba0f8d71ab9792.svg\" alt=\"\\theta_1=1-0.316227766\\approx0.683772234\" width=\"387.31\" height=\"20.89\" style=\"width:387.31px;height:20.89px;aspect-ratio:387.31/20.89\" loading=\"lazy\"></picture></div>","<p><strong>Iteration 2 — step 1: use s₁, not the original zero state.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a780b29bab6859eb.svg\"><img class=\"math display-math\" src=\"assets/equations/e9da8c8b2ad0696a.svg\" alt=\"s_2=0.9(0.4)+0.1(1^2)=0.46\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the denominator and signed correction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10263e4a8476b1fa.svg\"><img class=\"math display-math\" src=\"assets/equations/ae7e6b23e0aacbac.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.46}\\approx0.678232998\" width=\"301.38\" height=\"30.34\" style=\"width:301.38px;height:30.34px;aspect-ratio:301.38/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ce8864a56ffdc251.svg\"><img class=\"math display-math\" src=\"assets/equations/8d403055f469e062.svg\" alt=\"\\frac{\\eta g_2}{\\sqrt{s_2}}=\\frac{0.1(1)}{\\sqrt{0.46}}\\approx0.147441956\" width=\"322.89\" height=\"60.60\" style=\"width:322.89px;height:60.60px;aspect-ratio:322.89/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update from θ₁, retaining calculator precision.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.68px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd5064d2dd1b316c.svg\"><img class=\"math display-math\" src=\"assets/equations/7aa9a16e4306403f.svg\" alt=\"\\theta_2\\approx0.683772234-0.147441956\\approx0.536330278\" width=\"504.06\" height=\"20.89\" style=\"width:504.06px;height:20.89px;aspect-ratio:504.06/20.89\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> θ₁ ≈ 0.683772 and θ₂ ≈ 0.536330; s₁ = 0.4 and s₂ = 0.46.</p>","<h3>Comparison with AdaGrad and Adam</h3>","<p>AdaGrad stores an unweighted cumulative sum; RMSProp stores a decaying average. Basic RMSProp has no separate first-moment average and no Adam-style bias correction. With zero initialization, the early RMSProp state can therefore be much smaller than the first squared gradient, which explains the relatively large first correction in this example. The method still requires appropriate learning-rate and decay choices; adaptive scaling does not guarantee convergence to a global optimum.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s13","search":"RMSProp remembers recent squared gradients \n**Definition.** RMSProp is an adaptive optimizer that normalizes the current gradient by the root of an exponentially weighted moving average of squared gradients. Its decaying history addresses AdaGrad's permanently growing accumulator.\n\n### Recurrence and interpretation\nUsing decay β and zero initial state:\n\n\nβ is the fraction of the previous squared-gradient average retained, not a signed velocity. Some papers use ρ for this same decay. The square is applied to the gradient before averaging; the square root is applied to the resulting average in the update.\n\nIf recent squared gradients are smaller than the old average, s can decrease. Thus older large gradients do not remain in the denominator with their original weight forever.\n\n\n\n### Complete numerical: two iterations\n**Question.** θ₀ = 1, s₀ = 0, η = 0.1, β = 0.9; supplied gradients are 2 then 1. Perform two RMSProp updates, with ε = 0 for this hand calculation.\n\n\n\n### Given\n\nθ₀ = 1; initial state(s) = 0; η = 0.1.\n\nSupplied gradients g₁ = 2, g₂ = 1.\n\nε = 0 for this hand calculation.\n\nβ = 0.9.\n\n### To find\n\nCalculate all required states and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**RMSProp.** Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.\n\ns = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.\n\n\n\n\n\n**Yaad rakhne ka cue:** Saare purane squares nahi—unki fading average.\n\n### Solution — step by step\n\n\n\n\n\n**Iteration 1 — step 1: calculate the squared-gradient average.**\n\n**Step 2: calculate the denominator and signed correction.**\n\n\n**Step 3: update the parameter.**\n\n\n**Iteration 2 — step 1: use s₁, not the original zero state.**\n\n**Step 2: calculate the denominator and signed correction.**\n\n\n**Step 3: update from θ₁, retaining calculator precision.**\n\n\n**Final answer:** θ₁ ≈ 0.683772 and θ₂ ≈ 0.536330; s₁ = 0.4 and s₂ = 0.46.\n\n### Comparison with AdaGrad and Adam\nAdaGrad stores an unweighted cumulative sum; RMSProp stores a decaying average. Basic RMSProp has no separate first-moment average and no Adam-style bias correction. With zero initialization, the early RMSProp state can therefore be much smaller than the first squared gradient, which explains the relatively large first correction in this example. The method still requires appropriate learning-rate and decay choices; adaptive scaling does not guarantee convergence to a global optimum.\n\n"},{"title":"Adam remembers both direction and squared size","blocks":["<p class=\"definition\"><strong>Definition.</strong> Adam, or adaptive moment estimation, uses bias-corrected exponentially weighted estimates of the first moment and the uncentered second moment of gradients to calculate parameter-specific updates.</p>","<h3>What the two states represent</h3>","<div class=\"table-scroll\"><table><thead><tr><th>State or coefficient</th><th>Meaning</th></tr></thead><tbody><tr><td>mₜ</td><td>Moving average of signed gradients; retains directional information</td></tr><tr><td>sₜ</td><td>Moving average of squared gradients; estimates their uncentered second moment</td></tr><tr><td>β₁</td><td>Decay coefficient for the first-moment estimate</td></tr><tr><td>β₂</td><td>Decay coefficient for the second-moment estimate</td></tr><tr><td>t</td><td>Update number, starting at 1 for the first update</td></tr><tr><td>η and ε</td><td>Base learning rate and small denominator stabilizer</td></tr></tbody></table></div>","<p>The second moment is not the variance: it averages g² without subtracting a mean. Both states start at zero unless specified otherwise. These notes use s throughout this lesson; texts that use v for Adam&#x27;s second moment mean the same state, not momentum&#x27;s displacement velocity.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adam.svg\" aria-label=\"Enlarge diagram: The current gradient feeds two distinct estimates. Correct both estimates before combining direction and scale in the parameter update.\"><img src=\"assets/figures/v_adam.svg\" alt=\"The current gradient feeds two distinct estimates. Correct both estimates before combining direction and scale in the parameter update.\" width=\"1080\" height=\"710\" loading=\"lazy\"></button><figcaption>The current gradient feeds two distinct estimates. Correct both estimates before combining direction and scale in the parameter update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Recurrences, bias correction and update</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<p>Zero initialization reduces the total weight initially attached to observed gradients. Divide by the appropriate accumulated observation weight:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<p>The update uses the corrected signed average in the numerator and the root of the corrected squared-gradient average in the denominator:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ada7a51c96cfce92.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\varepsilon}\" width=\"220.64\" height=\"66.12\" style=\"width:220.64px;height:66.12px;aspect-ratio:220.64/66.12\" loading=\"lazy\"></div>","<p>The derivation in the next lesson explains why the correction factors contain powers of the iteration number. No additional multiplication by gₜ belongs in this final update: its contribution is already inside mₜ.</p>","<h3>Complete numerical: changing gradient magnitude</h3>","<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, m₀ = s₀ = 0, η = 0.1, β₁ = 0.9, β₂ = 0.999. Given g₁ = 2 and g₂ = 1, find two Adam updates, neglecting epsilon only in the numerical arithmetic.</p>","<h3>Given</h3>","<p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p>","<p>Supplied gradients g₁ = 2, g₂ = 1.</p>","<p>ε = 0 for this hand calculation.</p>","<p>β₁ = 0.9; β₂ = 0.999; use bias correction.</p>","<h3>To find</h3>","<p>Calculate all required states and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Adam with bias correction.</strong> Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.</p>","<p>m = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1b0801ea4c5e3b1.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\epsilon}\" width=\"219.18\" height=\"66.12\" style=\"width:219.18px;height:66.12px;aspect-ratio:219.18/66.12\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Direction memory + square memory; hats lagao, phir update.</p>","<h3>Solution — step by step</h3>","<p><strong>Iteration 1 — step 1: update the two raw states.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ac027abcdfcdb75.svg\" alt=\"m_1=0.9(0)+0.1(2)=0.2\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/664a8100f810d926.svg\"><img class=\"math display-math\" src=\"assets/equations/81bd015faf03cb0a.svg\" alt=\"s_1=0.999(0)+0.001(2^2)=0.004\" width=\"357.27\" height=\"27.70\" style=\"width:357.27px;height:27.70px;aspect-ratio:357.27/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: correct both states using t = 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/daa0ad010127bd94.svg\" alt=\"\\hat m_1=\\frac{0.2}{1-0.9^1}=\\frac{0.2}{0.1}=2\" width=\"278.80\" height=\"54.93\" style=\"width:278.80px;height:54.93px;aspect-ratio:278.80/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:173.88px;--narrow-height:120.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e60fd90ed8957afb.svg\"><img class=\"math display-math\" src=\"assets/equations/ffb98ca5eb20d577.svg\" alt=\"\\hat s_1=\\frac{0.004}{1-0.999^1}=\\frac{0.004}{0.001}=4\" width=\"317.68\" height=\"55.20\" style=\"width:317.68px;height:55.20px;aspect-ratio:317.68/55.20\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update the parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd2c0d46e60db2c0.svg\" alt=\"\\theta_1=1-\\frac{0.1(2)}{\\sqrt4}=0.9\" width=\"233.82\" height=\"60.60\" style=\"width:233.82px;height:60.60px;aspect-ratio:233.82/60.60\" loading=\"lazy\"></div>","<figure class=\"learning-visual lv-adam\" data-visual=\"adam\"><figcaption class=\"lv-title\">Adam iteration 1: follow the two state calculations</figcaption><p class=\"lv-instruction\">Start with the current gradient and the two states saved from the previous iteration.</p><div class=\"lv-input-states\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Current gradient</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">g1</span></div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Previous raw m</span><strong class=\"lv-value\">0</strong></div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Previous raw s</span><strong class=\"lv-value\">0</strong></div></div><div class=\"lv-adam-branches\"><div class=\"lv-adam-branch\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Signed average m1</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-input\"><span class=\"lv-label\">Bias-corrected m̂1</span><strong class=\"lv-value\">2</strong></div></div><div class=\"lv-adam-branch\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Squared-gradient average s1</span><strong class=\"lv-value\">0.004</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias-corrected ŝ1</span><strong class=\"lv-value\">4</strong></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Combine: ηm̂ / √ŝ</span><strong class=\"lv-value\">0.1</strong><span class=\"lv-detail\">ε is neglected for this specific numerical.</span></div></div><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old θ</span><strong class=\"lv-value\">1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New θ</span><strong class=\"lv-value\">0.9</strong></div></div><p class=\"lv-memory-line\"><b>Carry forward raw states:</b> m = 0.2, s = 0.004. The corrected values are used for this update.</p></figure>","<p><strong>Iteration 2 — step 1: carry forward the raw states m₁ and s₁.</strong></p>","<p>The recurrence uses the raw states 0.2 and 0.004, not the corrected values 2 and 4.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6a9a858d7c18aeb.svg\"><img class=\"math display-math\" src=\"assets/equations/4f47b7aabd4f81c4.svg\" alt=\"m_2=0.9(0.2)+0.1(1)=0.28\" width=\"314.52\" height=\"24.43\" style=\"width:314.52px;height:24.43px;aspect-ratio:314.52/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.32px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/528b23a17d8f719c.svg\"><img class=\"math display-math\" src=\"assets/equations/442e6bd08bfece88.svg\" alt=\"s_2=0.999(0.004)+0.001(1^2)=0.004996\" width=\"437.37\" height=\"27.70\" style=\"width:437.37px;height:27.70px;aspect-ratio:437.37/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: correct both states using t = 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.31px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0416e7f741fa3055.svg\"><img class=\"math display-math\" src=\"assets/equations/457ac955a89f3be2.svg\" alt=\"1-0.9^2=0.19,\\qquad1-0.999^2=0.001999\" width=\"453.06\" height=\"26.34\" style=\"width:453.06px;height:26.34px;aspect-ratio:453.06/26.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3d16280e17e8b649.svg\" alt=\"\\hat m_2=\\frac{0.28}{0.19}\\approx1.473684211\" width=\"280.45\" height=\"50.09\" style=\"width:280.45px;height:50.09px;aspect-ratio:280.45/50.09\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a22ef3b407f486c3.svg\"><img class=\"math display-math\" src=\"assets/equations/3d1151d9e31acb34.svg\" alt=\"\\hat s_2=\\frac{0.004996}{0.001999}\\approx2.499249625\" width=\"319.32\" height=\"50.36\" style=\"width:319.32px;height:50.36px;aspect-ratio:319.32/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: divide the corrected first moment by the corrected root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.53px;--narrow-height:180.47px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d8416409081efc8e.svg\"><img class=\"math display-math\" src=\"assets/equations/c636739e003f73e5.svg\" alt=\"\\frac{\\eta\\hat m_2}{\\sqrt{\\hat s_2}}\\approx\\frac{0.1(1.473684211)}{\\sqrt{2.499249625}}\\approx0.093217964\" width=\"441.89\" height=\"66.12\" style=\"width:441.89px;height:66.12px;aspect-ratio:441.89/66.12\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: update from θ₁.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c55d4ff26b9e4b3.svg\"><img class=\"math display-math\" src=\"assets/equations/60970554f64b5b60.svg\" alt=\"\\theta_2\\approx0.9-0.093217964\\approx0.806782036\" width=\"406.32\" height=\"20.89\" style=\"width:406.32px;height:20.89px;aspect-ratio:406.32/20.89\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-adam\" data-visual=\"adam\"><figcaption class=\"lv-title\">Adam iteration 2: follow the two state calculations</figcaption><p class=\"lv-instruction\">Start with the current gradient and the two states saved from the previous iteration.</p><div class=\"lv-input-states\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Current gradient</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">g2</span></div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Previous raw m</span><strong class=\"lv-value\">0.2</strong></div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Previous raw s</span><strong class=\"lv-value\">0.004</strong></div></div><div class=\"lv-adam-branches\"><div class=\"lv-adam-branch\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Signed average m2</span><strong class=\"lv-value\">0.28</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-input\"><span class=\"lv-label\">Bias-corrected m̂2</span><strong class=\"lv-value\">1.473684211</strong></div></div><div class=\"lv-adam-branch\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Squared-gradient average s2</span><strong class=\"lv-value\">0.004996</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias-corrected ŝ2</span><strong class=\"lv-value\">2.499249625</strong></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Combine: ηm̂ / √ŝ</span><strong class=\"lv-value\">0.093217964</strong><span class=\"lv-detail\">ε is neglected for this specific numerical.</span></div></div><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old θ</span><strong class=\"lv-value\">0.9</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New θ</span><strong class=\"lv-value\">0.806782036</strong></div></div><p class=\"lv-memory-line\"><b>Carry forward raw states:</b> m = 0.28, s = 0.004996. The corrected values are used for this update.</p></figure>","<div class=\"table-scroll\"><table><thead><tr><th>State</th><th>After iteration 1</th><th>After iteration 2</th></tr></thead><tbody><tr><td>Raw first moment m</td><td>0.2</td><td>0.28</td></tr><tr><td>Raw second moment s</td><td>0.004</td><td>0.004996</td></tr><tr><td>Corrected first moment</td><td>2</td><td>1.473684211</td></tr><tr><td>Corrected second moment</td><td>4</td><td>2.499249625</td></tr><tr><td>Parameter θ</td><td>0.9</td><td>0.806782036</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ ≈ 0.806782. Store the raw moments for the next recurrence and use the corrected moments for the current parameter update.</p>","<h3>Properties and limitations</h3>","<p>Adam combines directional averaging with coordinate-specific scaling, which can be useful with noisy or differently scaled gradients. It requires two state values per parameter in addition to the parameter itself. η, β₁, β₂ and ε remain hyperparameters. Faster reduction of training loss does not establish better generalization, and Adam does not guarantee the global optimum of a general neural-network objective.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s14","search":"Adam remembers both direction and squared size \n**Definition.** Adam, or adaptive moment estimation, uses bias-corrected exponentially weighted estimates of the first moment and the uncentered second moment of gradients to calculate parameter-specific updates.\n\n### What the two states represent\n| State or coefficient | Meaning |\n| mₜ | Moving average of signed gradients; retains directional information |\n| sₜ | Moving average of squared gradients; estimates their uncentered second moment |\n| β₁ | Decay coefficient for the first-moment estimate |\n| β₂ | Decay coefficient for the second-moment estimate |\n| t | Update number, starting at 1 for the first update |\n| η and ε | Base learning rate and small denominator stabilizer |\n\nThe second moment is not the variance: it averages g² without subtracting a mean. Both states start at zero unless specified otherwise. These notes use s throughout this lesson; texts that use v for Adam's second moment mean the same state, not momentum's displacement velocity.\n\n\n\n### Recurrences, bias correction and update\n\n\nZero initialization reduces the total weight initially attached to observed gradients. Divide by the appropriate accumulated observation weight:\n\n\nThe update uses the corrected signed average in the numerator and the root of the corrected squared-gradient average in the denominator:\n\nThe derivation in the next lesson explains why the correction factors contain powers of the iteration number. No additional multiplication by gₜ belongs in this final update: its contribution is already inside mₜ.\n\n### Complete numerical: changing gradient magnitude\n**Question.** θ₀ = 1, m₀ = s₀ = 0, η = 0.1, β₁ = 0.9, β₂ = 0.999. Given g₁ = 2 and g₂ = 1, find two Adam updates, neglecting epsilon only in the numerical arithmetic.\n\n\n\n### Given\n\nθ₀ = 1; initial state(s) = 0; η = 0.1.\n\nSupplied gradients g₁ = 2, g₂ = 1.\n\nε = 0 for this hand calculation.\n\nβ₁ = 0.9; β₂ = 0.999; use bias correction.\n\n### To find\n\nCalculate all required states and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Adam with bias correction.** Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.\n\nm = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Direction memory + square memory; hats lagao, phir update.\n\n### Solution — step by step\n\n\n\n\n\n**Iteration 1 — step 1: update the two raw states.**\n\n\n**Step 2: correct both states using t = 1.**\n\n\n**Step 3: update the parameter.**\n\n\n**Iteration 2 — step 1: carry forward the raw states m₁ and s₁.**\nThe recurrence uses the raw states 0.2 and 0.004, not the corrected values 2 and 4.\n\n\n**Step 2: correct both states using t = 2.**\n\n\n\n**Step 3: divide the corrected first moment by the corrected root.**\n\n**Step 4: update from θ₁.**\n\n\n| State | After iteration 1 | After iteration 2 |\n| Raw first moment m | 0.2 | 0.28 |\n| Raw second moment s | 0.004 | 0.004996 |\n| Corrected first moment | 2 | 1.473684211 |\n| Corrected second moment | 4 | 2.499249625 |\n| Parameter θ | 0.9 | 0.806782036 |\n\n**Final answer:** θ₁ = 0.9 and θ₂ ≈ 0.806782. Store the raw moments for the next recurrence and use the corrected moments for the current parameter update.\n\n### Properties and limitations\nAdam combines directional "},{"title":"Adam bias correction: why the denominator is one minus beta to a power","blocks":["<p class=\"definition\"><strong>Definition.</strong> Bias correction compensates for the reduced total observation weight caused by initializing an exponentially weighted accumulator to zero. Under a stationary gradient expectation, it removes the corresponding initialization bias in the moment estimate.</p>","<h3>Explanation and working</h3>","<h3>1. What the moving average actually contains</h3>","<p>Adam&#x27;s signed-gradient memory is m. Starting with m₀ = 0 and β = 0.9, the first average is 90% of zero plus 10% of the first gradient. If g₁ = 2, then m₁ = 0.2. That small value partly reflects the artificial zero initialization.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adam_correction.svg\" aria-label=\"Enlarge diagram: The first raw average is pulled toward its starting zero. Divide by the missing-weight correction factor.\"><img src=\"assets/figures/v_adam_correction.svg\" alt=\"The first raw average is pulled toward its starting zero. Divide by the missing-weight correction factor.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The first raw average is pulled toward its starting zero. Divide by the missing-weight correction factor. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/311f8a66ba1558a5.svg\" alt=\"m_1=(1-\\beta)g_1\" width=\"161.96\" height=\"24.43\" style=\"width:161.96px;height:24.43px;aspect-ratio:161.96/24.43\" loading=\"lazy\"></div>","<p>At the second step, substitute the first expression into the recurrence:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:175.78px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5bd41b82ae93376.svg\"><img class=\"math display-math\" src=\"assets/equations/8ca813db07725b2e.svg\" alt=\"m_2=\\beta(1-\\beta)g_1+(1-\\beta)g_2\" width=\"302.90\" height=\"24.43\" style=\"width:302.90px;height:24.43px;aspect-ratio:302.90/24.43\" loading=\"lazy\"></picture></div>","<h3>2. Add the coefficients</h3>","<p>After the first step, the total coefficient attached to observed gradients is 1 − β. After two steps it is β(1 − β) + (1 − β). Factor out the common term:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.24px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4c68b61c5bdf0798.svg\"><img class=\"math display-math\" src=\"assets/equations/420fad46aabea894.svg\" alt=\"\\beta(1-\\beta)+(1-\\beta)=(1-\\beta)(1+\\beta)=1-\\beta^2\" width=\"475.16\" height=\"27.70\" style=\"width:475.16px;height:27.70px;aspect-ratio:475.16/27.70\" loading=\"lazy\"></picture></div>","<p>After t steps the coefficients sum to 1 − βᵗ. Dividing the stored average by that quantity removes this zero-start coefficient deficit.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4c24c9160cc537a1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<p>The squared-gradient memory uses its own decay β₂ and the same reasoning:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3ebf23cb24a812d.svg\" alt=\"\\widehat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<h3>3. A constant-gradient example makes the purpose visible</h3>","<p>Let both gradients be 2 and use β₁ = 0.9. The first raw mean is 0.2; the second is 0.9 × 0.2 + 0.1 × 2 = 0.38.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/95360064605e4687.svg\" alt=\"\\widehat m_1=\\frac{0.2}{1-0.9}=2\" width=\"193.57\" height=\"51.56\" style=\"width:193.57px;height:51.56px;aspect-ratio:193.57/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.22px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/569c2f898bf0d2e3.svg\"><img class=\"math display-math\" src=\"assets/equations/8560767b69d9e851.svg\" alt=\"\\widehat m_2=\\frac{0.38}{1-0.9^2}=\\frac{0.38}{0.19}=2\" width=\"291.02\" height=\"54.93\" style=\"width:291.02px;height:54.93px;aspect-ratio:291.02/54.93\" loading=\"lazy\"></picture></div>","<p>Both corrected values now equal the constant observed gradient. If gradients differ over time, the corrected result is a weighted average, not necessarily the latest gradient.</p>","<h3>4. Two betas mean two separate powers</h3>","<p>At update 2 with β₁ = 0.9 and β₂ = 0.999, the first correction denominator is 1 − 0.9² = 0.19. The second is 1 − 0.999² = 0.001999. Do not use 0.19 for both memories, and do not keep using the first-step denominators.</p>","<h3>5. Correct first, then combine</h3>","<p>The parameter update uses the corrected signed mean divided by the square root of the corrected squared mean, plus ε in the stated position. The square root is taken after correcting s. The numerator is not the loss, and no extra multiplication by g follows.</p>","<p>This derivation explains the formula; the following solved Adam examples show the complete arithmetic when gradients change sign or magnitude.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s15","search":"Adam bias correction: why the denominator is one minus beta to a power **Definition.** Bias correction compensates for the reduced total observation weight caused by initializing an exponentially weighted accumulator to zero. Under a stationary gradient expectation, it removes the corresponding initialization bias in the moment estimate.\n\n### Explanation and working\n### 1. What the moving average actually contains\nAdam's signed-gradient memory is m. Starting with m₀ = 0 and β = 0.9, the first average is 90% of zero plus 10% of the first gradient. If g₁ = 2, then m₁ = 0.2. That small value partly reflects the artificial zero initialization.\n\n\n\n\nAt the second step, substitute the first expression into the recurrence:\n\n### 2. Add the coefficients\nAfter the first step, the total coefficient attached to observed gradients is 1 − β. After two steps it is β(1 − β) + (1 − β). Factor out the common term:\n\nAfter t steps the coefficients sum to 1 − βᵗ. Dividing the stored average by that quantity removes this zero-start coefficient deficit.\n\nThe squared-gradient memory uses its own decay β₂ and the same reasoning:\n\n\n### 3. A constant-gradient example makes the purpose visible\nLet both gradients be 2 and use β₁ = 0.9. The first raw mean is 0.2; the second is 0.9 × 0.2 + 0.1 × 2 = 0.38.\n\n\nBoth corrected values now equal the constant observed gradient. If gradients differ over time, the corrected result is a weighted average, not necessarily the latest gradient.\n\n### 4. Two betas mean two separate powers\nAt update 2 with β₁ = 0.9 and β₂ = 0.999, the first correction denominator is 1 − 0.9² = 0.19. The second is 1 − 0.999² = 0.001999. Do not use 0.19 for both memories, and do not keep using the first-step denominators.\n\n### 5. Correct first, then combine\nThe parameter update uses the corrected signed mean divided by the square root of the corrected squared mean, plus ε in the stated position. The square root is taken after correcting s. The numerator is not the loss, and no extra multiplication by g follows.\nThis derivation explains the formula; the following solved Adam examples show the complete arithmetic when gradients change sign or magnitude.\n"},{"title":"Model answer: AdaGrad, RMSProp and Adam","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare AdaGrad, RMSProp and Adam. Explain what each method stores and how that memory changes a parameter update.</p>"],"answer":["<p>AdaGrad, RMSProp and Adam are adaptive gradient-based optimizers. Each stores separate state for each trainable parameter and uses that state to scale its update. Let gₜ be the current gradient for parameter θ, η the base learning rate and ε a small positive stabilizer. The equations below put ε outside the square root.</p>","<h3>AdaGrad: cumulative squared-gradient history</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/32f05266b341eaa2.svg\" alt=\"s_t=s_{t-1}+g_t^2\" width=\"146.31\" height=\"27.82\" style=\"width:146.31px;height:27.82px;aspect-ratio:146.31/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Starting at s₀ = 0, every squared gradient contributes permanently. Parameters with frequent large gradients acquire smaller effective learning rates. This can be useful for sparse features, but the growing denominator can make later updates too small. The base learning rate still has to be chosen.</p>","<h3>RMSProp: a decaying squared-gradient average</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b2de5dc1fbe8c99.svg\" alt=\"s_t=\\beta s_{t-1}+(1-\\beta)g_t^2\" width=\"235.06\" height=\"27.82\" style=\"width:235.06px;height:27.82px;aspect-ratio:235.06/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Old contributions decay by repeated multiplication by β. The state can decrease when recent squared gradients are small, avoiding AdaGrad&#x27;s permanent accumulation. Basic RMSProp has one squared-gradient state and no separate signed-gradient average.</p>","<h3>Adam: first and second moments with bias correction</h3>","<p>Initialize m₀ = s₀ = 0 and count the first update as t = 1:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.17px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a84b9734c9141df3.svg\"><img class=\"math display-math\" src=\"assets/equations/eddaf3b9789092ac.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"329.01\" height=\"53.25\" style=\"width:329.01px;height:53.25px;aspect-ratio:329.01/53.25\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ada7a51c96cfce92.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\varepsilon}\" width=\"220.64\" height=\"66.12\" style=\"width:220.64px;height:66.12px;aspect-ratio:220.64/66.12\" loading=\"lazy\"></div>","<p>The first moment stores signed directional information; the second stores squared-gradient scale. Correction compensates for their zero initialization. The corrected first moment is already the numerator&#x27;s gradient estimate, so the update is not multiplied by gₜ again. Raw moments are carried into the next iteration.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Aspect</th><th>AdaGrad</th><th>RMSProp</th><th>Adam</th></tr></thead><tbody><tr><td>Squared-gradient history</td><td>Cumulative sum</td><td>Decaying average</td><td>Decaying average</td></tr><tr><td>Separate signed-gradient average</td><td>No</td><td>No in the basic method</td><td>Yes</td></tr><tr><td>Standard initialization correction</td><td>No</td><td>No in the basic method</td><td>Corrects both moments</td></tr><tr><td>State values per parameter</td><td>One</td><td>One</td><td>Two</td></tr><tr><td>Main concern</td><td>Effective rate can become very small</td><td>Learning rate and decay need tuning</td><td>More state; hyperparameters still matter</td></tr></tbody></table></div>","<p>All three adapt updates coordinate by coordinate. None removes the need for validation or guarantees a global minimum for a general neural-network objective.</p>"],"kind":"theory","id":"mt2-c5-s16","search":"Model answer: AdaGrad, RMSProp and Adam \n**Question.** Compare AdaGrad, RMSProp and Adam. Explain what each method stores and how that memory changes a parameter update.\n\n**Model answer.**\nAdaGrad, RMSProp and Adam are adaptive gradient-based optimizers. Each stores separate state for each trainable parameter and uses that state to scale its update. Let gₜ be the current gradient for parameter θ, η the base learning rate and ε a small positive stabilizer. The equations below put ε outside the square root.\n\n### AdaGrad: cumulative squared-gradient history\n\n\nStarting at s₀ = 0, every squared gradient contributes permanently. Parameters with frequent large gradients acquire smaller effective learning rates. This can be useful for sparse features, but the growing denominator can make later updates too small. The base learning rate still has to be chosen.\n\n### RMSProp: a decaying squared-gradient average\n\n\nOld contributions decay by repeated multiplication by β. The state can decrease when recent squared gradients are small, avoiding AdaGrad's permanent accumulation. Basic RMSProp has one squared-gradient state and no separate signed-gradient average.\n\n### Adam: first and second moments with bias correction\nInitialize m₀ = s₀ = 0 and count the first update as t = 1:\n\n\n\n\nThe first moment stores signed directional information; the second stores squared-gradient scale. Correction compensates for their zero initialization. The corrected first moment is already the numerator's gradient estimate, so the update is not multiplied by gₜ again. Raw moments are carried into the next iteration.\n\n| Aspect | AdaGrad | RMSProp | Adam |\n| Squared-gradient history | Cumulative sum | Decaying average | Decaying average |\n| Separate signed-gradient average | No | No in the basic method | Yes |\n| Standard initialization correction | No | No in the basic method | Corrects both moments |\n| State values per parameter | One | One | Two |\n| Main concern | Effective rate can become very small | Learning rate and decay need tuning | More state; hyperparameters still matter |\n\nAll three adapt updates coordinate by coordinate. None removes the need for validation or guarantees a global minimum for a general neural-network objective.\n\n"},{"title":"One comparison to rebuild all optimizer formulas","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>What is remembered</th><th>What changes the step</th></tr></thead><tbody><tr><td>GD or SGD</td><td>No optimizer memory in the basic rule</td><td>Current gradient × η</td></tr><tr><td>Momentum</td><td>Previous movement</td><td>Old velocity plus current correction</td></tr><tr><td>Nesterov</td><td>Previous movement</td><td>Gradient evaluated at lookahead</td></tr><tr><td>AdaGrad</td><td>Sum of all squared gradients</td><td>Divide current gradient by accumulated root</td></tr><tr><td>RMSProp</td><td>Moving average of squared gradients</td><td>Divide current gradient by recent root</td></tr><tr><td>Adam</td><td>Moving averages of gradients and squares</td><td>Divide corrected mean by corrected root</td></tr></tbody></table></div>","<p><strong>Working order.</strong> Start each method on a separate line with its states initialized. The solved examples use the same supplied gradients to show how their stored states differ. They do not have to give the same parameter value. The prescribed gradient sequence is practice data; if a question instead gives J(θ), recalculate its gradient at the appropriate current or lookahead parameter.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad_rms.svg\" aria-label=\"Enlarge diagram: Compare the memory rules first. Then use the matching memory in the denominator of the update.\"><img src=\"assets/figures/v_adagrad_rms.svg\" alt=\"Compare the memory rules first. Then use the matching memory in the denominator of the update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Compare the memory rules first. Then use the matching memory in the denominator of the update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s17","search":"One comparison to rebuild all optimizer formulas | Method | What is remembered | What changes the step |\n| GD or SGD | No optimizer memory in the basic rule | Current gradient × η |\n| Momentum | Previous movement | Old velocity plus current correction |\n| Nesterov | Previous movement | Gradient evaluated at lookahead |\n| AdaGrad | Sum of all squared gradients | Divide current gradient by accumulated root |\n| RMSProp | Moving average of squared gradients | Divide current gradient by recent root |\n| Adam | Moving averages of gradients and squares | Divide corrected mean by corrected root |\n**Working order.** Start each method on a separate line with its states initialized. The solved examples use the same supplied gradients to show how their stored states differ. They do not have to give the same parameter value. The prescribed gradient sequence is practice data; if a question instead gives J(θ), recalculate its gradient at the appropriate current or lookahead parameter.\n\n\n"},{"title":"AdaGrad and RMSProp with a negative gradient","blocks":["<p>The gradient has a sign, but its square is nonnegative. Both methods store squared gradients to control update size. The signed gradient is still used separately in the update numerator to preserve direction.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad_rms.svg\" aria-label=\"Enlarge diagram: The gradient sign remains in the numerator. Its square contributes a nonnegative value to the memory.\"><img src=\"assets/figures/v_adagrad_rms.svg\" alt=\"The gradient sign remains in the numerator. Its square contributes a nonnegative value to the memory.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The gradient sign remains in the numerator. Its square contributes a nonnegative value to the memory. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For an old stored state of 4 and a new gradient of −3, first square the gradient: (−3) × (−3) = 9.</p>","<p><strong>AdaGrad:</strong> add the new square to the entire old sum: 4 + 9 = 13.</p>","<p><strong>RMSProp with decay 0.9:</strong> keep 0.9 × 4 = 3.6 of the old state; add (1 − 0.9) × 9 = 0.1 × 9 = 0.9 of the new square. The new state is 3.6 + 0.9 = 4.5.</p>","<p>AdaGrad retains all earlier squares in a growing sum. RMSProp gradually discounts earlier squares. This difference explains why their effective step sizes change differently during training.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c5-s18","search":"AdaGrad and RMSProp with a negative gradient The gradient has a sign, but its square is nonnegative. Both methods store squared gradients to control update size. The signed gradient is still used separately in the update numerator to preserve direction.\n\n\n\nFor an old stored state of 4 and a new gradient of −3, first square the gradient: (−3) × (−3) = 9.\n**AdaGrad:** add the new square to the entire old sum: 4 + 9 = 13.\n**RMSProp with decay 0.9:** keep 0.9 × 4 = 3.6 of the old state; add (1 − 0.9) × 9 = 0.1 × 9 = 0.9 of the new square. The new state is 3.6 + 0.9 = 4.5.\nAdaGrad retains all earlier squares in a growing sum. RMSProp gradually discounts earlier squares. This difference explains why their effective step sizes change differently during training.\n"}]},{"n":6,"title":"Regularization and generalization","sections":[{"title":"Recognizing overfitting and underfitting","blocks":["<p class=\"definition\"><strong>Definitions.</strong> Generalization is a model&#x27;s ability to perform on unseen examples from the relevant task distribution. Underfitting occurs when the model fails to capture the task&#x27;s important relationships. Overfitting occurs when fitting the training data produces substantially poorer generalization, often by modeling noise or incidental details.</p>","<h3>Interpreting learning curves</h3>","<p>Underfitting commonly gives high training and validation errors. Overfitting commonly gives low training error with a substantially higher validation error, or validation loss that rises while training loss continues to fall. These patterns are diagnostic clues; distribution shift, leakage and an unrepresentative split can also affect the curves.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/overfitting.svg\" aria-label=\"Enlarge diagram: Compare training and validation behavior when selecting model capacity or a stopping point.\"><img src=\"assets/figures/overfitting.svg\" alt=\"Compare training and validation behavior when selecting model capacity or a stopping point.\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Compare training and validation behavior when selecting model capacity or a stopping point. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Observation</th><th>Plausible explanation</th><th>Appropriate response</th></tr></thead><tbody><tr><td>Both errors remain high</td><td>Insufficient capacity, weak features or inadequate optimization</td><td>Improve representation, train appropriately, reconsider architecture or reduce excessive regularization</td></tr><tr><td>Training error low; validation error high</td><td>Overfitting or a distribution/split problem</td><td>Inspect the split; use suitable regularization, more representative data or early stopping</td></tr><tr><td>Both losses fluctuate or diverge</td><td>Optimization instability</td><td>Examine learning rate, data scaling and gradient magnitude</td></tr></tbody></table></div>","<h3>Bias–variance perspective</h3>","<p>Insufficient model flexibility can create high approximation bias. A highly flexible model can be sensitive to the particular training sample, increasing variance. Regularization trades some training fit for constraints that can improve generalization. A more complex network is not automatically more accurate on unseen data.</p>","<p>The validation set is used to choose hyperparameters and checkpoints. The test set should remain outside these choices. Repeatedly selecting models from test results turns the test data into part of the selection process and weakens its role as an unbiased final evaluation.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c6-s0","search":"Recognizing overfitting and underfitting **Definitions.** Generalization is a model's ability to perform on unseen examples from the relevant task distribution. Underfitting occurs when the model fails to capture the task's important relationships. Overfitting occurs when fitting the training data produces substantially poorer generalization, often by modeling noise or incidental details.\n\n### Interpreting learning curves\nUnderfitting commonly gives high training and validation errors. Overfitting commonly gives low training error with a substantially higher validation error, or validation loss that rises while training loss continues to fall. These patterns are diagnostic clues; distribution shift, leakage and an unrepresentative split can also affect the curves.\n\n\n\n| Observation | Plausible explanation | Appropriate response |\n| Both errors remain high | Insufficient capacity, weak features or inadequate optimization | Improve representation, train appropriately, reconsider architecture or reduce excessive regularization |\n| Training error low; validation error high | Overfitting or a distribution/split problem | Inspect the split; use suitable regularization, more representative data or early stopping |\n| Both losses fluctuate or diverge | Optimization instability | Examine learning rate, data scaling and gradient magnitude |\n\n### Bias–variance perspective\nInsufficient model flexibility can create high approximation bias. A highly flexible model can be sensitive to the particular training sample, increasing variance. Regularization trades some training fit for constraints that can improve generalization. A more complex network is not automatically more accurate on unseen data.\n\nThe validation set is used to choose hyperparameters and checkpoints. The test set should remain outside these choices. Repeatedly selecting models from test results turns the test data into part of the selection process and weakens its role as an unbiased final evaluation.\n"},{"title":"L1 and L2 add a cost for large weights","blocks":["<p class=\"definition\"><strong>Definition.</strong> Regularization modifies a training objective or learning procedure to constrain the fitted model and improve generalization. L1 and L2 regularization add parameter-norm penalties to the data loss.</p>","<h3>Explanation and working</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:119.35px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/73a39a472fd87b8c.svg\"><img class=\"math display-math\" src=\"assets/equations/e5d7bc3aa72256c3.svg\" alt=\"J_{L1}=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|,\\qquad J_{L2}=J_{\\mathrm{data}}+\\lambda\\sum_iw_i^2\" width=\"537.60\" height=\"52.35\" style=\"width:537.60px;height:52.35px;aspect-ratio:537.60/52.35\" loading=\"lazy\"></picture></div>","<p>Lambda controls how strongly you discourage weight size. L1 encourages sparsity, meaning many weights can become exactly zero under suitable optimization. L2 shrinks weights smoothly and usually leaves small nonzero values. Larger lambda can reduce overfitting, but excessive regularization can underfit.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_penalties.svg\" aria-label=\"Enlarge diagram: The same two weights produce different costs because one rule uses absolute values and the other uses squares.\"><img src=\"assets/figures/v_penalties.svg\" alt=\"The same two weights produce different costs because one rule uses absolute values and the other uses squares.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The same two weights produce different costs because one rule uses absolute values and the other uses squares. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Data loss = 0.5; weights [2, −1]; λ = 0.1. Compute L1-regularized and L2-regularized objectives using the displayed convention.</p>","<h3>Given</h3>","<p>Data loss = 0.5; weights = [2,−1]; λ = 0.1.</p>","<p>The L2 convention here has no factor ½.</p>","<h3>To find</h3>","<p>Find L1/L2 penalties and the two regularized objective values.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>L2 penalty without a factor of one-half.</strong> This stated convention multiplies the sum of squares by λ, so differentiating contributes 2λw. Do not use the half-scaled gradient for this objective.</p>","<p>λ = penalty strength; J_data = original data loss; wᵢ = weight i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/008650efadbf4e29.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_iw_i^2\" width=\"212.95\" height=\"52.35\" style=\"width:212.95px;height:52.35px;aspect-ratio:212.95/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3465dcd568b96ffb.svg\" alt=\"\\frac{\\partial J}{\\partial w_i}=g_{\\mathrm{data},i}+2\\lambda w_i\" width=\"222.52\" height=\"54.60\" style=\"width:222.52px;height:54.60px;aspect-ratio:222.52/54.60\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half nahi diya toh L2 derivative mein 2 lambda × weight.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: take absolute values for L1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0f14566cc7516925.svg\" alt=\"|2|=2,\\qquad|-1|=1\" width=\"230.82\" height=\"24.41\" style=\"width:230.82px;height:24.41px;aspect-ratio:230.82/24.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the absolute values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23688a205b4ece73.svg\" alt=\"2+1=3\" width=\"99.10\" height=\"18.27\" style=\"width:99.10px;height:18.27px;aspect-ratio:99.10/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply by lambda.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/10346aae4a408d26.svg\" alt=\"0.1(3)=0.3\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the data loss.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8ed142793124641.svg\" alt=\"J_{L1}=0.5+0.3=0.8\" width=\"224.72\" height=\"20.36\" style=\"width:224.72px;height:20.36px;aspect-ratio:224.72/20.36\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: square both weights for L2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e11b2a71ed1c964f.svg\" alt=\"2^2=4,\\qquad(-1)^2=1\" width=\"233.13\" height=\"27.70\" style=\"width:233.13px;height:27.70px;aspect-ratio:233.13/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: add the squares.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c79fa7cad3c69e9.svg\" alt=\"4+1=5\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: multiply by lambda without adding a half.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3298085ce085f2d.svg\" alt=\"0.1(5)=0.5\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: add the data loss.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fde60160d7428d14.svg\" alt=\"J_{L2}=0.5+0.5=1.0\" width=\"224.72\" height=\"20.36\" style=\"width:224.72px;height:20.36px;aspect-ratio:224.72/20.36\" loading=\"lazy\"></div>","<p>For this L2 convention, the additional gradient is 2 λw. If the objective uses λ/2 times the squared sum, the additional gradient is λw instead. The factor is decided by the stated objective.</p>","<h3>L2 gradient update without a half factor</h3>","<p class=\"inline-question\"><strong>Question. A weight is 2, its data-loss gradient is 0.3, λ = 0.1 and η = 0.01. The objective adds λw². Perform one update.</strong></p>","<h3>Given</h3>","<p>w = 2; data gradient = 0.3; λ = 0.1; η = 0.01. The penalty has no factor ½.</p>","<h3>To find</h3>","<p>Penalty gradient, total gradient and updated weight.</p>","<h3>Formula — which one and why</h3>","<p>The derivative of λw² is 2λw. Add it to the data gradient before applying gradient descent.</p>","<p>λ is penalty strength; η is learning rate; g is the full objective gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e2245fb17ab44d83.svg\" alt=\"g_{\\mathrm{penalty}}=2\\lambda w\" width=\"146.39\" height=\"24.15\" style=\"width:146.39px;height:24.15px;aspect-ratio:146.39/24.15\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ed52defd9fef6cb.svg\" alt=\"g=g_{\\mathrm{data}}+g_{\\mathrm{penalty}}\" width=\"191.25\" height=\"21.44\" style=\"width:191.25px;height:21.44px;aspect-ratio:191.25/21.44\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Penalty ka gradient data gradient mein jodo, phir update.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the penalty gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b8811e22460d0c91.svg\" alt=\"2(0.1)(2)=0.4\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the data gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74fdb43956c5f462.svg\" alt=\"g=0.3+0.4=0.7\" width=\"200.37\" height=\"21.55\" style=\"width:200.37px;height:21.55px;aspect-ratio:200.37/21.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale by the learning rate.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9603f5d8320b5539.svg\" alt=\"\\eta g=0.01(0.7)=0.007\" width=\"238.31\" height=\"24.43\" style=\"width:238.31px;height:24.43px;aspect-ratio:238.31/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: subtract from the old weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28a66f5f8853795a.svg\" alt=\"w_{\\mathrm{new}}=2-0.007=1.993\" width=\"267.85\" height=\"20.37\" style=\"width:267.85px;height:20.37px;aspect-ratio:267.85/20.37\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Updated weight = 1.993. Bias penalties are omitted unless the objective includes them.</p>","<h3>Deriving the L2 update</h3>","<p>Under the objective written above, the data gradient and penalty gradient add:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/56481f4684193b6b.svg\" alt=\"\\nabla_w J=\\nabla_w J_{\\mathrm{data}}+2\\lambda w\" width=\"240.58\" height=\"20.81\" style=\"width:240.58px;height:20.81px;aspect-ratio:240.58/20.81\" loading=\"lazy\"></div>","<p>For ordinary gradient descent, regrouping the update gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:285.41px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/745f5ba3fa313836.svg\"><img class=\"math display-math\" src=\"assets/equations/e175e10221a61929.svg\" alt=\"w_{t+1}=w_t-\\eta(\\nabla_w J_{\\mathrm{data}}+2\\lambda w_t)=(1-2\\eta\\lambda)w_t-\\eta\\nabla_w J_{\\mathrm{data}}\" width=\"617.26\" height=\"24.43\" style=\"width:617.26px;height:24.43px;aspect-ratio:617.26/24.43\" loading=\"lazy\"></picture></div>","<p>This shows the shrinkage associated with this L2 convention. For an objective containing λ‖w‖²/2, replace 2λ by λ. This algebra explains the equivalence to appropriately scaled weight decay for ordinary gradient descent; adding an L2 term inside an adaptive optimizer is generally different from decoupled weight decay.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c6-s1","search":"L1 and L2 add a cost for large weights **Definition.** Regularization modifies a training objective or learning procedure to constrain the fitted model and improve generalization. L1 and L2 regularization add parameter-norm penalties to the data loss.\n\n### Explanation and working\n\nLambda controls how strongly you discourage weight size. L1 encourages sparsity, meaning many weights can become exactly zero under suitable optimization. L2 shrinks weights smoothly and usually leaves small nonzero values. Larger lambda can reduce overfitting, but excessive regularization can underfit.\n\n\n\n**Question.** Data loss = 0.5; weights [2, −1]; λ = 0.1. Compute L1-regularized and L2-regularized objectives using the displayed convention.\n\n\n\n### Given\n\nData loss = 0.5; weights = [2,−1]; λ = 0.1.\n\nThe L2 convention here has no factor ½.\n\n### To find\n\nFind L1/L2 penalties and the two regularized objective values.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**L2 penalty without a factor of one-half.** This stated convention multiplies the sum of squares by λ, so differentiating contributes 2λw. Do not use the half-scaled gradient for this objective.\n\nλ = penalty strength; J_data = original data loss; wᵢ = weight i.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half nahi diya toh L2 derivative mein 2 lambda × weight.\n\n### Solution — step by step\n\n\n\n\n**Step 1: take absolute values for L1.**\n\n\n\n\n\n\n\n**Step 2: add the absolute values.**\n\n\n\n\n\n\n\n**Step 3: multiply by lambda.**\n\n\n\n\n\n\n\n**Step 4: add the data loss.**\n\n\n\n\n\n\n\n\n**Step 5: square both weights for L2.**\n\n\n\n\n\n\n\n**Step 6: add the squares.**\n\n\n\n\n\n\n\n**Step 7: multiply by lambda without adding a half.**\n\n\n\n\n\n\n\n**Step 8: add the data loss.**\n\n\n\n\n\n\n\n\nFor this L2 convention, the additional gradient is 2 λw. If the objective uses λ/2 times the squared sum, the additional gradient is λw instead. The factor is decided by the stated objective.\n\n\n### L2 gradient update without a half factor\n\n**Question. A weight is 2, its data-loss gradient is 0.3, λ = 0.1 and η = 0.01. The objective adds λw². Perform one update.**\n\n\n\n### Given\n\nw = 2; data gradient = 0.3; λ = 0.1; η = 0.01. The penalty has no factor ½.\n\n### To find\n\nPenalty gradient, total gradient and updated weight.\n\n### Formula — which one and why\n\nThe derivative of λw² is 2λw. Add it to the data gradient before applying gradient descent.\n\nλ is penalty strength; η is learning rate; g is the full objective gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Penalty ka gradient data gradient mein jodo, phir update.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the penalty gradient.**\n\n\n\n\n\n\n\n**Step 2: add the data gradient.**\n\n\n\n\n\n\n\n**Step 3: scale by the learning rate.**\n\n\n\n\n\n\n\n**Step 4: subtract from the old weight.**\n\n\n\n\n\n\n\n**Final answer:** Updated weight = 1.993. Bias penalties are omitted unless the objective includes them.\n\n\n\n### Deriving the L2 update\nUnder the objective written above, the data gradient and penalty gradient add:\n\nFor ordinary gradient descent, regrouping the update gives:\n\nThis shows the shrinkage associated with this L2 convention. For an objective containing λ‖w‖²/2, replace 2λ by λ."},{"title":"Model answer: regularization and the L1–L2 difference","question":["<p class=\"inline-question\"><strong>Question.</strong> What is regularization? Compare L1 and L2 regularization, including the objective, gradient effect and influence of regularization strength.</p>"],"answer":["<p>Regularization restricts or discourages certain fitted solutions to improve generalization. Weight penalties add a cost for parameter size to the training objective. The optimizer must balance fitting the data against that extra cost.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_penalties.svg\" aria-label=\"Enlarge diagram: Follow the stated penalty convention, including lambda and any half factor, when you form the objective.\"><img src=\"assets/figures/v_penalties.svg\" alt=\"Follow the stated penalty convention, including lambda and any half factor, when you form the objective.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow the stated penalty convention, including lambda and any half factor, when you form the objective. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Objectives used in this course</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52bb091c05d16021.svg\" alt=\"J_{L1}=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"244.38\" height=\"52.35\" style=\"width:244.38px;height:52.35px;aspect-ratio:244.38/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9438fe7d9420663e.svg\" alt=\"J_{L2}=J_{\\mathrm{data}}+\\lambda\\sum_iw_i^2\" width=\"233.47\" height=\"52.35\" style=\"width:233.47px;height:52.35px;aspect-ratio:233.47/52.35\" loading=\"lazy\"></div>","<p>Jdata measures prediction error. λ controls the strength of the additional penalty. The sums are over the weights included by the stated question.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Basis</th><th>L1</th><th>L2</th></tr></thead><tbody><tr><td>Quantity penalized</td><td>Absolute weight magnitude</td><td>Squared weight magnitude</td></tr><tr><td>Penalty derivative at nonzero w</td><td>λ sign(w)</td><td>2λw under the displayed convention</td></tr><tr><td>Typical effect</td><td>Encourages sparse solutions</td><td>Smoothly shrinks weight magnitudes</td></tr><tr><td>Zero weights</td><td>Can promote exact zeros with suitable optimization</td><td>Usually leaves small nonzero weights</td></tr></tbody></table></div>","<p>The total gradient is the data-loss gradient plus the penalty gradient. With w = 2, data gradient 0.3 and λ = 0.1, the displayed L2 penalty adds 2 × 0.1 × 2 = 0.4. The total gradient is 0.7; update using that total.</p>","<p>Increasing λ strengthens the preference for smaller weights. Excessive regularization can prevent learning useful patterns and cause underfitting. L1 is not differentiable at zero, where a subgradient or suitable optimization method is used. If the examination writes λ/2 before the L2 sum, its penalty gradient becomes λw. Derive the factor from the printed objective.</p>"],"kind":"theory","id":"mt2-c6-s2","search":"Model answer: regularization and the L1–L2 difference **Question.** What is regularization? Compare L1 and L2 regularization, including the objective, gradient effect and influence of regularization strength.\n\n**Model answer.**\nRegularization restricts or discourages certain fitted solutions to improve generalization. Weight penalties add a cost for parameter size to the training objective. The optimizer must balance fitting the data against that extra cost.\n\n\n\n\n### Objectives used in this guide\n\n\nJdata measures prediction error. λ controls the strength of the additional penalty. The sums are over the weights included by the stated question.\n\n| Basis | L1 | L2 |\n| Quantity penalized | Absolute weight magnitude | Squared weight magnitude |\n| Penalty derivative at nonzero w | λ sign(w) | 2λw under the displayed convention |\n| Typical effect | Encourages sparse solutions | Smoothly shrinks weight magnitudes |\n| Zero weights | Can promote exact zeros with suitable optimization | Usually leaves small nonzero weights |\n\nThe total gradient is the data-loss gradient plus the penalty gradient. With w = 2, data gradient 0.3 and λ = 0.1, the displayed L2 penalty adds 2 × 0.1 × 2 = 0.4. The total gradient is 0.7; update using that total.\n\nIncreasing λ strengthens the preference for smaller weights. Excessive regularization can prevent learning useful patterns and cause underfitting. L1 is not differentiable at zero, where a subgradient or suitable optimization method is used. If the examination writes λ/2 before the L2 sum, its penalty gradient becomes λw. Derive the factor from the printed objective.\n"},{"title":"Dropout removes activations during training","blocks":["<p class=\"definition\"><strong>Definition.</strong> Dropout is a stochastic regularization method that randomly sets selected unit activations to zero during training. It discourages reliance on specific co-adapted activations; the inference behavior depends on the scaling convention used during training.</p>","<h3>Explanation and working</h3>","<p>Dropout randomly sets selected activations to zero during training. This discourages dependence on one particular set of neurons. A dropped activation is not a permanently deleted neuron, and dropout does not reduce the model’s stored parameter count.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dropout.svg\" aria-label=\"Enlarge diagram: Match each activation with its mask entry. Zero entries are removed; kept entries are divided by the keep probability.\"><img src=\"assets/figures/v_dropout.svg\" alt=\"Match each activation with its mask entry. Zero entries are removed; kept entries are divided by the keep probability.\" width=\"1080\" height=\"650\" loading=\"lazy\"></button><figcaption>Match each activation with its mask entry. Zero entries are removed; kept entries are divided by the keep probability. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Let drop probability be p and keep probability be q = 1 − p. A mask entry 1 means keep, 0 means drop. There are two internally consistent scaling conventions.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.63px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b6b21f6d03d2989f.svg\"><img class=\"math display-math\" src=\"assets/equations/cb674fd2e32b87a1.svg\" alt=\"a_{\\mathrm{train}}=m\\odot a\\quad\\text{and}\\quad a_{\\mathrm{test}}=q a\\quad\\text{in classical dropout}\" width=\"563.28\" height=\"21.70\" style=\"width:563.28px;height:21.70px;aspect-ratio:563.28/21.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.52px;--narrow-height:169.55px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7c8360afe0eaec6b.svg\"><img class=\"math display-math\" src=\"assets/equations/4b6a9d814bc5c7bb.svg\" alt=\"a_{\\mathrm{train}}=\\frac{m\\odot a}{q}\\quad\\text{and}\\quad a_{\\mathrm{test}}=a\\quad\\text{in inverted dropout}\" width=\"564.68\" height=\"52.26\" style=\"width:564.68px;height:52.26px;aspect-ratio:564.68/52.26\" loading=\"lazy\"></picture></div>","<p class=\"inline-question\"><strong>Question.</strong> Activations [0.8, −0.4, 0.6, 0.2] have dropout rate 50%. Choose mask [1,0,1,0] and compute outputs.</p>","<h3>Given</h3>","<p>Activations = [0.8,−0.4,0.6,0.2].</p>","<p>Dropout rate = 50%, so keep probability q = 0.5.</p>","<p>Chosen mask = [1,0,1,0].</p>","<h3>To find</h3>","<p>Find training outputs under inverted dropout.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1.</strong> q = 1 − 0.5 = 0.5. Apply mask elementwise: [1 × 0.8, 0 × (−0.4), 1 × 0.6, 0 × 0.2] = [0.8,0,0.6,0]. This is the unscaled training output, used by the supplied re-exam key.</p>","<p class=\"worked-step\"><strong>Step 2.</strong> For inverted dropout, divide the kept outputs by q: [0.8/0.5,0,0.6/0.5,0] = <strong>[1.6,0,1.2,0]</strong>. Inference then uses the full network without that extra scaling. State the convention in an answer.</p>","<p>Random dropout does not require exactly half the units to disappear in every small layer; each unit is kept or dropped according to the sampling rule. This mask is one possible outcome. If an exam explicitly specifies exactly two dropped units, follow that condition.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c6-s3","search":"Dropout removes activations during training **Definition.** Dropout is a stochastic regularization method that randomly sets selected unit activations to zero during training. It discourages reliance on specific co-adapted activations; the inference behavior depends on the scaling convention used during training.\n\n### Explanation and working\nDropout randomly sets selected activations to zero during training. This discourages dependence on one particular set of neurons. A dropped activation is not a permanently deleted neuron, and dropout does not reduce the model’s stored parameter count.\n\n\n\nLet drop probability be p and keep probability be q = 1 − p. A mask entry 1 means keep, 0 means drop. There are two internally consistent scaling conventions.\n\n\n**Question.** Activations [0.8, −0.4, 0.6, 0.2] have dropout rate 50%. Choose mask [1,0,1,0] and compute outputs.\n\n\n\n### Given\n\nActivations = [0.8,−0.4,0.6,0.2].\n\nDropout rate = 50%, so keep probability q = 0.5.\n\nChosen mask = [1,0,1,0].\n\n### To find\n\nFind training outputs under inverted dropout.\n\n### Formula — which one and why\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n### Solution — step by step\n\n\n\n\n**Step 1.** q = 1 − 0.5 = 0.5. Apply mask elementwise: [1 × 0.8, 0 × (−0.4), 1 × 0.6, 0 × 0.2] = [0.8,0,0.6,0]. This is the unscaled training output, used by the supplied re-exam key.\n**Step 2.** For inverted dropout, divide the kept outputs by q: [0.8/0.5,0,0.6/0.5,0] = **[1.6,0,1.2,0]**. Inference then uses the full network without that extra scaling. State the convention in an answer.\nRandom dropout does not require exactly half the units to disappear in every small layer; each unit is kept or dropped according to the sampling rule. This mask is one possible outcome. If an exam explicitly specifies exactly two dropped units, follow that condition."},{"title":"Early stopping uses the best validation point","blocks":["<p class=\"definition\"><strong>Definition.</strong> Early stopping is a regularization and model-selection procedure that terminates training when a monitored validation criterion no longer improves according to a specified rule, typically retaining the best checkpoint.</p>","<h3>Explanation and working</h3>","<p>Monitor validation loss after epochs. When it stops improving for a chosen patience interval, stop training and restore the best validation checkpoint. Training loss can fluctuate; it does not always decrease monotonically. Never select the stopping epoch by repeatedly consulting the test set.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_early_stop.svg\" aria-label=\"Enlarge diagram: Training loss keeps falling while validation loss starts rising. Keep the checkpoint from the validation minimum.\"><img src=\"assets/figures/v_early_stop.svg\" alt=\"Training loss keeps falling while validation loss starts rising. Keep the checkpoint from the validation minimum.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>Training loss keeps falling while validation loss starts rising. Keep the checkpoint from the validation minimum. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Validation losses after epochs 1–5 are [0.8,0.6,0.5,0.53,0.55]. Patience is 2 with no required minimum improvement. When do you stop and what do you restore?</p>","<h3>Given</h3>","<p>Validation losses at epochs 1–5 = [0.8,0.6,0.5,0.53,0.55].</p>","<p>Patience = 2; no required minimum improvement.</p>","<h3>To find</h3>","<p>Find the stop epoch and the best checkpoint to restore.</p>","<h3>Formula — which one and why</h3>","<p><strong>Early stopping rule.</strong> Compare each validation loss with the best one so far. A new best resets the waiting count; a non-improvement increases it. Stop when the count reaches patience and restore the best checkpoint.</p>","<p>Patience = allowed consecutive epochs without improvement. With minimum improvement zero, a strictly smaller validation loss counts as improvement.</p>","<p><strong>Yaad rakhne ka cue:</strong> Best validation save; patience khatam toh stop aur best restore.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: process epoch 1.</strong></p>","<p>Loss 0.8 establishes the first best checkpoint; wait = 0.</p>","<p class=\"worked-step\"><strong>Step 2: process epoch 2.</strong></p>","<p>0.6 &lt; 0.8: save epoch 2; wait = 0.</p>","<p class=\"worked-step\"><strong>Step 3: process epoch 3.</strong></p>","<p>0.5 &lt; 0.6: save epoch 3; wait = 0.</p>","<p class=\"worked-step\"><strong>Step 4: process epoch 4.</strong></p>","<p>0.53 &gt; 0.5: no improvement; wait = 1.</p>","<p class=\"worked-step\"><strong>Step 5: process epoch 5.</strong></p>","<p>0.55 &gt; 0.5: no improvement; wait = 2, equal to patience. Stop.</p>","<p class=\"worked-step\"><strong>Step 6: restore the best checkpoint.</strong></p>","<p>The smallest observed validation loss is 0.5 at epoch 3. Restore its weights.</p>","<p><strong>Final answer:</strong> stop after epoch 5; restore epoch 3. These are different epochs.</p>","<h3>Early stopping with [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]</h3>","<p class=\"inline-question\"><strong>Question. Validation losses are [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]. With patience 2 and strict improvement, identify the stopping epoch and checkpoint to restore.</strong></p>","<h3>Given</h3>","<p>Validation losses in epoch order = [0.8, 0.7, 0.72, 0.68, 0.69, 0.7].</p>","<p>Patience = 2; smaller loss is better; ties are not improvements.</p>","<h3>To find</h3>","<p>The stopping epoch and best checkpoint.</p>","<h3>Formula — which one and why</h3>","<p>Save an epoch when its validation loss is strictly lower than the best so far. Stop after the stated number of consecutive non-improving epochs.</p>","<p>Patience counts consecutive non-improvements. A new best resets the count.</p>","<p><strong>Yaad rakhne ka cue:</strong> Naya best mila toh save aur wait zero; patience khatam toh best restore.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: process epoch 1.</strong></p>","<p>Validation loss = 0.8; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 1, loss 0.8.</p>","<p class=\"worked-step\"><strong>Step 2: process epoch 2.</strong></p>","<p>Validation loss = 0.7; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 2, loss 0.7.</p>","<p class=\"worked-step\"><strong>Step 3: process epoch 3.</strong></p>","<p>Validation loss = 0.72; no strict improvement: wait count becomes 1. Best checkpoint is epoch 2, loss 0.7.</p>","<p class=\"worked-step\"><strong>Step 4: process epoch 4.</strong></p>","<p>Validation loss = 0.68; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 4, loss 0.68.</p>","<p class=\"worked-step\"><strong>Step 5: process epoch 5.</strong></p>","<p>Validation loss = 0.69; no strict improvement: wait count becomes 1. Best checkpoint is epoch 4, loss 0.68.</p>","<p class=\"worked-step\"><strong>Step 6: process epoch 6.</strong></p>","<p>Validation loss = 0.7; no strict improvement: wait count becomes 2. Best checkpoint is epoch 4, loss 0.68.</p>","<p><strong>Final answer:</strong> Stop after epoch 6; restore epoch 4, with validation loss 0.68.</p>","<h3>Early stopping with [0.6, 0.6, 0.61, 0.62]</h3>","<p class=\"inline-question\"><strong>Question. Validation losses are [0.6, 0.6, 0.61, 0.62]. With patience 2 and strict improvement, identify the stopping epoch and checkpoint to restore.</strong></p>","<h3>Given</h3>","<p>Validation losses in epoch order = [0.6, 0.6, 0.61, 0.62].</p>","<p>Patience = 2; smaller loss is better; ties are not improvements.</p>","<h3>To find</h3>","<p>The stopping epoch and best checkpoint.</p>","<h3>Formula — which one and why</h3>","<p>Save an epoch when its validation loss is strictly lower than the best so far. Stop after the stated number of consecutive non-improving epochs.</p>","<p>Patience counts consecutive non-improvements. A new best resets the count.</p>","<p><strong>Yaad rakhne ka cue:</strong> Naya best mila toh save aur wait zero; patience khatam toh best restore.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: process epoch 1.</strong></p>","<p>Validation loss = 0.6; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 1, loss 0.6.</p>","<p class=\"worked-step\"><strong>Step 2: process epoch 2.</strong></p>","<p>Validation loss = 0.6; no strict improvement: wait count becomes 1. Best checkpoint is epoch 1, loss 0.6.</p>","<p class=\"worked-step\"><strong>Step 3: process epoch 3.</strong></p>","<p>Validation loss = 0.61; no strict improvement: wait count becomes 2. Best checkpoint is epoch 1, loss 0.6.</p>","<p><strong>Final answer:</strong> Stop after epoch 3; restore epoch 1, with validation loss 0.6.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c6-s4","search":"Early stopping uses the best validation point **Definition.** Early stopping is a regularization and model-selection procedure that terminates training when a monitored validation criterion no longer improves according to a specified rule, typically retaining the best checkpoint.\n\n### Explanation and working\nMonitor validation loss after epochs. When it stops improving for a chosen patience interval, stop training and restore the best validation checkpoint. Training loss can fluctuate; it does not always decrease monotonically. Never select the stopping epoch by repeatedly consulting the test set.\n\n\n\n**Question.** Validation losses after epochs 1–5 are [0.8,0.6,0.5,0.53,0.55]. Patience is 2 with no required minimum improvement. When do you stop and what do you restore?\n\n\n\n### Given\n\nValidation losses at epochs 1–5 = [0.8,0.6,0.5,0.53,0.55].\n\nPatience = 2; no required minimum improvement.\n\n### To find\n\nFind the stop epoch and the best checkpoint to restore.\n\n### Formula — which one and why\n\n**Early stopping rule.** Compare each validation loss with the best one so far. A new best resets the waiting count; a non-improvement increases it. Stop when the count reaches patience and restore the best checkpoint.\n\nPatience = allowed consecutive epochs without improvement. With minimum improvement zero, a strictly smaller validation loss counts as improvement.\n\n**Yaad rakhne ka cue:** Best validation save; patience khatam toh stop aur best restore.\n\n### Solution — step by step\n\n\n\n\n**Step 1: process epoch 1.**\n\nLoss 0.8 establishes the first best checkpoint; wait = 0.\n\n**Step 2: process epoch 2.**\n\n0.6 < 0.8: save epoch 2; wait = 0.\n\n**Step 3: process epoch 3.**\n\n0.5 < 0.6: save epoch 3; wait = 0.\n\n**Step 4: process epoch 4.**\n\n0.53 > 0.5: no improvement; wait = 1.\n\n**Step 5: process epoch 5.**\n\n0.55 > 0.5: no improvement; wait = 2, equal to patience. Stop.\n\n**Step 6: restore the best checkpoint.**\n\nThe smallest observed validation loss is 0.5 at epoch 3. Restore its weights.\n\n**Final answer:** stop after epoch 5; restore epoch 3. These are different epochs.\n\n### Early stopping with [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]\n\n**Question. Validation losses are [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]. With patience 2 and strict improvement, identify the stopping epoch and checkpoint to restore.**\n\n\n\n### Given\n\nValidation losses in epoch order = [0.8, 0.7, 0.72, 0.68, 0.69, 0.7].\n\nPatience = 2; smaller loss is better; ties are not improvements.\n\n### To find\n\nThe stopping epoch and best checkpoint.\n\n### Formula — which one and why\n\nSave an epoch when its validation loss is strictly lower than the best so far. Stop after the stated number of consecutive non-improving epochs.\n\nPatience counts consecutive non-improvements. A new best resets the count.\n\n**Yaad rakhne ka cue:** Naya best mila toh save aur wait zero; patience khatam toh best restore.\n\n### Solution — step by step\n\n\n\n**Step 1: process epoch 1.**\n\nValidation loss = 0.8; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 1, loss 0.8.\n\n**Step 2: process epoch 2.**\n\nValidation loss = 0.7; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 2, loss 0.7.\n\n**Step 3: process epoch 3.**\n\nValidation loss = 0.72; no strict improvement: wait count becomes 1. Best checkpoint is epoch 2, loss 0.7.\n\n**Step 4: process epoch 4.**\n\nValidation loss = 0.68; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is ep"},{"title":"Model answer: generalization and early stopping","question":["<p class=\"inline-question\"><strong>Question.</strong> Distinguish underfitting and overfitting. Explain how validation data and early stopping help control overfitting.</p>"],"answer":["<p>Underfitting occurs when a model has not captured enough useful structure in the training data. Both training and validation errors are usually high relative to a sensible task baseline. Causes can include insufficient capacity, inadequate features, excessive regularization or incomplete optimization.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_early_stop.svg\" aria-label=\"Enlarge diagram: The best training score is not necessarily the best score on unseen validation examples.\"><img src=\"assets/figures/v_early_stop.svg\" alt=\"The best training score is not necessarily the best score on unseen validation examples.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>The best training score is not necessarily the best score on unseen validation examples. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Overfitting occurs when a model fits training-specific details or noise that do not generalize. Training error is low while validation error is substantially higher. A mismatch between training and validation data can produce a similar gap, so the split must also be examined.</p>","<h3>How early stopping works</h3>","<p>1. Train using the training set; do not learn parameters from the validation targets as training samples.</p>","<p>2. After an epoch or another chosen interval, evaluate validation loss.</p>","<p>3. Save the parameters whenever validation loss reaches a new best value.</p>","<p>4. Count consecutive intervals with no qualifying improvement.</p>","<p>5. When the count reaches the chosen patience, stop and restore the saved best parameters.</p>","<p>For validation losses 0.8, 0.6, 0.5, 0.53 and 0.55, epoch 3 is best. With patience 2, epochs 4 and 5 supply two non-improvements: stop after epoch 5 and restore epoch 3. The stopping epoch and the retained model epoch are different.</p>","<p>Other remedies for overfitting include appropriate L1/L2 penalties, dropout, augmentation and more representative training data. Underfitting may instead require a better model, adequate training or less regularization. Use the test set for final evaluation after those choices, not for repeatedly choosing the stopping point.</p>"],"kind":"theory","id":"mt2-c6-s5","search":"Model answer: generalization and early stopping **Question.** Distinguish underfitting and overfitting. Explain how validation data and early stopping help control overfitting.\n\n**Model answer.**\nUnderfitting occurs when a model has not captured enough useful structure in the training data. Both training and validation errors are usually high relative to a sensible task baseline. Causes can include insufficient capacity, inadequate features, excessive regularization or incomplete optimization.\n\n\n\n\nOverfitting occurs when a model fits training-specific details or noise that do not generalize. Training error is low while validation error is substantially higher. A mismatch between training and validation data can produce a similar gap, so the split must also be examined.\n\n### How early stopping works\n1. Train using the training set; do not learn parameters from the validation targets as training samples.\n2. After an epoch or another chosen interval, evaluate validation loss.\n3. Save the parameters whenever validation loss reaches a new best value.\n4. Count consecutive intervals with no qualifying improvement.\n5. When the count reaches the chosen patience, stop and restore the saved best parameters.\n\nFor validation losses 0.8, 0.6, 0.5, 0.53 and 0.55, epoch 3 is best. With patience 2, epochs 4 and 5 supply two non-improvements: stop after epoch 5 and restore epoch 3. The stopping epoch and the retained model epoch are different.\n\nOther remedies for overfitting include appropriate L1/L2 penalties, dropout, augmentation and more representative training data. Underfitting may instead require a better model, adequate training or less regularization. Use the test set for final evaluation after those choices, not for repeatedly choosing the stopping point.\n"},{"title":"Choosing a remedy","blocks":["<p>For overfitting: try L1/L2, dropout, suitable data augmentation, a smaller model, more representative training data and early stopping. For underfitting: improve features or architecture, train adequately, check optimization, or reduce excessive regularization. Evaluate changes on validation data.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_remedies.svg\" aria-label=\"Enlarge diagram: Read the training and validation pattern before selecting a remedy.\"><img src=\"assets/figures/v_remedies.svg\" alt=\"Read the training and validation pattern before selecting a remedy.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Read the training and validation pattern before selecting a remedy. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Data augmentation makes label-preserving variations of training examples, such as suitable crops or brightness changes in images. It must respect the task: flipping a digit or a medical image may change meaning. Augmentation happens within the training split; do not leak augmented copies into validation.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Change</th><th>Usual bias tendency</th><th>Usual variance tendency</th></tr></thead><tbody><tr><td>Stronger weight regularization</td><td>Increase</td><td>Decrease</td></tr><tr><td>More hidden units with other factors fixed</td><td>Decrease</td><td>Increase</td></tr><tr><td>Dropout</td><td>Increase</td><td>Decrease</td></tr><tr><td>More representative data from same distribution</td><td>Roughly unchanged model bias</td><td>Decrease</td></tr></tbody></table></div>","<p>These are classical tendencies for exam discussion, not exact laws for every deep-network training run. Distinguish model capacity from optimization failure.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c6-s6","search":"Choosing a remedy For overfitting: try L1/L2, dropout, suitable data augmentation, a smaller model, more representative training data and early stopping. For underfitting: improve features or architecture, train adequately, check optimization, or reduce excessive regularization. Evaluate changes on validation data.\n\n\n\nData augmentation makes label-preserving variations of training examples, such as suitable crops or brightness changes in images. It must respect the task: flipping a digit or a medical image may change meaning. Augmentation happens within the training split; do not leak augmented copies into validation.\n| Change | Usual bias tendency | Usual variance tendency |\n| Stronger weight regularization | Increase | Decrease |\n| More hidden units with other factors fixed | Decrease | Increase |\n| Dropout | Increase | Decrease |\n| More representative data from same distribution | Roughly unchanged model bias | Decrease |\nThese are classical tendencies for exam discussion, not exact laws for every deep-network training run. Distinguish model capacity from optimization failure.\n\n"},{"title":"Inverted dropout during training and inference","blocks":["<p class=\"definition\"><strong>Definition.</strong> Inverted dropout divides retained training activations by their keep probability so that their expectation equals the original activation. At inference, dropout is disabled and no compensating activation scaling is required.</p>","<h3>Explanation and working</h3>","<p>Inverted dropout first chooses which activations to keep, then divides each kept activation by the keep probability. This compensates for the missing activations in expectation. A dropped activation becomes zero.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dropout_expectation.svg\" aria-label=\"Enlarge diagram: Follow both possible training outcomes for activation 3. Their average remains 3; inference uses that ordinary activation.\"><img src=\"assets/figures/v_dropout_expectation.svg\" alt=\"Follow both possible training outcomes for activation 3. Their average remains 3; inference uses that ordinary activation.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow both possible training outcomes for activation 3. Their average remains 3; inference uses that ordinary activation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For activation 3 and keep probability q = 0.5, a kept value becomes 3 ÷ 0.5 = 6. A dropped value becomes 0. Since half the masks keep it, the average is 0.5 × 6 + 0.5 × 0 = 3, equal to the original activation.</p>","<p>At inference, dropout is disabled and the ordinary activation 3 is used. Under this inverted-dropout convention, no extra multiplication by q is required at inference.</p>","<h3>Expectation calculation</h3>","<p>For a fixed activation a and a Bernoulli keep mask m with P(m = 1) = q:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.90px;--narrow-height:122.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8a9a35419aebc53b.svg\"><img class=\"math display-math\" src=\"assets/equations/55c82e5345c55ebe.svg\" alt=\"\\mathbb E\\left[\\frac{ma}{q}\\right]=\\frac aq\\mathbb E[m]=\\frac aq\\,q=a\" width=\"316.00\" height=\"58.62\" style=\"width:316.00px;height:58.62px;aspect-ratio:316.00/58.62\" loading=\"lazy\"></picture></div>","<p>The equality concerns the activation&#x27;s expectation over masks. It does not say every sampled layer preserves its sum, nor does it generally make a nonlinear network&#x27;s complete stochastic prediction equal to its deterministic inference prediction.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c6-s7","search":"Inverted dropout during training and inference **Definition.** Inverted dropout divides retained training activations by their keep probability so that their expectation equals the original activation. At inference, dropout is disabled and no compensating activation scaling is required.\n\n### Explanation and working\nInverted dropout first chooses which activations to keep, then divides each kept activation by the keep probability. This compensates for the missing activations in expectation. A dropped activation becomes zero.\n\n\n\nFor activation 3 and keep probability q = 0.5, a kept value becomes 3 ÷ 0.5 = 6. A dropped value becomes 0. Since half the masks keep it, the average is 0.5 × 6 + 0.5 × 0 = 3, equal to the original activation.\nAt inference, dropout is disabled and the ordinary activation 3 is used. Under this inverted-dropout convention, no extra multiplication by q is required at inference.\n\n### Expectation calculation\nFor a fixed activation a and a Bernoulli keep mask m with P(m = 1) = q:\n\nThe equality concerns the activation's expectation over masks. It does not say every sampled layer preserves its sum, nor does it generally make a nonlinear network's complete stochastic prediction equal to its deterministic inference prediction.\n"},{"title":"Model answer: dropout with training and inference explained","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain dropout as a regularization technique. Distinguish its behavior during training and inference, and explain inverted-dropout scaling.</p>"],"answer":["<p>Dropout randomly replaces selected activations by zero during training. It discourages excessive reliance on particular units and their joint activity. The mask changes between training applications; it does not permanently remove neurons or stored weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dropout_expectation.svg\" aria-label=\"Enlarge diagram: The mask temporarily keeps or drops this activation during training. Inference uses the ordinary value without the random mask.\"><img src=\"assets/figures/v_dropout_expectation.svg\" alt=\"The mask temporarily keeps or drops this activation during training. Inference uses the ordinary value without the random mask.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The mask temporarily keeps or drops this activation during training. Inference uses the ordinary value without the random mask. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Let p be the probability of dropping an activation and q = 1 − p the probability of keeping it. A mask value m = 1 means keep; m = 0 means drop.</p>","<h3>Inverted dropout during training</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fda2e84f024891bd.svg\" alt=\"a&#x27;=\\frac{ma}{q}\" width=\"97.42\" height=\"48.82\" style=\"width:97.42px;height:48.82px;aspect-ratio:97.42/48.82\" loading=\"lazy\"></div>","<p>A kept activation is divided by q and a dropped activation becomes zero. This preserves the activation&#x27;s expectation over masks.</p>","<p>For a = 3 and q = 0.5, the kept result is 3/0.5 = 6 and the dropped result is 0. Their probability-weighted average is:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83765955bdb2c901.svg\" alt=\"0.5(6)+0.5(0)=3\" width=\"199.58\" height=\"24.43\" style=\"width:199.58px;height:24.43px;aspect-ratio:199.58/24.43\" loading=\"lazy\"></div>","<h3>Inference</h3>","<p>Disable dropout and use the ordinary activation. Under inverted dropout there is no further division or multiplication by q at inference. Under the alternative classical convention, training does not rescale kept activations and inference includes the compensating scaling; do not combine the two conventions.</p>","<p>Dropout has no trainable mask parameters. A dropped path contributes zero current data gradient through that activation, although a separately specified weight penalty can still contribute a parameter gradient. Excessive dropout can make optimization or fitting difficult. Choose its rate using validation data.</p>"],"kind":"theory","id":"mt2-c6-s8","search":"Model answer: dropout with training and inference explained **Question.** Explain dropout as a regularization technique. Distinguish its behavior during training and inference, and explain inverted-dropout scaling.\n\n**Model answer.**\nDropout randomly replaces selected activations by zero during training. It discourages excessive reliance on particular units and their joint activity. The mask changes between training applications; it does not permanently remove neurons or stored weights.\n\n\n\n\nLet p be the probability of dropping an activation and q = 1 − p the probability of keeping it. A mask value m = 1 means keep; m = 0 means drop.\n\n### Inverted dropout during training\n\nA kept activation is divided by q and a dropped activation becomes zero. This preserves the activation's expectation over masks.\n\nFor a = 3 and q = 0.5, the kept result is 3/0.5 = 6 and the dropped result is 0. Their probability-weighted average is:\n\n### Inference\nDisable dropout and use the ordinary activation. Under inverted dropout there is no further division or multiplication by q at inference. Under the alternative classical convention, training does not rescale kept activations and inference includes the compensating scaling; do not combine the two conventions.\n\nDropout has no trainable mask parameters. A dropped path contributes zero current data gradient through that activation, although a separately specified weight penalty can still contribute a parameter gradient. Excessive dropout can make optimization or fitting difficult. Choose its rate using validation data.\n"}]},{"n":7,"title":"Convolutional neural networks","sections":[{"title":"Reading image shapes before doing CNN arithmetic","blocks":["<p class=\"definition\"><strong>Definition.</strong> An image or intermediate CNN representation is a tensor indexed by spatial position and channel. This course writes its shape as height × width × channels, excluding the batch dimension.</p>","<h3>Explanation and working</h3>","<h3>Height, width and channels</h3>","<p>The shape 4 × 5 × 3 means 4 rows, 5 columns and 3 channels. It contains 4 × 5 × 3 = 60 numbers. A grayscale image commonly has one intensity channel; an RGB image has red, green and blue channels. Intermediate CNN channels are learned feature maps, not necessarily colors.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_image_shape.svg\" aria-label=\"Enlarge diagram: Count height, width and channels separately. Three channels are stacked at the same spatial positions.\"><img src=\"assets/figures/v_image_shape.svg\" alt=\"Count height, width and channels separately. Three channels are stacked at the same spatial positions.\" width=\"1080\" height=\"585\" loading=\"lazy\"></button><figcaption>Count height, width and channels separately. Three channels are stacked at the same spatial positions. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>One position versus the whole map</h3>","<p>A filter placed at one location computes one output value. Sliding that same filter over all valid locations creates one feature map. A second filter creates a second feature map. Therefore the number of filters equals the number of output channels.</p>","<h3>Why filter depth matches input channels</h3>","<p>A 3 × 3 filter applied to a 3-channel input has 3 × 3 × 3 = 27 weights. At one location, it combines 27 input values into one sum. A single bias is then added for that filter. It does not produce three separate output channels just because the input has three channels.</p>","<h3>Reading a complete shape calculation</h3>","<p>The spatial-size formula computes height and width. It does not compute the channel count.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N = current input size; P = padding on one side; K = filter size; S = stride. The floor symbol means keep only complete placements. Add one because the initial placement is also an output position.</p>","<h3>Shape, parameters and computation are three different counts</h3>","<p><strong>Shape</strong> counts the arrangement of output values. <strong>Parameters</strong> count learned weights and biases. <strong>Computation</strong> counts how many arithmetic operations are performed. Reusing the same filter at 100 positions creates 100 outputs but does not create 100 new sets of weights.</p>","<p>In a multi-layer question, write the output shape of a layer first. That becomes the next layer&#x27;s input shape. This is why the second convolution uses the first convolution&#x27;s channel count, not the original image&#x27;s channel count.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s0","search":"Reading image shapes before doing CNN arithmetic **Definition.** An image or intermediate CNN representation is a tensor indexed by spatial position and channel. This course writes its shape as height × width × channels, excluding the batch dimension.\n\n### Explanation and working\n### Height, width and channels\nThe shape 4 × 5 × 3 means 4 rows, 5 columns and 3 channels. It contains 4 × 5 × 3 = 60 numbers. A grayscale image commonly has one intensity channel; an RGB image has red, green and blue channels. Intermediate CNN channels are learned feature maps, not necessarily colors.\n\n\n\n### One position versus the whole map\nA filter placed at one location computes one output value. Sliding that same filter over all valid locations creates one feature map. A second filter creates a second feature map. Therefore the number of filters equals the number of output channels.\n### Why filter depth matches input channels\nA 3 × 3 filter applied to a 3-channel input has 3 × 3 × 3 = 27 weights. At one location, it combines 27 input values into one sum. A single bias is then added for that filter. It does not produce three separate output channels just because the input has three channels.\n### Reading a complete shape calculation\nThe spatial-size formula computes height and width. It does not compute the channel count.\n\nN = current input size; P = padding on one side; K = filter size; S = stride. The floor symbol means keep only complete placements. Add one because the initial placement is also an output position.\n### Shape, parameters and computation are three different counts\n**Shape** counts the arrangement of output values. **Parameters** count learned weights and biases. **Computation** counts how many arithmetic operations are performed. Reusing the same filter at 100 positions creates 100 outputs but does not create 100 new sets of weights.\nIn a multi-layer question, write the output shape of a layer first. That becomes the next layer's input shape. This is why the second convolution uses the first convolution's channel count, not the original image's channel count.\n"},{"title":"A computer sees an image as numbers","blocks":["<p class=\"definition\"><strong>Definition.</strong> A digital image is a spatially arranged numerical tensor. In a CNN, convolutions transform input channels into learned feature maps using local connectivity and spatially shared kernel parameters.</p>","<h3>Explanation and working</h3>","<p>A pixel is one position in an image. A grayscale image stores one intensity per position. A colour RGB image usually stores three numbers per position: red, green and blue. Therefore 32 × 32 × 3 means height 32, width 32 and 3 input channels. It contains 32 × 32 × 3 = 3,072 numbers, not 32 neurons.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_image_grid.svg\" aria-label=\"Enlarge diagram: Each visible pixel corresponds to a matrix entry. Brightness is a number the network can calculate with.\"><img src=\"assets/figures/v_image_grid.svg\" alt=\"Each visible pixel corresponds to a matrix entry. Brightness is a number the network can calculate with.\" width=\"1080\" height=\"575\" loading=\"lazy\"></button><figcaption>Each visible pixel corresponds to a matrix entry. Brightness is a number the network can calculate with. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A <strong>feature</strong> is a useful pattern, such as an edge or texture. A <strong>feature map</strong> is a grid of responses that says where a learned filter matches the input. Early CNN layers often detect local simple patterns; later layers combine them into parts and more complex patterns.</p>","<p>A filter, also called a kernel in many exam questions, is a small set of learned weights. Slide it across the image, multiply corresponding numbers, and add. The same weights are reused at every spatial position. This is <strong>weight sharing</strong>.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s1","search":"A computer sees an image as numbers **Definition.** A digital image is a spatially arranged numerical tensor. In a CNN, convolutions transform input channels into learned feature maps using local connectivity and spatially shared kernel parameters.\n\n### Explanation and working\nA pixel is one position in an image. A grayscale image stores one intensity per position. A colour RGB image usually stores three numbers per position: red, green and blue. Therefore 32 × 32 × 3 means height 32, width 32 and 3 input channels. It contains 32 × 32 × 3 = 3,072 numbers, not 32 neurons.\n\n\n\nA **feature** is a useful pattern, such as an edge or texture. A **feature map** is a grid of responses that says where a learned filter matches the input. Early CNN layers often detect local simple patterns; later layers combine them into parts and more complex patterns.\nA filter, also called a kernel in many exam questions, is a small set of learned weights. Slide it across the image, multiply corresponding numbers, and add. The same weights are reused at every spatial position. This is **weight sharing**."},{"title":"The convolution calculation","blocks":["<p class=\"definition\"><strong>Definition.</strong> A convolutional layer calculates local weighted sums with a spatially shared kernel and optional bias. Standard deep-learning implementations ordinarily use cross-correlation, without flipping the kernel; examination calculations must follow the stated convention.</p>","<h3>Explanation and working</h3>","<p>In deep-learning software, the operation normally called convolution is cross-correlation: use the kernel as written, without flipping it. This is the convention in this course’s CNN numericals and the supplied latest answer key. Mathematical convolution would rotate the kernel; state that convention if a question explicitly requests it.</p>","<p class=\"inline-question\"><strong>Question.</strong> Apply a 2 × 2 kernel Matrix 1 shown below to the 3 × 3 image Matrix 2 shown below, with stride 1, no padding and zero bias.</p>","<h3>Given</h3>","<p>Input X = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/0cf23d37eabd00e4.svg\" alt=\"\\begin{bmatrix}1 &amp; 2 &amp; 3\\\\4 &amp; 5 &amp; 6\\\\7 &amp; 8 &amp; 9\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>.</p>","<p>Kernel K = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5c899cfe4dee6d06.svg\" alt=\"\\begin{bmatrix}1 &amp; 0\\\\0 &amp; -1\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>.</p>","<p>Stride = 1; padding = 0; bias = 0; no kernel flip.</p>","<h3>To find</h3>","<p>Find the 2 × 2 output map.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_cd39cabe48.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_cd39cabe48.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"340\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbe5e0aa8714ed4e.svg\" alt=\"X=\\begin{bmatrix}1&amp;2&amp;3\\\\4&amp;5&amp;6\\\\7&amp;8&amp;9\\end{bmatrix},\\quad K=\\begin{bmatrix}1&amp;0\\\\0&amp;-1\\end{bmatrix}\" width=\"354.80\" height=\"92.85\" style=\"width:354.80px;height:92.85px;aspect-ratio:354.80/92.85\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 1. Top-left window.</strong> 1(1) + 2(0) + 4(0) + 5(−1) = 1 − 5 = −4.</p>","<p class=\"worked-step\"><strong>Step 2. Move right by one.</strong> 2(1) + 3(0) + 5(0) + 6(−1) = 2 − 6 = −4.</p>","<p class=\"worked-step\"><strong>Step 3. Move down and return left.</strong> 4(1) + 5(0) + 7(0) + 8(−1) = 4 − 8 = −4.</p>","<p class=\"worked-step\"><strong>Step 4. Bottom-right window.</strong> 5(1) + 6(0) + 8(0) + 9(−1) = 5 − 9 = −4. Output is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/7f45e7b63383ada2.svg\" alt=\"\\begin{bmatrix}-4 &amp; -4\\\\-4 &amp; -4\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>. If ReLU follows, that next layer changes all four entries to zero; do not silently apply it when it was not requested.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/convolution.svg\" aria-label=\"Enlarge diagram: Four windows produce four output cells\"><img src=\"assets/figures/convolution.svg\" alt=\"Four windows produce four output cells\" width=\"960\" height=\"630\" loading=\"lazy\"></button><figcaption>Four windows produce four output cells <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s2","search":"The convolution calculation **Definition.** A convolutional layer calculates local weighted sums with a spatially shared kernel and optional bias. Standard deep-learning implementations ordinarily use cross-correlation, without flipping the kernel; examination calculations must follow the stated convention.\n\n### Explanation and working\nIn deep-learning software, the operation normally called convolution is cross-correlation: use the kernel as written, without flipping it. This is the convention in this book’s CNN numericals and the supplied latest answer key. Mathematical convolution would rotate the kernel; state that convention if a question explicitly requests it.\n**Question.** Apply a 2 × 2 kernel Matrix 1 shown below to the 3 × 3 image Matrix 2 shown below, with stride 1, no padding and zero bias.\n\n\n\n### Given\n\nInput X = .\n\nKernel K = .\n\nStride = 1; padding = 0; bias = 0; no kernel flip.\n\n### To find\n\nFind the 2 × 2 output map.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n**Step 1. Top-left window.** 1(1) + 2(0) + 4(0) + 5(−1) = 1 − 5 = −4.\n**Step 2. Move right by one.** 2(1) + 3(0) + 5(0) + 6(−1) = 2 − 6 = −4.\n**Step 3. Move down and return left.** 4(1) + 5(0) + 7(0) + 8(−1) = 4 − 8 = −4.\n**Step 4. Bottom-right window.** 5(1) + 6(0) + 8(0) + 9(−1) = 5 − 9 = −4. Output is . If ReLU follows, that next layer changes all four entries to zero; do not silently apply it when it was not requested.\n"},{"title":"Stride padding and floor","blocks":["<p class=\"definition\"><strong>Definition.</strong> Stride is the spacing between consecutive kernel positions. Padding extends the input boundary. Together with kernel size and dilation, they determine the spatial dimensions of a convolutional output.</p>","<h3>Explanation and working</h3>","<p>Stride is how far the filter moves each time. Stride 2 visits starting positions 0, 2, 4 and so on. Padding adds border values, usually zeros. Padding 1 means one new row or column on each side, adding 2 to a spatial dimension.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_stride_padding.svg\" aria-label=\"Enlarge diagram: The border adds to both sides of the input. The stride changes the next starting position of the filter window.\"><img src=\"assets/figures/v_stride_padding.svg\" alt=\"The border adds to both sides of the input. The stride changes the next starting position of the filter window.\" width=\"1080\" height=\"645\" loading=\"lazy\"></button><figcaption>The border adds to both sides of the input. The stride changes the next starting position of the filter window. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is input size; P is padding per side; K is kernel size; S is stride. Floor means take the greatest integer not above the result: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a8acf65164593cb2.svg\" alt=\"\\left\\lfloor 2.5\\right\\rfloor\" width=\"41.16\" height=\"19.00\" style=\"width:41.16px;height:19.00px;aspect-ratio:41.16/19.00\" loading=\"lazy\"></span> = 2. It counts only positions where the entire window fits. The formula assumes dilation 1, the standard setting in these papers. Apply it separately to height and width for rectangular images or kernels.</p>","<p><strong>Why plus one?</strong> Even when the kernel exactly fits the image, there is one placement. If N = K, P = 0, S = 1, the formula is 0 + 1 = 1.</p>","<h3>Output dimension with a fractional intermediate result</h3>","<p class=\"inline-question\"><strong>Question. A convolution has input side N = 6, kernel side K = 3, stride S = 2 and padding P = 0. Find its output side.</strong></p>","<h3>Given</h3>","<p>N = 6; K = 3; S = 2; P = 0; dilation = 1.</p>","<h3>To find</h3>","<p>The integer output side length.</p>","<h3>Formula — which one and why</h3>","<p>The formula counts complete kernel placements. Flooring removes an incomplete final placement.</p>","<p>N is input side; P is padding on each side; K is kernel side; S is stride.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Padding dono side; stride se divide; floor; phir +1.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: include padding and subtract kernel size.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4027b9bc8f6fe22.svg\" alt=\"6+2(0)-3=3\" width=\"172.42\" height=\"24.43\" style=\"width:172.42px;height:24.43px;aspect-ratio:172.42/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the stride.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d103d3b0cd150006.svg\" alt=\"\\frac32=1.5\" width=\"86.78\" height=\"49.53\" style=\"width:86.78px;height:49.53px;aspect-ratio:86.78/49.53\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: take the floor.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2ff7c16eb83493b5.svg\" alt=\"\\lfloor1.5\\rfloor=1\" width=\"97.73\" height=\"24.43\" style=\"width:97.73px;height:24.43px;aspect-ratio:97.73/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: count the first placement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f3dfc60f0024b2c.svg\" alt=\"N_{\\mathrm{out}}=1+1=2\" width=\"178.31\" height=\"20.54\" style=\"width:178.31px;height:20.54px;aspect-ratio:178.31/20.54\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Output side = 2; a square input gives a 2 × 2 map per filter.</p>","<h3>Padding on both sides</h3>","<p class=\"inline-question\"><strong>Question. A square convolution input has side 5, kernel side 3, stride 1 and padding 1 on each side. Find the padded-input size and output size.</strong></p>","<h3>Given</h3>","<p>N = 5; K = 3; S = 1; P = 1 on each side.</p>","<h3>To find</h3>","<p>Padded input and output dimensions.</p>","<h3>Formula — which one and why</h3>","<p>Padding adds P entries on each of two opposite sides; the output counts complete kernel placements.</p>","<p>N = unpadded side; K = kernel side; S = stride; P = per-side padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6bbc5ec5f7e71fe.svg\" alt=\"N_{\\mathrm{padded}}=N+2P\" width=\"191.11\" height=\"23.71\" style=\"width:191.11px;height:23.71px;aspect-ratio:191.11/23.71\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.00px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/500258811ea3eb2f.svg\"><img class=\"math display-math\" src=\"assets/equations/a8df1422782a8067.svg\" alt=\"N_{\\mathrm{out}}=\\lfloor(N+2P-K)/S\\rfloor+1\" width=\"323.70\" height=\"24.43\" style=\"width:323.70px;height:24.43px;aspect-ratio:323.70/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Padded input aur output ka size alag cheez hain.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count both padding edges.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/741118212eb25f73.svg\" alt=\"2P=2(1)=2\" width=\"151.39\" height=\"24.43\" style=\"width:151.39px;height:24.43px;aspect-ratio:151.39/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the padded input side.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a0c02a700e3aef2c.svg\" alt=\"N+2P=5+2=7\" width=\"213.83\" height=\"18.69\" style=\"width:213.83px;height:18.69px;aspect-ratio:213.83/18.69\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: subtract kernel width.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b2ddd3dd39f8f0c.svg\" alt=\"7-3=4\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide by stride and take the floor.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ce7e863527f4bb8.svg\" alt=\"\\lfloor4/1\\rfloor=4\" width=\"103.15\" height=\"24.43\" style=\"width:103.15px;height:24.43px;aspect-ratio:103.15/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: include the first placement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/94437545b203f62e.svg\" alt=\"N_{out}=4+1=5\" width=\"177.84\" height=\"20.54\" style=\"width:177.84px;height:20.54px;aspect-ratio:177.84/20.54\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Padded input = 7 × 7; output = 5 × 5 per filter.</p>","<p>“Valid” usually means P = 0. For odd K and S = 1, padding (K − 1)/2 preserves the spatial size. For S greater than 1, software “same” padding can be asymmetric and commonly gives ceiling(N/S); do not force the stride-1 rule into that case.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s3","search":"Stride padding and floor **Definition.** Stride is the spacing between consecutive kernel positions. Padding extends the input boundary. Together with kernel size and dilation, they determine the spatial dimensions of a convolutional output.\n\n### Explanation and working\nStride is how far the filter moves each time. Stride 2 visits starting positions 0, 2, 4 and so on. Padding adds border values, usually zeros. Padding 1 means one new row or column on each side, adding 2 to a spatial dimension.\n\n\n\n\nN is input size; P is padding per side; K is kernel size; S is stride. Floor means take the greatest integer not above the result: \\(\\left\\lfloor 2.5\\right\\rfloor\\) = 2. It counts only positions where the entire window fits. The formula assumes dilation 1, the standard setting in these papers. Apply it separately to height and width for rectangular images or kernels.\n**Why plus one?** Even when the kernel exactly fits the image, there is one placement. If N = K, P = 0, S = 1, the formula is 0 + 1 = 1.\n\n\n### Output dimension with a fractional intermediate result\n\n**Question. A convolution has input side N = 6, kernel side K = 3, stride S = 2 and padding P = 0. Find its output side.**\n\n\n\n### Given\n\nN = 6; K = 3; S = 2; P = 0; dilation = 1.\n\n### To find\n\nThe integer output side length.\n\n### Formula — which one and why\n\nThe formula counts complete kernel placements. Flooring removes an incomplete final placement.\n\nN is input side; P is padding on each side; K is kernel side; S is stride.\n\n\n\n**Yaad rakhne ka cue:** Padding dono side; stride se divide; floor; phir +1.\n\n### Solution — step by step\n\n\n\n**Step 1: include padding and subtract kernel size.**\n\n\n\n\n\n\n\n**Step 2: divide by the stride.**\n\n\n\n\n\n\n\n**Step 3: take the floor.**\n\n\n\n\n\n\n\n**Step 4: count the first placement.**\n\n\n\n\n\n\n\n**Final answer:** Output side = 2; a square input gives a 2 × 2 map per filter.\n\n\n\n\n### Padding on both sides\n\n**Question. A square convolution input has side 5, kernel side 3, stride 1 and padding 1 on each side. Find the padded-input size and output size.**\n\n\n\n### Given\n\nN = 5; K = 3; S = 1; P = 1 on each side.\n\n### To find\n\nPadded input and output dimensions.\n\n### Formula — which one and why\n\nPadding adds P entries on each of two opposite sides; the output counts complete kernel placements.\n\nN = unpadded side; K = kernel side; S = stride; P = per-side padding.\n\n\n\n\n\n**Yaad rakhne ka cue:** Padded input aur output ka size alag cheez hain.\n\n### Solution — step by step\n\n\n\n**Step 1: count both padding edges.**\n\n\n\n\n\n\n\n**Step 2: calculate the padded input side.**\n\n\n\n\n\n\n\n**Step 3: subtract kernel width.**\n\n\n\n\n\n\n\n**Step 4: divide by stride and take the floor.**\n\n\n\n\n\n\n\n**Step 5: include the first placement.**\n\n\n\n\n\n\n\n**Final answer:** Padded input = 7 × 7; output = 5 × 5 per filter.\n\n\n“Valid” usually means P = 0. For odd K and S = 1, padding (K − 1)/2 preserves the spatial size. For S greater than 1, software “same” padding can be asymmetric and commonly gives ceiling(N/S); do not force the stride-1 rule into that case."},{"title":"Convolution over several channels","blocks":["<p class=\"definition\"><strong>Definition.</strong> A standard convolutional filter spans every input channel. At one spatial position, channel-wise weighted sums are accumulated and one filter bias is added, producing one scalar output in that filter&#x27;s feature map.</p>","<h3>Explanation and working</h3>","<p>A 3 × 3 filter receiving RGB input has depth 3, so it contains 3 × 3 × 3 weights. At one position, compute a weighted sum in each of the three channels, add those sums, and then add the filter’s one bias. One filter produces one output channel. Sixteen filters produce sixteen output channels.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_channels.svg\" aria-label=\"Enlarge diagram: Add the channel contributions into one output cell. The filter bias is added once after those contributions.\"><img src=\"assets/figures/v_channels.svg\" alt=\"Add the channel contributions into one output cell. The filter bias is added once after those contributions.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Add the channel contributions into one output cell. The filter bias is added once after those contributions. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Tiny example.</strong> At one position the red, green and blue channel sums are 2, −1 and 4. With bias 0.5, the output is 2 − 1 + 4 + 0.5 = 5.5. Do not keep three separate outputs for this one filter; they have been added.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s4","search":"Convolution over several channels **Definition.** A standard convolutional filter spans every input channel. At one spatial position, channel-wise weighted sums are accumulated and one filter bias is added, producing one scalar output in that filter's feature map.\n\n### Explanation and working\nA 3 × 3 filter receiving RGB input has depth 3, so it contains 3 × 3 × 3 weights. At one position, compute a weighted sum in each of the three channels, add those sums, and then add the filter’s one bias. One filter produces one output channel. Sixteen filters produce sixteen output channels.\n\n\n\n**Tiny example.** At one position the red, green and blue channel sums are 2, −1 and 4. With bias 0.5, the output is 2 − 1 + 4 + 0.5 = 5.5. Do not keep three separate outputs for this one filter; they have been added."},{"title":"One filter over multiple channels: all contributions go into one cell","blocks":["<p class=\"definition\"><strong>Definition.</strong> Multi-channel convolution contracts the kernel&#x27;s spatial and input-channel dimensions to produce one output value per filter at each spatial location. Different filters have independent learned kernels.</p>","<h3>Explanation and working</h3>","<h3>1. Separate spatial size from depth</h3>","<p>Imagine a 1 × 1 spatial location with three input channels [2, 5, 1]. A 1 × 1 filter still has one weight for each channel. Suppose its weights are [0.1, −0.2, 0.5] and its bias is 0.3.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_channel_products.svg\" aria-label=\"Enlarge diagram: Multiply each channel by its own weight, add the three contributions, then add the single bias. These are the numbers in the example.\"><img src=\"assets/figures/v_channel_products.svg\" alt=\"Multiply each channel by its own weight, add the three contributions, then add the single bias. These are the numbers in the example.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Multiply each channel by its own weight, add the three contributions, then add the single bias. These are the numbers in the example. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.75px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/86f1a8b54476b2cb.svg\"><img class=\"math display-math\" src=\"assets/equations/36e8e2cc2919ceb8.svg\" alt=\"z=0.1(2)+(-0.2)(5)+0.5(1)+0.3\" width=\"390.16\" height=\"24.43\" style=\"width:390.16px;height:24.43px;aspect-ratio:390.16/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c377dccccbc387a.svg\" alt=\"z=0.2-1+0.5+0.3=0\" width=\"284.26\" height=\"18.27\" style=\"width:284.26px;height:18.27px;aspect-ratio:284.26/18.27\" loading=\"lazy\"></div>","<p>The three channels contributed to one output value. A single filter creates one output channel, even when its input has several channels.</p>","<h3>2. A larger filter has one spatial grid per input channel</h3>","<p>A 3 × 3 filter on a three-channel input has three 3 × 3 weight grids, totaling 27 weights. At one output location, calculate the nine products for channel 1, nine for channel 2 and nine for channel 3. Add all 27 products and then add the filter&#x27;s one bias.</p>","<p>The channel-wise sums are intermediate contributions; do not treat them as three final output channels unless three distinct filters were specified.</p>","<h3>3. What changes when there are several filters?</h3>","<p>Each filter has its own full-depth weight set and bias. Four filters give four independent sums at each output location, so the result has four channels. The filters all receive the same input depth.</p>","<p>For three input channels and four 3 × 3 filters, parameters are (27 + 1) × 4 = 112. Moving those filters over more image locations reuses these same 112 parameters.</p>","<h3>4. One-by-one does not mean one weight</h3>","<p>A 1 × 1 convolution with 64 input channels and 16 filters has 64 weights and one bias per filter: (64 + 1) × 16 = 1,040 parameters. It mixes channel information at each spatial position. With 16 outputs it reduces depth from 64 to 16; height and width stay unchanged when stride is 1 and no padding is needed.</p>","<p>This is the channel-reduction idea used by Inception bottlenecks and some residual projections. Spatial kernel size, input depth and output-channel count must all be read separately.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s5","search":"One filter over multiple channels: all contributions go into one cell **Definition.** Multi-channel convolution contracts the kernel's spatial and input-channel dimensions to produce one output value per filter at each spatial location. Different filters have independent learned kernels.\n\n### Explanation and working\n### 1. Separate spatial size from depth\nImagine a 1 × 1 spatial location with three input channels [2, 5, 1]. A 1 × 1 filter still has one weight for each channel. Suppose its weights are [0.1, −0.2, 0.5] and its bias is 0.3.\n\n\n\n\n\nThe three channels contributed to one output value. A single filter creates one output channel, even when its input has several channels.\n\n### 2. A larger filter has one spatial grid per input channel\nA 3 × 3 filter on a three-channel input has three 3 × 3 weight grids, totaling 27 weights. At one output location, calculate the nine products for channel 1, nine for channel 2 and nine for channel 3. Add all 27 products and then add the filter's one bias.\nThe channel-wise sums are intermediate contributions; do not treat them as three final output channels unless three distinct filters were specified.\n\n### 3. What changes when there are several filters?\nEach filter has its own full-depth weight set and bias. Four filters give four independent sums at each output location, so the result has four channels. The filters all receive the same input depth.\nFor three input channels and four 3 × 3 filters, parameters are (27 + 1) × 4 = 112. Moving those filters over more image locations reuses these same 112 parameters.\n\n### 4. One-by-one does not mean one weight\nA 1 × 1 convolution with 64 input channels and 16 filters has 64 weights and one bias per filter: (64 + 1) × 16 = 1,040 parameters. It mixes channel information at each spatial position. With 16 outputs it reduces depth from 64 to 16; height and width stay unchanged when stride is 1 and no padding is needed.\nThis is the channel-reduction idea used by Inception bottlenecks and some residual projections. Spatial kernel size, input depth and output-channel count must all be read separately.\n"},{"title":"Choosing more or fewer filters","blocks":["<p class=\"definition\"><strong>Definition.</strong> The number of convolutional filters determines the number of output channels. Kernel height, kernel width, stride and padding determine spatial processing; input-channel count determines each filter&#x27;s depth.</p>","<h3>Explanation and working</h3>","<p>Each filter produces one output channel and can learn a different pattern. More filters increase representational capacity, output depth, parameter count and activation memory. They may improve performance but can overfit small datasets or exceed a compute budget. Choose counts using validation results and resource constraints. More filters in one layer increase its width, not the number of network layers.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_filters.svg\" aria-label=\"Enlarge diagram: Each filter has the full incoming depth. Each produces one map, so the number of filters sets the output depth.\"><img src=\"assets/figures/v_filters.svg\" alt=\"Each filter has the full incoming depth. Each produces one map, so the number of filters sets the output depth.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>Each filter has the full incoming depth. Each produces one map, so the number of filters sets the output depth. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s6","search":"Choosing more or fewer filters **Definition.** The number of convolutional filters determines the number of output channels. Kernel height, kernel width, stride and padding determine spatial processing; input-channel count determines each filter's depth.\n\n### Explanation and working\nEach filter produces one output channel and can learn a different pattern. More filters increase representational capacity, output depth, parameter count and activation memory. They may improve performance but can overfit small datasets or exceed a compute budget. Choose counts using validation results and resource constraints. More filters in one layer increase its width, not the number of network layers.\n\n\n"},{"title":"Pooling needs comparisons or averages","blocks":["<p class=\"definition\"><strong>Definition.</strong> Pooling is a local aggregation operation that summarizes each spatial window, usually independently per channel. Max pooling selects the largest value; average pooling calculates a mean. Standard pooling has no learned weights or biases.</p>","<h3>Explanation and working</h3>","<p>Max pooling selects the largest value inside each window. Average pooling adds window entries and divides by their count. Ordinary max and average pooling have no learned weights or biases. Pool each input channel independently, so the number of channels is unchanged.</p>","<p class=\"inline-question\"><strong>Question.</strong> Pool this 4 × 4 map with 2 × 2 windows, stride 2 and no padding:</p>","<h3>Given</h3>","<p>The 4 × 4 input map is printed below.</p>","<p>Window = 2 × 2; stride = 2; padding = 0.</p>","<h3>To find</h3>","<p>Find the pooled output by the operation(s) requested.</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbeeead3eba02270.svg\" alt=\"A=\\begin{bmatrix}21&amp;11&amp;15&amp;10\\\\12&amp;9&amp;10&amp;11\\\\11&amp;13&amp;18&amp;12\\\\7&amp;4&amp;15&amp;12\\end{bmatrix}\" width=\"254.55\" height=\"127.06\" style=\"width:254.55px;height:127.06px;aspect-ratio:254.55/127.06\" loading=\"lazy\"></div>","<h3>Top-left window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[21, 11, 12, 9]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf103da2c4c32945.svg\" alt=\"y_{\\max}=21\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f9a0a96d6f9e048.svg\" alt=\"21+11+12+9=53\" width=\"232.15\" height=\"18.27\" style=\"width:232.15px;height:18.27px;aspect-ratio:232.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3fb67b8edc22789.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{53}4=13.25\" width=\"196.42\" height=\"49.55\" style=\"width:196.42px;height:49.55px;aspect-ratio:196.42/49.55\" loading=\"lazy\"></div>","<h3>Top-right window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[15, 10, 10, 11]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a17ef02b89e67e2.svg\" alt=\"y_{\\max}=15\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18d73c8a689f86bd.svg\" alt=\"15+10+10+11=46\" width=\"244.36\" height=\"18.54\" style=\"width:244.36px;height:18.54px;aspect-ratio:244.36/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4bcedeb9a26a70b6.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{46}4=11.5\" width=\"184.20\" height=\"49.82\" style=\"width:184.20px;height:49.82px;aspect-ratio:184.20/49.82\" loading=\"lazy\"></div>","<h3>Bottom-left window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[11, 13, 7, 4]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/37fcb9070f6a3c0a.svg\" alt=\"y_{\\max}=13\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba50b6f7e4060a25.svg\" alt=\"11+13+7+4=35\" width=\"219.93\" height=\"18.54\" style=\"width:219.93px;height:18.54px;aspect-ratio:219.93/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90fc093dce5b3464.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{35}4=8.75\" width=\"184.20\" height=\"49.55\" style=\"width:184.20px;height:49.55px;aspect-ratio:184.20/49.55\" loading=\"lazy\"></div>","<h3>Bottom-right window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[18, 12, 15, 12]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6e005f373e798e70.svg\" alt=\"y_{\\max}=18\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/437a8b87df7ffce7.svg\" alt=\"18+12+15+12=57\" width=\"244.36\" height=\"18.52\" style=\"width:244.36px;height:18.52px;aspect-ratio:244.36/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aaffd26053e275ce.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{57}4=14.25\" width=\"196.42\" height=\"49.80\" style=\"width:196.42px;height:49.80px;aspect-ratio:196.42/49.80\" loading=\"lazy\"></div>","<p>Outputs are max <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/89ec596cf1c6ec68.svg\" alt=\"\\begin{bmatrix}21 &amp; 15\\\\13 &amp; 18\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span> and average <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/94682b0fab3f0b97.svg\" alt=\"\\begin{bmatrix}13.25 &amp; 11.5\\\\8.75 &amp; 14.25\\end{bmatrix}\" width=\"125.66\" height=\"45.61\" style=\"width:125.66px;height:45.61px;aspect-ratio:125.66/45.61\" loading=\"lazy\"></span>.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/pooling.svg\" aria-label=\"Enlarge diagram: Each pooling window reduces several values to one\"><img src=\"assets/figures/pooling.svg\" alt=\"Each pooling window reduces several values to one\" width=\"960\" height=\"500\" loading=\"lazy\"></button><figcaption>Each pooling window reduces several values to one <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Pooling reduces spatial size and later computation and can provide limited robustness to small shifts. It can lose exact position information. It does not guarantee complete translation invariance.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s7","search":"Pooling needs comparisons or averages **Definition.** Pooling is a local aggregation operation that summarizes each spatial window, usually independently per channel. Max pooling selects the largest value; average pooling calculates a mean. Standard pooling has no learned weights or biases.\n\n### Explanation and working\nMax pooling selects the largest value inside each window. Average pooling adds window entries and divides by their count. Ordinary max and average pooling have no learned weights or biases. Pool each input channel independently, so the number of channels is unchanged.\n**Question.** Pool this 4 × 4 map with 2 × 2 windows, stride 2 and no padding:\n\n\n\n### Given\n\nThe 4 × 4 input map is printed below.\n\nWindow = 2 × 2; stride = 2; padding = 0.\n\n### To find\n\nFind the pooled output by the operation(s) requested.\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n\n### Top-left window\n\n**Step 1: select the four entries.**\n\n[21, 11, 12, 9]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\n### Top-right window\n\n**Step 1: select the four entries.**\n\n[15, 10, 10, 11]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\n### Bottom-left window\n\n**Step 1: select the four entries.**\n\n[11, 13, 7, 4]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\n### Bottom-right window\n\n**Step 1: select the four entries.**\n\n[18, 12, 15, 12]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\nOutputs are max  and average .\n\nPooling reduces spatial size and later computation and can provide limited robustness to small shifts. It can lose exact position information. It does not guarantee complete translation invariance."},{"title":"Parameters are different from activation values","blocks":["<p class=\"definition\"><strong>Definition.</strong> Parameters are learned coefficients shared across evaluations. Activations are input-dependent values computed during a forward pass. The number of activation values therefore differs from the number of trainable parameters.</p>","<h3>Explanation and working</h3>","<p>An activation is a number produced for a particular input. A parameter is a learned number reused across inputs. A 100 × 100 feature map can be produced by a filter with only a few weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters_activations.svg\" aria-label=\"Enlarge diagram: The ten learned parameters are reused at nine spatial positions. The resulting nine numbers are activations.\"><img src=\"assets/figures/v_parameters_activations.svg\" alt=\"The ten learned parameters are reused at nine spatial positions. The resulting nine numbers are activations.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The ten learned parameters are reused at nine spatial positions. The resulting nine numbers are activations. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<p>The +1 is one bias per filter. If bias is explicitly disabled, remove it. Height and width of the image do not enter the parameter formula; they enter the number of output activations and the amount of computation.</p>","<h3>One filter, then all filters</h3>","<p class=\"inline-question\"><strong>Question. A 3 × 3 convolution receives 3 input channels and has 16 filters, each with one bias. Find its trainable parameters and output-channel count.</strong></p>","<h3>Given</h3>","<p>Kernel = 3 × 3; input channels = 3; filters = 16; one bias per filter.</p>","<h3>To find</h3>","<p>Weights, biases, total trainable parameters and output channels.</p>","<h3>Formula — which one and why</h3>","<p>Each filter spans every input channel and owns one bias. Spatial reuse does not create extra weights.</p>","<p>Kₕ,Kw are kernel dimensions; Cᵢₙ is input depth; Cₒᵤₜ is the number of filters.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a603987eb773068.svg\" alt=\"P=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.27\" height=\"24.43\" style=\"width:258.27px;height:24.43px;aspect-ratio:258.27/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek filter ka count banao, phir filters se multiply.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count weights in one filter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ee13fc57d61624d3.svg\" alt=\"3(3)(3)=27\" width=\"131.70\" height=\"24.43\" style=\"width:131.70px;height:24.43px;aspect-ratio:131.70/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: include its one bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5f8acbeb6a1db0ac.svg\" alt=\"27+1=28\" width=\"123.54\" height=\"18.52\" style=\"width:123.54px;height:18.52px;aspect-ratio:123.54/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: count all weights.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f7cebde5567e220a.svg\" alt=\"27(16)=432\" width=\"137.12\" height=\"24.43\" style=\"width:137.12px;height:24.43px;aspect-ratio:137.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: count all biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96319009caa148f5.svg\" alt=\"1(16)=16\" width=\"112.68\" height=\"24.43\" style=\"width:112.68px;height:24.43px;aspect-ratio:112.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add and state channel count.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17c5c3c49aac5f53.svg\" alt=\"P=432+16=448\" width=\"211.13\" height=\"18.69\" style=\"width:211.13px;height:18.69px;aspect-ratio:211.13/18.69\" loading=\"lazy\"></div>","<p>Each filter produces one channel, so output channels = 16.</p>","<p><strong>Final answer:</strong> 432 weights + 16 biases = 448 trainable parameters; 16 output channels.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/676bf495296f4651.svg\"><img class=\"math display-math\" src=\"assets/equations/3d36d7d9ab25e138.svg\" alt=\"P_{\\mathrm{pool}}=0,\\quad P_{\\mathrm{flatten}}=0,\\quad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"502.29\" height=\"25.35\" style=\"width:502.29px;height:25.35px;aspect-ratio:502.29/25.35\" loading=\"lazy\"></picture></div>","<p>Flatten rearranges H × W × C activation values into one vector of length HWC. It does not learn anything. A following dense layer connects to every one of those values.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s8","search":"Parameters are different from activation values **Definition.** Parameters are learned coefficients shared across evaluations. Activations are input-dependent values computed during a forward pass. The number of activation values therefore differs from the number of trainable parameters.\n\n### Explanation and working\nAn activation is a number produced for a particular input. A parameter is a learned number reused across inputs. A 100 × 100 feature map can be produced by a filter with only a few weights.\n\n\n\n\nThe +1 is one bias per filter. If bias is explicitly disabled, remove it. Height and width of the image do not enter the parameter formula; they enter the number of output activations and the amount of computation.\n\n\n### One filter, then all filters\n\n**Question. A 3 × 3 convolution receives 3 input channels and has 16 filters, each with one bias. Find its trainable parameters and output-channel count.**\n\n\n\n### Given\n\nKernel = 3 × 3; input channels = 3; filters = 16; one bias per filter.\n\n### To find\n\nWeights, biases, total trainable parameters and output channels.\n\n### Formula — which one and why\n\nEach filter spans every input channel and owns one bias. Spatial reuse does not create extra weights.\n\nKₕ,Kw are kernel dimensions; Cᵢₙ is input depth; Cₒᵤₜ is the number of filters.\n\n\n\n**Yaad rakhne ka cue:** Ek filter ka count banao, phir filters se multiply.\n\n### Solution — step by step\n\n\n\n**Step 1: count weights in one filter.**\n\n\n\n\n\n\n\n**Step 2: include its one bias.**\n\n\n\n\n\n\n\n**Step 3: count all weights.**\n\n\n\n\n\n\n\n**Step 4: count all biases.**\n\n\n\n\n\n\n\n**Step 5: add and state channel count.**\n\n\n\n\n\nEach filter produces one channel, so output channels = 16.\n\n**Final answer:** 432 weights + 16 biases = 448 trainable parameters; 16 output channels.\n\n\n\nFlatten rearranges H × W × C activation values into one vector of length HWC. It does not learn anything. A following dense layer connects to every one of those values."},{"title":"One complete CNN pipeline","blocks":["<p class=\"inline-question\"><strong>Question.</strong> Input 128 × 128 × 3 → convolution 3 × 3, 16 filters, stride 1, no padding → pooling 2 × 2, stride 2 → convolution 3 × 3, 32 filters, stride 1, no padding → pooling 2 × 2, stride 2 → dense 240 → dense 120 → dense 5 with softmax. Find every output shape and trainable parameter count. Assume one bias per receiving filter or dense neuron.</p>","<h3>Given</h3>","<p>Input = 128 × 128 × 3.</p>","<p>Conv: 3 × 3,16 filters,stride 1,valid → pool 2,stride 2.</p>","<p>Conv: 3 × 3,32 filters,stride 1,valid → pool 2,stride 2.</p>","<p>Flatten → dense 240 → dense 120 → dense 5.</p>","<p>One bias per learned filter/dense neuron.</p>","<h3>To find</h3>","<p>Find every output shape and layer parameter count, then the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1. Conv 1 size.</strong> (128 − 3)/1 + 1 = 126; output 126 × 126 × 16. Parameters = (3 × 3 × 3 + 1) × 16 = 448.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_cnn_pipeline.svg\" aria-label=\"Enlarge diagram: Follow all eight layers from the question. Each row keeps the output shape separate from its learned-parameter count.\"><img src=\"assets/figures/v_cnn_pipeline.svg\" alt=\"Follow all eight layers from the question. Each row keeps the output shape separate from its learned-parameter count.\" width=\"1080\" height=\"1080\" loading=\"lazy\"></button><figcaption>Follow all eight layers from the question. Each row keeps the output shape separate from its learned-parameter count. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 2. Pool 1 size.</strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/9e62fef4c3e773c7.svg\" alt=\"\\left\\lfloor\\frac{126 - 2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span> = 63; output 63 × 63 × 16. Parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 3. Conv 2 size.</strong> (63 − 3)/1 + 1 = 61; output 61 × 61 × 32. Input channels are now 16, not the original 3. Parameters = (3 × 3 × 16 + 1) × 32 = 4,640.</p>","<p class=\"worked-step\"><strong>Step 4. Pool 2 size.</strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4d2232cedf251bfa.svg\" alt=\"\\left\\lfloor\\frac{61 - 2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span> = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/dfb80f08b9b0c4e1.svg\" alt=\"\\left\\lfloor 29.5\\right\\rfloor\" width=\"50.67\" height=\"19.00\" style=\"width:50.67px;height:19.00px;aspect-ratio:50.67/19.00\" loading=\"lazy\"></span> + 1 = 30; output 30 × 30 × 32. Parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 5. Flatten.</strong> 30 × 30 × 32 = 28,800 values. Parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 6. Dense 240.</strong> 28,800 weights per neuron plus one bias, multiplied by 240: (28,800 + 1) × 240 = 6,912,240.</p>","<p class=\"worked-step\"><strong>Step 7. Dense 120.</strong> (240 + 1) × 120 = 28,920.</p>","<p class=\"worked-step\"><strong>Step 8. Classifier.</strong> (120 + 1) × 5 = 605. Softmax itself adds no extra parameters; these 605 belong to the dense class-score layer.</p>","<p class=\"worked-step\"><strong>Step 9. Total.</strong> 448 + 4,640 + 6,912,240 + 28,920 + 605 = <strong>6,946,853</strong>. Most parameters come from the first dense layer.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s9","search":"One complete CNN pipeline **Question.** Input 128 × 128 × 3 → convolution 3 × 3, 16 filters, stride 1, no padding → pooling 2 × 2, stride 2 → convolution 3 × 3, 32 filters, stride 1, no padding → pooling 2 × 2, stride 2 → dense 240 → dense 120 → dense 5 with softmax. Find every output shape and trainable parameter count. Assume one bias per receiving filter or dense neuron.\n\n\n\n### Given\n\nInput = 128 × 128 × 3.\n\nConv: 3 × 3,16 filters,stride 1,valid → pool 2,stride 2.\n\nConv: 3 × 3,32 filters,stride 1,valid → pool 2,stride 2.\n\nFlatten → dense 240 → dense 120 → dense 5.\n\nOne bias per learned filter/dense neuron.\n\n### To find\n\nFind every output shape and layer parameter count, then the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n**Step 1. Conv 1 size.** (128 − 3)/1 + 1 = 126; output 126 × 126 × 16. Parameters = (3 × 3 × 3 + 1) × 16 = 448.\n\n\n\n**Step 2. Pool 1 size.** \\(\\left\\lfloor\\frac{126 - 2}{2}\\right\\rfloor+1\\) = 63; output 63 × 63 × 16. Parameters = 0.\n**Step 3. Conv 2 size.** (63 − 3)/1 + 1 = 61; output 61 × 61 × 32. Input channels are now 16, not the original 3. Parameters = (3 × 3 × 16 + 1) × 32 = 4,640.\n**Step 4. Pool 2 size.** \\(\\left\\lfloor\\frac{61 - 2}{2}\\right\\rfloor+1\\) = \\(\\left\\lfloor 29.5\\right\\rfloor\\) + 1 = 30; output 30 × 30 × 32. Parameters = 0.\n**Step 5. Flatten.** 30 × 30 × 32 = 28,800 values. Parameters = 0.\n**Step 6. Dense 240.** 28,800 weights per neuron plus one bias, multiplied by 240: (28,800 + 1) × 240 = 6,912,240.\n**Step 7. Dense 120.** (240 + 1) × 120 = 28,920.\n**Step 8. Classifier.** (120 + 1) × 5 = 605. Softmax itself adds no extra parameters; these 605 belong to the dense class-score layer.\n**Step 9. Total.** 448 + 4,640 + 6,912,240 + 28,920 + 605 = **6,946,853**. Most parameters come from the first dense layer."},{"title":"CNN versus a fully connected image network","blocks":["<p class=\"definition\"><strong>Definition.</strong> A convolutional neural network uses local receptive fields and spatial parameter sharing, unlike a dense layer&#x27;s independent connection weights. These architectural constraints exploit spatial structure and can greatly reduce parameter counts.</p>","<h3>Explanation and working</h3>","<p>A fully connected layer can learn image features, but flattening pixels and connecting every pixel to every neuron ignores the useful local structure built into a CNN and can require many parameters. CNNs exploit local connections and shared filters. They learn hierarchical features and reuse a pattern detector at many locations.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_fc_cnn.svg\" aria-label=\"Enlarge diagram: Compare where connections go and which weights are reused.\"><img src=\"assets/figures/v_fc_cnn.svg\" alt=\"Compare where connections go and which weights are reused.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Compare where connections go and which weights are reused. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For a 32 × 32 × 3 input, a dense layer with 100 neurons has (3,072 + 1) × 100 = 307,300 parameters. A convolution with 100 filters of size 3 × 3 has (27 + 1) × 100 = 2,800 parameters. The outputs are different shapes, so this is a parameter-efficiency illustration, not two identical computational tasks.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s10","search":"CNN versus a fully connected image network **Definition.** A convolutional neural network uses local receptive fields and spatial parameter sharing, unlike a dense layer's independent connection weights. These architectural constraints exploit spatial structure and can greatly reduce parameter counts.\n\n### Explanation and working\nA fully connected layer can learn image features, but flattening pixels and connecting every pixel to every neuron ignores the useful local structure built into a CNN and can require many parameters. CNNs exploit local connections and shared filters. They learn hierarchical features and reuse a pattern detector at many locations.\n\n\n\nFor a 32 × 32 × 3 input, a dense layer with 100 neurons has (3,072 + 1) × 100 = 307,300 parameters. A convolution with 100 filters of size 3 × 3 has (27 + 1) × 100 = 2,800 parameters. The outputs are different shapes, so this is a parameter-efficiency illustration, not two identical computational tasks.\n"},{"title":"Model answer: CNN structure and parameter sharing","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain the main layers of a convolutional neural network and why CNNs are suitable for image data. Compare them with a fully connected image network.</p>"],"answer":["<p>A CNN processes spatially arranged data using filters that examine local regions. The same filter weights are reused at different positions. This combination of local connectivity and weight sharing builds an image-specific structure into the model and can greatly reduce the number of learned weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_weight_sharing.svg\" aria-label=\"Enlarge diagram: The highlighted patch uses the same filter that will be reused at the next position.\"><img src=\"assets/figures/v_weight_sharing.svg\" alt=\"The highlighted patch uses the same filter that will be reused at the next position.\" width=\"1080\" height=\"590\" loading=\"lazy\"></button><figcaption>The highlighted patch uses the same filter that will be reused at the next position. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Typical layer sequence</h3>","<p><strong>Input → convolution → nonlinear activation → optional pooling → further feature extraction → classifier.</strong></p>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Operation</th><th>Learned parameters?</th></tr></thead><tbody><tr><td>Convolution</td><td>Multiply a local window by a filter, sum and add its bias</td><td>Filter weights and usually one bias per filter</td></tr><tr><td>ReLU</td><td>Replace negative values by zero</td><td>No ordinary ReLU parameters</td></tr><tr><td>Pooling</td><td>Summarize each window by maximum or average</td><td>None for ordinary max/average pooling</td></tr><tr><td>Flatten</td><td>Rearrange H × W × C values into a vector</td><td>None</td></tr><tr><td>Dense layer</td><td>Form weighted combinations of all incoming values</td><td>Weights and receiving-neuron biases</td></tr><tr><td>Softmax</td><td>Convert class scores into probabilities</td><td>No additional weights of its own</td></tr></tbody></table></div>","<p>Early filters can learn local patterns such as edges. Later layers combine features over larger receptive fields. A filter responding at several image positions uses one shared set of weights, not a new set at every location.</p>","<p>Flattening an image and using a dense layer does not enforce this local, shared structure. A dense layer has a separate connection weight for each input–output pair. CNNs can therefore be more parameter-efficient for visual patterns, although they still need suitable data and training. Pooling can provide some robustness to small shifts; it does not guarantee complete invariance to every translation.</p>"],"kind":"theory","id":"mt2-c7-s11","search":"Model answer: CNN structure and parameter sharing **Question.** Explain the main layers of a convolutional neural network and why CNNs are suitable for image data. Compare them with a fully connected image network.\n\n**Model answer.**\nA CNN processes spatially arranged data using filters that examine local regions. The same filter weights are reused at different positions. This combination of local connectivity and weight sharing builds an image-specific structure into the model and can greatly reduce the number of learned weights.\n\n\n\n\n### Typical layer sequence\n**Input → convolution → nonlinear activation → optional pooling → further feature extraction → classifier.**\n\n| Layer | Operation | Learned parameters? |\n| Convolution | Multiply a local window by a filter, sum and add its bias | Filter weights and usually one bias per filter |\n| ReLU | Replace negative values by zero | No ordinary ReLU parameters |\n| Pooling | Summarize each window by maximum or average | None for ordinary max/average pooling |\n| Flatten | Rearrange H × W × C values into a vector | None |\n| Dense layer | Form weighted combinations of all incoming values | Weights and receiving-neuron biases |\n| Softmax | Convert class scores into probabilities | No additional weights of its own |\n\nEarly filters can learn local patterns such as edges. Later layers combine features over larger receptive fields. A filter responding at several image positions uses one shared set of weights, not a new set at every location.\n\nFlattening an image and using a dense layer does not enforce this local, shared structure. A dense layer has a separate connection weight for each input–output pair. CNNs can therefore be more parameter-efficient for visual patterns, although they still need suitable data and training. Pooling can provide some robustness to small shifts; it does not guarantee complete invariance to every translation.\n"},{"title":"Output size and parameter count are different","blocks":["<p class=\"definition\"><strong>Definition.</strong> Output shape specifies the size of a layer&#x27;s computed tensor. Parameter count specifies the number of independent trainable coefficients. Spatial weight sharing allows a convolutional layer to produce many activations from comparatively few parameters.</p>","<h3>Explanation and working</h3>","<p class=\"inline-question\"><strong>Question.</strong> A 7 × 7 × 3 input passes through two 3 × 3 filters, stride 2 and padding 1. Find output shape and parameter count, including bias.</p>","<h3>Given</h3>","<p>Input = 7 × 7 × 3; two 3 × 3 filters.</p>","<p>Stride = 2; padding = 1; include biases.</p>","<h3>To find</h3>","<p>Find the output shape and trainable parameter count.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 spatial size:</strong> padding adds two, giving 7 + 2 − 3 = 6. Divide by stride: 6 ÷ 2 = 3. Apply floor and add the first position: 3 + 1 = 4. There are two filters, so output is 4 × 4 × 2.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters_activations.svg\" aria-label=\"Enlarge diagram: Output size counts produced values; parameter count counts adjustable weights and biases.\"><img src=\"assets/figures/v_parameters_activations.svg\" alt=\"Output size counts produced values; parameter count counts adjustable weights and biases.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Output size counts produced values; parameter count counts adjustable weights and biases. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 2 parameters:</strong> one filter has 3 × 3 × 3 = 27 weights and one bias, giving 28. Two filters have 56 parameters. The 4 × 4 output positions reuse those weights; they do not create 16 new sets of parameters.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s12","search":"Output size and parameter count are different **Definition.** Output shape specifies the size of a layer's computed tensor. Parameter count specifies the number of independent trainable coefficients. Spatial weight sharing allows a convolutional layer to produce many activations from comparatively few parameters.\n\n### Explanation and working\n**Question.** A 7 × 7 × 3 input passes through two 3 × 3 filters, stride 2 and padding 1. Find output shape and parameter count, including bias.\n\n\n\n### Given\n\nInput = 7 × 7 × 3; two 3 × 3 filters.\n\nStride = 2; padding = 1; include biases.\n\n### To find\n\nFind the output shape and trainable parameter count.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n**Step 1 spatial size:** padding adds two, giving 7 + 2 − 3 = 6. Divide by stride: 6 ÷ 2 = 3. Apply floor and add the first position: 3 + 1 = 4. There are two filters, so output is 4 × 4 × 2.\n\n\n\n**Step 2 parameters:** one filter has 3 × 3 × 3 = 27 weights and one bias, giving 28. Two filters have 56 parameters. The 4 × 4 output positions reuse those weights; they do not create 16 new sets of parameters.\n\n"},{"title":"Model answer: shape, activations and parameters","question":["<p class=\"inline-question\"><strong>Question.</strong> Distinguish a CNN layer&#x27;s output shape, number of output activations and number of trainable parameters. Explain the formulas used to calculate them.</p>"],"answer":["<p>Output shape tells how the produced values are arranged. The activation count tells how many values were produced for one input. Parameter count tells how many learned weights and biases define the layer. These are three different questions.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters_activations.svg\" aria-label=\"Enlarge diagram: Keep output shape, activation count and parameter count as three separate quantities.\"><img src=\"assets/figures/v_parameters_activations.svg\" alt=\"Keep output shape, activation count and parameter count as three separate quantities.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Keep output shape, activation count and parameter count as three separate quantities. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Spatial output shape</h3>","<p>For an ordinary convolution with dilation 1:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is the incoming spatial size, P is padding on each side, K is kernel size and S is stride. Apply the rule independently to height and width. The number of output channels is the number of filters.</p>","<h3>Output activations</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c9b86a3e71336c4.svg\" alt=\"A=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}\" width=\"192.74\" height=\"21.35\" style=\"width:192.74px;height:21.35px;aspect-ratio:192.74/21.35\" loading=\"lazy\"></div>","<p>This is the number of output values for one example, excluding any batch dimension.</p>","<h3>Trainable parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<p>Each filter spans every incoming channel. The +1 is one bias per filter. Remove it if biases are disabled. Spatial output dimensions do not appear here because filters share their weights across positions.</p>","<h3>Small example</h3>","<p>A 7 × 7 × 3 input, two 3 × 3 filters, stride 2 and padding 1 gives output 4 × 4 × 2. It contains 32 activations but has (3 × 3 × 3 + 1) × 2 = 56 parameters. These counts do not need to match. In a multilayer question, the current layer&#x27;s output channels become the next convolution&#x27;s input channels.</p>"],"kind":"theory","id":"mt2-c7-s13","search":"Model answer: shape, activations and parameters **Question.** Distinguish a CNN layer's output shape, number of output activations and number of trainable parameters. Explain the formulas used to calculate them.\n\n**Model answer.**\nOutput shape tells how the produced values are arranged. The activation count tells how many values were produced for one input. Parameter count tells how many learned weights and biases define the layer. These are three different questions.\n\n\n\n\n### Spatial output shape\nFor an ordinary convolution with dilation 1:\n\nN is the incoming spatial size, P is padding on each side, K is kernel size and S is stride. Apply the rule independently to height and width. The number of output channels is the number of filters.\n\n### Output activations\n\nThis is the number of output values for one example, excluding any batch dimension.\n\n### Trainable parameters\n\nEach filter spans every incoming channel. The +1 is one bias per filter. Remove it if biases are disabled. Spatial output dimensions do not appear here because filters share their weights across positions.\n\n### Small example\nA 7 × 7 × 3 input, two 3 × 3 filters, stride 2 and padding 1 gives output 4 × 4 × 2. It contains 32 activations but has (3 × 3 × 3 + 1) × 2 = 56 parameters. These counts do not need to match. In a multilayer question, the current layer's output channels become the next convolution's input channels.\n"},{"title":"Faculty example: a complete binary-image convolution","blocks":["<p class=\"inline-question\"><strong>Question. Apply the shown 3 × 3 filter to the 5 × 5 image. Use stride 1, no padding and zero bias. Calculate every output value without flipping the filter. (Practice: 5 marks)</strong></p>","<h3>Given</h3>","<p>Image X = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/acdfbb90974d971f.svg\" alt=\"\\begin{bmatrix}1 &amp; 1 &amp; 1 &amp; 0 &amp; 0\\\\0 &amp; 1 &amp; 1 &amp; 1 &amp; 0\\\\0 &amp; 0 &amp; 1 &amp; 1 &amp; 1\\\\0 &amp; 0 &amp; 1 &amp; 1 &amp; 0\\\\0 &amp; 1 &amp; 1 &amp; 0 &amp; 0\\end{bmatrix}\" width=\"148.88\" height=\"125.43\" style=\"width:148.88px;height:125.43px;aspect-ratio:148.88/125.43\" loading=\"lazy\"></span>.</p>","<p>Filter K = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/305a3f29286c4e55.svg\" alt=\"\\begin{bmatrix}1 &amp; 0 &amp; 1\\\\0 &amp; 1 &amp; 0\\\\1 &amp; 0 &amp; 1\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>. These are the values in the Unit 4 lecture example.</p>","<h3>To find</h3>","<p>The output shape and all nine feature-map values.</p>","<h3>Formula — which one and why</h3>","<p>The output-size formula counts complete filter placements. At each placement, multiply matching image/filter cells and add the products. A filter entry of zero makes that particular product zero; it does not remove the image cell from the input.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>Here N is input side, K is kernel side, P is padding per side and S is stride. The symbol K in the shape formula is the size 3, whereas the matrix K above contains the filter&#x27;s coefficients.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p>For this particular filter, only the four corners and the centre of each 3 × 3 window contribute. We can therefore write each sum using those five entries after explaining the four zero products. Below, their order is always <strong>top-left, top-right, centre, bottom-left, bottom-right</strong> within the current window.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_binary_windows.svg\" aria-label=\"Enlarge diagram: Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions.\"><img src=\"assets/figures/u4_binary_windows.svg\" alt=\"Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions.\" width=\"900\" height=\"405\" loading=\"lazy\"></button><figcaption>Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find the shape.</strong> (5 − 3)/1 + 1 = 3. The output is 3 × 3.</p>","<p class=\"worked-step\"><strong>Step 2: top-left output, showing all nine products.</strong> 1×1 + 1×0 + 1×1 + 0×0 + 1×1 + 1×0 + 0×1 + 0×0 + 1×1 = 1+0+1+0+1+0+0+0+1 = <strong>4</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: top-middle output.</strong> Move the window one column right. Corners and centre are 1,0,1,0,1. Sum = 1+0+1+0+1 = <strong>3</strong>.</p>","<p class=\"worked-step\"><strong>Step 4: top-right output.</strong> Move one more column right. Corners and centre are 1,0,1,1,1. Sum = 1+0+1+1+1 = <strong>4</strong>.</p>","<p class=\"worked-step\"><strong>Step 5: middle-left output.</strong> Return to column 1 and move down one row. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = <strong>2</strong>.</p>","<p class=\"worked-step\"><strong>Step 6: middle-middle output.</strong> Corners and centre are 1,1,1,0,1. Sum = 1+1+1+0+1 = <strong>4</strong>.</p>","<p class=\"worked-step\"><strong>Step 7: middle-right output.</strong> Corners and centre are 1,0,1,1,0. Sum = 1+0+1+1+0 = <strong>3</strong>.</p>","<p class=\"worked-step\"><strong>Step 8: bottom-left output.</strong> Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = <strong>2</strong>.</p>","<p class=\"worked-step\"><strong>Step 9: bottom-middle output.</strong> Corners and centre are 0,1,1,1,0. Sum = 0+1+1+1+0 = <strong>3</strong>.</p>","<p class=\"worked-step\"><strong>Step 10: bottom-right output.</strong> Corners and centre are 1,1,1,1,0. Sum = 1+1+1+1+0 = <strong>4</strong>.</p>","<p><strong>Final answer:</strong> Y = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/12aa767f92286deb.svg\" alt=\"\\begin{bmatrix}4 &amp; 3 &amp; 4\\\\2 &amp; 4 &amp; 3\\\\2 &amp; 3 &amp; 4\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>. All nine outputs use the same nine filter weights. They do not introduce nine different filters.</p>","<p><strong>Yaad rakho:</strong> Window badalta hai; filter ke numbers same rehte hain.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s14","search":"Faculty example: a complete binary-image convolution **Question. Apply the shown 3 × 3 filter to the 5 × 5 image. Use stride 1, no padding and zero bias. Calculate every output value without flipping the filter. (Practice: 5 marks)**\n\n### Given\nImage X = .\n\nFilter K = . These are the values in the Unit 4 lecture example.\n\n### To find\nThe output shape and all nine feature-map values.\n\n### Formula — which one and why\nThe output-size formula counts complete filter placements. At each placement, multiply matching image/filter cells and add the products. A filter entry of zero makes that particular product zero; it does not remove the image cell from the input.\n\n\n\nHere N is input side, K is kernel side, P is padding per side and S is stride. The symbol K in the shape formula is the size 3, whereas the matrix K above contains the filter's coefficients.\n\n\n\nFor this particular filter, only the four corners and the centre of each 3 × 3 window contribute. We can therefore write each sum using those five entries after explaining the four zero products. Below, their order is always **top-left, top-right, centre, bottom-left, bottom-right** within the current window.\n\n\n\n### Solution — step by step\n**Step 1: find the shape.** (5 − 3)/1 + 1 = 3. The output is 3 × 3.\n\n**Step 2: top-left output, showing all nine products.** 1×1 + 1×0 + 1×1 + 0×0 + 1×1 + 1×0 + 0×1 + 0×0 + 1×1 = 1+0+1+0+1+0+0+0+1 = **4**.\n\n**Step 3: top-middle output.** Move the window one column right. Corners and centre are 1,0,1,0,1. Sum = 1+0+1+0+1 = **3**.\n\n**Step 4: top-right output.** Move one more column right. Corners and centre are 1,0,1,1,1. Sum = 1+0+1+1+1 = **4**.\n\n**Step 5: middle-left output.** Return to column 1 and move down one row. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = **2**.\n\n**Step 6: middle-middle output.** Corners and centre are 1,1,1,0,1. Sum = 1+1+1+0+1 = **4**.\n\n**Step 7: middle-right output.** Corners and centre are 1,0,1,1,0. Sum = 1+0+1+1+0 = **3**.\n\n**Step 8: bottom-left output.** Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = **2**.\n\n**Step 9: bottom-middle output.** Corners and centre are 0,1,1,1,0. Sum = 0+1+1+1+0 = **3**.\n\n**Step 10: bottom-right output.** Corners and centre are 1,1,1,1,0. Sum = 1+1+1+1+0 = **4**.\n\n**Final answer:** Y = . All nine outputs use the same nine filter weights. They do not introduce nine different filters.\n\n**Yaad rakho:** Window badalta hai; filter ke numbers same rehte hain.\n"},{"title":"Faculty example: combine three RGB channel sums","blocks":["<p class=\"inline-question\"><strong>Question. At one position, a convolutional filter receives the following red, green and blue 3 × 3 patches and matching kernel slices. Calculate one output value with bias 1. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>Red patch = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/54e18a92743f2660.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 156 &amp; 155\\\\0 &amp; 153 &amp; 154\\end{bmatrix}\" width=\"129.88\" height=\"72.21\" style=\"width:129.88px;height:72.21px;aspect-ratio:129.88/72.21\" loading=\"lazy\"></span>; red kernel = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/05d6756a9472b44c.svg\" alt=\"\\begin{bmatrix}-1 &amp; -1 &amp; 1\\\\0 &amp; 1 &amp; -1\\\\0 &amp; 1 &amp; 1\\end{bmatrix}\" width=\"136.22\" height=\"72.21\" style=\"width:136.22px;height:72.21px;aspect-ratio:136.22/72.21\" loading=\"lazy\"></span>.</p>","<p>Green patch = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ca174e19344d6ef9.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 167 &amp; 166\\\\0 &amp; 164 &amp; 165\\end{bmatrix}\" width=\"129.88\" height=\"72.21\" style=\"width:129.88px;height:72.21px;aspect-ratio:129.88/72.21\" loading=\"lazy\"></span>; green kernel = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/7b136c068c1d807b.svg\" alt=\"\\begin{bmatrix}1 &amp; 0 &amp; 0\\\\1 &amp; -1 &amp; -1\\\\1 &amp; 0 &amp; -1\\end{bmatrix}\" width=\"121.44\" height=\"72.21\" style=\"width:121.44px;height:72.21px;aspect-ratio:121.44/72.21\" loading=\"lazy\"></span>.</p>","<p>Blue patch = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/8798bafaa1889aed.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 163 &amp; 162\\\\0 &amp; 160 &amp; 161\\end{bmatrix}\" width=\"129.88\" height=\"72.21\" style=\"width:129.88px;height:72.21px;aspect-ratio:129.88/72.21\" loading=\"lazy\"></span>; blue kernel = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/fccc1fad371104fc.svg\" alt=\"\\begin{bmatrix}0 &amp; 1 &amp; 1\\\\0 &amp; 1 &amp; 0\\\\1 &amp; -1 &amp; 1\\end{bmatrix}\" width=\"106.65\" height=\"72.21\" style=\"width:106.65px;height:72.21px;aspect-ratio:106.65/72.21\" loading=\"lazy\"></span>. Bias = 1.</p>","<p>These are three slices of <strong>one</strong> full-depth filter, not three independent output filters.</p>","<h3>To find</h3>","<p>The contribution of each input channel and the final scalar output at this position.</p>","<h3>Formula — which one and why</h3>","<p>Multiply corresponding entries within each channel. Add the three channel sums because this filter spans all input channels. Add its single bias once, after accumulating the channel contributions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/15d63177c46d68fd.svg\" alt=\"z=s_R+s_G+s_B+b\" width=\"224.31\" height=\"21.01\" style=\"width:224.31px;height:21.01px;aspect-ratio:224.31/21.01\" loading=\"lazy\"></div>","<p>The quantities s_R, s_G and s_B are intermediate weighted sums, not separate final output channels.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: red-channel products.</strong> The top row and first column contribute zero. The remaining terms are 156×1 + 155×(−1) + 153×1 + 154×1.</p>","<p class=\"worked-step\"><strong>Step 2: red-channel sum.</strong> 156 − 155 + 153 + 154 = <strong>308</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: green-channel products.</strong> The remaining patch terms are 167×(−1) + 166×(−1) + 164×0 + 165×(−1).</p>","<p class=\"worked-step\"><strong>Step 4: green-channel sum.</strong> −167 −166 +0 −165 = <strong>−498</strong>.</p>","<p class=\"worked-step\"><strong>Step 5: blue-channel products.</strong> The nonzero-patch terms are 163×1 + 162×0 + 160×(−1) + 161×1.</p>","<p class=\"worked-step\"><strong>Step 6: blue-channel sum.</strong> 163 +0 −160 +161 = <strong>164</strong>.</p>","<p class=\"worked-step\"><strong>Step 7: add the channel contributions.</strong> 308 −498 +164 = −26.</p>","<p class=\"worked-step\"><strong>Step 8: add one filter bias.</strong> −26 +1 = <strong>−25</strong>.</p>","<p><strong>Final answer:</strong> The convolution output is −25. If a subsequent ReLU is explicitly requested, that activation produces max(0,−25) = 0. The convolution value and activated value are different stages.</p>","<p><strong>Yaad rakho:</strong> Teen channels ka contribution jodo; ek filter ka bias ek baar jodo.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s15","search":"Faculty example: combine three RGB channel sums **Question. At one position, a convolutional filter receives the following red, green and blue 3 × 3 patches and matching kernel slices. Calculate one output value with bias 1. (Practice: 3 marks)**\n\n### Given\nRed patch = ; red kernel = .\n\nGreen patch = ; green kernel = .\n\nBlue patch = ; blue kernel = . Bias = 1.\n\nThese are three slices of **one** full-depth filter, not three independent output filters.\n\n### To find\nThe contribution of each input channel and the final scalar output at this position.\n\n### Formula — which one and why\nMultiply corresponding entries within each channel. Add the three channel sums because this filter spans all input channels. Add its single bias once, after accumulating the channel contributions.\n\n\n\nThe quantities s_R, s_G and s_B are intermediate weighted sums, not separate final output channels.\n\n### Solution — step by step\n**Step 1: red-channel products.** The top row and first column contribute zero. The remaining terms are 156×1 + 155×(−1) + 153×1 + 154×1.\n\n**Step 2: red-channel sum.** 156 − 155 + 153 + 154 = **308**.\n\n**Step 3: green-channel products.** The remaining patch terms are 167×(−1) + 166×(−1) + 164×0 + 165×(−1).\n\n**Step 4: green-channel sum.** −167 −166 +0 −165 = **−498**.\n\n**Step 5: blue-channel products.** The nonzero-patch terms are 163×1 + 162×0 + 160×(−1) + 161×1.\n\n**Step 6: blue-channel sum.** 163 +0 −160 +161 = **164**.\n\n**Step 7: add the channel contributions.** 308 −498 +164 = −26.\n\n**Step 8: add one filter bias.** −26 +1 = **−25**.\n\n**Final answer:** The convolution output is −25. If a subsequent ReLU is explicitly requested, that activation produces max(0,−25) = 0. The convolution value and activated value are different stages.\n\n**Yaad rakho:** Teen channels ka contribution jodo; ek filter ka bias ek baar jodo.\n"},{"title":"Max, min and average pooling on the same lecture grid","blocks":["<p class=\"definition\"><strong>Definition.</strong> Pooling summarizes each local window separately within each channel. Max pooling keeps its largest value, min pooling its smallest value, and average pooling its arithmetic mean. Ordinary versions have no trainable weights or biases.</p>","<p class=\"inline-question\"><strong>Question. Apply 2 × 2 max, min and average pooling with stride 2 and no padding to the following 4 × 4 input. Give all three output matrices. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>X = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/33f58372f0707267.svg\" alt=\"\\begin{bmatrix}12 &amp; 20 &amp; 30 &amp; 0\\\\8 &amp; 12 &amp; 2 &amp; 0\\\\34 &amp; 70 &amp; 37 &amp; 4\\\\112 &amp; 100 &amp; 25 &amp; 12\\end{bmatrix}\" width=\"177.39\" height=\"98.83\" style=\"width:177.39px;height:98.83px;aspect-ratio:177.39/98.83\" loading=\"lazy\"></span>. Window = 2 × 2; stride = 2; padding = 0.</p>","<h3>To find</h3>","<p>The shared output shape and each of the four cells for each pooling method.</p>","<h3>Formula — which one and why</h3>","<p>Each output summarizes four input numbers. Use max for the largest, min for the smallest, and sum divided by 4 for the average. The window moves two cells, so these four windows do not overlap.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/208abbe18f11b701.svg\" alt=\"y_{\\max}=\\max(x_1,x_2,x_3,x_4)\" width=\"274.40\" height=\"24.43\" style=\"width:274.40px;height:24.43px;aspect-ratio:274.40/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/619bb1c028de4233.svg\" alt=\"y_{\\min}=\\min(x_1,x_2,x_3,x_4)\" width=\"266.30\" height=\"24.43\" style=\"width:266.30px;height:24.43px;aspect-ratio:266.30/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0dcf475f3132c0a4.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{x_1+x_2+x_3+x_4}{4}\" width=\"271.92\" height=\"47.52\" style=\"width:271.92px;height:47.52px;aspect-ratio:271.92/47.52\" loading=\"lazy\"></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_pooling_windows.svg\" aria-label=\"Enlarge diagram: The four colours identify four separate pooling windows. Each window creates one cell in each output map.\"><img src=\"assets/figures/u4_pooling_windows.svg\" alt=\"The four colours identify four separate pooling windows. Each window creates one cell in each output map.\" width=\"900\" height=\"425\" loading=\"lazy\"></button><figcaption>The four colours identify four separate pooling windows. Each window creates one cell in each output map. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: output size.</strong> (4 −2)/2 +1 = 2. Each output has shape 2 × 2.</p>","<p class=\"worked-step\"><strong>Step 2: top-left window [12,20,8,12].</strong> Largest = 20; smallest = 8. Sum = 12+20+8+12 = 52. Average = 52/4 = 13.</p>","<p class=\"worked-step\"><strong>Step 3: top-right window [30,0,2,0].</strong> Largest = 30; smallest = 0. Sum = 30+0+2+0 = 32. Average = 32/4 = 8.</p>","<p class=\"worked-step\"><strong>Step 4: bottom-left window [34,70,112,100].</strong> Largest = 112; smallest = 34. Sum = 34+70+112+100 = 316. Average = 316/4 = 79.</p>","<p class=\"worked-step\"><strong>Step 5: bottom-right window [37,4,25,12].</strong> Largest = 37; smallest = 4. Sum = 37+4+25+12 = 78. Average = 78/4 = <strong>19.5</strong>. Do not silently round this to 20.</p>","<p class=\"worked-step\"><strong>Step 6: put each result back in its window&#x27;s position.</strong> Max = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/63c5529d08234533.svg\" alt=\"\\begin{bmatrix}20 &amp; 30\\\\112 &amp; 37\\end{bmatrix}\" width=\"86.59\" height=\"45.61\" style=\"width:86.59px;height:45.61px;aspect-ratio:86.59/45.61\" loading=\"lazy\"></span>. Min = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/54afd252549c8a81.svg\" alt=\"\\begin{bmatrix}8 &amp; 0\\\\34 &amp; 4\\end{bmatrix}\" width=\"67.58\" height=\"45.61\" style=\"width:67.58px;height:45.61px;aspect-ratio:67.58/45.61\" loading=\"lazy\"></span>. Average = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/7d1100eaf9980bd3.svg\" alt=\"\\begin{bmatrix}13 &amp; 8\\\\79 &amp; 19.5\\end{bmatrix}\" width=\"91.87\" height=\"45.61\" style=\"width:91.87px;height:45.61px;aspect-ratio:91.87/45.61\" loading=\"lazy\"></span>.</p>","<p><strong>Final answer:</strong> Three 2 × 2 maps as above; zero trainable parameters for each pooling operation.</p>","<h3>Why the choice matters</h3>","<p>Max retains the largest activation in a feature window, which can still be negative if every entry is negative. Min retains the lowest response. Average retains an overall response but can dilute a sharp local peak. On raw intensity images, min can retain a dark stroke and max can retain a bright stroke. A learned CNN feature map represents filter responses; the best pooling choice is not determined solely by the original background colour.</p>","<p>Pooling has no parameters to update, but gradients can still pass through it. For a unique max, the upstream gradient is routed to the winning input. For an average over four inputs, each receives one-fourth of that gradient. Fewer pooled activations can reduce a later dense layer&#x27;s parameter count; they do not change the size of an earlier convolution&#x27;s filter.</p>","<p><strong>Yaad rakho:</strong> Max = sabse bada; min = sabse chhota; average = sab jodo, count se divide.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s16","search":"Max, min and average pooling on the same lecture grid **Definition.** Pooling summarizes each local window separately within each channel. Max pooling keeps its largest value, min pooling its smallest value, and average pooling its arithmetic mean. Ordinary versions have no trainable weights or biases.\n\n**Question. Apply 2 × 2 max, min and average pooling with stride 2 and no padding to the following 4 × 4 input. Give all three output matrices. (Practice: 3 marks)**\n\n### Given\nX = . Window = 2 × 2; stride = 2; padding = 0.\n\n### To find\nThe shared output shape and each of the four cells for each pooling method.\n\n### Formula — which one and why\nEach output summarizes four input numbers. Use max for the largest, min for the smallest, and sum divided by 4 for the average. The window moves two cells, so these four windows do not overlap.\n\n\n\n\n\n\n\n### Solution — step by step\n**Step 1: output size.** (4 −2)/2 +1 = 2. Each output has shape 2 × 2.\n\n**Step 2: top-left window [12,20,8,12].** Largest = 20; smallest = 8. Sum = 12+20+8+12 = 52. Average = 52/4 = 13.\n\n**Step 3: top-right window [30,0,2,0].** Largest = 30; smallest = 0. Sum = 30+0+2+0 = 32. Average = 32/4 = 8.\n\n**Step 4: bottom-left window [34,70,112,100].** Largest = 112; smallest = 34. Sum = 34+70+112+100 = 316. Average = 316/4 = 79.\n\n**Step 5: bottom-right window [37,4,25,12].** Largest = 37; smallest = 4. Sum = 37+4+25+12 = 78. Average = 78/4 = **19.5**. Do not silently round this to 20.\n\n**Step 6: put each result back in its window's position.** Max = . Min = . Average = .\n\n**Final answer:** Three 2 × 2 maps as above; zero trainable parameters for each pooling operation.\n\n### Why the choice matters\nMax retains the largest activation in a feature window, which can still be negative if every entry is negative. Min retains the lowest response. Average retains an overall response but can dilute a sharp local peak. On raw intensity images, min can retain a dark stroke and max can retain a bright stroke. A learned CNN feature map represents filter responses; the best pooling choice is not determined solely by the original background colour.\n\nPooling has no parameters to update, but gradients can still pass through it. For a unique max, the upstream gradient is routed to the winning input. For an average over four inputs, each receives one-fourth of that gradient. Fewer pooled activations can reduce a later dense layer's parameter count; they do not change the size of an earlier convolution's filter.\n\n**Yaad rakho:** Max = sabse bada; min = sabse chhota; average = sab jodo, count se divide.\n"},{"title":"Faculty CNN table: shapes, activations and 62958 parameters","blocks":["<p class=\"inline-question\"><strong>Question. A CNN receives a 32 × 32 × 3 image. It uses Conv1: eight 5 × 5 filters, stride 1, no padding; Pool1: 2 × 2, stride 2; Conv2: sixteen 5 × 5 filters, stride 1, no padding; Pool2: 2 × 2, stride 2; flatten; dense 120; dense 84; dense 10 followed by softmax. Include one bias per filter or receiving dense neuron. Find every output shape, activation count and trainable-parameter count. (Practice: 10 marks)</strong></p>","<h3>Given</h3>","<p>Input = 32 × 32 × 3. Both convolutions are ordinary full-channel convolutions. Pooling has no padding. Dense widths are 120, 84 and 10. No batch-normalization layer is present in this particular question.</p>","<h3>To find</h3>","<p>Output shape and number of output values for each layer, its trainable parameters, and the total parameters.</p>","<h3>Formula — which one and why</h3>","<p>Use the spatial-size formula for each convolution/pool. Use one full-depth kernel plus one bias per convolutional filter. Flattening counts all remaining values before the first dense layer. Each dense neuron then receives one weight per input plus one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c9b86a3e71336c4.svg\" alt=\"A=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}\" width=\"192.74\" height=\"21.35\" style=\"width:192.74px;height:21.35px;aspect-ratio:192.74/21.35\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<p>A counts produced activations. P_conv and P_dense count independent learned coefficients. They are not the same quantity. Pooling, flattening and softmax itself add zero learned parameters here.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: input.</strong> Shape = 32 × 32 × 3. Values = 32×32×3 = 3,072. Trainable parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 2: Conv1 spatial size.</strong> (32−5)/1 +1 = 28. Eight filters give shape 28 × 28 × 8. Activations = 28×28×8 = 6,272.</p>","<p class=\"worked-step\"><strong>Step 3: Conv1 parameters.</strong> One filter contains 5×5×3 = 75 weights. Add one bias: 76. Multiply by eight filters: 76×8 = <strong>608</strong>.</p>","<p class=\"worked-step\"><strong>Step 4: Pool1.</strong> (28−2)/2 +1 = 14. Shape = 14 × 14 × 8. Activations = 14×14×8 = 1,568. Parameters = 0; channel count remains eight.</p>","<p class=\"worked-step\"><strong>Step 5: Conv2 spatial size.</strong> (14−5)/1 +1 = 10. Sixteen filters give shape 10 × 10 × 16. Activations = 1,600.</p>","<p class=\"worked-step\"><strong>Step 6: Conv2 parameters.</strong> Its input has <strong>eight</strong> channels. Each filter has 5×5×8 = 200 weights, then one bias. Total = 201×16 = <strong>3,216</strong>.</p>","<p class=\"worked-step\"><strong>Step 7: Pool2 and flatten.</strong> (10−2)/2 +1 = 5. Pool shape = 5 × 5 × 16. Flattened length = 5×5×16 = <strong>400</strong>. Neither operation adds parameters.</p>","<p class=\"worked-step\"><strong>Step 8: dense 120.</strong> Weights = 400×120 = 48,000. Biases = 120. Parameters = <strong>48,120</strong>. Output contains 120 activations.</p>","<p class=\"worked-step\"><strong>Step 9: dense 84.</strong> Weights = 120×84 = 10,080. Biases = 84. Parameters = <strong>10,164</strong>. Output contains 84 activations.</p>","<p class=\"worked-step\"><strong>Step 10: dense 10 and softmax.</strong> Weights = 84×10 = 840. Biases = 10. Dense parameters = <strong>850</strong>. Softmax converts the ten logits into ten probabilities and adds <strong>zero</strong> parameters. A table naming the combined classifier row “Softmax” attributes these 850 parameters to its preceding dense transformation.</p>","<p class=\"worked-step\"><strong>Step 11: add only the trainable counts.</strong> 608+3,216 = 3,824; +48,120 = 51,944; +10,164 = 62,108; +850 = <strong>62,958</strong>.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Output shape</th><th>Activations</th><th>Parameters</th></tr></thead><tbody><tr><td>Input</td><td>32 × 32 × 3</td><td>3,072</td><td>0</td></tr><tr><td>Conv1</td><td>28 × 28 × 8</td><td>6,272</td><td>608</td></tr><tr><td>Pool1</td><td>14 × 14 × 8</td><td>1,568</td><td>0</td></tr><tr><td>Conv2</td><td>10 × 10 × 16</td><td>1,600</td><td>3,216</td></tr><tr><td>Pool2 / flatten</td><td>5 × 5 × 16 / 400</td><td>400</td><td>0</td></tr><tr><td>Dense 120</td><td>120</td><td>120</td><td>48,120</td></tr><tr><td>Dense 84</td><td>84</td><td>84</td><td>10,164</td></tr><tr><td>Dense 10 → softmax</td><td>10</td><td>10</td><td>850 + 0</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> The network has <strong>62,958 trainable parameters</strong>. This is the specified classroom CNN, not a universal parameter total for every LeNet-like network.</p>","<p><strong>Yaad rakho:</strong> Shape aage carry karo; weights aur activations ko alag columns mein rakho.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s17","search":"Faculty CNN table: shapes, activations and 62958 parameters **Question. A CNN receives a 32 × 32 × 3 image. It uses Conv1: eight 5 × 5 filters, stride 1, no padding; Pool1: 2 × 2, stride 2; Conv2: sixteen 5 × 5 filters, stride 1, no padding; Pool2: 2 × 2, stride 2; flatten; dense 120; dense 84; dense 10 followed by softmax. Include one bias per filter or receiving dense neuron. Find every output shape, activation count and trainable-parameter count. (Practice: 10 marks)**\n\n### Given\nInput = 32 × 32 × 3. Both convolutions are ordinary full-channel convolutions. Pooling has no padding. Dense widths are 120, 84 and 10. No batch-normalization layer is present in this particular question.\n\n### To find\nOutput shape and number of output values for each layer, its trainable parameters, and the total parameters.\n\n### Formula — which one and why\nUse the spatial-size formula for each convolution/pool. Use one full-depth kernel plus one bias per convolutional filter. Flattening counts all remaining values before the first dense layer. Each dense neuron then receives one weight per input plus one bias.\n\n\n\n\n\n\nA counts produced activations. P_conv and P_dense count independent learned coefficients. They are not the same quantity. Pooling, flattening and softmax itself add zero learned parameters here.\n\n### Solution — step by step\n**Step 1: input.** Shape = 32 × 32 × 3. Values = 32×32×3 = 3,072. Trainable parameters = 0.\n\n**Step 2: Conv1 spatial size.** (32−5)/1 +1 = 28. Eight filters give shape 28 × 28 × 8. Activations = 28×28×8 = 6,272.\n\n**Step 3: Conv1 parameters.** One filter contains 5×5×3 = 75 weights. Add one bias: 76. Multiply by eight filters: 76×8 = **608**.\n\n**Step 4: Pool1.** (28−2)/2 +1 = 14. Shape = 14 × 14 × 8. Activations = 14×14×8 = 1,568. Parameters = 0; channel count remains eight.\n\n**Step 5: Conv2 spatial size.** (14−5)/1 +1 = 10. Sixteen filters give shape 10 × 10 × 16. Activations = 1,600.\n\n**Step 6: Conv2 parameters.** Its input has **eight** channels. Each filter has 5×5×8 = 200 weights, then one bias. Total = 201×16 = **3,216**.\n\n**Step 7: Pool2 and flatten.** (10−2)/2 +1 = 5. Pool shape = 5 × 5 × 16. Flattened length = 5×5×16 = **400**. Neither operation adds parameters.\n\n**Step 8: dense 120.** Weights = 400×120 = 48,000. Biases = 120. Parameters = **48,120**. Output contains 120 activations.\n\n**Step 9: dense 84.** Weights = 120×84 = 10,080. Biases = 84. Parameters = **10,164**. Output contains 84 activations.\n\n**Step 10: dense 10 and softmax.** Weights = 84×10 = 840. Biases = 10. Dense parameters = **850**. Softmax converts the ten logits into ten probabilities and adds **zero** parameters. A table naming the combined classifier row “Softmax” attributes these 850 parameters to its preceding dense transformation.\n\n**Step 11: add only the trainable counts.** 608+3,216 = 3,824; +48,120 = 51,944; +10,164 = 62,108; +850 = **62,958**.\n\n| Layer | Output shape | Activations | Parameters |\n|---|---|---|---|\n| Input | 32 × 32 × 3 | 3,072 | 0 |\n| Conv1 | 28 × 28 × 8 | 6,272 | 608 |\n| Pool1 | 14 × 14 × 8 | 1,568 | 0 |\n| Conv2 | 10 × 10 × 16 | 1,600 | 3,216 |\n| Pool2 / flatten | 5 × 5 × 16 / 400 | 400 | 0 |\n| Dense 120 | 120 | 120 | 48,120 |\n| Dense 84 | 84 | 84 | 10,164 |\n| Dense 10 → softmax | 10 | 10 | 850 + 0 |\n\n**Final answer:** The network has **62,958 trainable parameters**. This is the specified classroom CNN, not a universal parameter total for every LeNet-like network.\n\n**Yaad rakho:** Shape aage carry karo; weights aur activati"},{"title":"Even-sized kernels: SAME padding is not always symmetric","blocks":["<p class=\"definition\"><strong>Definition.</strong> A numerical padding value specifies how many entries to add at each boundary. SAME is an output-size convention. At stride 1, SAME preserves height and width; an even-sized kernel can require unequal padding on opposite sides.</p>","<p>For a 2 by 2 kernel at stride 1, preserving the input size requires <strong>one padding entry in total per axis</strong>, not one on each side. For example, add no row above and one row below, and no column on the left and one on the right. Reversing which side receives the extra entry preserves the output size too, but changes which input cells contribute at each output location; follow the question&#x27;s convention.</p>","<p><strong>Hinglish cue:</strong> P = 1 means dono taraf ek; SAME means output ka size bachao. Dono instructions ko same mat samjho.</p>","<h3>Example 1: one entry on every side</h3>","<p class=\"inline-question\"><strong>Question. A 5 × 5 single-channel input is processed by one 2 × 2 convolution filter. The stride is 1. Exactly one zero is padded on each of the four sides. Find the padded-input size and output size. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>Input height and width N = 5; kernel size K = 2; stride S = 1; padding P = 1 on each side; dilation = 1; one output filter.</p>","<h3>To find</h3>","<p>The padded input dimensions and the convolution output dimensions.</p>","<h3>Formula — which one and why</h3>","<p>The two opposite borders contribute P entries each. The output formula counts complete filter placements after padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6bbc5ec5f7e71fe.svg\" alt=\"N_{\\mathrm{padded}}=N+2P\" width=\"191.11\" height=\"23.71\" style=\"width:191.11px;height:23.71px;aspect-ratio:191.11/23.71\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is one input dimension; P is padding on each side; K is kernel size; S is stride. Apply the same calculation separately to height and width. One filter produces one output channel.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count the two padding borders.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/741118212eb25f73.svg\" alt=\"2P=2(1)=2\" width=\"151.39\" height=\"24.43\" style=\"width:151.39px;height:24.43px;aspect-ratio:151.39/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: find the padded side length.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e288268af2ced78c.svg\" alt=\"N_{\\mathrm{padded}}=5+2=7\" width=\"208.07\" height=\"23.71\" style=\"width:208.07px;height:23.71px;aspect-ratio:208.07/23.71\" loading=\"lazy\"></div>","<p>The padded input is 7 × 7 × 1.</p>","<p class=\"worked-step\"><strong>Step 3: subtract the kernel size.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b07e3025ba7ec8bf.svg\" alt=\"7-2=5\" width=\"99.10\" height=\"18.52\" style=\"width:99.10px;height:18.52px;aspect-ratio:99.10/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide by stride, take the floor and count the first placement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c9e9b01d59dde654.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{5}{1}\\right\\rfloor+1=5+1=6\" width=\"304.44\" height=\"58.62\" style=\"width:304.44px;height:58.62px;aspect-ratio:304.44/58.62\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: write height, width and channels.</strong></p>","<p>Both spatial dimensions equal 6. There is one filter, so there is one output channel.</p>","<p><strong>Final answer:</strong> padded input = <strong>7 × 7 × 1</strong>; output = <strong>6 × 6 × 1</strong>. This explicitly specified padding does not implement SAME for this even kernel.</p>","<h3>Example 2: preserve the size with SAME padding</h3>","<p class=\"inline-question\"><strong>Question. The same 5 × 5 single-channel input is processed by one 2 × 2 convolution filter with stride 1 and SAME padding. Find the total padding required along each axis and the output size. Use zero padding above and to the left, with any required extra padding below and to the right. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>Input side N = 5; kernel side K = 2; stride S = 1; desired output side Nout = 5; dilation = 1; one filter. Padding before the input is 0; padding after the input must be found.</p>","<h3>To find</h3>","<p>Padding above, below, left and right; padded-input shape; final output shape.</p>","<h3>Formula — which one and why</h3>","<p>For unequal padding, replace 2P by the sum of the before and after padding. Pbefore and Pafter are the entries added on the two opposite sides of one axis.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fb9e63f94b876bf.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+P_{\\mathrm{before}}+P_{\\mathrm{after}}-K}{S}\\right\\rfloor+1\" width=\"409.73\" height=\"58.62\" style=\"width:409.73px;height:58.62px;aspect-ratio:409.73/58.62\" loading=\"lazy\"></div>","<p>At stride 1, the quantities are integers. To keep Nout = N, the total padding must equal K − 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9c76650bca9e58b.svg\" alt=\"P_{\\mathrm{total}}=P_{\\mathrm{before}}+P_{\\mathrm{after}}=K-1\" width=\"328.26\" height=\"20.54\" style=\"width:328.26px;height:20.54px;aspect-ratio:328.26/20.54\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate total padding along the height.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebca391be173fb93.svg\" alt=\"P_{\\mathrm{total}}=2-1=1\" width=\"184.93\" height=\"20.54\" style=\"width:184.93px;height:20.54px;aspect-ratio:184.93/20.54\" loading=\"lazy\"></div>","<p>Only one extra row in total is needed.</p>","<p class=\"worked-step\"><strong>Step 2: place the row using the stated convention.</strong></p>","<p>Padding above = 0; padding below = 1.</p>","<p class=\"worked-step\"><strong>Step 3: apply the same calculation to width.</strong></p>","<p>Only one extra column in total is needed. Padding left = 0; padding right = 1.</p>","<p class=\"worked-step\"><strong>Step 4: find the padded-input shape.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bd37f3052feb0554.svg\" alt=\"H_{\\mathrm{padded}}=5+0+1=6\" width=\"250.85\" height=\"23.71\" style=\"width:250.85px;height:23.71px;aspect-ratio:250.85/23.71\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ab52e1fac6848205.svg\" alt=\"W_{\\mathrm{padded}}=5+0+1=6\" width=\"253.61\" height=\"23.71\" style=\"width:253.61px;height:23.71px;aspect-ratio:253.61/23.71\" loading=\"lazy\"></div>","<p>The padded input is 6 × 6 × 1.</p>","<p class=\"worked-step\"><strong>Step 5: count the output positions along each axis.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9a5597c2b0d54bcf.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{5+0+1-2}{1}\\right\\rfloor+1=4+1=5\" width=\"430.69\" height=\"58.62\" style=\"width:430.69px;height:58.62px;aspect-ratio:430.69/58.62\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: include the output channel.</strong></p>","<p>One filter creates one output channel.</p>","<p><strong>Final answer:</strong> add <strong>0 above, 1 below, 0 left and 1 right</strong>; padded input = <strong>6 × 6 × 1</strong>; output = <strong>5 × 5 × 1</strong>.</p>","<p>The two questions have the same input and kernel but different padding instructions. Read the stated boundary padding before applying the formula.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c7-s18","search":"Even-sized kernels: SAME padding is not always symmetric \n**Definition.** A numerical padding value specifies how many entries to add at each boundary. SAME is an output-size convention. At stride 1, SAME preserves height and width; an even-sized kernel can require unequal padding on opposite sides.\n\nFor a 2 by 2 kernel at stride 1, preserving the input size requires **one padding entry in total per axis**, not one on each side. For example, add no row above and one row below, and no column on the left and one on the right. Reversing which side receives the extra entry preserves the output size too, but changes which input cells contribute at each output location; follow the question's convention.\n\n**Hinglish cue:** P = 1 means dono taraf ek; SAME means output ka size bachao. Dono instructions ko same mat samjho.\n\n### Example 1: one entry on every side\n\n**Question. A 5 × 5 single-channel input is processed by one 2 × 2 convolution filter. The stride is 1. Exactly one zero is padded on each of the four sides. Find the padded-input size and output size. (Practice: 3 marks)**\n\n### Given\n\nInput height and width N = 5; kernel size K = 2; stride S = 1; padding P = 1 on each side; dilation = 1; one output filter.\n\n### To find\n\nThe padded input dimensions and the convolution output dimensions.\n\n### Formula — which one and why\n\nThe two opposite borders contribute P entries each. The output formula counts complete filter placements after padding.\n\n\n\n\n\nN is one input dimension; P is padding on each side; K is kernel size; S is stride. Apply the same calculation separately to height and width. One filter produces one output channel.\n\n### Solution — step by step\n\n**Step 1: count the two padding borders.**\n\n\n\n**Step 2: find the padded side length.**\n\n\n\nThe padded input is 7 × 7 × 1.\n\n**Step 3: subtract the kernel size.**\n\n\n\n**Step 4: divide by stride, take the floor and count the first placement.**\n\n\n\n**Step 5: write height, width and channels.**\n\nBoth spatial dimensions equal 6. There is one filter, so there is one output channel.\n\n**Final answer:** padded input = **7 × 7 × 1**; output = **6 × 6 × 1**. This explicitly specified padding does not implement SAME for this even kernel.\n\n### Example 2: preserve the size with SAME padding\n\n**Question. The same 5 × 5 single-channel input is processed by one 2 × 2 convolution filter with stride 1 and SAME padding. Find the total padding required along each axis and the output size. Use zero padding above and to the left, with any required extra padding below and to the right. (Practice: 3 marks)**\n\n### Given\n\nInput side N = 5; kernel side K = 2; stride S = 1; desired output side Nout = 5; dilation = 1; one filter. Padding before the input is 0; padding after the input must be found.\n\n### To find\n\nPadding above, below, left and right; padded-input shape; final output shape.\n\n### Formula — which one and why\n\nFor unequal padding, replace 2P by the sum of the before and after padding. Pbefore and Pafter are the entries added on the two opposite sides of one axis.\n\n\n\nAt stride 1, the quantities are integers. To keep Nout = N, the total padding must equal K − 1.\n\n\n\n### Solution — step by step\n\n**Step 1: calculate total padding along the height.**\n\n\n\nOnly one extra row in total is needed.\n\n**Step 2: place the row using the stated convention.**\n\nPadding above = 0; padding below = 1.\n\n**Step 3: apply the same calculation to width.**\n\nOnly one extra column in total is needed. Padding left = 0; padding right = 1.\n\n**St"}]},{"n":8,"title":"CNN architectures and transfer learning","sections":[{"title":"AlexNet and the reason for its components","blocks":["<p class=\"definition\"><strong>Definition.</strong> AlexNet is a deep convolutional architecture introduced for ImageNet classification, conventionally described as five convolutional layers followed by three fully connected layers. Its historical significance is the effective combination of learned convolutional features, nonlinear activations, GPU training and regularization at large scale.</p>","<h3>Architecture and information flow</h3>","<p>Input image → convolution and ReLU stages → spatial pooling → fully connected representations → class scores and softmax. The original model used local response normalization in selected early stages and overlapping max pooling. Grouped computation across two GPUs was part of the original implementation. Exact sizes must follow the architecture specified in an examination question.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/alexnet.svg\" aria-label=\"Enlarge diagram: Convolution extracts representations before the fully connected classification stages.\"><img src=\"assets/figures/alexnet.svg\" alt=\"Convolution extracts representations before the fully connected classification stages.\" width=\"960\" height=\"480\" loading=\"lazy\"></button><figcaption>Convolution extracts representations before the fully connected classification stages. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Role of the components</h3>","<p><strong>ReLU</strong> supplies a nonlinear transformation and avoids sigmoid-style saturation for positive preactivations. <strong>Convolution</strong> uses local connectivity and spatial weight sharing. <strong>Pooling</strong> reduces spatial dimensions and increases tolerance to small local changes. <strong>Dropout</strong> regularizes the fully connected layers. <strong>Data augmentation</strong> supplies transformed training examples to reduce dependence on a fixed view. These components perform different jobs and should not be described as interchangeable methods of reducing overfitting.</p>","<h3>Limitations and exam distinction</h3>","<p>The dense layers contribute a large number of parameters; the model has substantial memory and computation requirements. AlexNet is much shallower than later residual architectures. Its original use of local response normalization is different from batch normalization. For a comparison answer, identify its sequential convolutional design, then contrast it with Inception&#x27;s parallel branches and ResNet&#x27;s residual addition.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s0","search":"AlexNet and the reason for its components **Definition.** AlexNet is a deep convolutional architecture introduced for ImageNet classification, conventionally described as five convolutional layers followed by three fully connected layers. Its historical significance is the effective combination of learned convolutional features, nonlinear activations, GPU training and regularization at large scale.\n\n### Architecture and information flow\nInput image → convolution and ReLU stages → spatial pooling → fully connected representations → class scores and softmax. The original model used local response normalization in selected early stages and overlapping max pooling. Grouped computation across two GPUs was part of the original implementation. Exact sizes must follow the architecture specified in an examination question.\n\n\n\n### Role of the components\n**ReLU** supplies a nonlinear transformation and avoids sigmoid-style saturation for positive preactivations. **Convolution** uses local connectivity and spatial weight sharing. **Pooling** reduces spatial dimensions and increases tolerance to small local changes. **Dropout** regularizes the fully connected layers. **Data augmentation** supplies transformed training examples to reduce dependence on a fixed view. These components perform different jobs and should not be described as interchangeable methods of reducing overfitting.\n\n### Limitations and exam distinction\nThe dense layers contribute a large number of parameters; the model has substantial memory and computation requirements. AlexNet is much shallower than later residual architectures. Its original use of local response normalization is different from batch normalization. For a comparison answer, identify its sequential convolutional design, then contrast it with Inception's parallel branches and ResNet's residual addition.\n"},{"title":"Inception examines several spatial scales","blocks":["<p class=\"definition\"><strong>Definition.</strong> An Inception module is a convolutional building block that processes the same input through parallel branches using different receptive-field operations and concatenates their output feature maps along the channel dimension.</p>","<h3>Structure and working</h3>","<p>A conventional early Inception module includes 1 × 1, 3 × 3 and 5 × 5 convolution branches and a pooling branch. Suitable stride and padding preserve compatible spatial dimensions. The branch outputs are then concatenated. If branch channel counts are c₁, c₂, c₃ and c₄, the output depth is c₁ + c₂ + c₃ + c₄.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Branches operate on the same input. Matching spatial outputs are joined along the channel axis.\"><img src=\"assets/figures/inception.svg\" alt=\"Branches operate on the same input. Matching spatial outputs are joined along the channel axis.\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Branches operate on the same input. Matching spatial outputs are joined along the channel axis. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Why use several branches?</h3>","<p>Different branch receptive fields can capture patterns at different spatial scales. A 1 × 1 convolution mixes channel information at each position. Before an expensive larger kernel, it can reduce the number of input channels and therefore the parameter count and multiplication cost. The bottleneck calculation is developed in the following section.</p>","<h3>Concatenation is not addition</h3>","<p>Concatenation increases channel depth and retains each branch&#x27;s feature maps separately. Elementwise addition requires equal shapes and combines corresponding values. Inception commonly uses concatenation; a standard residual block uses addition. A question giving branch sizes tests this distinction as well as the convolution formula.</p>","<p>Early Inception designs reduce reliance on a large fully connected classifier through global average pooling. The parallel design still needs compatible branch shapes and carefully chosen channel widths; increasing the number of branches or filters increases computation.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s1","search":"Inception examines several spatial scales **Definition.** An Inception module is a convolutional building block that processes the same input through parallel branches using different receptive-field operations and concatenates their output feature maps along the channel dimension.\n\n### Structure and working\nA conventional early Inception module includes 1 × 1, 3 × 3 and 5 × 5 convolution branches and a pooling branch. Suitable stride and padding preserve compatible spatial dimensions. The branch outputs are then concatenated. If branch channel counts are c₁, c₂, c₃ and c₄, the output depth is c₁ + c₂ + c₃ + c₄.\n\n\n\n### Why use several branches?\nDifferent branch receptive fields can capture patterns at different spatial scales. A 1 × 1 convolution mixes channel information at each position. Before an expensive larger kernel, it can reduce the number of input channels and therefore the parameter count and multiplication cost. The bottleneck calculation is developed in the following section.\n\n### Concatenation is not addition\nConcatenation increases channel depth and retains each branch's feature maps separately. Elementwise addition requires equal shapes and combines corresponding values. Inception commonly uses concatenation; a standard residual block uses addition. A question giving branch sizes tests this distinction as well as the convolution formula.\n\nEarly Inception designs reduce reliance on a large fully connected classifier through global average pooling. The parallel design still needs compatible branch shapes and carefully chosen channel widths; increasing the number of branches or filters increases computation.\n"},{"title":"Why one by one convolution saves work","blocks":["<p class=\"definition\"><strong>Definition.</strong> A 1 × 1 convolution combines the input channels independently at each spatial location. A bottleneck uses fewer output channels before a larger spatial convolution, reducing its parameter and multiplication counts.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bottleneck.svg\" aria-label=\"Enlarge diagram: Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size.\"><img src=\"assets/figures/v_bottleneck.svg\" alt=\"Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size.\" width=\"1080\" height=\"790\" loading=\"lazy\"></button><figcaption>Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question. Input is 28 × 28 × 192. Compare a direct same-padded 5 × 5 convolution with 32 filters against a 1 × 1 reduction to 16 channels followed by the same 5 × 5 convolution. Count MACs and ignore bias additions.</strong></p>","<h3>Given</h3>","<p>Both paths produce 28 × 28 × 32. The direct layer receives 192 channels; the bottleneck&#x27;s spatial layer receives 16 channels. Stride is 1 and padding preserves spatial size.</p>","<h3>To find</h3>","<p>Direct MACs, total two-stage bottleneck MACs and percentage saved.</p>","<h3>Formula — which one and why</h3>","<p>Each output scalar uses one product per input-channel kernel entry. Multiply that cost by the number of output positions and channels. The two bottleneck layers require separate counts, which are added.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<p>One MAC counts one multiply–accumulate pair. A convention counting multiplication and addition separately gives approximately twice as many FLOPs.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: direct layer.</strong> Each output uses 5 × 5 × 192 = 4,800 products. There are 28 × 28 × 32 = 25,088 outputs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f08b61aa51f8fc4.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=25088(4800)=120422400\" width=\"417.37\" height=\"24.43\" style=\"width:417.37px;height:24.43px;aspect-ratio:417.37/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: 1 × 1 reduction.</strong> There are 16 receiving filters, each spanning all 192 original channels.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aaefb7a933a188a0.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=28(28)(16)(192)=2408448\" width=\"418.42\" height=\"24.43\" style=\"width:418.42px;height:24.43px;aspect-ratio:418.42/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: reduced-depth spatial layer.</strong> Its 32 filters now span 16 channels.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6f81bb572b38322.svg\" alt=\"\\mathrm{MACs}_{5\\times5}=28(28)(32)(25)(16)=10035200\" width=\"461.86\" height=\"24.43\" style=\"width:461.86px;height:24.43px;aspect-ratio:461.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the two bottleneck costs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3917ad1b6a4cc0eb.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=2408448+10035200=12443648\" width=\"524.30\" height=\"21.35\" style=\"width:524.30px;height:21.35px;aspect-ratio:524.30/21.35\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the saving.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe529a7c8d14263e.svg\" alt=\"\\mathrm{saving}=120422400-12443648=107978752\" width=\"480.03\" height=\"21.58\" style=\"width:480.03px;height:21.58px;aspect-ratio:480.03/21.58\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e22e38a0d749a968.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{107978752}{120422400}\\approx89.666667\\%\" width=\"534.95\" height=\"50.34\" style=\"width:534.95px;height:50.34px;aspect-ratio:534.95/50.34\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> direct = 120,422,400 MACs; bottleneck = 12,443,648 MACs, saving about 89.67%. Spatial size is unchanged; the saving comes from reducing the channels entering the expensive 5 × 5 layer. If the reduction width is not supplied, use a symbol for it and label any numerical choice as an assumption.</p>","<h3>A second bottleneck with different dimensions</h3>","<p class=\"inline-question\"><strong>Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with a 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.</strong></p>","<h3>Given</h3>","<p>Spatial output = 8 × 8; original channels = 16; final filters = 8; bottleneck channels = 4; stride = 1.</p>","<h3>To find</h3>","<p>Direct MACs, bottleneck MACs and saving.</p>","<h3>Formula — which one and why</h3>","<p>Use the same MAC formula above once for the direct path and once for each bottleneck stage. Every branch must include all of its layers.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: direct spatial convolution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dffc8608ebe7e697.svg\" alt=\"8(8)(8)(3)(3)(16)=73728\" width=\"274.24\" height=\"24.43\" style=\"width:274.24px;height:24.43px;aspect-ratio:274.24/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: 1 × 1 reduction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbfbed2568dc51ee.svg\" alt=\"8(8)(4)(1)(1)(16)=4096\" width=\"262.02\" height=\"24.43\" style=\"width:262.02px;height:24.43px;aspect-ratio:262.02/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: reduced-depth 3 × 3 convolution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60dc7f05c85051f9.svg\" alt=\"8(8)(8)(3)(3)(4)=18432\" width=\"262.02\" height=\"24.43\" style=\"width:262.02px;height:24.43px;aspect-ratio:262.02/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the stages and subtract from the direct cost.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4821e959cb7a516.svg\" alt=\"4096+18432=22528\" width=\"233.50\" height=\"18.54\" style=\"width:233.50px;height:18.54px;aspect-ratio:233.50/18.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be3a4d13f46b02ba.svg\" alt=\"73728-22528=51200\" width=\"245.71\" height=\"18.52\" style=\"width:245.71px;height:18.52px;aspect-ratio:245.71/18.52\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> direct = 73,728 MACs; bottleneck = 22,528 MACs; saving = 51,200 MACs, about 69.44%. Both paths produce 8 × 8 × 8, but they are different learned transformations and need not produce identical feature values.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s2","search":"Why one by one convolution saves work **Definition.** A 1 × 1 convolution combines the input channels independently at each spatial location. A bottleneck uses fewer output channels before a larger spatial convolution, reducing its parameter and multiplication counts.\n\n\n\n**Question. Input is 28 × 28 × 192. Compare a direct same-padded 5 × 5 convolution with 32 filters against a 1 × 1 reduction to 16 channels followed by the same 5 × 5 convolution. Count MACs and ignore bias additions.**\n\n### Given\nBoth paths produce 28 × 28 × 32. The direct layer receives 192 channels; the bottleneck's spatial layer receives 16 channels. Stride is 1 and padding preserves spatial size.\n\n### To find\nDirect MACs, total two-stage bottleneck MACs and percentage saved.\n\n### Formula — which one and why\nEach output scalar uses one product per input-channel kernel entry. Multiply that cost by the number of output positions and channels. The two bottleneck layers require separate counts, which are added.\n\nOne MAC counts one multiply–accumulate pair. A convention counting multiplication and addition separately gives approximately twice as many FLOPs.\n\n### Solution — step by step\n**Step 1: direct layer.** Each output uses 5 × 5 × 192 = 4,800 products. There are 28 × 28 × 32 = 25,088 outputs.\n\n\n**Step 2: 1 × 1 reduction.** There are 16 receiving filters, each spanning all 192 original channels.\n\n\n**Step 3: reduced-depth spatial layer.** Its 32 filters now span 16 channels.\n\n\n**Step 4: add the two bottleneck costs.**\n\n\n**Step 5: calculate the saving.**\n\n\n\n**Final answer:** direct = 120,422,400 MACs; bottleneck = 12,443,648 MACs, saving about 89.67%. Spatial size is unchanged; the saving comes from reducing the channels entering the expensive 5 × 5 layer. If the reduction width is not supplied, use a symbol for it and label any numerical choice as an assumption.\n\n### A second bottleneck with different dimensions\n**Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with a 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.**\n\n### Given\nSpatial output = 8 × 8; original channels = 16; final filters = 8; bottleneck channels = 4; stride = 1.\n\n### To find\nDirect MACs, bottleneck MACs and saving.\n\n### Formula — which one and why\nUse the same MAC formula above once for the direct path and once for each bottleneck stage. Every branch must include all of its layers.\n\n### Solution — step by step\n**Step 1: direct spatial convolution.**\n\n\n**Step 2: 1 × 1 reduction.**\n\n\n**Step 3: reduced-depth 3 × 3 convolution.**\n\n\n**Step 4: add the stages and subtract from the direct cost.**\n\n\n**Final answer:** direct = 73,728 MACs; bottleneck = 22,528 MACs; saving = 51,200 MACs, about 69.44%. Both paths produce 8 × 8 × 8, but they are different learned transformations and need not produce identical feature values.\n"},{"title":"ResNet adds a shortcut","blocks":["<p class=\"definition\"><strong>Definition.</strong> A residual network uses shortcut connections to learn a residual mapping relative to a block&#x27;s input. A basic residual block adds the block transformation F(x) to a shortcut representation of x.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d9d34020eaab826.svg\" alt=\"y=F(x)+x\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div>","<p>If the desired mapping is H(x), the residual branch represents F(x) = H(x) − x. When the useful mapping is close to identity, a small residual can be easier to optimize than reconstructing identity through the entire branch.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The two paths must have equal output shape before elementwise addition.\"><img src=\"assets/figures/residual.svg\" alt=\"The two paths must have equal output shape before elementwise addition.\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The two paths must have equal output shape before elementwise addition. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Effect on gradient propagation</h3>","<p>For the identity-shortcut formulation, the derivative includes a direct identity contribution.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/505f1041667e53bb.svg\" alt=\"\\frac{\\partial y}{\\partial x}=\\frac{\\partial F}{\\partial x}+I\" width=\"156.21\" height=\"51.29\" style=\"width:156.21px;height:51.29px;aspect-ratio:156.21/51.29\" loading=\"lazy\"></div>","<p>This provides a path for information and derivatives that does not require passing through every weight layer in the residual branch. It helps optimize deep networks and addresses the degradation problem. It does not imply that every possible ResNet is immune to vanishing gradients.</p>","<h3>Projection when dimensions differ</h3>","<p>If channels or spatial dimensions change, use a projection shortcut, often a 1 × 1 convolution with suitable stride.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ffeadda67cc02f9.svg\" alt=\"y=F(x)+W_sx\" width=\"172.89\" height=\"24.43\" style=\"width:172.89px;height:24.43px;aspect-ratio:172.89/24.43\" loading=\"lazy\"></div>","<p>An identity shortcut has no learned parameters. A projection does. For Cᵢ input channels and Cₒ output channels, a biased 1 × 1 projection has CᵢCₒ + Cₒ parameters. The residual branch&#x27;s output must match the projection output for addition.</p>","<p class=\"inline-question\"><strong>Question.</strong> Let x = [1, 2, 3] and F(x) = [0.1, −0.2, 0.3]. Find the residual sum.</p>","<h3>Given</h3>","<p>x = [1,2,3]; residual branch F(x) = [0.1,−0.2,0.3].</p>","<h3>To find</h3>","<p>Find the three components of x+F(x).</p>","<h3>Formula — which one and why</h3>","<p><strong>Residual addition.</strong> Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.</p>","<p>x = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec48bb473e2d7934.svg\" alt=\"y=x+F(x)\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position ke numbers add; shape same rehni chahiye.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add the first matching pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/db025849e060d366.svg\" alt=\"1+0.1=1.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the second matching pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ab49a448719b780e.svg\" alt=\"2+(-0.2)=1.8\" width=\"175.14\" height=\"24.43\" style=\"width:175.14px;height:24.43px;aspect-ratio:175.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the third matching pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d117d7aaf6f65395.svg\" alt=\"3+0.3=3.3\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: assemble in the original order.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f3d1f51931e7a8d.svg\" alt=\"y=[1.1,1.8,3.3]\" width=\"173.56\" height=\"24.43\" style=\"width:173.56px;height:24.43px;aspect-ratio:173.56/24.43\" loading=\"lazy\"></div>","<p>The vector length remains 3. Concatenating these vectors would give length 6 and would implement a different operation. Any post-addition activation specified in the architecture is applied after this sum.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s3","search":"ResNet adds a shortcut **Definition.** A residual network uses shortcut connections to learn a residual mapping relative to a block's input. A basic residual block adds the block transformation F(x) to a shortcut representation of x.\n\nIf the desired mapping is H(x), the residual branch represents F(x) = H(x) − x. When the useful mapping is close to identity, a small residual can be easier to optimize than reconstructing identity through the entire branch.\n\n\n\n### Effect on gradient propagation\nFor the identity-shortcut formulation, the derivative includes a direct identity contribution.\n\nThis provides a path for information and derivatives that does not require passing through every weight layer in the residual branch. It helps optimize deep networks and addresses the degradation problem. It does not imply that every possible ResNet is immune to vanishing gradients.\n\n### Projection when dimensions differ\nIf channels or spatial dimensions change, use a projection shortcut, often a 1 × 1 convolution with suitable stride.\n\nAn identity shortcut has no learned parameters. A projection does. For Cᵢ input channels and Cₒ output channels, a biased 1 × 1 projection has CᵢCₒ + Cₒ parameters. The residual branch's output must match the projection output for addition.\n\n**Question.** Let x = [1, 2, 3] and F(x) = [0.1, −0.2, 0.3]. Find the residual sum.\n\n\n\n### Given\n\nx = [1,2,3]; residual branch F(x) = [0.1,−0.2,0.3].\n\n### To find\n\nFind the three components of x+F(x).\n\n### Formula — which one and why\n\n**Residual addition.** Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.\n\nx = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.\n\n\n\n**Yaad rakhne ka cue:** Same position ke numbers add; shape same rehni chahiye.\n\n### Solution — step by step\n\n\n\n\n**Step 1: add the first matching pair.**\n\n\n\n\n\n\n\n**Step 2: add the second matching pair.**\n\n\n\n\n\n\n\n**Step 3: add the third matching pair.**\n\n\n\n\n\n\n\n**Step 4: assemble in the original order.**\n\n\n\n\n\n\n\n\nThe vector length remains 3. Concatenating these vectors would give length 6 and would implement a different operation. Any post-addition activation specified in the architecture is applied after this sum.\n"},{"title":"Transfer learning from a small dataset","blocks":["<p class=\"definition\"><strong>Definition.</strong> Transfer learning reuses representations or parameters learned on a source task to support a target task. With a pretrained neural network, common strategies are fixed feature extraction and fine-tuning selected pretrained layers.</p>","<h3>Explanation and working</h3>","<p>Transfer learning reuses a model or representation learned on one task for a related new task. A pretrained CNN may already detect useful edges, textures and shapes, saving data and training effort.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Full scenario.</strong> Build a face-attendance model with few images per student. Explain a training plan.</p>","<p class=\"worked-step\"><strong>Step 1. Define and split the data.</strong> Collect varied, permitted images and separate training/validation/test by suitable independent captures. Keep duplicates out of different splits. Apply the pretrained model’s required input size and normalization.</p>","<p class=\"worked-step\"><strong>Step 2. Choose a suitable pretrained backbone.</strong> For a course example, use VGG 16 or ResNet as an image-feature extractor. ImageNet-pretrained VGG 16 was trained on ImageNet, not automatically on a face-specific dataset. A face-trained model can be a more task-specific choice if available.</p>","<p class=\"worked-step\"><strong>Step 3. Replace the classifier.</strong> Remove the original class head. Add a new classifier matching the required student classes, or an appropriate embedding-based recognition system if that is the chosen formulation. For the exam classification example, use a softmax head and cross-entropy.</p>","<p class=\"worked-step\"><strong>Step 4. Freeze and train.</strong> Freeze the base weights and train the new head first. Use suitable augmentation, regularization and validation monitoring.</p>","<p class=\"worked-step\"><strong>Step 5. Fine-tune if justified.</strong> Unfreeze selected later layers and train at a smaller learning rate. Early layers may remain frozen. Compare validation performance and restore the best checkpoint.</p>","<p class=\"worked-step\"><strong>Step 6. Evaluate.</strong> Use the held-out test set once for the final estimate. Include unfamiliar faces and a rejection rule if describing a real attendance system; a closed-set classroom example alone does not solve unknown-person recognition.</p>","<p>Feature extraction keeps the backbone fixed. Fine-tuning changes some pretrained weights. Training the entire model from scratch is a third option when enough representative data and compute are available, but it is usually harder for the stated small-dataset scenario.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s4","search":"Transfer learning from a small dataset **Definition.** Transfer learning reuses representations or parameters learned on a source task to support a target task. With a pretrained neural network, common strategies are fixed feature extraction and fine-tuning selected pretrained layers.\n\n### Explanation and working\nTransfer learning reuses a model or representation learned on one task for a related new task. A pretrained CNN may already detect useful edges, textures and shapes, saving data and training effort.\n\n\n\n**Full scenario.** Build a face-attendance model with few images per student. Explain a training plan.\n**Step 1. Define and split the data.** Collect varied, permitted images and separate training/validation/test by suitable independent captures. Keep duplicates out of different splits. Apply the pretrained model’s required input size and normalization.\n**Step 2. Choose a suitable pretrained backbone.** For a course example, use VGG 16 or ResNet as an image-feature extractor. ImageNet-pretrained VGG 16 was trained on ImageNet, not automatically on a face-specific dataset. A face-trained model can be a more task-specific choice if available.\n**Step 3. Replace the classifier.** Remove the original class head. Add a new classifier matching the required student classes, or an appropriate embedding-based recognition system if that is the chosen formulation. For the exam classification example, use a softmax head and cross-entropy.\n**Step 4. Freeze and train.** Freeze the base weights and train the new head first. Use suitable augmentation, regularization and validation monitoring.\n**Step 5. Fine-tune if justified.** Unfreeze selected later layers and train at a smaller learning rate. Early layers may remain frozen. Compare validation performance and restore the best checkpoint.\n**Step 6. Evaluate.** Use the held-out test set once for the final estimate. Include unfamiliar faces and a rejection rule if describing a real attendance system; a closed-set classroom example alone does not solve unknown-person recognition.\nFeature extraction keeps the backbone fixed. Fine-tuning changes some pretrained weights. Training the entire model from scratch is a third option when enough representative data and compute are available, but it is usually harder for the stated small-dataset scenario."},{"title":"Model answer: feature extraction and fine-tuning","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain transfer learning for image classification with limited labeled data. Distinguish feature extraction from fine-tuning and describe the training procedure.</p>"],"answer":["<p>Transfer learning reuses knowledge represented by a model trained on a source task to support a related target task. A pretrained CNN can provide useful visual representations, reducing the target data and training effort needed compared with learning all features from random initialization.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Procedure</h3>","<p>1. Define the target classes and create separate training, validation and test splits. Prevent duplicate or closely related captures from leaking across splits.</p>","<p>2. Choose a suitable pretrained backbone and apply its required input size and preprocessing.</p>","<p>3. Replace the original classifier with a new head whose output count matches the target classes.</p>","<p>4. Freeze the backbone and train the new head. Only the unfrozen parameters receive optimizer updates.</p>","<p>5. If validation results justify it, unfreeze selected later backbone layers and continue training with a suitably smaller learning rate.</p>","<p>6. Select hyperparameters and checkpoints using validation data. Evaluate the selected model on the held-out test set.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Feature extraction</th><th>Fine-tuning</th></tr></thead><tbody><tr><td>Pretrained backbone weights remain fixed</td><td>Some or all selected pretrained weights are updated</td></tr><tr><td>New classifier learns from fixed representations</td><td>Representations can adapt to the target task</td></tr><tr><td>Usually fewer trainable parameters</td><td>Usually more trainable parameters and greater risk of overfitting on a small dataset</td></tr></tbody></table></div>","<p>The benefit depends on how useful the source features are for the target data. Transfer is not guaranteed to help every unrelated task. For a numerical, count all stored parameters separately from the trainable subset; freezing a layer does not delete its weights.</p>"],"kind":"theory","id":"mt2-c8-s5","search":"Model answer: feature extraction and fine-tuning **Question.** Explain transfer learning for image classification with limited labeled data. Distinguish feature extraction from fine-tuning and describe the training procedure.\n\n**Model answer.**\nTransfer learning reuses knowledge represented by a model trained on a source task to support a related target task. A pretrained CNN can provide useful visual representations, reducing the target data and training effort needed compared with learning all features from random initialization.\n\n\n\n\n### Procedure\n1. Define the target classes and create separate training, validation and test splits. Prevent duplicate or closely related captures from leaking across splits.\n2. Choose a suitable pretrained backbone and apply its required input size and preprocessing.\n3. Replace the original classifier with a new head whose output count matches the target classes.\n4. Freeze the backbone and train the new head. Only the unfrozen parameters receive optimizer updates.\n5. If validation results justify it, unfreeze selected later backbone layers and continue training with a suitably smaller learning rate.\n6. Select hyperparameters and checkpoints using validation data. Evaluate the selected model on the held-out test set.\n\n| Feature extraction | Fine-tuning |\n| Pretrained backbone weights remain fixed | Some or all selected pretrained weights are updated |\n| New classifier learns from fixed representations | Representations can adapt to the target task |\n| Usually fewer trainable parameters | Usually more trainable parameters and greater risk of overfitting on a small dataset |\n\nThe benefit depends on how useful the source features are for the target data. Transfer is not guaranteed to help every unrelated task. For a numerical, count all stored parameters separately from the trainable subset; freezing a layer does not delete its weights.\n"},{"title":"How to draw the architecture diagrams","blocks":["<p>For AlexNet, draw a sequence of convolution/pooling stages followed by dense layers and classifier. For Inception, draw four parallel branches and a channel-concatenation join. For ResNet, draw one transformation branch and one shortcut meeting at a plus sign. For transfer learning, draw frozen pretrained base → new trainable head, then mark selected base layers optionally unfrozen for fine-tuning.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_architectures.svg\" aria-label=\"Enlarge diagram: Draw the sequential path, parallel branches or additive shortcut that explains the architecture.\"><img src=\"assets/figures/v_architectures.svg\" alt=\"Draw the sequential path, parallel branches or additive shortcut that explains the architecture.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Draw the sequential path, parallel branches or additive shortcut that explains the architecture. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s6","search":"How to draw the architecture diagrams For AlexNet, draw a sequence of convolution/pooling stages followed by dense layers and classifier. For Inception, draw four parallel branches and a channel-concatenation join. For ResNet, draw one transformation branch and one shortcut meeting at a plus sign. For transfer learning, draw frozen pretrained base → new trainable head, then mark selected base layers optionally unfrozen for fine-tuning.\n\n\n\n\n"},{"title":"Inception concatenation and residual addition","blocks":["<p class=\"definition\"><strong>Definition.</strong> Channel concatenation joins feature tensors while preserving their separate channels. Residual addition sums corresponding entries. These operations impose different shape constraints and produce different output depths.</p>","<h3>Explanation and working</h3>","<p>Concatenation joins feature channels; elementwise addition sums matching entries. They are different operations.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_join_add.svg\" aria-label=\"Enlarge diagram: Concatenation stacks channels. Residual addition combines matching values and preserves the matched shape.\"><img src=\"assets/figures/v_join_add.svg\" alt=\"Concatenation stacks channels. Residual addition combines matching values and preserves the matched shape.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Concatenation stacks channels. Residual addition combines matching values and preserves the matched shape. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Four Inception branches of spatial size 14 × 14 have 16, 32, 8 and 8 channels. First add the channel counts: 16 + 32 = 48; 48 + 8 = 56; 56 + 8 = 64. Height and width stay 14. The concatenated output is 14 × 14 × 64.</p>","<p>A residual addition requires matching shapes. A 14 × 14 × 64 tensor cannot be directly added to a 14 × 14 × 32 tensor. A projection, often a 1 × 1 convolution, can transform one path to the matching shape before addition.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s7","search":"Inception concatenation and residual addition **Definition.** Channel concatenation joins feature tensors while preserving their separate channels. Residual addition sums corresponding entries. These operations impose different shape constraints and produce different output depths.\n\n### Explanation and working\nConcatenation joins feature channels; elementwise addition sums matching entries. They are different operations.\n\n\n\nFour Inception branches of spatial size 14 × 14 have 16, 32, 8 and 8 channels. First add the channel counts: 16 + 32 = 48; 48 + 8 = 56; 56 + 8 = 64. Height and width stay 14. The concatenated output is 14 × 14 × 64.\nA residual addition requires matching shapes. A 14 × 14 × 64 tensor cannot be directly added to a 14 × 14 × 32 tensor. A projection, often a 1 × 1 convolution, can transform one path to the matching shape before addition.\n"},{"title":"Model answer: AlexNet, Inception and ResNet","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare the main ideas of AlexNet, Inception and ResNet. Explain how to recognize their architecture diagrams.</p>"],"answer":["<p>All three are CNN architectures, but their characteristic structures differ.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_architectures.svg\" aria-label=\"Enlarge diagram: Each block illustrates the defining design idea; the full architecture diagrams give its detailed layout.\"><img src=\"assets/figures/v_architectures.svg\" alt=\"Each block illustrates the defining design idea; the full architecture diagrams give its detailed layout.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Each block illustrates the defining design idea; the full architecture diagrams give its detailed layout. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Architecture</th><th>Main idea</th><th>What to show in a diagram</th></tr></thead><tbody><tr><td>AlexNet</td><td>Successive convolutional feature extraction followed by dense classification</td><td>Five convolutional layers and three fully connected layers, with the stated pooling/normalization stages</td></tr><tr><td>Inception v1</td><td>Parallel branches analyze features at different spatial scales</td><td>1 × 1, reduced 3 × 3, reduced 5 × 5 and pooling branches joined by channel concatenation</td></tr><tr><td>ResNet</td><td>Learn a residual transformation and add a shortcut</td><td>A transformation branch and input shortcut meeting at a plus sign</td></tr></tbody></table></div>","<p>AlexNet&#x27;s exam-relevant features include ReLU, GPU-based training, augmentation and dropout in the fully connected part. A parameter calculation must follow the given channel connectivity; a grouped implementation and a simplified fully connected-channel diagram need not have the same count.</p>","<p>Inception uses 1 × 1 convolutions to mix channels and, when a smaller number of filters is chosen, reduce the channel depth before expensive spatial filters. Branch outputs must have compatible height and width for concatenation. Concatenation adds channel counts by joining their lists.</p>","<p>ResNet computes a learned transformation F(x) and combines it with the shortcut:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d30a7ff979462f45.svg\" alt=\"H(x)=F(x)+x\" width=\"182.40\" height=\"24.43\" style=\"width:182.40px;height:24.43px;aspect-ratio:182.40/24.43\" loading=\"lazy\"></div>","<p>This is entrywise addition. The two shapes must match; a projection can adapt a shortcut when they do not. The shortcut supplies an additional route for information and gradients and makes identity-like mappings easy to represent.</p>","<p><strong>Key distinction:</strong> an Inception join concatenates feature maps; a residual join adds corresponding values. Their diagram symbols and output-channel calculations must therefore differ.</p>"],"kind":"theory","id":"mt2-c8-s8","search":"Model answer: AlexNet, Inception and ResNet **Question.** Compare the main ideas of AlexNet, Inception and ResNet. Explain how to recognize their architecture diagrams.\n\n**Model answer.**\nAll three are CNN architectures, but their characteristic structures differ.\n\n\n\n\n| Architecture | Main idea | What to show in a diagram |\n| AlexNet | Successive convolutional feature extraction followed by dense classification | Five convolutional layers and three fully connected layers, with the stated pooling/normalization stages |\n| Inception v1 | Parallel branches analyze features at different spatial scales | 1 × 1, reduced 3 × 3, reduced 5 × 5 and pooling branches joined by channel concatenation |\n| ResNet | Learn a residual transformation and add a shortcut | A transformation branch and input shortcut meeting at a plus sign |\n\nAlexNet's exam-relevant features include ReLU, GPU-based training, augmentation and dropout in the fully connected part. A parameter calculation must follow the given channel connectivity; a grouped implementation and a simplified fully connected-channel diagram need not have the same count.\n\nInception uses 1 × 1 convolutions to mix channels and, when a smaller number of filters is chosen, reduce the channel depth before expensive spatial filters. Branch outputs must have compatible height and width for concatenation. Concatenation adds channel counts by joining their lists.\n\nResNet computes a learned transformation F(x) and combines it with the shortcut:\n\nThis is entrywise addition. The two shapes must match; a projection can adapt a shortcut when they do not. The shortcut supplies an additional route for information and gradients and makes identity-like mappings easy to represent.\n\n**Key distinction:** an Inception join concatenates feature maps; a residual join adds corresponding values. Their diagram symbols and output-channel calculations must therefore differ.\n"},{"title":"Applications of convolutional neural networks","blocks":["<p class=\"definition\"><strong>Definition.</strong> A CNN application combines a convolutional feature extractor with an output head designed for a particular prediction task. Shared local filters learn spatial patterns; the output head determines what is predicted and the loss determines how it is trained.</p>","<h3>Classification, detection and segmentation</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Task</th><th>Required output</th><th>What distinguishes it</th></tr></thead><tbody><tr><td>Image classification</td><td>One label or class distribution for the image</td><td>Answers what category the whole image belongs to</td></tr><tr><td>Object detection</td><td>Object classes and bounding-box coordinates</td><td>Also identifies where each detected object is located</td></tr><tr><td>Semantic segmentation</td><td>A class label or distribution for each pixel</td><td>Produces a spatial label map rather than one image-wide class</td></tr><tr><td>Face recognition</td><td>Identity class or a learned face representation</td><td>Compares or classifies learned visual features</td></tr></tbody></table></div>","<p>A softmax image classifier alone does not produce boxes or pixel labels. Detection and segmentation require appropriate task heads, targets and objectives. In an applications question, explain the prediction required instead of listing model names without their purpose.</p>","<h3>Examples across domains</h3>","<p><strong>Medical imaging:</strong> classify an image or use a segmentation model to identify regions of interest. The target may be an image-level label or a pixel mask, so the architecture and loss must match that choice.</p>","<p><strong>Autonomous perception:</strong> use camera images for tasks such as detecting pedestrians and vehicles or segmenting road regions. These outputs are inputs to a larger perception and decision system.</p>","<p><strong>Manufacturing:</strong> classify product images as defective or non-defective, or localize defects when position information is needed.</p>","<p><strong>Document analysis:</strong> classify cropped handwritten characters; a complete document-reading system must also locate and order text regions.</p>","<p><strong>Remote sensing:</strong> classify land-use regions or segment different surface categories in satellite images. Spatial context and texture can help distinguish classes.</p>","<h3>Complete exam-style application answer</h3>","<p class=\"inline-question\"><strong>Question. Describe how a CNN can classify product photographs into three classes: acceptable, scratched and cracked. Explain the input, network stages, output activation, loss, training and evaluation.</strong></p>","<p class=\"worked-step\"><strong>Step 1: define data and labels.</strong> Each example contains an image and one of the three class labels. Use separate training, validation and test sets, keeping near-duplicate photographs of the same item out of different splits. Apply the chosen model&#x27;s input size and scaling consistently.</p>","<p class=\"worked-step\"><strong>Step 2: extract spatial features.</strong> Convolutional layers calculate local responses using shared kernels. Nonlinear activations allow more complex combinations of those responses. Further convolution stages combine local patterns; pooling may reduce spatial dimensions.</p>","<p class=\"worked-step\"><strong>Step 3: produce three class scores.</strong> Convert the final representation into a feature vector, using flattening or an appropriate global pooling operation, and apply a dense layer with three outputs. These raw outputs are logits.</p>","<p class=\"worked-step\"><strong>Step 4: calculate class probabilities and loss.</strong> For mutually exclusive classes, use softmax and categorical cross-entropy. A one-hot label selects the probability of the correct class.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.11px;--narrow-height:153.31px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f4b48b92a27eca9.svg\"><img class=\"math display-math\" src=\"assets/equations/c00adcf16ff90eab.svg\" alt=\"q_k=\\frac{e^{z_k}}{\\sum_{j=1}^{3}e^{z_j}},\\qquad L=-\\sum_{k=1}^{3}y_k\\ln q_k\" width=\"399.14\" height=\"74.70\" style=\"width:399.14px;height:74.70px;aspect-ratio:399.14/74.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: train the parameters.</strong> Run forward propagation, evaluate the loss, backpropagate derivatives and update the trainable convolutional and dense parameters using the selected optimizer. Use validation results for hyperparameters and stopping decisions.</p>","<p class=\"worked-step\"><strong>Step 6: evaluate the selected model.</strong> Assess the final model on held-out photographs. Report overall classification performance and inspect which defects are confused. With limited data, a pretrained CNN can provide features and selected layers can be fine-tuned.</p>","<p><strong>Numerical extension. If the last pooled feature vector has 64 components, how many parameters does the three-class dense head have, including bias?</strong></p>","<p class=\"worked-step\"><strong>Step 1:</strong> each output receives 64 weights, so three outputs require 64 × 3 = 192 weights.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> each of the three outputs has one bias, giving 3 biases.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5453c1fee1f9ccef.svg\"><img class=\"math display-math\" src=\"assets/equations/5a75359a035a6d76.svg\" alt=\"P_{\\mathrm{head}}=64(3)+3=(64+1)3=195\" width=\"383.14\" height=\"24.43\" style=\"width:383.14px;height:24.43px;aspect-ratio:383.14/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> 195 trainable parameters in this head. Softmax adds no trainable parameters. The backbone&#x27;s parameters are counted separately.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s9","search":"Applications of convolutional neural networks **Definition.** A CNN application combines a convolutional feature extractor with an output head designed for a particular prediction task. Shared local filters learn spatial patterns; the output head determines what is predicted and the loss determines how it is trained.\n\n### Classification, detection and segmentation\n| Task | Required output | What distinguishes it |\n| Image classification | One label or class distribution for the image | Answers what category the whole image belongs to |\n| Object detection | Object classes and bounding-box coordinates | Also identifies where each detected object is located |\n| Semantic segmentation | A class label or distribution for each pixel | Produces a spatial label map rather than one image-wide class |\n| Face recognition | Identity class or a learned face representation | Compares or classifies learned visual features |\n\nA softmax image classifier alone does not produce boxes or pixel labels. Detection and segmentation require appropriate task heads, targets and objectives. In an applications question, explain the prediction required instead of listing model names without their purpose.\n\n### Examples across domains\n**Medical imaging:** classify an image or use a segmentation model to identify regions of interest. The target may be an image-level label or a pixel mask, so the architecture and loss must match that choice.\n\n**Autonomous perception:** use camera images for tasks such as detecting pedestrians and vehicles or segmenting road regions. These outputs are inputs to a larger perception and decision system.\n\n**Manufacturing:** classify product images as defective or non-defective, or localize defects when position information is needed.\n\n**Document analysis:** classify cropped handwritten characters; a complete document-reading system must also locate and order text regions.\n\n**Remote sensing:** classify land-use regions or segment different surface categories in satellite images. Spatial context and texture can help distinguish classes.\n\n### Complete exam-style application answer\n**Question. Describe how a CNN can classify product photographs into three classes: acceptable, scratched and cracked. Explain the input, network stages, output activation, loss, training and evaluation.**\n\n**Step 1: define data and labels.** Each example contains an image and one of the three class labels. Use separate training, validation and test sets, keeping near-duplicate photographs of the same item out of different splits. Apply the chosen model's input size and scaling consistently.\n\n**Step 2: extract spatial features.** Convolutional layers calculate local responses using shared kernels. Nonlinear activations allow more complex combinations of those responses. Further convolution stages combine local patterns; pooling may reduce spatial dimensions.\n\n**Step 3: produce three class scores.** Convert the final representation into a feature vector, using flattening or an appropriate global pooling operation, and apply a dense layer with three outputs. These raw outputs are logits.\n\n**Step 4: calculate class probabilities and loss.** For mutually exclusive classes, use softmax and categorical cross-entropy. A one-hot label selects the probability of the correct class.\n\n\n**Step 5: train the parameters.** Run forward propagation, evaluate the loss, backpropagate derivatives and update the trainable convolutional and dense parameters using the selected optimizer. Us"},{"title":"Reading LeNet and AlexNet layer diagrams","blocks":["<p><strong>A layer diagram describes two different things:</strong> the size of the data moving through the network and the trainable operations that transform that data. A number such as 9,216 beside a flatten operation describes data length; it does not automatically mean another dense layer with 9,216 neurons.</p>","<h3>LeNet: follow the image as it becomes a class prediction</h3>","<p>The classroom LeNet layout begins with a 32 × 32 grayscale image. A valid 5 × 5 convolution with six filters produces 28 × 28 × 6. A 2 × 2 pooling operation with stride 2 produces 14 × 14 × 6. The next valid 5 × 5 convolution produces 10 × 10 × 16, and pooling reduces this to 5 × 5 × 16. A 5 × 5 convolution across those 16 channels produces 1 × 1 × 120. The final representation passes through 84 units and then ten class outputs.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Stage</th><th>What happens</th><th>Output shape</th></tr></thead><tbody><tr><td>Input</td><td>One grayscale image</td><td>32 × 32 × 1</td></tr><tr><td>C1</td><td>Six 5 × 5 filters, stride 1, no padding</td><td>28 × 28 × 6</td></tr><tr><td>S2</td><td>2 × 2 average pooling, stride 2</td><td>14 × 14 × 6</td></tr><tr><td>C3</td><td>Sixteen 5 × 5 filters, stride 1, no padding</td><td>10 × 10 × 16</td></tr><tr><td>S4</td><td>2 × 2 average pooling, stride 2</td><td>5 × 5 × 16</td></tr><tr><td>C5</td><td>120 filters covering the complete 5 × 5 spatial map</td><td>1 × 1 × 120</td></tr><tr><td>F6</td><td>Dense transformation</td><td>84 values</td></tr><tr><td>Classifier</td><td>Modern classroom softmax classifier</td><td>Ten probabilities</td></tr></tbody></table></div>","<p>The original LeNet-5 used details such as partial channel connectivity, trainable subsampling and an RBF output. A modern full-channel implementation with ordinary pooling and softmax is a different parameter-count convention. For a numerical, follow the question&#x27;s diagram and state the convention. The complete LeNet parameter numerical in the solved-paper section uses the modern classroom convention.</p>","<h3>AlexNet: identify the flatten step correctly</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/alexnet.svg\" aria-label=\"Enlarge diagram: Five convolutional layers extract image features; three dense layers produce the classifier output. Flattening only rearranges the final feature maps.\"><img src=\"assets/figures/alexnet.svg\" alt=\"Five convolutional layers extract image features; three dense layers produce the classifier output. Flattening only rearranges the final feature maps.\" width=\"960\" height=\"480\" loading=\"lazy\"></button><figcaption>Five convolutional layers extract image features; three dense layers produce the classifier output. Flattening only rearranges the final feature maps. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For the faculty&#x27;s 227 × 227 × 3 classroom input, the main shape sequence is 55 × 55 × 96 → 27 × 27 × 96 → 27 × 27 × 256 → 13 × 13 × 256 → 13 × 13 × 384 → 13 × 13 × 384 → 13 × 13 × 256 → 6 × 6 × 256. Flattening gives 9,216 values; the three dense outputs are 4,096, 4,096 and 1,000. There is no extra learned 9,216-unit layer between flattening and the first 4,096-unit layer.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). An AlexNet-style first layer receives a 227 × 227 RGB image and uses 96 filters of size 11 × 11, stride 4 and no padding. Find its output shape, trainable parameters including bias, and the number of output activation values.</strong></p>","<h3>Given</h3>","<p>Input height and width = 227; input channels = 3; kernel = 11; stride = 4; padding = 0; output filters = 96. One bias is used per filter.</p>","<h3>To find</h3>","<p>The three-dimensional output shape, parameter count and activation count.</p>","<h3>Formula — which one and why</h3>","<p>The output-size formula counts valid window positions. Parameter count counts stored filter coefficients, reused at every position. Activation count counts the values produced for one image.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/368322f7f93c9e79.svg\" alt=\"H_o=W_o=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"344.41\" height=\"58.62\" style=\"width:344.41px;height:58.62px;aspect-ratio:344.41/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fd2a21cf67217e86.svg\" alt=\"A=H_oW_oC_{\\mathrm{out}}\" width=\"159.56\" height=\"21.35\" style=\"width:159.56px;height:21.35px;aspect-ratio:159.56/21.35\" loading=\"lazy\"></div>","<p>Here N is input side length, P is padding per side, K is kernel side length, S is stride, and C denotes channel count. The symbol P in the output formula means padding; the labelled quantity P_conv means parameters.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate one spatial side.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8187570cd03b5f03.svg\" alt=\"\\frac{227-11}{4}+1=\\frac{216}{4}+1=54+1=55\" width=\"421.99\" height=\"49.80\" style=\"width:421.99px;height:49.80px;aspect-ratio:421.99/49.80\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: attach the output depth.</strong> There is one output map per filter, so the output is <strong>55 × 55 × 96</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: count the weights in one filter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8b467d436e9d44e.svg\" alt=\"11(11)(3)=363\" width=\"168.34\" height=\"24.43\" style=\"width:168.34px;height:24.43px;aspect-ratio:168.34/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add one bias and multiply by 96 filters.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a95b022f4ca93164.svg\" alt=\"P_{\\mathrm{conv}}=(363+1)(96)=34944\" width=\"320.20\" height=\"24.43\" style=\"width:320.20px;height:24.43px;aspect-ratio:320.20/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: count activation values for one image.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/200bca238c47286b.svg\" alt=\"A=55(55)(96)=290400\" width=\"268.12\" height=\"24.43\" style=\"width:268.12px;height:24.43px;aspect-ratio:268.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> output = 55 × 55 × 96; parameters = 34,944; activations = 290,400. The weights are reused, so parameters and activations are different counts. The full faculty-style ungrouped AlexNet table totals 62,378,344 parameters; the original grouped model uses different channel connectivity.</p>","<p><strong>Yaad rakho:</strong> shape = kitne answers nikle; parameters = kitne numbers seekhe.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s10","search":"Reading LeNet and AlexNet layer diagrams \n**A layer diagram describes two different things:** the size of the data moving through the network and the trainable operations that transform that data. A number such as 9,216 beside a flatten operation describes data length; it does not automatically mean another dense layer with 9,216 neurons.\n\n### LeNet: follow the image as it becomes a class prediction\n\nThe classroom LeNet layout begins with a 32 × 32 grayscale image. A valid 5 × 5 convolution with six filters produces 28 × 28 × 6. A 2 × 2 pooling operation with stride 2 produces 14 × 14 × 6. The next valid 5 × 5 convolution produces 10 × 10 × 16, and pooling reduces this to 5 × 5 × 16. A 5 × 5 convolution across those 16 channels produces 1 × 1 × 120. The final representation passes through 84 units and then ten class outputs.\n\n| Stage | What happens | Output shape |\n| Input | One grayscale image | 32 × 32 × 1 |\n| C1 | Six 5 × 5 filters, stride 1, no padding | 28 × 28 × 6 |\n| S2 | 2 × 2 average pooling, stride 2 | 14 × 14 × 6 |\n| C3 | Sixteen 5 × 5 filters, stride 1, no padding | 10 × 10 × 16 |\n| S4 | 2 × 2 average pooling, stride 2 | 5 × 5 × 16 |\n| C5 | 120 filters covering the complete 5 × 5 spatial map | 1 × 1 × 120 |\n| F6 | Dense transformation | 84 values |\n| Classifier | Modern classroom softmax classifier | Ten probabilities |\n\nThe original LeNet-5 used details such as partial channel connectivity, trainable subsampling and an RBF output. A modern full-channel implementation with ordinary pooling and softmax is a different parameter-count convention. For a numerical, follow the question's diagram and state the convention. The complete LeNet parameter numerical in the solved-paper section uses the modern classroom convention.\n\n### AlexNet: identify the flatten step correctly\n\n\n\nFor the faculty's 227 × 227 × 3 classroom input, the main shape sequence is 55 × 55 × 96 → 27 × 27 × 96 → 27 × 27 × 256 → 13 × 13 × 256 → 13 × 13 × 384 → 13 × 13 × 384 → 13 × 13 × 256 → 6 × 6 × 256. Flattening gives 9,216 values; the three dense outputs are 4,096, 4,096 and 1,000. There is no extra learned 9,216-unit layer between flattening and the first 4,096-unit layer.\n\n**Question (practice, 3 marks). An AlexNet-style first layer receives a 227 × 227 RGB image and uses 96 filters of size 11 × 11, stride 4 and no padding. Find its output shape, trainable parameters including bias, and the number of output activation values.**\n\n### Given\nInput height and width = 227; input channels = 3; kernel = 11; stride = 4; padding = 0; output filters = 96. One bias is used per filter.\n\n### To find\nThe three-dimensional output shape, parameter count and activation count.\n\n### Formula — which one and why\nThe output-size formula counts valid window positions. Parameter count counts stored filter coefficients, reused at every position. Activation count counts the values produced for one image.\n\n\n\nHere N is input side length, P is padding per side, K is kernel side length, S is stride, and C denotes channel count. The symbol P in the output formula means padding; the labelled quantity P_conv means parameters.\n\n### Solution — step by step\n**Step 1: calculate one spatial side.**\n\n\n**Step 2: attach the output depth.** There is one output map per filter, so the output is **55 × 55 × 96**.\n\n**Step 3: count the weights in one filter.**\n\n\n**Step 4: add one bias and multiply by 96 filters.**\n\n\n**Step 5: count activation values for one image.**\n\n\n**Final answer:** output = 55 × 55 ×"},{"title":"Top-1 and top-5 error: what an ImageNet result means","blocks":["<p><strong>Top-1 prediction</strong> is the class with the highest score. A top-1 mistake occurs when that class is wrong. <strong>Top-5 prediction</strong> is the list of the five highest-scoring classes. A top-5 mistake occurs only when the correct class is absent from that list. It is not the average error of five separate models.</p>","<p>For an image of a cat, the ordered list dog, cat, fox, horse, bird is a top-1 error but a top-5 success. The ordered list dog, fox, horse, bird, car is an error under both measures.</p>","<p class=\"inline-question\"><strong>Question (practice, 2 marks). A classifier evaluates 100 images. The correct class is ranked first for 78 images and appears somewhere in the first five positions for 92 images. Calculate top-1 error and top-5 error.</strong></p>","<h3>Given</h3>","<p>Total images = 100; top-1 successes = 78; top-5 successes = 92. The 78 first-place successes are already included in the 92 top-five successes.</p>","<h3>To find</h3>","<p>The percentage of mistakes under each rule.</p>","<h3>Formula — which one and why</h3>","<p>Subtract successful images from the total to obtain mistakes. Divide mistakes by the total and multiply by 100 to express a percentage.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fb17785121a672d.svg\" alt=\"E_k=\\frac{N-C_k}{N}\\times100\\%\" width=\"239.34\" height=\"50.50\" style=\"width:239.34px;height:50.50px;aspect-ratio:239.34/50.50\" loading=\"lazy\"></div>","<p>N means total evaluated images; C_k means images whose correct class appears among the top k predictions.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: top-1 mistakes.</strong> 100 − 78 = 22.</p>","<p class=\"worked-step\"><strong>Step 2: top-1 error percentage.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e21c77c5c190c14b.svg\" alt=\"E_1=\\frac{22}{100}\\times100\\%=22\\%\" width=\"272.94\" height=\"50.09\" style=\"width:272.94px;height:50.09px;aspect-ratio:272.94/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: top-5 mistakes.</strong> 100 − 92 = 8.</p>","<p class=\"worked-step\"><strong>Step 4: top-5 error percentage.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbf5783f9d42ea19.svg\" alt=\"E_5=\\frac{8}{100}\\times100\\%=8\\%\" width=\"260.72\" height=\"50.09\" style=\"width:260.72px;height:50.09px;aspect-ratio:260.72/50.09\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> top-1 error = 22%; top-5 error = 8%. A broader acceptable list makes top-5 error no greater than top-1 error for the same evaluated predictions.</p>","<p><strong>Yaad rakho:</strong> top-five mein sahi naam mil gaya toh top-five success.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s11","search":"Top-1 and top-5 error: what an ImageNet result means \n**Top-1 prediction** is the class with the highest score. A top-1 mistake occurs when that class is wrong. **Top-5 prediction** is the list of the five highest-scoring classes. A top-5 mistake occurs only when the correct class is absent from that list. It is not the average error of five separate models.\n\nFor an image of a cat, the ordered list dog, cat, fox, horse, bird is a top-1 error but a top-5 success. The ordered list dog, fox, horse, bird, car is an error under both measures.\n\n**Question (practice, 2 marks). A classifier evaluates 100 images. The correct class is ranked first for 78 images and appears somewhere in the first five positions for 92 images. Calculate top-1 error and top-5 error.**\n\n### Given\nTotal images = 100; top-1 successes = 78; top-5 successes = 92. The 78 first-place successes are already included in the 92 top-five successes.\n\n### To find\nThe percentage of mistakes under each rule.\n\n### Formula — which one and why\nSubtract successful images from the total to obtain mistakes. Divide mistakes by the total and multiply by 100 to express a percentage.\n\nN means total evaluated images; C_k means images whose correct class appears among the top k predictions.\n\n### Solution — step by step\n**Step 1: top-1 mistakes.** 100 − 78 = 22.\n\n**Step 2: top-1 error percentage.**\n\n\n**Step 3: top-5 mistakes.** 100 − 92 = 8.\n\n**Step 4: top-5 error percentage.**\n\n\n**Final answer:** top-1 error = 22%; top-5 error = 8%. A broader acceptable list makes top-5 error no greater than top-1 error for the same evaluated predictions.\n\n**Yaad rakho:** top-five mein sahi naam mil gaya toh top-five success.\n"},{"title":"VGG16: small filters in a regular sequence","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_vgg16.svg\" aria-label=\"Enlarge diagram: Follow the five blocks and their output sizes. The 16 counts learned layers, not pooling or flattening.\"><img src=\"assets/figures/u4_vgg16.svg\" alt=\"Follow the five blocks and their output sizes. The 16 counts learned layers, not pooling or flattening.\" width=\"900\" height=\"350\" loading=\"lazy\"></button><figcaption>Follow the five blocks and their output sizes. The 16 counts learned layers, not pooling or flattening. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"definition\"><strong>Definition.</strong> VGG16 is a convolutional architecture with 13 convolutional layers and three dense layers. Its standard convolution blocks contain 2, 2, 3, 3 and 3 convolutions. Pooling, activations and flattening are not counted in the name&#x27;s 16 weight layers.</p>","<p>Each convolution uses a 3 × 3 kernel, stride 1 and padding 1, preserving height and width. Each block ends with 2 × 2 max pooling of stride 2. The final classifier is 4,096 → 4,096 → 1,000 for the original 1,000-class task.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Block</th><th>Convolutions</th><th>Channels after its convolutions</th><th>Size after its pooling</th></tr></thead><tbody><tr><td>1</td><td>Two</td><td>64</td><td>112 × 112 × 64</td></tr><tr><td>2</td><td>Two</td><td>128</td><td>56 × 56 × 128</td></tr><tr><td>3</td><td>Three</td><td>256</td><td>28 × 28 × 256</td></tr><tr><td>4</td><td>Three</td><td>512</td><td>14 × 14 × 512</td></tr><tr><td>5</td><td>Three</td><td>512</td><td>7 × 7 × 512</td></tr></tbody></table></div>","<p>This table starts with 224 × 224 × 3. The flattened length is 7 × 7 × 512 = 25,088. Flattening has zero learned parameters. Stacking small filters provides repeated nonlinear transformations while progressively combining spatial information. A limitation is the large dense classifier and its memory cost.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). VGG16&#x27;s first block contains two same-padded 3 × 3 convolutions with 64 output filters each, followed by 2 × 2 max pooling with stride 2. Input is 224 × 224 × 3. Find both convolution parameter counts including bias and the pooled output shape.</strong></p>","<h3>Given</h3>","<p>Conv1: 3 input channels, 64 output channels. Conv2: 64 input channels, 64 output channels. Both have kernel 3, stride 1 and padding 1. Pooling has kernel 2, stride 2 and no padding.</p>","<h3>To find</h3>","<p>Trainable parameters in each convolution and the output after pooling.</p>","<h3>Formula — which one and why</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<p>Use each layer&#x27;s own input depth; the second layer receives the first layer&#x27;s 64 maps. Use the spatial-output formula for pooling. Max pooling introduces no trainable parameters.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: first convolution.</strong> Each filter has 3 × 3 × 3 = 27 weights and one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e82763edab004507.svg\" alt=\"P_1=(27+1)(64)=1792\" width=\"269.36\" height=\"24.43\" style=\"width:269.36px;height:24.43px;aspect-ratio:269.36/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: second convolution.</strong> Each filter now spans 64 channels, giving 3 × 3 × 64 = 576 weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ff96ebed9174c6f1.svg\" alt=\"P_2=(576+1)(64)=36928\" width=\"293.80\" height=\"24.43\" style=\"width:293.80px;height:24.43px;aspect-ratio:293.80/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add parameters.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc9e657e6b2a7ee5.svg\" alt=\"P_{\\mathrm{block}}=1792+36928=38720\" width=\"323.63\" height=\"20.54\" style=\"width:323.63px;height:20.54px;aspect-ratio:323.63/20.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: calculate pooled side length.</strong> The same-padded convolutions retained side length 224.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/71feab89feae610a.svg\" alt=\"\\frac{224-2}{2}+1=111+1=112\" width=\"312.13\" height=\"49.82\" style=\"width:312.13px;height:49.82px;aspect-ratio:312.13/49.82\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 1,792 and 36,928 parameters; total = 38,720; pooled shape = <strong>112 × 112 × 64</strong>.</p>","<p><strong>Exam convention:</strong> use the architecture explicitly supplied in a calculation. For the standard VGG16 architecture, remember <strong>2–2–3–3–3 convolutions and 2 × 2 pooling</strong>; 25,088 is the flattened feature length.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s12","search":"VGG16: small filters in a regular sequence \n\n\n**Definition.** VGG16 is a convolutional architecture with 13 convolutional layers and three dense layers. Its standard convolution blocks contain 2, 2, 3, 3 and 3 convolutions. Pooling, activations and flattening are not counted in the name's 16 weight layers.\n\nEach convolution uses a 3 × 3 kernel, stride 1 and padding 1, preserving height and width. Each block ends with 2 × 2 max pooling of stride 2. The final classifier is 4,096 → 4,096 → 1,000 for the original 1,000-class task.\n\n| Block | Convolutions | Channels after its convolutions | Size after its pooling |\n| 1 | Two | 64 | 112 × 112 × 64 |\n| 2 | Two | 128 | 56 × 56 × 128 |\n| 3 | Three | 256 | 28 × 28 × 256 |\n| 4 | Three | 512 | 14 × 14 × 512 |\n| 5 | Three | 512 | 7 × 7 × 512 |\n\nThis table starts with 224 × 224 × 3. The flattened length is 7 × 7 × 512 = 25,088. Flattening has zero learned parameters. Stacking small filters provides repeated nonlinear transformations while progressively combining spatial information. A limitation is the large dense classifier and its memory cost.\n\n**Question (practice, 3 marks). VGG16's first block contains two same-padded 3 × 3 convolutions with 64 output filters each, followed by 2 × 2 max pooling with stride 2. Input is 224 × 224 × 3. Find both convolution parameter counts including bias and the pooled output shape.**\n\n### Given\nConv1: 3 input channels, 64 output channels. Conv2: 64 input channels, 64 output channels. Both have kernel 3, stride 1 and padding 1. Pooling has kernel 2, stride 2 and no padding.\n\n### To find\nTrainable parameters in each convolution and the output after pooling.\n\n### Formula — which one and why\n\nUse each layer's own input depth; the second layer receives the first layer's 64 maps. Use the spatial-output formula for pooling. Max pooling introduces no trainable parameters.\n\n### Solution — step by step\n**Step 1: first convolution.** Each filter has 3 × 3 × 3 = 27 weights and one bias.\n\n\n**Step 2: second convolution.** Each filter now spans 64 channels, giving 3 × 3 × 64 = 576 weights.\n\n\n**Step 3: add parameters.**\n\n\n**Step 4: calculate pooled side length.** The same-padded convolutions retained side length 224.\n\n\n**Final answer:** 1,792 and 36,928 parameters; total = 38,720; pooled shape = **112 × 112 × 64**.\n\n**Exam convention:** use the architecture explicitly supplied in a calculation. For the standard VGG16 architecture, remember **2–2–3–3–3 convolutions and 2 × 2 pooling**; 25,088 is the flattened feature length.\n"},{"title":"Global average pooling: one average for each channel","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_gap.svg\" aria-label=\"Enlarge diagram: Average each channel separately: these are the exact values used in the worked example.\"><img src=\"assets/figures/u4_gap.svg\" alt=\"Average each channel separately: these are the exact values used in the worked example.\" width=\"900\" height=\"330\" loading=\"lazy\"></button><figcaption>Average each channel separately: these are the exact values used in the worked example. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"definition\"><strong>Definition.</strong> Global average pooling, or GAP, replaces every complete spatial feature map by its mean. An H × W × C tensor becomes C numbers. The channels remain separate; we do not average all channels into one number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/002749b4b374cf54.svg\" alt=\"g_c=\\frac{1}{HW}\\sum_{i=1}^{H}\\sum_{j=1}^{W}a_{i,j,c}\" width=\"239.71\" height=\"74.90\" style=\"width:239.71px;height:74.90px;aspect-ratio:239.71/74.90\" loading=\"lazy\"></div>","<p>The letter c selects a channel; i and j select its row and column; a is the value at that location. Add all H × W entries in that channel and divide by H × W. GAP has no learned weights or biases. A classifier after GAP can still have trainable parameters. In GoogLeNet, 7 × 7 × 1,024 becomes 1 × 1 × 1,024 before the final 1,000-class linear classifier.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). A 2 × 2 × 2 tensor has channel A = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e857333332fbdd17.svg\" alt=\"\\begin{bmatrix}1 &amp; 3\\\\5 &amp; 7\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> and channel B = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c890243a56df9f91.svg\" alt=\"\\begin{bmatrix}2 &amp; 4\\\\6 &amp; 8\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Apply GAP, then find the parameters of a three-output dense classifier receiving the result, including one bias per output.</strong></p>","<h3>Given</h3>","<p>H = 2, W = 2, C = 2. Each of the two channels contains four values. The classifier has three outputs.</p>","<h3>To find</h3>","<p>The GAP result and dense-head parameter count.</p>","<h3>Formula — which one and why</h3>","<p>Use one mean per channel. The dense layer receives two numbers, so each of its three outputs needs two weights and one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add channel A.</strong> 1 + 3 + 5 + 7 = 16.</p>","<p class=\"worked-step\"><strong>Step 2: average channel A.</strong> 16 ÷ 4 = 4.</p>","<p class=\"worked-step\"><strong>Step 3: add channel B.</strong> 2 + 4 + 6 + 8 = 20.</p>","<p class=\"worked-step\"><strong>Step 4: average channel B.</strong> 20 ÷ 4 = 5. Thus GAP outputs <strong>[4,5]</strong>.</p>","<p class=\"worked-step\"><strong>Step 5: count the classifier&#x27;s weights.</strong> 2 inputs × 3 outputs = 6 weights.</p>","<p class=\"worked-step\"><strong>Step 6: add three biases.</strong> 6 + 3 = <strong>9 parameters</strong>. GAP itself contributes zero.</p>","<p><strong>Final answer:</strong> GAP = [4,5]; GAP shape = 1 × 1 × 2; classifier parameters = 9. If we flattened all eight inputs instead, that head would require (8 + 1) × 3 = 27 parameters.</p>","<p><strong>Yaad rakho:</strong> ek channel ka poora average; channels ko aapas mein mat milao.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s13","search":"Global average pooling: one average for each channel \n\n\n**Definition.** Global average pooling, or GAP, replaces every complete spatial feature map by its mean. An H × W × C tensor becomes C numbers. The channels remain separate; we do not average all channels into one number.\n\n\n\nThe letter c selects a channel; i and j select its row and column; a is the value at that location. Add all H × W entries in that channel and divide by H × W. GAP has no learned weights or biases. A classifier after GAP can still have trainable parameters. In GoogLeNet, 7 × 7 × 1,024 becomes 1 × 1 × 1,024 before the final 1,000-class linear classifier.\n\n**Question (practice, 3 marks). A 2 × 2 × 2 tensor has channel A =  and channel B = . Apply GAP, then find the parameters of a three-output dense classifier receiving the result, including one bias per output.**\n\n### Given\nH = 2, W = 2, C = 2. Each of the two channels contains four values. The classifier has three outputs.\n\n### To find\nThe GAP result and dense-head parameter count.\n\n### Formula — which one and why\nUse one mean per channel. The dense layer receives two numbers, so each of its three outputs needs two weights and one bias.\n\n\n### Solution — step by step\n**Step 1: add channel A.** 1 + 3 + 5 + 7 = 16.\n\n**Step 2: average channel A.** 16 ÷ 4 = 4.\n\n**Step 3: add channel B.** 2 + 4 + 6 + 8 = 20.\n\n**Step 4: average channel B.** 20 ÷ 4 = 5. Thus GAP outputs **[4,5]**.\n\n**Step 5: count the classifier's weights.** 2 inputs × 3 outputs = 6 weights.\n\n**Step 6: add three biases.** 6 + 3 = **9 parameters**. GAP itself contributes zero.\n\n**Final answer:** GAP = [4,5]; GAP shape = 1 × 1 × 2; classifier parameters = 9. If we flattened all eight inputs instead, that head would require (8 + 1) × 3 = 27 parameters.\n\n**Yaad rakho:** ek channel ka poora average; channels ko aapas mein mat milao.\n"},{"title":"The faculty's 480-channel bottleneck numerical","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_bottleneck_480.svg\" aria-label=\"Enlarge diagram: Both paths start from 14 × 14 × 480 and end at 14 × 14 × 48. The bottleneck cost includes both layers.\"><img src=\"assets/figures/u4_bottleneck_480.svg\" alt=\"Both paths start from 14 × 14 × 480 and end at 14 × 14 × 48. The bottleneck cost includes both layers.\" width=\"900\" height=\"465\" loading=\"lazy\"></button><figcaption>Both paths start from 14 × 14 × 480 and end at 14 × 14 × 48. The bottleneck cost includes both layers. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). Compare a direct same-padded 5 × 5 convolution with 48 filters on a 14 × 14 × 480 input against a 1 × 1 reduction to 16 channels followed by the same 5 × 5, 48-filter layer. Use stride 1. Count MACs, ignore bias additions, and find the percentage reduction.</strong></p>","<h3>Given</h3>","<p>Both paths produce 14 × 14 × 48. Direct spatial filters span 480 channels; reduced spatial filters span 16. The reduction has 16 output filters.</p>","<h3>To find</h3>","<p>MACs for the direct path, both bottleneck stages, their total and percentage saved.</p>","<h3>Formula — which one and why</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48494d663392b9d5.svg\" alt=\"M=H_oW_oC_oK^2C_i\" width=\"209.44\" height=\"25.46\" style=\"width:209.44px;height:25.46px;aspect-ratio:209.44/25.46\" loading=\"lazy\"></div>","<p>M is the MAC count. H_oW_oC_o counts output values; K²C_i is the products used for each output. One MAC means one multiply-accumulate pair. Count both layers of the bottleneck.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78cf62ab96d05d20.svg\" alt=\"\\mathrm{saving}\\%=100\\frac{M_{\\mathrm{direct}}-M_{\\mathrm{bottleneck}}}{M_{\\mathrm{direct}}}\" width=\"370.49\" height=\"53.83\" style=\"width:370.49px;height:53.83px;aspect-ratio:370.49/53.83\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: direct output count.</strong> 14 × 14 × 48 = 9,408.</p>","<p class=\"worked-step\"><strong>Step 2: products per direct output.</strong> 5 × 5 × 480 = 12,000.</p>","<p class=\"worked-step\"><strong>Step 3: direct MACs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7c9631645fc9930b.svg\" alt=\"9408(12000)=112896000\" width=\"271.50\" height=\"24.43\" style=\"width:271.50px;height:24.43px;aspect-ratio:271.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: reduction-layer MACs.</strong> Each of 14 × 14 × 16 outputs combines 480 values.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8486a56714848659.svg\" alt=\"14(14)(16)(480)=1505280\" width=\"285.09\" height=\"24.43\" style=\"width:285.09px;height:24.43px;aspect-ratio:285.09/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: reduced spatial-layer MACs.</strong> Each of 9,408 outputs now combines 5 × 5 × 16 = 400 values.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d32e7e22a58c8e10.svg\" alt=\"9408(400)=3763200\" width=\"222.63\" height=\"24.43\" style=\"width:222.63px;height:24.43px;aspect-ratio:222.63/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: add both bottleneck costs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7061d250d8255604.svg\" alt=\"1505280+3763200=5268480\" width=\"319.01\" height=\"18.54\" style=\"width:319.01px;height:18.54px;aspect-ratio:319.01/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate the saving.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a866c1ac7a2fce39.svg\" alt=\"112896000-5268480=107627520\" width=\"367.88\" height=\"18.54\" style=\"width:367.88px;height:18.54px;aspect-ratio:367.88/18.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18ccfe0746a80b04.svg\" alt=\"100\\frac{107627520}{112896000}\\approx95.333333\\%\" width=\"314.83\" height=\"50.34\" style=\"width:314.83px;height:50.34px;aspect-ratio:314.83/50.34\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> direct = <strong>112.896 million MACs</strong>; bottleneck = <strong>5.26848 million MACs</strong>; saving ≈ <strong>95.33%</strong>. The lecture&#x27;s 112.9M and 5.3M are rounded versions. This arithmetic proves reduced computation; equal prediction accuracy is not guaranteed by the count alone.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s14","search":"The faculty's 480-channel bottleneck numerical \n\n\n**Question (practice, 3 marks). Compare a direct same-padded 5 × 5 convolution with 48 filters on a 14 × 14 × 480 input against a 1 × 1 reduction to 16 channels followed by the same 5 × 5, 48-filter layer. Use stride 1. Count MACs, ignore bias additions, and find the percentage reduction.**\n\n### Given\nBoth paths produce 14 × 14 × 48. Direct spatial filters span 480 channels; reduced spatial filters span 16. The reduction has 16 output filters.\n\n### To find\nMACs for the direct path, both bottleneck stages, their total and percentage saved.\n\n### Formula — which one and why\n\nM is the MAC count. H_oW_oC_o counts output values; K²C_i is the products used for each output. One MAC means one multiply-accumulate pair. Count both layers of the bottleneck.\n\n\n### Solution — step by step\n**Step 1: direct output count.** 14 × 14 × 48 = 9,408.\n\n**Step 2: products per direct output.** 5 × 5 × 480 = 12,000.\n\n**Step 3: direct MACs.**\n\n\n**Step 4: reduction-layer MACs.** Each of 14 × 14 × 16 outputs combines 480 values.\n\n\n**Step 5: reduced spatial-layer MACs.** Each of 9,408 outputs now combines 5 × 5 × 16 = 400 values.\n\n\n**Step 6: add both bottleneck costs.**\n\n\n**Step 7: calculate the saving.**\n\n\n\n**Final answer:** direct = **112.896 million MACs**; bottleneck = **5.26848 million MACs**; saving ≈ **95.33%**. The lecture's 112.9M and 5.3M are rounded versions. This arithmetic proves reduced computation; equal prediction accuracy is not guaranteed by the count alone.\n"},{"title":"Batch normalization inside a residual network","blocks":["<p class=\"definition\"><strong>Definition.</strong> Batch normalization normalizes a feature using training-batch statistics, then applies a learned scale and shift. It operates on intermediate activations and is different from normalizing the original dataset once before training.</p>","<p>For one feature with m values in a training batch:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a91b1c9216cbd799.svg\" alt=\"\\mu_B=\\frac{1}{m}\\sum_{i=1}^{m}x_i\" width=\"160.06\" height=\"68.62\" style=\"width:160.06px;height:68.62px;aspect-ratio:160.06/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcfc8cc5fd3adc8.svg\" alt=\"\\sigma_B^2=\\frac{1}{m}\\sum_{i=1}^{m}(x_i-\\mu_B)^2\" width=\"244.63\" height=\"68.62\" style=\"width:244.63px;height:68.62px;aspect-ratio:244.63/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13126b94bcd9d415.svg\" alt=\"\\hat{x}_i=\\frac{x_i-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\" width=\"159.11\" height=\"75.23\" style=\"width:159.11px;height:75.23px;aspect-ratio:159.11/75.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7fd3e426f48f08b9.svg\" alt=\"y_i=\\gamma\\hat{x}_i+\\beta\" width=\"131.48\" height=\"25.07\" style=\"width:131.48px;height:25.07px;aspect-ratio:131.48/25.07\" loading=\"lazy\"></div>","<p>The batch mean μ_B is the centre; batch variance σ²_B measures squared spread. Epsilon ε is a small positive stability constant <strong>inside the square root</strong>. Gamma γ is a learned scale and beta β is a learned shift. For convolutional BN, statistics are usually computed separately for each channel across batch and spatial positions. Ordinary inference uses stored running statistics rather than the current test batch.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). For one feature, a training batch contains [2,4]. Use ε = 0.00001, γ = 2 and β = 0.5. Calculate both batch-normalized outputs using population variance.</strong></p>","<h3>Given</h3>","<p>x₁ = 2; x₂ = 4; m = 2; ε = 0.00001; γ = 2; β = 0.5.</p>","<h3>To find</h3>","<p>Batch mean, variance, normalized values and scale-and-shift outputs.</p>","<h3>Formula — which one and why</h3>","<p>Use the four formulas above in order. Population variance divides by m = 2, not m − 1. Scale and shift follow normalization because the model can learn the useful final feature scale.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dcbc368ca301a562.svg\" alt=\"\\mu_B=\\frac{2+4}{2}=3\" width=\"172.31\" height=\"49.82\" style=\"width:172.31px;height:49.82px;aspect-ratio:172.31/49.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: deviations.</strong> 2 − 3 = −1 and 4 − 3 = 1.</p>","<p class=\"worked-step\"><strong>Step 3: squared deviations and variance.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8c2f38c1c4da922.svg\" alt=\"\\sigma_B^2=\\frac{(-1)^2+1^2}{2}=\\frac{1+1}{2}=1\" width=\"328.53\" height=\"54.49\" style=\"width:328.53px;height:54.49px;aspect-ratio:328.53/54.49\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: stable denominator.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64e8bea52d19d8d8.svg\" alt=\"d=\\sqrt{1+0.00001}\\approx1.00000499999\" width=\"374.30\" height=\"25.90\" style=\"width:374.30px;height:25.90px;aspect-ratio:374.30/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: normalize separately.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3676422778896944.svg\" alt=\"\\hat{x}_1=\\frac{-1}{d}\\approx-0.99999500004\" width=\"304.20\" height=\"49.80\" style=\"width:304.20px;height:49.80px;aspect-ratio:304.20/49.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3c9c2142072c8bc9.svg\" alt=\"\\hat{x}_2=\\frac{1}{d}\\approx0.99999500004\" width=\"266.67\" height=\"49.80\" style=\"width:266.67px;height:49.80px;aspect-ratio:266.67/49.80\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: scale the first normalized value, then shift it.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4655c2949211af8b.svg\" alt=\"y_1=2(-0.99999500004)+0.5\\approx-1.49999000008\" width=\"524.96\" height=\"24.43\" style=\"width:524.96px;height:24.43px;aspect-ratio:524.96/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: scale the second normalized value, then shift it.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3848a4f079b59c74.svg\" alt=\"y_2=2(0.99999500004)+0.5\\approx2.49999000008\" width=\"486.93\" height=\"24.43\" style=\"width:486.93px;height:24.43px;aspect-ratio:486.93/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> output ≈ <strong>[−1.49999,2.49999]</strong>. Its mean is β = 0.5; the final output need not have zero mean after the learned shift. The normalized values themselves have mean zero here.</p>","<p><strong>Yaad rakho:</strong> centre hatao → spread se divide → learned scale lagao → shift add karo.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s15","search":"Batch normalization inside a residual network \n**Definition.** Batch normalization normalizes a feature using training-batch statistics, then applies a learned scale and shift. It operates on intermediate activations and is different from normalizing the original dataset once before training.\n\nFor one feature with m values in a training batch:\n\n\n\n\n\nThe batch mean μ_B is the centre; batch variance σ²_B measures squared spread. Epsilon ε is a small positive stability constant **inside the square root**. Gamma γ is a learned scale and beta β is a learned shift. For convolutional BN, statistics are usually computed separately for each channel across batch and spatial positions. Ordinary inference uses stored running statistics rather than the current test batch.\n\n**Question (practice, 3 marks). For one feature, a training batch contains [2,4]. Use ε = 0.00001, γ = 2 and β = 0.5. Calculate both batch-normalized outputs using population variance.**\n\n### Given\nx₁ = 2; x₂ = 4; m = 2; ε = 0.00001; γ = 2; β = 0.5.\n\n### To find\nBatch mean, variance, normalized values and scale-and-shift outputs.\n\n### Formula — which one and why\nUse the four formulas above in order. Population variance divides by m = 2, not m − 1. Scale and shift follow normalization because the model can learn the useful final feature scale.\n\n### Solution — step by step\n**Step 1: mean.**\n\n\n**Step 2: deviations.** 2 − 3 = −1 and 4 − 3 = 1.\n\n**Step 3: squared deviations and variance.**\n\n\n**Step 4: stable denominator.**\n\n\n**Step 5: normalize separately.**\n\n\n\n**Step 6: scale the first normalized value, then shift it.**\n\n\n**Step 7: scale the second normalized value, then shift it.**\n\n\n**Final answer:** output ≈ **[−1.49999,2.49999]**. Its mean is β = 0.5; the final output need not have zero mean after the learned shift. The normalized values themselves have mean zero here.\n\n**Yaad rakho:** centre hatao → spread se divide → learned scale lagao → shift add karo.\n"},{"title":"Residual-block order and architecture qualifications","blocks":["<p>The original post-activation basic block has this sequence: <strong>convolution → BN → ReLU → convolution → BN → add shortcut → ReLU</strong>. Thus the second branch convolution is not followed by a separate ReLU before the addition in this particular block. A pre-activation ResNet is another design; use the stated diagram.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: Add the shortcut to the residual branch, then apply the post-addition ReLU when the specified block requires it.\"><img src=\"assets/figures/residual.svg\" alt=\"Add the shortcut to the residual branch, then apply the post-addition ReLU when the specified block requires it.\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>Add the shortcut to the residual branch, then apply the post-addition ReLU when the specified block requires it. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>An identity shortcut has no learned parameters. A projection shortcut changes the shape using learned weights. Original ImageNet ResNets include an initial max-pooling operation; a basic residual block does not need a max-pooling layer inside it. ResNet-18/34 use two-convolution basic blocks, whereas deeper standard variants use bottleneck blocks. Avoid treating every ResNet as the same two-layer diagram.</p>","<p>The main advantage is easier optimization of deep networks: shortcuts provide an additional information and gradient path. This reduces the degradation problem but does not prove immunity to every vanishing/exploding-gradient case. Large networks still need compute, memory, suitable data and regularization. Reusing early features can help; it does not guarantee that every deeper model generalizes better.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s16","search":"Residual-block order and architecture qualifications \nThe original post-activation basic block has this sequence: **convolution → BN → ReLU → convolution → BN → add shortcut → ReLU**. Thus the second branch convolution is not followed by a separate ReLU before the addition in this particular block. A pre-activation ResNet is another design; use the stated diagram.\n\n\n\nAn identity shortcut has no learned parameters. A projection shortcut changes the shape using learned weights. Original ImageNet ResNets include an initial max-pooling operation; a basic residual block does not need a max-pooling layer inside it. ResNet-18/34 use two-convolution basic blocks, whereas deeper standard variants use bottleneck blocks. Avoid treating every ResNet as the same two-layer diagram.\n\nThe main advantage is easier optimization of deep networks: shortcuts provide an additional information and gradient path. This reduces the degradation problem but does not prove immunity to every vanishing/exploding-gradient case. Large networks still need compute, memory, suitable data and regularization. Reusing early features can help; it does not guarantee that every deeper model generalizes better.\n"},{"title":"Choosing frozen layers from dataset size and similarity","blocks":["<p>Early image layers commonly learn reusable edges and textures. Later layers become more specialized to source-task categories. “Earlier” means closer to the input, regardless of whether a drawing places those layers at the top or bottom.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Target dataset</th><th>Sensible starting choice</th><th>Reason</th></tr></thead><tbody><tr><td>Small and similar</td><td>Freeze the backbone; train a new head first</td><td>Useful features already exist, while few examples make overfitting likely</td></tr><tr><td>Large and similar</td><td>Train a new head, then fine-tune more layers if validation improves</td><td>More data can support more trainable parameters</td></tr><tr><td>Small and different</td><td>Try a more relevant pretrained model or fixed earlier/intermediate features; tune cautiously</td><td>Later source features may be unsuitable, but small data still makes extensive tuning risky</td></tr><tr><td>Large and different</td><td>Compare broad fine-tuning with training from scratch</td><td>Sufficient data permits stronger adaptation; the value of source features must be tested</td></tr></tbody></table></div>","<p>These are starting strategies, not universal rules. Fine-tuning an early layer means updating its pretrained weights, not automatically learning it “from scratch”. With very little data, simply unfreezing early layers because the task differs can overfit. Choose changes using validation performance and apply the required preprocessing consistently.</p>","<p><strong>Example.</strong> With 100 labelled microscopic images, an ImageNet model may provide reusable low-level patterns, but its animal/object classifier is inappropriate. Replace the head, test fixed representations and monitor validation before increasing the number of trainable layers. With a large representative image dataset, broader fine-tuning becomes a more reasonable candidate.</p>","<p><strong>Yaad rakho:</strong> data kam toh kam weights hilao; task alag toh features ki suitability pehle dekho.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s17","search":"Choosing frozen layers from dataset size and similarity \nEarly image layers commonly learn reusable edges and textures. Later layers become more specialized to source-task categories. “Earlier” means closer to the input, regardless of whether a drawing places those layers at the top or bottom.\n\n| Target dataset | Sensible starting choice | Reason |\n| Small and similar | Freeze the backbone; train a new head first | Useful features already exist, while few examples make overfitting likely |\n| Large and similar | Train a new head, then fine-tune more layers if validation improves | More data can support more trainable parameters |\n| Small and different | Try a more relevant pretrained model or fixed earlier/intermediate features; tune cautiously | Later source features may be unsuitable, but small data still makes extensive tuning risky |\n| Large and different | Compare broad fine-tuning with training from scratch | Sufficient data permits stronger adaptation; the value of source features must be tested |\n\nThese are starting strategies, not universal rules. Fine-tuning an early layer means updating its pretrained weights, not automatically learning it “from scratch”. With very little data, simply unfreezing early layers because the task differs can overfit. Choose changes using validation performance and apply the required preprocessing consistently.\n\n**Example.** With 100 labelled microscopic images, an ImageNet model may provide reusable low-level patterns, but its animal/object classifier is inappropriate. Replace the head, test fixed representations and monitor validation before increasing the number of trainable layers. With a large representative image dataset, broader fine-tuning becomes a more reasonable candidate.\n\n**Yaad rakho:** data kam toh kam weights hilao; task alag toh features ki suitability pehle dekho.\n"},{"title":"Four ways to reuse a pretrained model","blocks":["<p class=\"definition\"><strong>Definition.</strong> A pretrained model has already learned parameters from an earlier training task. We can reuse its complete classifier, reuse its feature extractor, or use its learned weights as the starting point for further training. The choice determines which output labels are available and which parameters change.</p>","<p><strong>First identify two parts.</strong> The <strong>backbone</strong> converts an input image into useful features. The <strong>head</strong> converts those features into the required prediction, such as class scores. A new task can reuse the backbone while replacing the head.</p>","<p><strong>Yaad rakhne ka cue:</strong> Purane model ka poora answer use karna, sirf features lena, ya uske weights ko aage train karna—yeh teen decisions alag hain.</p>","<p>The faculty reference divides these choices into the following four uses. The two feature-extractor uses differ in whether features are saved separately or computed inside the new model.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Use</th><th>What happens to the pretrained part?</th><th>What learns for the target task?</th><th>Concrete example</th></tr></thead><tbody><tr><td>Direct classifier</td><td>Keep the complete model and its existing output head. Run it on new inputs.</td><td>Nothing is updated during ordinary prediction.</td><td>A model already trained to classify cats and dogs labels new cat/dog photographs. It can do this because the required labels match its existing outputs.</td></tr><tr><td>Standalone feature extractor</td><td>Run images through the fixed backbone and save the resulting feature vectors. A feature vector is an ordered list of numbers describing the image.</td><td>Train a separate classifier using these saved vectors.</td><td>Extract one vector per product photograph, then train a classifier to distinguish acceptable, scratched and cracked products. The extractor stays unchanged.</td></tr><tr><td>Integrated feature extractor</td><td>Place the pretrained backbone inside the new network and freeze it. Add a new head. The backbone calculates features whenever the new model runs.</td><td>Train the new head while the backbone&#x27;s weights remain fixed.</td><td>Use a frozen image backbone followed by a new three-output head for acceptable, scratched and cracked products. The complete image-to-class pipeline is one model.</td></tr><tr><td>Weight initialization followed by fine-tuning</td><td>Start from the pretrained weights, then allow selected pretrained layers to update. Replace or adapt the head as required.</td><td>Train the new head and the unfrozen part of the backbone.</td><td>After first training a product-defect head, unfreeze the last backbone block and train it with a smaller learning rate to adapt to the factory&#x27;s photographs.</td></tr></tbody></table></div>","<h3>Why the existing class labels matter</h3>","<p>A cat/dog head has two outputs with learned meanings: cat and dog. Giving it a photograph of a scratched product does not create a new output called “scratched.” For the product task, use an appropriate new head and train it on labeled product examples. Direct reuse of the original classifier is suitable only when its output meanings and preprocessing match the required task. When the task and data distribution are unchanged, this is ordinary inference rather than adaptation to a new task.</p>","<h3>Standalone versus integrated features</h3>","<p>Both methods can keep the backbone frozen. In the standalone method, feature vectors are calculated first and saved as a separate dataset; a later classifier reads that dataset. In the integrated method, each image passes through the backbone and head within one pipeline. Freezing means that the backbone parameters receive no training updates; it does not mean that the backbone stops performing calculations or that its stored weights disappear.</p>","<h3>When transfer learning is useful</h3>","<p>It is useful when labeled target data are limited and a pretrained model has learned representations relevant to the target task. It can reduce training time and the amount of target data needed. Improvement is not guaranteed: unrelated source features, unsuitable preprocessing or excessive fine-tuning on a small dataset can hurt performance. Choose the frozen or fine-tuned configuration using validation data, then evaluate the chosen model on the held-out test set.</p>","<p><strong>Exam answer structure:</strong> define transfer learning → identify the backbone and head → explain the selected reuse mode → state which weights remain fixed and which learn → give a matching example and a limitation.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c8-s18","search":"Four ways to reuse a pretrained model \n**Definition.** A pretrained model has already learned parameters from an earlier training task. We can reuse its complete classifier, reuse its feature extractor, or use its learned weights as the starting point for further training. The choice determines which output labels are available and which parameters change.\n\n**First identify two parts.** The **backbone** converts an input image into useful features. The **head** converts those features into the required prediction, such as class scores. A new task can reuse the backbone while replacing the head.\n\n**Yaad rakhne ka cue:** Purane model ka poora answer use karna, sirf features lena, ya uske weights ko aage train karna—yeh teen decisions alag hain.\n\nThe faculty reference divides these choices into the following four uses. The two feature-extractor uses differ in whether features are saved separately or computed inside the new model.\n\n| Use | What happens to the pretrained part? | What learns for the target task? | Concrete example |\n| Direct classifier | Keep the complete model and its existing output head. Run it on new inputs. | Nothing is updated during ordinary prediction. | A model already trained to classify cats and dogs labels new cat/dog photographs. It can do this because the required labels match its existing outputs. |\n| Standalone feature extractor | Run images through the fixed backbone and save the resulting feature vectors. A feature vector is an ordered list of numbers describing the image. | Train a separate classifier using these saved vectors. | Extract one vector per product photograph, then train a classifier to distinguish acceptable, scratched and cracked products. The extractor stays unchanged. |\n| Integrated feature extractor | Place the pretrained backbone inside the new network and freeze it. Add a new head. The backbone calculates features whenever the new model runs. | Train the new head while the backbone's weights remain fixed. | Use a frozen image backbone followed by a new three-output head for acceptable, scratched and cracked products. The complete image-to-class pipeline is one model. |\n| Weight initialization followed by fine-tuning | Start from the pretrained weights, then allow selected pretrained layers to update. Replace or adapt the head as required. | Train the new head and the unfrozen part of the backbone. | After first training a product-defect head, unfreeze the last backbone block and train it with a smaller learning rate to adapt to the factory's photographs. |\n\n### Why the existing class labels matter\n\nA cat/dog head has two outputs with learned meanings: cat and dog. Giving it a photograph of a scratched product does not create a new output called “scratched.” For the product task, use an appropriate new head and train it on labeled product examples. Direct reuse of the original classifier is suitable only when its output meanings and preprocessing match the required task. When the task and data distribution are unchanged, this is ordinary inference rather than adaptation to a new task.\n\n### Standalone versus integrated features\n\nBoth methods can keep the backbone frozen. In the standalone method, feature vectors are calculated first and saved as a separate dataset; a later classifier reads that dataset. In the integrated method, each image passes through the backbone and head within one pipeline. Freezing means that the backbone parameters receive no training updates; it does not mean that "}]},{"n":9,"title":"Recurrent neural networks","sections":[{"title":"Start here","blocks":["<p>This recurrent-network material is retained as an additional reference. The faculty update received on 12 October focuses MT2 on Units 3 and 4; use the TEE route for RNN study.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_state.svg\" aria-label=\"Enlarge diagram: At each time step, combine the new input with a summary carried from the previous step.\"><img src=\"assets/figures/v_rnn_state.svg\" alt=\"At each time step, combine the new input with a summary carried from the previous step.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>At each time step, combine the new input with a summary carried from the previous step. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"read","id":"mt2-c9-intro"},{"title":"What makes a sequence different","blocks":["<p class=\"definition\"><strong>Definition.</strong> A recurrent neural network (RNN) is a neural architecture that models sequential data by updating a hidden state from the current input and the previous state, using shared parameters across time steps.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c5a9455cdb766031.svg\" alt=\"h_t=\\phi(W_{xh}x_t+W_{hh}h_{t-1}+b_h)\" width=\"327.28\" height=\"24.43\" style=\"width:327.28px;height:24.43px;aspect-ratio:327.28/24.43\" loading=\"lazy\"></div>","<p>The state hₜ is a learned representation of information available up to time t. It is not a guaranteed lossless record of the entire sequence. The initial state is supplied, initialized to zero or learned, according to the model or question.</p>","<h3>Why order matters</h3>","<p>In language, audio and time series, the meaning of an observation can depend on earlier observations and their order. A basic feedforward network treating each input independently has no recurrent state. An RNN allows the output at a time step to depend on previous processing through hₜ₋₁.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Unrolling shows successive evaluations of one recurrent cell with shared parameters.\"><img src=\"assets/figures/rnn.svg\" alt=\"Unrolling shows successive evaluations of one recurrent cell with shared parameters.\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Unrolling shows successive evaluations of one recurrent cell with shared parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Parameter sharing</h3>","<p>The unrolled cells use the same Wₓₕ, Wₕₕ and bₕ at every time step. A longer input sequence increases the number of evaluations, not the number of independently learned copies of these parameters. Each new hidden state must be calculated before it is used by the next step.</p>","<h3>MT2 interpretation</h3>","<p>The TEE route contains the state equation, time-step computations, shared parameters, sequence mappings, BPTT, vanishing/exploding gradients, LSTM and GRU. RNN is outside the current focused MT2 path based on the 12 October faculty update.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c9-s0","search":"What makes a sequence different **Definition.** A recurrent neural network (RNN) is a neural architecture that models sequential data by updating a hidden state from the current input and the previous state, using shared parameters across time steps.\n\nThe state hₜ is a learned representation of information available up to time t. It is not a guaranteed lossless record of the entire sequence. The initial state is supplied, initialized to zero or learned, according to the model or question.\n\n### Why order matters\nIn language, audio and time series, the meaning of an observation can depend on earlier observations and their order. A basic feedforward network treating each input independently has no recurrent state. An RNN allows the output at a time step to depend on previous processing through hₜ₋₁.\n\n\n\n### Parameter sharing\nThe unrolled cells use the same Wₓₕ, Wₕₕ and bₕ at every time step. A longer input sequence increases the number of evaluations, not the number of independently learned copies of these parameters. Each new hidden state must be calculated before it is used by the next step.\n\n### MT2 interpretation\nThe TEE route contains the state equation, time-step computations, shared parameters, sequence mappings, BPTT, vanishing/exploding gradients, LSTM and GRU. RNN is outside the current focused MT2 path based on the 12 October faculty update.\n"},{"title":"Model answer: why recurrent networks use a hidden state","question":["<p class=\"inline-question\"><strong>Question.</strong> What is a recurrent neural network? Explain how a hidden state allows it to process a sequence and distinguish it from a feedforward network.</p>"],"answer":["<p>An RNN processes ordered inputs using a hidden state that is carried from one time step to the next. The current state combines information from the new input with information retained from earlier inputs. The same recurrent weights are reused across time steps.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_state.svg\" aria-label=\"Enlarge diagram: The previous hidden state brings earlier information into the current calculation alongside the new input.\"><img src=\"assets/figures/v_rnn_state.svg\" alt=\"The previous hidden state brings earlier information into the current calculation alongside the new input.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>The previous hidden state brings earlier information into the current calculation alongside the new input. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For a simple tanh RNN:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/015d839835ad8254.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h)\" width=\"361.62\" height=\"24.43\" style=\"width:361.62px;height:24.43px;aspect-ratio:361.62/24.43\" loading=\"lazy\"></div>","<div class=\"table-scroll\"><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>xₜ</td><td>Input at the current time step</td></tr><tr><td>hₜ₋₁</td><td>Hidden state passed from the previous step</td></tr><tr><td>Wxh</td><td>Weights connecting the current input to the hidden state</td></tr><tr><td>Whh</td><td>Weights connecting the previous state to the current state</td></tr><tr><td>bₕ</td><td>Hidden-state bias</td></tr><tr><td>hₜ</td><td>New state after the activation</td></tr></tbody></table></div>","<p>For words in a sentence, earlier words affect the state used when the next word arrives. Changing the order can therefore change the final representation. The state is a learned summary; it is not a guaranteed exact copy of every earlier input.</p>","<p>A feedforward network maps inputs through its layers without this recurrent state transition. An RNN can accept a sequence, reuse its parameters at each step and produce either an output at each step or an output from a final state, depending on the task. Examples include sentiment classification, next-word prediction and time-series modeling.</p>","<p>Unrolling an RNN draws its repeated use at t = 1, 2, 3 and so on. Those boxes share parameters; drawing three time steps does not create three independently learned copies of Whh.</p>"],"kind":"theory","id":"mt2-c9-s1","search":"Model answer: why recurrent networks use a hidden state **Question.** What is a recurrent neural network? Explain how a hidden state allows it to process a sequence and distinguish it from a feedforward network.\n\n**Model answer.**\nAn RNN processes ordered inputs using a hidden state that is carried from one time step to the next. The current state combines information from the new input with information retained from earlier inputs. The same recurrent weights are reused across time steps.\n\n\n\n\nFor a simple tanh RNN:\n\n| Symbol | Meaning |\n| xₜ | Input at the current time step |\n| hₜ₋₁ | Hidden state passed from the previous step |\n| Wxh | Weights connecting the current input to the hidden state |\n| Whh | Weights connecting the previous state to the current state |\n| bₕ | Hidden-state bias |\n| hₜ | New state after the activation |\n\nFor words in a sentence, earlier words affect the state used when the next word arrives. Changing the order can therefore change the final representation. The state is a learned summary; it is not a guaranteed exact copy of every earlier input.\n\nA feedforward network maps inputs through its layers without this recurrent state transition. An RNN can accept a sequence, reuse its parameters at each step and produce either an output at each step or an output from a final state, depending on the task. Examples include sentiment classification, next-word prediction and time-series modeling.\n\nUnrolling an RNN draws its repeated use at t = 1, 2, 3 and so on. Those boxes share parameters; drawing three time steps does not create three independently learned copies of Whh.\n"},{"title":"The vanilla RNN equations from scratch","blocks":["<p class=\"definition\"><strong>Definition.</strong> A vanilla recurrent neural network updates a hidden state from the current sequence input and the previous hidden state, using the same trainable parameters at every time step. An output transformation converts that state into the task&#x27;s prediction.</p>","<h3>Hidden-state and output equations</h3>","<p>For a tanh recurrent layer:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.24px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99a78e2772b9da6e.svg\"><img class=\"math display-math\" src=\"assets/equations/16c56e35b4a96bc6.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b_h\" width=\"292.57\" height=\"22.04\" style=\"width:292.57px;height:22.04px;aspect-ratio:292.57/22.04\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p>aₜ is the preactivation and hₜ is the activated hidden state. Wₓₕ transforms the new input; Wₕₕ transforms the previous state. Both contributions have the same hidden dimension before they are added. bₕ has one component per hidden unit.</p>","<p>For classification at time t, an output layer can produce logits and probabilities:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.07px;--narrow-height:64.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f6b889b0139771ed.svg\"><img class=\"math display-math\" src=\"assets/equations/41eb927502818778.svg\" alt=\"z_t=W_{hy}h_t+b_y,\\qquad p_t=\\operatorname{softmax}(z_t)\" width=\"404.72\" height=\"25.53\" style=\"width:404.72px;height:25.53px;aspect-ratio:404.72/25.53\" loading=\"lazy\"></picture></div>","<p>A regression output may instead be linear. A question asking only for hidden states does not require an output-layer prediction, and such a prediction cannot be calculated without the output transformation.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_state.svg\" aria-label=\"Enlarge diagram: The current input and previous activated state enter different weight transformations. Their sum is activated to obtain the next state.\"><img src=\"assets/figures/v_rnn_state.svg\" alt=\"The current input and previous activated state enter different weight transformations. Their sum is activated to obtain the next state.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>The current input and previous activated state enter different weight transformations. Their sum is activated to obtain the next state. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two recurrent time steps</h3>","<p class=\"inline-question\"><strong>Question.</strong> Let h₀ = 0, Wₓₕ = 0.5, Wₕₕ = 0.2, bₕ = 0, x₁ = 1 and x₂ = 2. Calculate h₁ and h₂ using tanh activation.</p>","<h3>Given</h3>","<p>h₀ = 0; Wxh = 0.5; Whh = 0.2; b = 0.</p>","<p>x₁ = 1; x₂ = 2; activation = tanh.</p>","<h3>To find</h3>","<p>Find h₁ and h₂ in order.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: Time step 1 — calculate the preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.04px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a11d26405f8ffbf6.svg\"><img class=\"math display-math\" src=\"assets/equations/6d7c2d3322af892b.svg\" alt=\"a_1=0.5(1)+0.2(0)+0=0.5\" width=\"316.85\" height=\"24.43\" style=\"width:316.85px;height:24.43px;aspect-ratio:316.85/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Apply the recurrent activation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc76aa14d3af5acb.svg\"><img class=\"math display-math\" src=\"assets/equations/7c336c24f0f94322.svg\" alt=\"h_1=\\tanh(0.5)\\approx0.462117157\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<p>This activated value, not a₁ = 0.5, is passed to the next time step.</p>","<p class=\"worked-step\"><strong>Step 2: Time step 2 — combine the new input and previous state.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a530e8ec85bf260b.svg\" alt=\"a_2=0.5(2)+0.2h_1+0\" width=\"246.55\" height=\"24.43\" style=\"width:246.55px;height:24.43px;aspect-ratio:246.55/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/67ad1cca6bc26681.svg\"><img class=\"math display-math\" src=\"assets/equations/45ba45a94914183c.svg\" alt=\"a_2\\approx1+0.2(0.462117157)\\approx1.092423431\" width=\"439.02\" height=\"24.43\" style=\"width:439.02px;height:24.43px;aspect-ratio:439.02/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Apply tanh to the complete new preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/47f73b96c961ac1f.svg\"><img class=\"math display-math\" src=\"assets/equations/7c7eb453d84ea5ea.svg\" alt=\"h_2=\\tanh(a_2)\\approx0.797760954\" width=\"310.37\" height=\"24.43\" style=\"width:310.37px;height:24.43px;aspect-ratio:310.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Time step</th><th>Current input</th><th>Previous state</th><th>Preactivation</th><th>New state</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>0</td><td>0.5</td><td>0.462117157</td></tr><tr><td>2</td><td>2</td><td>0.462117157</td><td>1.092423431</td><td>0.797760954</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> h₁ ≈ 0.462117 and h₂ ≈ 0.797761. Keep the full calculator value of h₁ while computing the second step. Although a₂ is greater than 1, h₂ is between −1 and 1 because tanh is applied after the affine sum. Both time steps use the same weights; this calculation contains no parameter update.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c9-s2","search":"The vanilla RNN equations from scratch \n**Definition.** A vanilla recurrent neural network updates a hidden state from the current sequence input and the previous hidden state, using the same trainable parameters at every time step. An output transformation converts that state into the task's prediction.\n\n### Hidden-state and output equations\nFor a tanh recurrent layer:\n\n\naₜ is the preactivation and hₜ is the activated hidden state. Wₓₕ transforms the new input; Wₕₕ transforms the previous state. Both contributions have the same hidden dimension before they are added. bₕ has one component per hidden unit.\n\nFor classification at time t, an output layer can produce logits and probabilities:\n\nA regression output may instead be linear. A question asking only for hidden states does not require an output-layer prediction, and such a prediction cannot be calculated without the output transformation.\n\n\n\n### Complete numerical: two recurrent time steps\n**Question.** Let h₀ = 0, Wₓₕ = 0.5, Wₕₕ = 0.2, bₕ = 0, x₁ = 1 and x₂ = 2. Calculate h₁ and h₂ using tanh activation.\n\n\n\n### Given\n\nh₀ = 0; Wxh = 0.5; Whh = 0.2; b = 0.\n\nx₁ = 1; x₂ = 2; activation = tanh.\n\n### To find\n\nFind h₁ and h₂ in order.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: Time step 1 — calculate the preactivation.**\n\n**Apply the recurrent activation.**\n\nThis activated value, not a₁ = 0.5, is passed to the next time step.\n\n**Step 2: Time step 2 — combine the new input and previous state.**\n\n\n**Apply tanh to the complete new preactivation.**\n\n\n| Time step | Current input | Previous state | Preactivation | New state |\n| 1 | 1 | 0 | 0.5 | 0.462117157 |\n| 2 | 2 | 0.462117157 | 1.092423431 | 0.797760954 |\n\n**Final answer:** h₁ ≈ 0.462117 and h₂ ≈ 0.797761. Keep the full calculator value of h₁ while computing the second step. Although a₂ is greater than 1, h₂ is between −1 and 1 because tanh is applied after the affine sum. Both time steps use the same weights; this calculation contains no parameter update.\n\n"},{"title":"A complete vector RNN calculation","blocks":["<p class=\"inline-question\"><strong>Question from R26 Q5a.</strong> xₜ = [0,1], hₜ₋₁ = [0,1], no bias is supplied, Wxh is shown below, Whh is shown below. Use tanh and rows as receiving neurons.</p>","<h3>Given</h3>","<p>Input x = [0,1]ᵀ; previous h = [0,1]ᵀ.</p>","<p>Wxh = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4f3aa9485d9c39f6.svg\" alt=\"\\begin{bmatrix}0.6 &amp; 0.4\\\\0.3 &amp; 0.7\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>.</p>","<p>Whh = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/339cb87bfb0225e4.svg\" alt=\"\\begin{bmatrix}0.5 &amp; 0.3\\\\0.2 &amp; 0.4\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>; bias = 0.</p>","<p>Apply tanh separately to the two sums.</p>","<h3>To find</h3>","<p>Find the new two-component hidden state; output-layer parameters are not supplied.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_deac39f14c.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_deac39f14c.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 new input: </strong> Wxh x = [0.6 × 0 + 0.4 × 1, 0.3 × 0 + 0.7 × 1] = [0.4,0.7].</p>","<p class=\"worked-step\"><strong>Step 2 old memory: </strong> Whh hprevious = [0.5 × 0 + 0.3 × 1, 0.2 × 0 + 0.4 × 1] = [0.3,0.4].</p>","<p class=\"worked-step\"><strong>Step 3 add: </strong> a = [0.4+0.3, 0.7+0.4] = [0.7,1.1].</p>","<p class=\"worked-step\"><strong>Step 4 activate each element: </strong> h = [tanh(0.7), tanh(1.1)] = <strong>[0.604368,0.800499]</strong>. An output-layer prediction cannot be numerically calculated without its weights and bias.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c9-s3","search":"A complete vector RNN calculation **Question from R26 Q5a.** xₜ = [0,1], hₜ₋₁ = [0,1], no bias is supplied, Wxh is shown below, Whh is shown below. Use tanh and rows as receiving neurons.\n\n\n\n### Given\n\nInput x = [0,1]ᵀ; previous h = [0,1]ᵀ.\n\nWxh = .\n\nWhh = ; bias = 0.\n\nApply tanh separately to the two sums.\n\n### To find\n\nFind the new two-component hidden state; output-layer parameters are not supplied.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1 new input: ** Wxh x = [0.6 × 0 + 0.4 × 1, 0.3 × 0 + 0.7 × 1] = [0.4,0.7].\n**Step 2 old memory: ** Whh hprevious = [0.5 × 0 + 0.3 × 1, 0.2 × 0 + 0.4 × 1] = [0.3,0.4].\n**Step 3 add: ** a = [0.4+0.3, 0.7+0.4] = [0.7,1.1].\n**Step 4 activate each element: ** h = [tanh(0.7), tanh(1.1)] = **[0.604368,0.800499]**. An output-layer prediction cannot be numerically calculated without its weights and bias."},{"title":"Sequence mappings and applications","blocks":["<p class=\"definition\"><strong>Definition.</strong> A sequence-model configuration specifies how many inputs and outputs are processed and how their time indices relate. One-to-many, many-to-one and many-to-many configurations correspond to different prediction tasks.</p>","<h3>Explanation and working</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: The number and timing of inputs and outputs determine the sequence mapping\"><img src=\"assets/figures/sequences.svg\" alt=\"The number and timing of inputs and outputs determine the sequence mapping\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>The number and timing of inputs and outputs determine the sequence mapping <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Mapping</th><th>Meaning</th><th>Example and output</th></tr></thead><tbody><tr><td>One to many</td><td>One input conditions several outputs</td><td>Image captioning: image to a word sequence</td></tr><tr><td>Many to one</td><td>Sequence summarized as one output</td><td>Review sentiment: words to positive neutral or negative</td></tr><tr><td>Many to many aligned</td><td>Output associated with each input time</td><td>Video frame labeling or per-word tagging</td></tr><tr><td>Many to many unaligned</td><td>Output sequence length may differ</td><td>Encoder-decoder translation</td></tr></tbody></table></div>","<p>Music generation can use earlier notes to predict the next note repeatedly. Next-word prediction uses the prefix to produce a probability distribution over a vocabulary. A word with the largest predicted probability is a simple choice, but the precise prediction cannot be calculated without the learned model&#x27;s weights.</p>","<p><strong>Sentence explanation: </strong> In “The dogs that bark near my house are loud,” the model should retain the plural subject across the intervening words when choosing “are”. A useful hidden representation should retain subject information while reading later words. This is an interpretation of what a trained model may learn, not a claim that an individual gate is guaranteed to represent grammar.</p>","<p><strong>Sentiment model answer: </strong> tokenize the review, map tokens to numerical embeddings, process them with a vanilla RNN, use a final state or pooled sequence representation, then a dense layer and softmax over three sentiment classes. Train with categorical cross-entropy on labeled reviews; evaluate on held-out data. A bidirectional model is not needed for this answer and is not explicitly listed in the current syllabus.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c9-s4","search":"Sequence mappings and applications **Definition.** A sequence-model configuration specifies how many inputs and outputs are processed and how their time indices relate. One-to-many, many-to-one and many-to-many configurations correspond to different prediction tasks.\n\n### Explanation and working\n\n| Mapping | Meaning | Example and output |\n| One to many | One input conditions several outputs | Image captioning: image to a word sequence |\n| Many to one | Sequence summarized as one output | Review sentiment: words to positive neutral or negative |\n| Many to many aligned | Output associated with each input time | Video frame labeling or per-word tagging |\n| Many to many unaligned | Output sequence length may differ | Encoder-decoder translation |\nMusic generation can use earlier notes to predict the next note repeatedly. Next-word prediction uses the prefix to produce a probability distribution over a vocabulary. A word with the largest predicted probability is a simple choice, but the precise prediction cannot be calculated without the learned model's weights.\n**Sentence explanation: ** In “The dogs that bark near my house are loud,” the model should retain the plural subject across the intervening words when choosing “are”. A useful hidden representation should retain subject information while reading later words. This is an interpretation of what a trained model may learn, not a claim that an individual gate is guaranteed to represent grammar.\n**Sentiment model answer: ** tokenize the review, map tokens to numerical embeddings, process them with a vanilla RNN, use a final state or pooled sequence representation, then a dense layer and softmax over three sentiment classes. Train with categorical cross-entropy on labeled reviews; evaluate on held-out data. A bidirectional model is not needed for this answer and is not explicitly listed in the current syllabus.\n"},{"title":"Shared weights and RNN applications","blocks":["<p class=\"definition\"><strong>Definition.</strong> Temporal parameter sharing means that one recurrent transition function is reused at each sequence step. It permits variable sequence lengths without learning a separate transition matrix for each position.</p>","<h3>Explanation and working</h3>","<p>The RNN applies the same input and recurrent weights at every time step. The hidden state changes as new inputs arrive; the learned rule itself is reused. This is temporal weight sharing.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_state.svg\" aria-label=\"Enlarge diagram: The same learned rule combines previous state and new input at each time step.\"><img src=\"assets/figures/v_rnn_state.svg\" alt=\"The same learned rule combines previous state and new input at each time step.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>The same learned rule combines previous state and new input at each time step. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For sentiment classification, a sequence of words leads to one sentiment label: many-to-one. For image captioning, an image representation conditions a sequence of words: one-to-many. These patterns describe how inputs and outputs are arranged, not separate update rules.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c9-s5","search":"Shared weights and RNN applications **Definition.** Temporal parameter sharing means that one recurrent transition function is reused at each sequence step. It permits variable sequence lengths without learning a separate transition matrix for each position.\n\n### Explanation and working\nThe RNN applies the same input and recurrent weights at every time step. The hidden state changes as new inputs arrive; the learned rule itself is reused. This is temporal weight sharing.\n\n\n\nFor sentiment classification, a sequence of words leads to one sentiment label: many-to-one. For image captioning, an image representation conditions a sequence of words: one-to-many. These patterns describe how inputs and outputs are arranged, not separate update rules.\n"}]},{"n":10,"title":"Prerequisite repair and teacher backprop examples","sections":[{"title":"Start here","blocks":["<p>Sources S03, S01 and the three Teams photographs supplied later. Use the short neuron and gradient questions first. The longer teacher examples are backup practice after completing the Unit 3 and Unit 4 priorities; their presence here is not a confirmed MT2 announcement.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"mt2-c10-intro"},{"title":"MT1A Q2","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> A sigmoid neuron has inputs [2,1,3], weights [0.4,−0.2,0.5] and bias 0.1. Compute its output.</p>"],"answer":["<h3>Given</h3>","<p>Inputs x₁ = 2,x₂ = 1,x₃ = 3.</p>","<p>Matching weights w₁ = 0.4,w₂ = −0.2,w₃ = 0.5.</p>","<p>Bias b = 0.1; activation = sigmoid.</p>","<h3>To find</h3>","<p>Calculate net input z and activated output a.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid output.</strong> The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.</p>","<p>z = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Minus-z ki e power, plus one, phir one divided by whole denominator.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/568d8f8a50e883d1.svg\" alt=\"x_1w_1=2(0.4)=0.8\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by weight 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2aecb1c03e00ecf3.svg\" alt=\"x_2w_2=1(-0.2)=-0.2\" width=\"249.67\" height=\"24.43\" style=\"width:249.67px;height:24.43px;aspect-ratio:249.67/24.43\" loading=\"lazy\"></div>","<p>The minus sign belongs to the weight, so the contribution stays negative.</p>","<p class=\"worked-step\"><strong>Step 3: multiply input 3 by weight 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b26c8cde278f5783.svg\" alt=\"x_3w_3=3(0.5)=1.5\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the three contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.48px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/928ca4d8a84ae46e.svg\"><img class=\"math display-math\" src=\"assets/equations/fa72e2cee0620f1c.svg\" alt=\"s=0.8+(-0.2)+1.5=0.6+1.5=2.1\" width=\"424.20\" height=\"24.43\" style=\"width:424.20px;height:24.43px;aspect-ratio:424.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc2fbdf24fc7fcdc.svg\" alt=\"z=s+b=2.1+0.1=2.2\" width=\"284.48\" height=\"18.96\" style=\"width:284.48px;height:18.96px;aspect-ratio:284.48/18.96\" loading=\"lazy\"></div>","<p>This is the preactivation. It is not yet the requested sigmoid output.</p>","<p class=\"worked-step\"><strong>Step 6: negate z for the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6ae6042702919060.svg\" alt=\"-z=-2.2\" width=\"113.19\" height=\"18.27\" style=\"width:113.19px;height:18.27px;aspect-ratio:113.19/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3e8120863f30069.svg\" alt=\"e^{-z}=e^{-2.2}\\approx0.110803158\" width=\"277.96\" height=\"23.60\" style=\"width:277.96px;height:23.60px;aspect-ratio:277.96/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:104.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/417b75e5d36172d1.svg\"><img class=\"math display-math\" src=\"assets/equations/72d833375eab0d1c.svg\" alt=\"1+e^{-z}=1+0.110803158=1.110803158\" width=\"442.16\" height=\"22.17\" style=\"width:442.16px;height:22.17px;aspect-ratio:442.16/22.17\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide one by that denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:155.40px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bc1ac01a29b10b0.svg\"><img class=\"math display-math\" src=\"assets/equations/7567a6adfafdbad0.svg\" alt=\"a=\\frac1{1+e^{-z}}=\\frac1{1.110803158}\\approx0.900249511\" width=\"467.09\" height=\"51.56\" style=\"width:467.09px;height:51.56px;aspect-ratio:467.09/51.56\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> sigmoid output ≈ 0.900249511. It lies between 0 and 1. The raw sum was 2.2, whereas the activated output is approximately 0.90025.</p>"],"kind":"practice","id":"mt2-c10-s0","search":"MT1A Q2 **Question (3 marks).** A sigmoid neuron has inputs [2,1,3], weights [0.4,−0.2,0.5] and bias 0.1. Compute its output.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInputs x₁ = 2,x₂ = 1,x₃ = 3.\n\nMatching weights w₁ = 0.4,w₂ = −0.2,w₃ = 0.5.\n\nBias b = 0.1; activation = sigmoid.\n\n### To find\n\nCalculate net input z and activated output a.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**Sigmoid output.** The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.\n\nz = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.\n\n\n\n**Yaad rakhne ka cue:** Minus-z ki e power, plus one, phir one divided by whole denominator.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: multiply input 1 by weight 1.**\n\n\n**Step 2: multiply input 2 by weight 2.**\n\nThe minus sign belongs to the weight, so the contribution stays negative.\n\n**Step 3: multiply input 3 by weight 3.**\n\n\n**Step 4: add the three contributions.**\n\n\n**Step 5: add the bias once.**\n\nThis is the preactivation. It is not yet the requested sigmoid output.\n\n**Step 6: negate z for the exponential.**\n\n\n\n**Step 7: calculate the complete denominator.**\n\n\n**Step 8: divide one by that denominator.**\n\n**Final answer:** sigmoid output ≈ 0.900249511. It lies between 0 and 1. The raw sum was 2.2, whereas the activated output is approximately 0.90025.\n"},{"title":"MT1A Q3","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> For z = [−1,0,1], calculate sigmoid, softmax and Leaky ReLU with α = 0.01 (an explicit assumption because the paper does not give the slope).</p>"],"answer":["<h3>Given</h3>","<p>Scores z = [−1,0,1].</p>","<p>Calculate sigmoid, softmax and Leaky ReLU.</p>","<p>The paper omits the Leaky slope: α = 0.01 is the stated practice assumption.</p>","<h3>To find</h3>","<p>Calculate every component under each of the three activations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<p>Sigmoid is applied separately: σ(−1) = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/983a154bf3030fc0.svg\" alt=\"\\frac{1}{1+e^{1}}\" width=\"58.25\" height=\"40.75\" style=\"width:58.25px;height:40.75px;aspect-ratio:58.25/40.75\" loading=\"lazy\"></span> = 0.268941421; σ(0) = 1/2 = 0.5; σ(1) = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b1ad72f023278d5b.svg\" alt=\"\\frac{1}{1+e^{-1}}\" width=\"68.70\" height=\"40.75\" style=\"width:68.70px;height:40.75px;aspect-ratio:68.70/40.75\" loading=\"lazy\"></span> = 0.731058579.</p>","<p class=\"worked-step\"><strong>Step 1 stabilize: </strong> subtract the largest logit 1 from every value: [-2, -1, 0]. This does not change softmax.</p>","<p class=\"worked-step\"><strong>Step 2 exponentiate: </strong> exp values = [0.135335283, 0.367879441, 1].</p>","<p class=\"worked-step\"><strong>Step 3 denominator: </strong> sum = 1.503214724.</p>","<p class=\"worked-step\"><strong>Step 4 divide each value by this same sum: </strong> probabilities = <strong>[0.090030573, 0.244728471, 0.665240956]</strong>. <strong>Check: </strong> all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.</p>","<p>Leaky ReLU multiplies only negative values by α: [0.01 × (−1),0,1] = <strong>[−0.01,0,1]</strong>. Softmax normalizes the entire vector; independent sigmoid values need not sum to 1.</p>"],"kind":"practice","id":"mt2-c10-s1","search":"MT1A Q3 **Question (3 marks).** For z = [−1,0,1], calculate sigmoid, softmax and Leaky ReLU with α = 0.01 (an explicit assumption because the paper does not give the slope).\n\n**Complete worked answer.**\n\n\n\n### Given\n\nScores z = [−1,0,1].\n\nCalculate sigmoid, softmax and Leaky ReLU.\n\nThe paper omits the Leaky slope: α = 0.01 is the stated practice assumption.\n\n### To find\n\nCalculate every component under each of the three activations.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n\nSigmoid is applied separately: σ(−1) = \\(\\frac{1}{1+e^{1}}\\) = 0.268941421; σ(0) = 1/2 = 0.5; σ(1) = \\(\\frac{1}{1+e^{-1}}\\) = 0.731058579.\n**Step 1 stabilize: ** subtract the largest logit 1 from every value: [-2, -1, 0]. This does not change softmax.\n\n**Step 2 exponentiate: ** exp values = [0.135335283, 0.367879441, 1].\n\n**Step 3 denominator: ** sum = 1.503214724.\n\n**Step 4 divide each value by this same sum: ** probabilities = **[0.090030573, 0.244728471, 0.665240956]**. **Check: ** all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.\nLeaky ReLU multiplies only negative values by α: [0.01 × (−1),0,1] = **[−0.01,0,1]**. Softmax normalizes the entire vector; independent sigmoid values need not sum to 1.\n"},{"title":"MT1A Q4","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Input x = [2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1]; W₂ is shown below; b₂ = [0.2]. Hidden and output activations are ReLU. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_bbb5f79ed7.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_bbb5f79ed7.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"210\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [2].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.2].</p>","<p>Hidden and output activations are ReLU.</p>","<p>Target y = [1].</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.90px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/11165a2e9ad9cccb.svg\"><img class=\"math display-math\" src=\"assets/equations/aac90742e2057dd1.svg\" alt=\"z_{h_1} = (0.5 \\times  2) + (0.1) = 1.1\" width=\"299.71\" height=\"24.58\" style=\"width:299.71px;height:24.58px;aspect-ratio:299.71/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51f4d0c29cd3e471.svg\" alt=\"h_{1} = \\max(0,1.1) = 1.1\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.34px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ef13baba40338fd0.svg\"><img class=\"math display-math\" src=\"assets/equations/7f3c69d6493dcb74.svg\" alt=\"z_{o_1} = (0.8 \\times  1.1) + (0.2) = 1.08\" width=\"329.37\" height=\"24.58\" style=\"width:329.37px;height:24.58px;aspect-ratio:329.37/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/965f3f37dce04d5d.svg\" alt=\"o_{1} = \\max(0,1.08) = 1.08\" width=\"262.14\" height=\"24.43\" style=\"width:262.14px;height:24.43px;aspect-ratio:262.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> The question specifies half squared loss. No learning rate is supplied, so report gradients, not invented weight updates.</p>","<p>Prediction minus target = [0.08]. Squared errors = [0.0064]. Half-sum squared loss = 0.0032; mean squared error = 0.0064. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/156b50e8d480457c.svg\"><img class=\"math display-math\" src=\"assets/equations/71054ce9ec8e2e00.svg\" alt=\"\\delta_{o_1} = 1 \\times  (1.08-1) \\times  1 = 0.08\" width=\"326.13\" height=\"24.58\" style=\"width:326.13px;height:24.58px;aspect-ratio:326.13/24.58\" loading=\"lazy\"></picture></div>","<p>The ReLU derivative is 1 here because this preactivation is positive.</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">1.1</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.08</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.088</strong><span class=\"lv-detail\">h1 → o1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.91px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/58dabafbc78878c9.svg\"><img class=\"math display-math\" src=\"assets/equations/4f9573bd5025e29a.svg\" alt=\"g_{1,1}^{(2)}=(0.08)\\times(1.1)\\approx 0.088\" width=\"299.16\" height=\"36.54\" style=\"width:299.16px;height:36.54px;aspect-ratio:299.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.08</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.8</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.064</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.064</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:203.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/234bc238f68f3454.svg\"><img class=\"math display-math\" src=\"assets/equations/8d62e6bfc12bb1ba.svg\" alt=\"C_1=(0.8)\\times(0.08)\\approx 0.064\" width=\"291.52\" height=\"24.43\" style=\"width:291.52px;height:24.43px;aspect-ratio:291.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/37af0a1e41171eca.svg\" alt=\"\\text{Sum}=C_1\\approx 0.064\" width=\"196.50\" height=\"20.89\" style=\"width:196.50px;height:20.89px;aspect-ratio:196.50/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b10ee7f796aaf918.svg\" alt=\"\\delta_{h_1} = 0.064 \\times  1 = 0.064\" width=\"248.95\" height=\"23.78\" style=\"width:248.95px;height:23.78px;aspect-ratio:248.95/23.78\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.064</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.128</strong><span class=\"lv-detail\">x1 → h1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.12px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/12beed29e7a45da4.svg\"><img class=\"math display-math\" src=\"assets/equations/a8c9a6cdcee54a64.svg\" alt=\"g_{1,1}^{(1)}=(0.064)\\times(2)\\approx 0.128\" width=\"292.37\" height=\"36.54\" style=\"width:292.37px;height:36.54px;aspect-ratio:292.37/36.54\" loading=\"lazy\"></picture></div>","<p><strong>Requested answers: </strong> dL/dw₂ = <strong>0.088</strong> and dL/db₂ = <strong>0.08</strong>. Hidden gradients above explain the dependency and are additional practice.</p>"],"kind":"practice","id":"mt2-c10-s2","search":"MT1A Q4 **Question (3 marks).** Input x = [2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1]; W₂ is shown below; b₂ = [0.2]. Hidden and output activations are ReLU. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [2].\n\nW₁ is printed with the question.\n\nb₁ = [0.1].\n\nW₂ is printed with the question.\n\nb₂ = [0.2].\n\nHidden and output activations are ReLU.\n\nTarget y = [1].\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** The question specifies half squared loss. No learning rate is supplied, so report gradients, not invented weight updates.\nPrediction minus target = [0.08]. Squared errors = [0.0064]. Half-sum squared loss = 0.0032; mean squared error = 0.0064. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe ReLU derivative is 1 here because this preactivation is positive.\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (0.08) × 1.1 = 0.088.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n**Hidden 1 downstream contribution:**\n\n\n**Step 5 input weights.** Multiply the hidden delta by the corresponding raw input, not by the hidden output.\nx1 → h1: gradient = (0.064) × (2) = 0.128.\n**Requested answers: ** dL/dw₂ = **0.088** and dL/db₂ = **0.08**. Hidden gradients above explain the dependency and are additional practice.\n"},{"title":"MT1B Q3","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Calculate sigmoid, ReLU and tanh for z = [−2,0,2].</p>"],"answer":["<h3>Given</h3>","<p>Input scores = [−2,0,2].</p>","<p>Required activations: sigmoid, ReLU and tanh.</p>","<h3>To find</h3>","<p>Calculate all three activation outputs for each score.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<p><strong>Tanh and its slope.</strong> Tanh preserves a signed output between −1 and 1. Once its output a is known, the local slope is 1−a².</p>","<p>z = value entering tanh; a = its output. A prime means derivative, or local rate of change.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11b2c40e39b0ee66.svg\" alt=\"a=\\tanh z=\\frac{e^z-e^{-z}}{e^z+e^{-z}}\" width=\"239.38\" height=\"54.23\" style=\"width:239.38px;height:54.23px;aspect-ratio:239.38/54.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b6ac5e0c1df9b26.svg\" alt=\"\\frac{da}{dz}=1-a^2\" width=\"134.64\" height=\"50.50\" style=\"width:134.64px;height:50.50px;aspect-ratio:134.64/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh signed output deta hai; slope = 1 minus output ka square.</p>","<h3>Solution — step by step</h3>","<h3>Preactivation z = -2</h3>","<p class=\"worked-step\"><strong>Step 1: negate z for sigmoid.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baed17557936141e.svg\" alt=\"-z=2\" width=\"75.18\" height=\"18.27\" style=\"width:75.18px;height:18.27px;aspect-ratio:75.18/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ee2ca92f60ab98c1.svg\" alt=\"e^{-z}\\approx7.389056099\" width=\"196.44\" height=\"20.70\" style=\"width:196.44px;height:20.70px;aspect-ratio:196.44/20.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one to form the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c833999cba87b62d.svg\"><img class=\"math display-math\" src=\"assets/equations/16b7ac365fcbbf5e.svg\" alt=\"1+7.389056099=8.389056099\" width=\"332.60\" height=\"18.52\" style=\"width:332.60px;height:18.52px;aspect-ratio:332.60/18.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: take the reciprocal for sigmoid.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.49px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c492fd878121169c.svg\"><img class=\"math display-math\" src=\"assets/equations/610916657193c755.svg\" alt=\"\\sigma(-2)=\\frac1{8.389056099}\\approx0.119202922\" width=\"398.03\" height=\"50.09\" style=\"width:398.03px;height:50.09px;aspect-ratio:398.03/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: compare z with zero for ReLU.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eb663510f8ab435b.svg\"><img class=\"math display-math\" src=\"assets/equations/31ec7384f72f0b9e.svg\" alt=\"\\mathrm{ReLU}(-2)=\\max(0,-2)=0\" width=\"308.85\" height=\"24.43\" style=\"width:308.85px;height:24.43px;aspect-ratio:308.85/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: calculate the tanh numerator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d6baa3ddebec66e.svg\"><img class=\"math display-math\" src=\"assets/equations/efa746faa7f9257e.svg\" alt=\"e^{-2}-e^{2}\\approx0.135335283-7.389056099=-7.253720816\" width=\"588.36\" height=\"23.60\" style=\"width:588.36px;height:23.60px;aspect-ratio:588.36/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: calculate the tanh denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee253631806c17e2.svg\"><img class=\"math display-math\" src=\"assets/equations/8e33913f50550c4f.svg\" alt=\"e^{-2}+e^{2}\\approx0.135335283+7.389056099=7.524391382\" width=\"569.35\" height=\"23.60\" style=\"width:569.35px;height:23.60px;aspect-ratio:569.35/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide for tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.31px;--narrow-height:128.52px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4bb67612e76e38e6.svg\"><img class=\"math display-math\" src=\"assets/equations/5a3af3ace5989f73.svg\" alt=\"\\tanh(-2)\\approx\\frac{-7.253720816}{7.524391382}\\approx-0.964027580\" width=\"471.00\" height=\"50.34\" style=\"width:471.00px;height:50.34px;aspect-ratio:471.00/50.34\" loading=\"lazy\"></picture></div>","<h3>Preactivation z = 0</h3>","<p class=\"worked-step\"><strong>Step 1: negate z for sigmoid.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3aebd020c0eccec6.svg\" alt=\"-z=0\" width=\"75.18\" height=\"18.27\" style=\"width:75.18px;height:18.27px;aspect-ratio:75.18/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f5ab9de96f693147.svg\" alt=\"e^{-z}\\approx1.000000000\" width=\"196.44\" height=\"20.70\" style=\"width:196.44px;height:20.70px;aspect-ratio:196.44/20.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one to form the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29756201dd5e46c6.svg\"><img class=\"math display-math\" src=\"assets/equations/aa21aa600ebc8e6e.svg\" alt=\"1+1.000000000=2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: take the reciprocal for sigmoid.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.48px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc3feba9268d5c6f.svg\"><img class=\"math display-math\" src=\"assets/equations/e2631bc2ce7ebc9e.svg\" alt=\"\\sigma(0)=\\frac1{2.000000000}\\approx0.500000000\" width=\"379.03\" height=\"50.09\" style=\"width:379.03px;height:50.09px;aspect-ratio:379.03/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: compare z with zero for ReLU.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8512edeebdecaad0.svg\" alt=\"\\mathrm{ReLU}(0)=\\max(0,0)=0\" width=\"270.82\" height=\"24.43\" style=\"width:270.82px;height:24.43px;aspect-ratio:270.82/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: calculate the tanh numerator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2df025bea6def52b.svg\"><img class=\"math display-math\" src=\"assets/equations/d9a65f4b4641a1c1.svg\" alt=\"e^{0}-e^{0}\\approx1.000000000-1.000000000=0.000000000\" width=\"555.91\" height=\"23.60\" style=\"width:555.91px;height:23.60px;aspect-ratio:555.91/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: calculate the tanh denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c3fb9efcb35a389.svg\"><img class=\"math display-math\" src=\"assets/equations/f1f2e3760e822d0f.svg\" alt=\"e^{0}+e^{0}\\approx1.000000000+1.000000000=2.000000000\" width=\"555.91\" height=\"23.60\" style=\"width:555.91px;height:23.60px;aspect-ratio:555.91/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide for tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.42px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3179ee482059cbdd.svg\"><img class=\"math display-math\" src=\"assets/equations/6b66e253736ed179.svg\" alt=\"\\tanh(0)\\approx\\frac{0.000000000}{2.000000000}\\approx0.000000000\" width=\"413.97\" height=\"50.09\" style=\"width:413.97px;height:50.09px;aspect-ratio:413.97/50.09\" loading=\"lazy\"></picture></div>","<h3>Preactivation z = 2</h3>","<p class=\"worked-step\"><strong>Step 1: negate z for sigmoid.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e116d9c93aba3d51.svg\" alt=\"-z=-2\" width=\"94.19\" height=\"18.27\" style=\"width:94.19px;height:18.27px;aspect-ratio:94.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/63363cd12105c12d.svg\" alt=\"e^{-z}\\approx0.135335283\" width=\"196.44\" height=\"20.70\" style=\"width:196.44px;height:20.70px;aspect-ratio:196.44/20.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one to form the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4e918224e5cd8eaa.svg\"><img class=\"math display-math\" src=\"assets/equations/cec6cfa7eb635dc5.svg\" alt=\"1+0.135335283=1.135335283\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: take the reciprocal for sigmoid.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.48px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b29d72f7254a4877.svg\"><img class=\"math display-math\" src=\"assets/equations/398e028b924c49e3.svg\" alt=\"\\sigma(2)=\\frac1{1.135335283}\\approx0.880797078\" width=\"379.03\" height=\"50.09\" style=\"width:379.03px;height:50.09px;aspect-ratio:379.03/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: compare z with zero for ReLU.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c454b416d112784d.svg\" alt=\"\\mathrm{ReLU}(2)=\\max(0,2)=2\" width=\"270.82\" height=\"24.43\" style=\"width:270.82px;height:24.43px;aspect-ratio:270.82/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: calculate the tanh numerator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/beea5fae2dfeb83f.svg\"><img class=\"math display-math\" src=\"assets/equations/03ff82884c1feede.svg\" alt=\"e^{2}-e^{-2}\\approx7.389056099-0.135335283=7.253720816\" width=\"569.35\" height=\"23.60\" style=\"width:569.35px;height:23.60px;aspect-ratio:569.35/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: calculate the tanh denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/597fbd34bf357417.svg\"><img class=\"math display-math\" src=\"assets/equations/54c21815de76e465.svg\" alt=\"e^{2}+e^{-2}\\approx7.389056099+0.135335283=7.524391382\" width=\"569.35\" height=\"23.60\" style=\"width:569.35px;height:23.60px;aspect-ratio:569.35/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide for tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.42px;--narrow-height:89.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c415e8a033259d4.svg\"><img class=\"math display-math\" src=\"assets/equations/99823d0144ee439b.svg\" alt=\"\\tanh(2)\\approx\\frac{7.253720816}{7.524391382}\\approx0.964027580\" width=\"413.97\" height=\"50.34\" style=\"width:413.97px;height:50.34px;aspect-ratio:413.97/50.34\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> sigmoid = [0.119202922, 0.5, 0.880797078]; ReLU = [0, 0, 2]; tanh = [−0.964027580, 0, 0.964027580].</p>"],"kind":"practice","id":"mt2-c10-s3","search":"MT1B Q3 **Question (3 marks).** Calculate sigmoid, ReLU and tanh for z = [−2,0,2].\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput scores = [−2,0,2].\n\nRequired activations: sigmoid, ReLU and tanh.\n\n### To find\n\nCalculate all three activation outputs for each score.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n**Tanh and its slope.** Tanh preserves a signed output between −1 and 1. Once its output a is known, the local slope is 1−a².\n\nz = value entering tanh; a = its output. A prime means derivative, or local rate of change.\n\n\n\n\n\n**Yaad rakhne ka cue:** Tanh signed output deta hai; slope = 1 minus output ka square.\n\n### Solution — step by step\n\n\n\n\n\n\n### Preactivation z = -2\n\n**Step 1: negate z for sigmoid.**\n\n\n\n\n\n\n\n**Step 2: evaluate the exponential.**\n\n\n\n\n\n\n\n**Step 3: add one to form the denominator.**\n\n\n\n\n\n\n\n**Step 4: take the reciprocal for sigmoid.**\n\n\n\n\n\n\n\n**Step 5: compare z with zero for ReLU.**\n\n\n\n\n\n\n\n**Step 6: calculate the tanh numerator.**\n\n\n\n\n\n\n\n**Step 7: calculate the tanh denominator.**\n\n\n\n\n\n\n\n**Step 8: divide for tanh.**\n\n\n\n\n\n\n\n\n### Preactivation z = 0\n\n**Step 1: negate z for sigmoid.**\n\n\n\n\n\n\n\n**Step 2: evaluate the exponential.**\n\n\n\n\n\n\n\n**Step 3: add one to form the denominator.**\n\n\n\n\n\n\n\n**Step 4: take the reciprocal for sigmoid.**\n\n\n\n\n\n\n\n**Step 5: compare z with zero for ReLU.**\n\n\n\n\n\n\n\n**Step 6: calculate the tanh numerator.**\n\n\n\n\n\n\n\n**Step 7: calculate the tanh denominator.**\n\n\n\n\n\n\n\n**Step 8: divide for tanh.**\n\n\n\n\n\n\n\n\n### Preactivation z = 2\n\n**Step 1: negate z for sigmoid.**\n\n\n\n\n\n\n\n**Step 2: evaluate the exponential.**\n\n\n\n\n\n\n\n**Step 3: add one to form the denominator.**\n\n\n\n\n\n\n\n**Step 4: take the reciprocal for sigmoid.**\n\n\n\n\n\n\n\n**Step 5: compare z with zero for ReLU.**\n\n\n\n\n\n\n\n**Step 6: calculate the tanh numerator.**\n\n\n\n\n\n\n\n**Step 7: calculate the tanh denominator.**\n\n\n\n\n\n\n\n**Step 8: divide for tanh.**\n\n\n\n\n\n\n\n**Final answer:** sigmoid = [0.119202922, 0.5, 0.880797078]; ReLU = [0, 0, 2]; tanh = [−0.964027580, 0, 0.964027580].\n"},{"title":"MT1B Q4","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Input x = [3]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are sigmoid. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_ec03263237.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_ec03263237.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"210\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [3].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.1].</p>","<p>Hidden and output activations are sigmoid.</p>","<p>Target y = [1].</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.90px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/624d0aa704cb40ed.svg\"><img class=\"math display-math\" src=\"assets/equations/8d4aa9c483de249e.svg\" alt=\"z_{h_1} = (0.4 \\times  3) + (0.2) = 1.4\" width=\"299.71\" height=\"24.58\" style=\"width:299.71px;height:24.58px;aspect-ratio:299.71/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c20e39027aee1353.svg\"><img class=\"math display-math\" src=\"assets/equations/eddfa3ffedc7ea27.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(1.4)}}=0.802183889\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f73d73bef40a3e53.svg\"><img class=\"math display-math\" src=\"assets/equations/6ee49ebab88ca242.svg\" alt=\"z_{o_1} = (0.6 \\times  0.802183889) + (0.1) = 0.581310333\" width=\"512.62\" height=\"24.58\" style=\"width:512.62px;height:24.58px;aspect-ratio:512.62/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72c83495e26a383d.svg\"><img class=\"math display-math\" src=\"assets/equations/909595bd0fd39ab1.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.581310333)}}=0.641368858\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> Use the half squared loss stated in this question. No learning rate is supplied.</p>","<p>Prediction minus target = [-0.358631142]. Squared errors = [0.128616296]. Half-sum squared loss = 0.064308148; mean squared error = 0.128616296. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4b919c902c0118b6.svg\"><img class=\"math display-math\" src=\"assets/equations/cee1321a8d736f56.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.641368858-1) \\times  0.230014846 = -0.082490487\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.802183889</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.082490487</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.066172539</strong><span class=\"lv-detail\">h1 → o1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/275f10a4f3768fee.svg\"><img class=\"math display-math\" src=\"assets/equations/79c1b8202fcf991a.svg\" alt=\"g_{1,1}^{(2)}=(-0.082490487)\\times(0.802183889)\\approx -0.066172539\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.082490487</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.6</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.049494292</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.049494292</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d8c0fdc1c33b51f1.svg\"><img class=\"math display-math\" src=\"assets/equations/8e21ad6a02297b75.svg\" alt=\"C_1=(0.6)\\times(-0.082490487)\\approx -0.049494292\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8e5ced5b8d72aefa.svg\"><img class=\"math display-math\" src=\"assets/equations/569b8ebcbf1272c9.svg\" alt=\"\\text{Sum}=C_1\\approx -0.049494292\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d94f5a36d64f33c1.svg\"><img class=\"math display-math\" src=\"assets/equations/059d2cfd4db853f1.svg\" alt=\"\\delta_{h_1} = -0.049494292 \\times  0.158684897 = -0.007853997\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">3</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.007853997</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.02356199</strong><span class=\"lv-detail\">x1 → h1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8fbb5c252349f4b6.svg\"><img class=\"math display-math\" src=\"assets/equations/d7d37c7aaeaeb2f8.svg\" alt=\"g_{1,1}^{(1)}=(-0.007853997)\\times(3)\\approx -0.02356199\" width=\"464.77\" height=\"36.54\" style=\"width:464.77px;height:36.54px;aspect-ratio:464.77/36.54\" loading=\"lazy\"></picture></div>","<p><strong>Requested answers: </strong> dL/dw₂ = <strong>−0.066172539</strong>; dL/db₂ = <strong>−0.082490487</strong>. Negative gradients mean ordinary gradient descent would increase those parameters.</p>"],"kind":"practice","id":"mt2-c10-s4","search":"MT1B Q4 **Question (3 marks).** Input x = [3]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are sigmoid. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [3].\n\nW₁ is printed with the question.\n\nb₁ = [0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.1].\n\nHidden and output activations are sigmoid.\n\nTarget y = [1].\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** Use the half squared loss stated in this question. No learning rate is supplied.\nPrediction minus target = [-0.358631142]. Squared errors = [0.128616296]. Half-sum squared loss = 0.064308148; mean squared error = 0.128616296. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe derivative is o(1−o).\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (-0.082490487) × 0.802183889 = -0.066172539.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n**Hidden 1 downstream contribution:**\n\n\n**Step 5 input weights.** Multiply the hidden delta by the corresponding raw input, not by the hidden output.\nx1 → h1: gradient = (-0.007853997) × (3) = -0.02356199.\n**Requested answers: ** dL/dw₂ = **−0.066172539**; dL/db₂ = **−0.082490487**. Negative gradients mean ordinary gradient descent would increase those parameters.\n"},{"title":"Teacher vectorized ReLU example","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_handwritten.svg\" aria-label=\"Enlarge diagram: The teacher vectorized example with its exact connections\"><img src=\"assets/figures/net_handwritten.svg\" alt=\"The teacher vectorized example with its exact connections\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>The teacher vectorized example with its exact connections <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Input x = [2, 3]. Each row below lists the incoming weights of one receiving neuron. W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/386eee5b3bdd13ab.svg\" alt=\"\\begin{bmatrix}0.11 &amp; 0.21\\\\0.12 &amp; 0.08\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>; b₁ = [0, 0]; W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/d33649adcaa2e9c5.svg\" alt=\"\\begin{bmatrix}0.14 &amp; 0.15\\end{bmatrix}\" width=\"97.15\" height=\"19.00\" style=\"width:97.15px;height:19.00px;aspect-ratio:97.15/19.00\" loading=\"lazy\"></span>; b₂ = [0]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.05. Use half squared loss and perform forward and backward passes.</p>","<h3>Given</h3>","<p>Input x = [2, 3].</p>","<p>W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/386eee5b3bdd13ab.svg\" alt=\"\\begin{bmatrix}0.11 &amp; 0.21\\\\0.12 &amp; 0.08\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>.</p>","<p>b₁ = [0, 0].</p>","<p>W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/d33649adcaa2e9c5.svg\" alt=\"\\begin{bmatrix}0.14 &amp; 0.15\\end{bmatrix}\" width=\"97.15\" height=\"19.00\" style=\"width:97.15px;height:19.00px;aspect-ratio:97.15/19.00\" loading=\"lazy\"></span>.</p>","<p>b₂ = [0].</p>","<p>Hidden and output activations are ReLU.</p>","<p>Target y = [1].</p>","<p>Learning rate η = 0.05.</p>","<p>Use half squared loss and perform forward and backward passes.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.51px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/89d0bf0bfbd0eee8.svg\"><img class=\"math display-math\" src=\"assets/equations/977db4dfa37a6afe.svg\" alt=\"z_{h_1} = (0.11 \\times  2) + (0.21 \\times  3) + (0) = 0.85\" width=\"439.55\" height=\"24.58\" style=\"width:439.55px;height:24.58px;aspect-ratio:439.55/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86a3de78168e02c1.svg\" alt=\"h_{1} = \\max(0,0.85) = 0.85\" width=\"264.36\" height=\"24.43\" style=\"width:264.36px;height:24.43px;aspect-ratio:264.36/24.43\" loading=\"lazy\"></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.51px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/71f2cfea44a277ff.svg\"><img class=\"math display-math\" src=\"assets/equations/ae9a1b94e41b8118.svg\" alt=\"z_{h_2} = (0.12 \\times  2) + (0.08 \\times  3) + (0) = 0.48\" width=\"439.55\" height=\"24.58\" style=\"width:439.55px;height:24.58px;aspect-ratio:439.55/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5c17f7904703c18.svg\" alt=\"h_{2} = \\max(0,0.48) = 0.48\" width=\"264.36\" height=\"24.43\" style=\"width:264.36px;height:24.43px;aspect-ratio:264.36/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.74px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30c6287eca7be224.svg\"><img class=\"math display-math\" src=\"assets/equations/c5d0ce28abb02731.svg\" alt=\"z_{o_1} = (0.14 \\times  0.85) + (0.15 \\times  0.48) + (0) = 0.191\" width=\"512.64\" height=\"24.58\" style=\"width:512.64px;height:24.58px;aspect-ratio:512.64/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0510bc5bdad8a8b2.svg\" alt=\"o_{1} = \\max(0,0.191) = 0.191\" width=\"286.58\" height=\"24.43\" style=\"width:286.58px;height:24.43px;aspect-ratio:286.58/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.809]. Squared errors = [0.654481]. Half-sum squared loss = 0.3272405; mean squared error = 0.654481. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.23px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0231cff1e5d205d.svg\"><img class=\"math display-math\" src=\"assets/equations/24763fc6860afd3e.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.191-1) \\times  1 = -0.809\" width=\"369.58\" height=\"24.58\" style=\"width:369.58px;height:24.58px;aspect-ratio:369.58/24.58\" loading=\"lazy\"></picture></div>","<p>The ReLU derivative is 1 here because this preactivation is positive.</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.85</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.809</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.68765</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.14</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.1743825</strong></div></div><p>Subtract η × gradient = <b>−0.0343825</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.35px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7b158dc1aab8c85.svg\"><img class=\"math display-math\" src=\"assets/equations/e7ee971a6dfd8bcc.svg\" alt=\"g_{1,1}^{(2)}=(-0.809)\\times(0.85)\\approx -0.68765\" width=\"386.05\" height=\"36.54\" style=\"width:386.05px;height:36.54px;aspect-ratio:386.05/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5a6b892831ec0aa5.svg\"><img class=\"math display-math\" src=\"assets/equations/a1a6aafaa6af94cf.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.14-0.05(-0.68765)\\approx 0.1743825\" width=\"486.30\" height=\"36.54\" style=\"width:486.30px;height:36.54px;aspect-ratio:486.30/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.48</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.809</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.38832</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.169416</strong></div></div><p>Subtract η × gradient = <b>−0.019416</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.35px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d09d2ce4b3621339.svg\"><img class=\"math display-math\" src=\"assets/equations/289592bf5d88c4d2.svg\" alt=\"g_{1,2}^{(2)}=(-0.809)\\times(0.48)\\approx -0.38832\" width=\"386.05\" height=\"36.54\" style=\"width:386.05px;height:36.54px;aspect-ratio:386.05/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/780b675c44e8ec0a.svg\"><img class=\"math display-math\" src=\"assets/equations/ae18879446b6ea9d.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.15-0.05(-0.38832)\\approx 0.169416\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.809</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.14</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.11326</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.11326</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9be822c811879a17.svg\"><img class=\"math display-math\" src=\"assets/equations/53405206a97657fd.svg\" alt=\"C_1=(0.14)\\times(-0.809)\\approx -0.11326\" width=\"378.42\" height=\"24.43\" style=\"width:378.42px;height:24.43px;aspect-ratio:378.42/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e31db28d376c594d.svg\" alt=\"\\text{Sum}=C_1\\approx -0.11326\" width=\"239.93\" height=\"20.89\" style=\"width:239.93px;height:20.89px;aspect-ratio:239.93/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.15px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0406bf395ccea595.svg\"><img class=\"math display-math\" src=\"assets/equations/ce1e6b90f6c99a43.svg\" alt=\"\\delta_{h_1} = -0.11326 \\times  1 = -0.11326\" width=\"335.84\" height=\"23.78\" style=\"width:335.84px;height:23.78px;aspect-ratio:335.84/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.809</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.12135</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.12135</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/628dab575705c1e4.svg\"><img class=\"math display-math\" src=\"assets/equations/1763bcb69a11b8d9.svg\" alt=\"C_1=(0.15)\\times(-0.809)\\approx -0.12135\" width=\"378.42\" height=\"24.43\" style=\"width:378.42px;height:24.43px;aspect-ratio:378.42/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f74169ed59976f22.svg\" alt=\"\\text{Sum}=C_1\\approx -0.12135\" width=\"239.93\" height=\"20.89\" style=\"width:239.93px;height:20.89px;aspect-ratio:239.93/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.15px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/73149a9e0e57e742.svg\"><img class=\"math display-math\" src=\"assets/equations/bff8528433d7519f.svg\" alt=\"\\delta_{h_2} = -0.12135 \\times  1 = -0.12135\" width=\"335.84\" height=\"23.78\" style=\"width:335.84px;height:23.78px;aspect-ratio:335.84/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.11326</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.22652</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.11</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.121326</strong></div></div><p>Subtract η × gradient = <b>−0.011326</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6540c5b7941f90d3.svg\"><img class=\"math display-math\" src=\"assets/equations/d4fe1c7bccab7769.svg\" alt=\"g_{1,1}^{(1)}=(-0.11326)\\times(2)\\approx -0.22652\" width=\"379.25\" height=\"36.54\" style=\"width:379.25px;height:36.54px;aspect-ratio:379.25/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/857c0ad228d64fc5.svg\"><img class=\"math display-math\" src=\"assets/equations/f709770d92b5a6d7.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.11-0.05(-0.22652)\\approx 0.121326\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.11326</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.33978</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.21</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.226989</strong></div></div><p>Subtract η × gradient = <b>−0.016989</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93e0a3007b972754.svg\"><img class=\"math display-math\" src=\"assets/equations/851d3df89190bcd1.svg\" alt=\"g_{1,2}^{(1)}=(-0.11326)\\times(3)\\approx -0.33978\" width=\"379.25\" height=\"36.54\" style=\"width:379.25px;height:36.54px;aspect-ratio:379.25/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3e18578432e574df.svg\"><img class=\"math display-math\" src=\"assets/equations/5a3350f101c32e1b.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.21-0.05(-0.33978)\\approx 0.226989\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.12135</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.2427</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.12</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.132135</strong></div></div><p>Subtract η × gradient = <b>−0.012135</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5d0a80d06a8382c.svg\"><img class=\"math display-math\" src=\"assets/equations/80079b2d3df7b0fb.svg\" alt=\"g_{2,1}^{(1)}=(-0.12135)\\times(2)\\approx -0.2427\" width=\"367.04\" height=\"36.54\" style=\"width:367.04px;height:36.54px;aspect-ratio:367.04/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:179.22px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f91b7787569a2882.svg\"><img class=\"math display-math\" src=\"assets/equations/ce1785dad16e9ba5.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.12-0.05(-0.2427)\\approx 0.132135\" width=\"461.87\" height=\"36.54\" style=\"width:461.87px;height:36.54px;aspect-ratio:461.87/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.12135</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.36405</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.08</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.0982025</strong></div></div><p>Subtract η × gradient = <b>−0.0182025</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f8d27aa1e3f5627.svg\"><img class=\"math display-math\" src=\"assets/equations/a1b23a6eb1610029.svg\" alt=\"g_{2,2}^{(1)}=(-0.12135)\\times(3)\\approx -0.36405\" width=\"379.25\" height=\"36.54\" style=\"width:379.25px;height:36.54px;aspect-ratio:379.25/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6cd428530ca786f9.svg\"><img class=\"math display-math\" src=\"assets/equations/5d899a39e45c0338.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.08-0.05(-0.36405)\\approx 0.0982025\" width=\"486.30\" height=\"36.54\" style=\"width:486.30px;height:36.54px;aspect-ratio:486.30/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2bb2563809fc624e.svg\"><img class=\"math display-math\" src=\"assets/equations/6a689b75bd65601f.svg\" alt=\"b_{h_1,\\mathrm{new}}=0-0.05(-0.113260000)=0.005663000\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2db77709ff0c80b8.svg\"><img class=\"math display-math\" src=\"assets/equations/1a16f67956817315.svg\" alt=\"b_{h_2,\\mathrm{new}}=0-0.05(-0.121350000)=0.006067500\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a95d59624552356.svg\"><img class=\"math display-math\" src=\"assets/equations/f01c357a6fdbd536.svg\" alt=\"b_{o_1,\\mathrm{new}}=0-0.05(-0.809000000)=0.040450000\" width=\"509.64\" height=\"25.35\" style=\"width:509.64px;height:25.35px;aspect-ratio:509.64/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Correction to the handwritten working: </strong> the hidden deltas are negative (−0.11326 and −0.12135). A positive value at that step is a sign error. Keep output error as prediction minus target throughout.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c10-s5","search":"Teacher vectorized ReLU example \n**Question.** Input x = [2, 3]. Each row below lists the incoming weights of one receiving neuron. W₁ = ; b₁ = [0, 0]; W₂ = ; b₂ = [0]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.05. Use half squared loss and perform forward and backward passes.\n\n\n\n### Given\n\nInput x = [2, 3].\n\nW₁ = .\n\nb₁ = [0, 0].\n\nW₂ = .\n\nb₂ = [0].\n\nHidden and output activations are ReLU.\n\nTarget y = [1].\n\nLearning rate η = 0.05.\n\nUse half squared loss and perform forward and backward passes.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.809]. Squared errors = [0.654481]. Half-sum squared loss = 0.3272405; mean squared error = 0.654481. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe ReLU derivative is 1 here because this preactivation is positive.\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (-0.809) × 0.85 = -0.68765. New weight = 0.14−0.05 × (-0.68765) = **0.1743825**.\nh2 → o1: gradient = (-0.809) × 0.48 = -0.38832. New weight = 0.15−0.05 × (-0.38832) = **0.169416**.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n*"},{"title":"Teams photos full sigmoid example","blocks":["<p>The three photographs show this 2 → 2 → 2 network and its chain rule. The photo label for w₃ is read as 0.25, consistent with the visible output/error values and the matching worked example in S05. Learning rate is not legible/specified in these photos; η = 0.5 below is an explicit practice assumption.</p>","<p class=\"inline-question\"><strong>Question.</strong> Input x = [0.05, 0.1]. Each row below lists the incoming weights of one receiving neuron. W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/82d4501fc485058b.svg\" alt=\"\\begin{bmatrix}0.15 &amp; 0.2\\\\0.25 &amp; 0.3\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>; b₁ = [0.35, 0.35]; W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6699cc1064bfaf3.svg\" alt=\"\\begin{bmatrix}0.4 &amp; 0.45\\\\0.5 &amp; 0.55\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>; b₂ = [0.6, 0.6]. Hidden and output activations are sigmoid. Target y = [0.01, 0.99]. Learning rate η = 0.5. Compute all outputs, total half squared loss, all eight weight gradients and one simultaneous weight update. Map weights in order: w₁ = x₁ → h₁, w₂ = x₂ → h₁, w₃ = x₁ → h₂, w₄ = x₂ → h₂; w₅ = h₁ → o₁, w₆ = h₂ → o₁, w₇ = h₁ → o₂, w₈ = h₂ → o₂.</p>","<h3>Given</h3>","<p>Input x = [0.05, 0.1].</p>","<p>W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/82d4501fc485058b.svg\" alt=\"\\begin{bmatrix}0.15 &amp; 0.2\\\\0.25 &amp; 0.3\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>.</p>","<p>b₁ = [0.35, 0.35].</p>","<p>W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6699cc1064bfaf3.svg\" alt=\"\\begin{bmatrix}0.4 &amp; 0.45\\\\0.5 &amp; 0.55\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>.</p>","<p>b₂ = [0.6, 0.6].</p>","<p>Hidden and output activations are sigmoid.</p>","<p>Target y = [0.01, 0.99].</p>","<p>Learning rate η = 0.5.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/teams.svg\" aria-label=\"Enlarge diagram: Every arrow in the teacher example is labeled so the two backward paths can be traced\"><img src=\"assets/figures/teams.svg\" alt=\"Every arrow in the teacher example is labeled so the two backward paths can be traced\" width=\"960\" height=\"490\" loading=\"lazy\"></button><figcaption>Every arrow in the teacher example is labeled so the two backward paths can be traced <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.53px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/feca30d72e6cdb12.svg\"><img class=\"math display-math\" src=\"assets/equations/1be2ce6f8e5a6ae7.svg\" alt=\"z_{h_1} = (0.15 \\times  0.05) + (0.2 \\times  0.1) + (0.35) = 0.3775\" width=\"533.23\" height=\"24.58\" style=\"width:533.23px;height:24.58px;aspect-ratio:533.23/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.46px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e586b2530e4f9cf0.svg\"><img class=\"math display-math\" src=\"assets/equations/2196ffb4d15fecbe.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(0.3775)}}=0.593269992\" width=\"360.01\" height=\"53.84\" style=\"width:360.01px;height:53.84px;aspect-ratio:360.01/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.53px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0d0fc7f16047fdb4.svg\"><img class=\"math display-math\" src=\"assets/equations/3ec93d9dd746e448.svg\" alt=\"z_{h_2} = (0.25 \\times  0.05) + (0.3 \\times  0.1) + (0.35) = 0.3925\" width=\"533.23\" height=\"24.58\" style=\"width:533.23px;height:24.58px;aspect-ratio:533.23/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.46px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/78d6d0a3e42830ce.svg\"><img class=\"math display-math\" src=\"assets/equations/8275f180adb30096.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.3925)}}=0.596884378\" width=\"360.01\" height=\"53.84\" style=\"width:360.01px;height:53.84px;aspect-ratio:360.01/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/587365feb9b3026e.svg\"><img class=\"math display-math\" src=\"assets/equations/a499c079904c4335.svg\" alt=\"z_{o_1} = (0.4 \\times  0.593269992) + (0.45 \\times  0.596884378) + (0.6) = 1.105905967\" width=\"763.79\" height=\"24.58\" style=\"width:763.79px;height:24.58px;aspect-ratio:763.79/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a028b62b987f7076.svg\"><img class=\"math display-math\" src=\"assets/equations/3a8725cabdafc869.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(1.105905967)}}=0.75136507\" width=\"388.77\" height=\"53.84\" style=\"width:388.77px;height:53.84px;aspect-ratio:388.77/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a3d7358ccdf52d31.svg\"><img class=\"math display-math\" src=\"assets/equations/8f06ed5dcff2563f.svg\" alt=\"z_{o_2} = (0.5 \\times  0.593269992) + (0.55 \\times  0.596884378) + (0.6) = 1.224921404\" width=\"763.79\" height=\"24.58\" style=\"width:763.79px;height:24.58px;aspect-ratio:763.79/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/378ac86a046b16fc.svg\"><img class=\"math display-math\" src=\"assets/equations/624e9e7741da0cb6.svg\" alt=\"o_{2}=\\frac{1}{1+e^{-(1.224921404)}}=0.772928465\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> The photos explicitly use ½(t₁−o₁)² + ½(t₂−o₂)². With exactly two output components, this equals their mean squared error, 0.298371109. The unhalved sum is 0.596742218.</p>","<p>Prediction minus target = [0.74136507, -0.217071535]. Squared errors = [0.549622166, 0.047120051]. Half-sum squared loss = 0.298371109; mean squared error = 0.298371109. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.94px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ffde7979414e34c0.svg\"><img class=\"math display-math\" src=\"assets/equations/071d20abad3f9df8.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.75136507-0.01) \\times  0.186815602 = 0.138498562\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p><strong>Output delta 2:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e7235b42f1e0b22.svg\"><img class=\"math display-math\" src=\"assets/equations/65a80e7107d22398.svg\" alt=\"\\delta_{o_2} = 1 \\times  (0.772928465-0.99) \\times  0.175510053 = -0.038098237\" width=\"664.16\" height=\"24.58\" style=\"width:664.16px;height:24.58px;aspect-ratio:664.16/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.593269992</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.138498562</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.082167041</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.35891648</strong></div></div><p>Subtract η × gradient = <b>0.04108352</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8d844a8676791dfd.svg\"><img class=\"math display-math\" src=\"assets/equations/a9b1122ca44cd5cd.svg\" alt=\"g_{1,1}^{(2)}=(0.138498562)\\times(0.593269992)\\approx 0.082167041\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3afaa45378006799.svg\"><img class=\"math display-math\" src=\"assets/equations/89c2c818c7a2e7dd.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.4-0.5(0.082167041)\\approx 0.35891648\" width=\"503.95\" height=\"36.54\" style=\"width:503.95px;height:36.54px;aspect-ratio:503.95/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.596884378</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.138498562</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.082667628</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.45</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.408666186</strong></div></div><p>Subtract η × gradient = <b>0.041333814</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/df479afdae4fe00d.svg\"><img class=\"math display-math\" src=\"assets/equations/c40f5279cb6e8a57.svg\" alt=\"g_{1,2}^{(2)}=(0.138498562)\\times(0.596884378)\\approx 0.082667628\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ad573638df0109c.svg\"><img class=\"math display-math\" src=\"assets/equations/4aaec1199c9864bb.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.45-0.5(0.082667628)\\approx 0.408666186\" width=\"528.38\" height=\"36.54\" style=\"width:528.38px;height:36.54px;aspect-ratio:528.38/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h1 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.593269992</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.038098237</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.02260254</strong><span class=\"lv-detail\">h1 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.51130127</strong></div></div><p>Subtract η × gradient = <b>−0.01130127</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dde4ee7e9e8f997c.svg\" alt=\"g_{2,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,1}}=\\delta_{o_2}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f032d0a14a103c60.svg\"><img class=\"math display-math\" src=\"assets/equations/35e5314b87f154a8.svg\" alt=\"g_{2,1}^{(2)}=(-0.038098237)\\times(0.593269992)\\approx -0.02260254\" width=\"581.52\" height=\"36.54\" style=\"width:581.52px;height:36.54px;aspect-ratio:581.52/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.86px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/62292012970cdab4.svg\"><img class=\"math display-math\" src=\"assets/equations/80442c4c79c12529.svg\" alt=\"W^{(2)}_{2,1,\\mathrm{new}}=0.5-0.5(-0.02260254)\\approx 0.51130127\" width=\"510.74\" height=\"36.54\" style=\"width:510.74px;height:36.54px;aspect-ratio:510.74/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.596884378</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.038098237</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.022740242</strong><span class=\"lv-detail\">h2 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.561370121</strong></div></div><p>Subtract η × gradient = <b>−0.011370121</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57d7e754e94fe533.svg\" alt=\"g_{2,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,2}}=\\delta_{o_2}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/02d5efeb8dafde38.svg\"><img class=\"math display-math\" src=\"assets/equations/890a2f895bb237f9.svg\" alt=\"g_{2,2}^{(2)}=(-0.038098237)\\times(0.596884378)\\approx -0.022740242\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/af1284429e824dd6.svg\"><img class=\"math display-math\" src=\"assets/equations/f2313d50d5e6909b.svg\" alt=\"W^{(2)}_{2,2,\\mathrm{new}}=0.55-0.5(-0.022740242)\\approx 0.561370121\" width=\"547.39\" height=\"36.54\" style=\"width:547.39px;height:36.54px;aspect-ratio:547.39/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.138498562</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.055399425</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.038098237</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.019049118</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.036350306</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7ba541a2ae61050.svg\"><img class=\"math display-math\" src=\"assets/equations/4e8c5af2cd60942b.svg\" alt=\"C_1=(0.4)\\times(0.138498562)\\approx 0.055399425\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/899ef2a84df9b3cd.svg\"><img class=\"math display-math\" src=\"assets/equations/fb089b7c1d8f6873.svg\" alt=\"C_2=(0.5)\\times(-0.038098237)\\approx -0.019049118\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/167389750e490b23.svg\"><img class=\"math display-math\" src=\"assets/equations/2537e0a69ea64761.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.036350306\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3d990b0c410497e3.svg\"><img class=\"math display-math\" src=\"assets/equations/2792e998f36b387c.svg\" alt=\"\\delta_{h_1} = 0.036350306 \\times  0.241300709 = 0.008771355\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.138498562</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.45</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.062324353</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.038098237</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.02095403</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.041370323</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/78866731f335909d.svg\"><img class=\"math display-math\" src=\"assets/equations/88812c8e2d3784df.svg\" alt=\"C_1=(0.45)\\times(0.138498562)\\approx 0.062324353\" width=\"462.57\" height=\"24.43\" style=\"width:462.57px;height:24.43px;aspect-ratio:462.57/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2b032a83e37967d3.svg\"><img class=\"math display-math\" src=\"assets/equations/fea577940f5fb0f2.svg\" alt=\"C_2=(0.55)\\times(-0.038098237)\\approx -0.02095403\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5c3c002092c7eca9.svg\"><img class=\"math display-math\" src=\"assets/equations/e59e8769f280fbd2.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.041370323\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bdbc44ac317050d2.svg\"><img class=\"math display-math\" src=\"assets/equations/31d2f2dbdaea47ab.svg\" alt=\"\\delta_{h_2} = 0.041370323 \\times  0.240613417 = 0.009954255\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.05</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008771355</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000438568</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.149780716</strong></div></div><p>Subtract η × gradient = <b>0.000219284</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2525430dc0c2af1f.svg\"><img class=\"math display-math\" src=\"assets/equations/9d2ed0236b62ab2a.svg\" alt=\"g_{1,1}^{(1)}=(0.008771355)\\times(0.05)\\approx 0.000438568\" width=\"470.20\" height=\"36.54\" style=\"width:470.20px;height:36.54px;aspect-ratio:470.20/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/db7d742025f4d68e.svg\"><img class=\"math display-math\" src=\"assets/equations/4f7a0b344b0cf201.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.15-0.5(0.000438568)\\approx 0.149780716\" width=\"528.38\" height=\"36.54\" style=\"width:528.38px;height:36.54px;aspect-ratio:528.38/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008771355</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000877135</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.199561432</strong></div></div><p>Subtract η × gradient = <b>0.000438568</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/753fcf33c45e8537.svg\"><img class=\"math display-math\" src=\"assets/equations/1850aa156783fa4e.svg\" alt=\"g_{1,2}^{(1)}=(0.008771355)\\times(0.1)\\approx 0.000877135\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/738f6089731cd94e.svg\"><img class=\"math display-math\" src=\"assets/equations/0bf05631c8b81136.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.2-0.5(0.000877135)\\approx 0.199561432\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.05</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.009954255</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000497713</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.249751144</strong></div></div><p>Subtract η × gradient = <b>0.000248856</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/76611b6fffb6eae0.svg\"><img class=\"math display-math\" src=\"assets/equations/12dc3d7596ccb7c2.svg\" alt=\"g_{2,1}^{(1)}=(0.009954255)\\times(0.05)\\approx 0.000497713\" width=\"470.20\" height=\"36.54\" style=\"width:470.20px;height:36.54px;aspect-ratio:470.20/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8c4ebc4a08766591.svg\"><img class=\"math display-math\" src=\"assets/equations/46b3c1d000945dc9.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.25-0.5(0.000497713)\\approx 0.249751144\" width=\"528.38\" height=\"36.54\" style=\"width:528.38px;height:36.54px;aspect-ratio:528.38/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.009954255</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000995425</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.299502287</strong></div></div><p>Subtract η × gradient = <b>0.000497712</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3534da4dd6514b21.svg\"><img class=\"math display-math\" src=\"assets/equations/28799f80ac592874.svg\" alt=\"g_{2,2}^{(1)}=(0.009954255)\\times(0.1)\\approx 0.000995425\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/770fd618f5ab4f7d.svg\"><img class=\"math display-math\" src=\"assets/equations/f0ef9e4142c40173.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.3-0.5(0.000995425)\\approx 0.299502287\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0caa37a084caf21.svg\"><img class=\"math display-math\" src=\"assets/equations/2c688c2612d04439.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.35-0.5(0.008771355)=0.345614322\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b81e2513786c90a9.svg\"><img class=\"math display-math\" src=\"assets/equations/ef67240d0fdef037.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.35-0.5(0.009954255)=0.345022872\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37ec194c9837cd70.svg\"><img class=\"math display-math\" src=\"assets/equations/59d69997bb013f94.svg\" alt=\"b_{o_1,\\mathrm{new}}=0.6-0.5(0.138498562)=0.530750719\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2267211e36f3ce48.svg\"><img class=\"math display-math\" src=\"assets/equations/f8b71ed80001f62a.svg\" alt=\"b_{o_2,\\mathrm{new}}=0.6-0.5(-0.038098237)=0.619049118\" width=\"516.43\" height=\"25.35\" style=\"width:516.43px;height:25.35px;aspect-ratio:516.43/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Why the photos add two terms for h₁: </strong> dL/dh₁ = δo₁w₅ + δo₂w₇ = 0.138498562 × 0.4 + (−0.038098237) × 0.5 = 0.055399425−0.019049118 = 0.036350306. Now multiply by h₁(1−h₁) = 0.241300709 to obtain δh₁ = 0.008771355; multiply by x₁ = 0.05 to obtain dL/dw₁ = 0.000438568. Adding the two output paths is essential.</p>","<p><strong>Memory sequence: </strong> error → output slope → outgoing weight → add paths → hidden slope → input. If you can explain why each factor appears, changed numbers or extra output neurons are much less confusing.</p>","<p><strong>Bias convention: </strong> the photo draws one bias value per layer. If these are literally tied scalars rather than equal initial per-neuron biases, sum the relevant deltas: hidden shared b becomes 0.35−0.5(0.008771355+0.009954255) = 0.340637195; output shared b becomes 0.6−0.5(0.138498562−0.038098237) = 0.549799837. If only weights are requested, do not invent a bias update requirement.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c10-s6","search":"Teams photos full sigmoid example The three photographs show this 2 → 2 → 2 network and its chain rule. The photo label for w₃ is read as 0.25, consistent with the visible output/error values and the matching worked example in S05. Learning rate is not legible/specified in these photos; η = 0.5 below is an explicit practice assumption.\n**Question.** Input x = [0.05, 0.1]. Each row below lists the incoming weights of one receiving neuron. W₁ = ; b₁ = [0.35, 0.35]; W₂ = ; b₂ = [0.6, 0.6]. Hidden and output activations are sigmoid. Target y = [0.01, 0.99]. Learning rate η = 0.5. Compute all outputs, total half squared loss, all eight weight gradients and one simultaneous weight update. Map weights in order: w₁ = x₁ → h₁, w₂ = x₂ → h₁, w₃ = x₁ → h₂, w₄ = x₂ → h₂; w₅ = h₁ → o₁, w₆ = h₂ → o₁, w₇ = h₁ → o₂, w₈ = h₂ → o₂.\n\n\n\n### Given\n\nInput x = [0.05, 0.1].\n\nW₁ = .\n\nb₁ = [0.35, 0.35].\n\nW₂ = .\n\nb₂ = [0.6, 0.6].\n\nHidden and output activations are sigmoid.\n\nTarget y = [0.01, 0.99].\n\nLearning rate η = 0.5.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Output neuron 2: **\n\n\n**Step 2 loss convention.** The photos explicitly use "}]},{"n":11,"title":"F25 selected MT2 practice","sections":[{"title":"Start here","blocks":["<p>The source archive retains historical optimization, CNN and introductory RNN questions. Following the 12 October faculty update, the focused MT2 website presents the Unit 3–4 questions; retained RNN bookmarks lead to TEE. Original question IDs and marks are preserved. Full assessed tasks and numerical data are transcribed in readable language; worked solutions follow each question. This selection does not predict the paper.</p>"],"kind":"read","id":"mt2-c11-intro"},{"title":"F25 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Which regularizer leads to sparsity and why? For an MNIST CNN with high training accuracy and lower validation accuracy, explain how dropout works during training and how it can improve generalization.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>"],"kind":"practice","id":"mt2-c11-s0","search":"F25 Q1c **Question (5 marks).** Which regularizer leads to sparsity and why? For an MNIST CNN with high training accuracy and lower validation accuracy, explain how dropout works during training and how it can improve generalization.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n"},{"title":"F25 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Describe sequence processing, context and variable-length sentences in RNNs. Explain their use in language translation, as illustrated by the historical reference to Google Translate.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>"],"kind":"practice","id":"mt2-c11-s1","search":"F25 Q1d **Question (5 marks).** Describe sequence processing, context and variable-length sentences in RNNs. Explain their use in language translation, as illustrated by the historical reference to Google Translate.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n"},{"title":"F25 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain how ResNet skip connections influence gradient flow, feature reuse and vanishing gradients. Compare InceptionNet and AlexNet learning and feature extraction.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>","<p>AlexNet learns features along a mainly sequential stack of convolutional layers. Inception learns several spatial scales in parallel within a module and combines their channels. Both learn filter weights through backpropagation; their structural organization differs.</p>"],"kind":"practice","id":"mt2-c11-s2","search":"F25 Q2b **Question (10 marks).** Explain how ResNet skip connections influence gradient flow, feature reuse and vanishing gradients. Compare InceptionNet and AlexNet learning and feature extraction.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\nAlexNet learns features along a mainly sequential stack of convolutional layers. Inception learns several spatial scales in parallel within a module and combines their channels. Both learn filter weights through backpropagation; their structural organization differs.\n"},{"title":"F25 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design face-recognition attendance using a CNN when the supplied dataset is very small. Discuss ways to address the issue and explain transfer learning.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>"],"kind":"practice","id":"mt2-c11-s3","search":"F25 Q3b **Question (10 marks).** Design face-recognition attendance using a CNN when the supplied dataset is very small. Discuss ways to address the issue and explain transfer learning.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n"},{"title":"F25 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For N = 1,000 samples and batch size 100, count weight updates per epoch for batch GD, SGD and mini-batch GD. For J(θ) = 0.5 θ², η = 0.1, momentum 0.9, v₀ = 0, θ₀ = 1, compute two momentum iterations. List the required momentum-training hyperparameters.</p>"],"answer":["<h3>Given</h3>","<p>N = 1,000; mini-batch size = 100.</p>","<p>J(θ) = 0.5θ²; θ₀ = 1; v₀ = 0; η = 0.1; β = 0.9.</p>","<p>Use signed velocity.</p>","<h3>To find</h3>","<p>Count updates per epoch for batch, stochastic and mini-batch GD; then perform two momentum iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count full-batch updates.</strong></p>","<p>All 1,000 samples contribute to one update: 1 per epoch.</p>","<p class=\"worked-step\"><strong>Step 2: count stochastic updates.</strong></p>","<p>One update per sample: 1,000 per epoch.</p>","<p class=\"worked-step\"><strong>Step 3: count mini-batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eee877d70ea14115.svg\" alt=\"1000/100=10\" width=\"154.75\" height=\"24.43\" style=\"width:154.75px;height:24.43px;aspect-ratio:154.75/24.43\" loading=\"lazy\"></div>","<p>Use signed velocity vₜ = βvₜ₋₁−ηgₜ and θₜ = θₜ₋₁+vₜ; g(θ) = θ.</p>","<h3>Momentum iteration 1</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the gradient at the current parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/228fc3b3267b30c9.svg\" alt=\"g_1=1\" width=\"67.12\" height=\"21.29\" style=\"width:67.12px;height:21.29px;aspect-ratio:67.12/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the previous displacement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4351a4e3442a023e.svg\" alt=\"0.9(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the current gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cde65d80bbbce53.svg\" alt=\"0.1(1)=0.1\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: combine to obtain the new signed velocity.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2c6e04e58352c2ce.svg\" alt=\"v_1=0-0.1=-0.1\" width=\"211.24\" height=\"19.94\" style=\"width:211.24px;height:19.94px;aspect-ratio:211.24/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add new velocity to the actual old parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<h3>Momentum iteration 2</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the gradient at the current parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc4532aff9a9a2da.svg\" alt=\"g_2=0.9\" width=\"86.13\" height=\"21.29\" style=\"width:86.13px;height:21.29px;aspect-ratio:86.13/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the previous displacement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8fd30bce103b617.svg\" alt=\"0.9(-0.1)=-0.09\" width=\"195.51\" height=\"24.43\" style=\"width:195.51px;height:24.43px;aspect-ratio:195.51/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the current gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf93339d0945c688.svg\" alt=\"0.1(0.9)=0.09\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: combine to obtain the new signed velocity.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f18fc7f5dc715d05.svg\" alt=\"v_2=-0.09-0.09=-0.18\" width=\"285.91\" height=\"19.94\" style=\"width:285.91px;height:19.94px;aspect-ratio:285.91/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add new velocity to the actual old parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Hyperparameters: </strong> the basic momentum update has two main tunable coefficients, learning rate η and momentum β. A full training run also requires choices such as epochs and batch size (one for literal SGD), and may include a learning-rate schedule. There is no universal single count for all training configurations; state what is counted. Initial θ and v are initialization values, not learned outputs of the first update.</p>"],"kind":"practice","id":"mt2-c11-s4","search":"F25 Q4a **Question (10 marks).** For N = 1,000 samples and batch size 100, count weight updates per epoch for batch GD, SGD and mini-batch GD. For J(θ) = 0.5 θ², η = 0.1, momentum 0.9, v₀ = 0, θ₀ = 1, compute two momentum iterations. List the required momentum-training hyperparameters.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nN = 1,000; mini-batch size = 100.\n\nJ(θ) = 0.5θ²; θ₀ = 1; v₀ = 0; η = 0.1; β = 0.9.\n\nUse signed velocity.\n\n### To find\n\nCount updates per epoch for batch, stochastic and mini-batch GD; then perform two momentum iterations.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: count full-batch updates.**\n\nAll 1,000 samples contribute to one update: 1 per epoch.\n\n**Step 2: count stochastic updates.**\n\nOne update per sample: 1,000 per epoch.\n\n**Step 3: count mini-batches.**\n\n\n\n\n\n\n\n\nUse signed velocity vₜ = βvₜ₋₁−ηgₜ and θₜ = θₜ₋₁+vₜ; g(θ) = θ.\n### Momentum iteration 1\n\n**Step 1: evaluate the gradient at the current parameter.**\n\n\n\n\n\n\n\n**Step 2: retain the previous displacement.**\n\n\n\n\n\n\n\n**Step 3: scale the current gradient.**\n\n\n\n\n\n\n\n**Step 4: combine to obtain the new signed velocity.**\n\n\n\n\n\n\n\n**Step 5: add new velocity to the actual old parameter.**\n\n\n\n\n\n\n\n\n### Momentum iteration 2\n\n**Step 1: evaluate the gradient at the current parameter.**\n\n\n\n\n\n\n\n**Step 2: retain the previous displacement.**\n\n\n\n\n\n\n\n**Step 3: scale the current gradient.**\n\n\n\n\n\n\n\n**Step 4: combine to obtain the new signed velocity.**\n\n\n\n\n\n\n\n**Step 5: add new velocity to the actual old parameter.**\n\n\n\n\n\n\n\n\n**Hyperparameters: ** the basic momentum update has two main tunable coefficients, learning rate η and momentum β. A full training run also requires choices such as epochs and batch size (one for literal SGD), and may include a learning-rate schedule. There is no universal single count for all training configurations; state what is counted. Initial θ and v are initialization values, not learned outputs of the first update.\n"},{"title":"F25 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain AdaGrad, give its update rule and discuss advantages and disadvantages compared with standard SGD.</p>"],"answer":["<p>AdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p>Frequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.</p>","<p>Example with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.</p>","<p>Advantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.</p>"],"kind":"practice","id":"mt2-c11-s5","search":"F25 Q5b **Question (10 marks).** Explain AdaGrad, give its update rule and discuss advantages and disadvantages compared with standard SGD.\n\n**Complete worked answer.**\nAdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:\n\nFrequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.\nExample with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.\nAdvantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.\n"},{"title":"F25 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Calculate every activation shape and trainable-parameter count for: Input 128 × 128 × 3. → Conv K = 3, filters = 16, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 3, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 240 units. → Dense 120 units. → Dense 5 units. Also convolve the input A with the kernel K shown below, valid padding and stride 2.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 2; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Input 128 × 128 × 3.</p>","<p>Conv K = 3, filters = 16, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 240 units.</p>","<p>Dense 120 units.</p>","<p>Dense 5 units.</p>","<p>Also convolve the input A with the kernel K shown below, valid padding and stride 2.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total. Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">128 × 128 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">16 filters · 3 × 3 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">126 × 126 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">432</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">16</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">448</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>128 × 128 × 3</strong>. Use 16 filters of spatial size 3 × 3, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60bad070a07deb57.svg\"><img class=\"math display-math\" src=\"assets/equations/32d2786097210b6e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{128+2(0)-3}{1}\\right\\rfloor+1=126\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>126 × 126 × 16</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd36df36d5f6f027.svg\"><img class=\"math display-math\" src=\"assets/equations/2eb50e4698b8f7ed.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times3\\times16=432\" width=\"330.89\" height=\"23.91\" style=\"width:330.89px;height:23.91px;aspect-ratio:330.89/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc0c940eb69b41c0.svg\" alt=\"N_{\\mathrm{biases}}=16\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe2e71f3a8efffa4.svg\" alt=\"P_1=432+16=448\" width=\"219.13\" height=\"20.36\" style=\"width:219.13px;height:20.36px;aspect-ratio:219.13/20.36\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">126 × 126 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">63 × 63 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>126 × 126 × 16</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31d9e5cfd413812f.svg\"><img class=\"math display-math\" src=\"assets/equations/3c15021631c4c384.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1=63\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>63 × 63 × 16</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">63 × 63 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 3 × 3 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">61 × 61 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,608</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,640</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>63 × 63 × 16</strong>. Use 32 filters of spatial size 3 × 3, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d1b1c42ec3b8b44b.svg\"><img class=\"math display-math\" src=\"assets/equations/a0caa4135f45ed9c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{63+2(0)-3}{1}\\right\\rfloor+1=61\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>61 × 61 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 16 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcf6aecafd4a3651.svg\"><img class=\"math display-math\" src=\"assets/equations/767ba18d56e40888.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times16\\times32=4{,}608\" width=\"362.11\" height=\"23.91\" style=\"width:362.11px;height:23.91px;aspect-ratio:362.11/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebc484850d4827e3.svg\" alt=\"P_3=4{,}608+32=4{,}640\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">61 × 61 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">30 × 30 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>61 × 61 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2fa03284017c373e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1=30\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>30 × 30 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 29.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 5 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">30 × 30 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">28,800</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>30 × 30 × 32</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f8d6a23f5595005e.svg\"><img class=\"math display-math\" src=\"assets/equations/9fedbcb21e866a38.svg\" alt=\"n_{\\mathrm{flat}}=30\\times30\\times32=28{,}800\" width=\"308.23\" height=\"21.02\" style=\"width:308.23px;height:21.02px;aspect-ratio:308.23/21.02\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>28,800 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 6 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">28,800</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">240 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">240</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">6,912,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">240</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">6,912,240</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>28,800 features</strong>. Output: <strong>240 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e815f655162e42b.svg\"><img class=\"math display-math\" src=\"assets/equations/24e6116ce6d82f93.svg\" alt=\"N_{\\mathrm{weights}}=28{,}800\\times240=6{,}912{,}000\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/237f8d226a0fb66a.svg\" alt=\"N_{\\mathrm{biases}}=240\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a36eb80ee2f332fd.svg\"><img class=\"math display-math\" src=\"assets/equations/a4474a3c31a68206.svg\" alt=\"P_6=6{,}912{,}000+240=6{,}912{,}240\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">240</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">28,800</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">28,920</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>240 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.13px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55419bb786cbe655.svg\"><img class=\"math display-math\" src=\"assets/equations/67cf05b2fc828555.svg\" alt=\"N_{\\mathrm{weights}}=240\\times120=28{,}800\" width=\"314.59\" height=\"23.91\" style=\"width:314.59px;height:23.91px;aspect-ratio:314.59/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/780340973d3c0ce4.svg\"><img class=\"math display-math\" src=\"assets/equations/056fc82ce0b81134.svg\" alt=\"P_7=28{,}800+120=28{,}920\" width=\"293.80\" height=\"21.43\" style=\"width:293.80px;height:21.43px;aspect-ratio:293.80/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">5 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">5</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">600</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">605</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>5 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26857a3f5e70fd9d.svg\" alt=\"N_{\\mathrm{weights}}=120\\times5=600\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8917be67939f2d89.svg\" alt=\"N_{\\mathrm{biases}}=5\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4289ff8bd02992b.svg\" alt=\"P_8=600+5=605\" width=\"206.92\" height=\"20.74\" style=\"width:206.92px;height:20.74px;aspect-ratio:206.92/20.74\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/dbb0832b53a96b49.svg\" alt=\"\\left\\lfloor\\frac{128+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>126 x 126 x 16</td><td>432</td><td>16</td><td>448</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6979fd0d1f6b483.svg\" alt=\"\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>63 x 63 x 16</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f9e5ee2c7c7e1bbb.svg\" alt=\"\\left\\lfloor\\frac{63+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>61 x 61 x 32</td><td>4,608</td><td>32</td><td>4,640</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/1ac02853de1445dd.svg\" alt=\"\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>30 x 30 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 flat</td><td>30 × 30 × 32</td><td>28800</td><td>0</td><td>0</td><td>0</td></tr><tr><td>6 dense</td><td>28800 → 240</td><td>240</td><td>6,912,000</td><td>240</td><td>6,912,240</td></tr><tr><td>7 dense</td><td>240 → 120</td><td>120</td><td>28,800</td><td>120</td><td>28,920</td></tr><tr><td>8 dense</td><td>120 → 5</td><td>5</td><td>600</td><td>5</td><td>605</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (3 x 3 x 3 + 1) x 16 = 448.</p>","<p>Layer 3: (3 x 3 x 16 + 1) x 32 = 4,640.</p>","<p>Layer 6: (28800 + 1) x 240 = 6,912,240.</p>","<p>Layer 7: (240 + 1) x 120 = 28,920.</p>","<p>Layer 8: (120 + 1) x 5 = 605.</p>","<p><strong>Total: </strong> 448 + 4,640 + 6,912,240 + 28,920 + 605 = <strong>6,946,853 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p><strong>Separate convolution calculation: </strong></p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/966c8fb493880239.svg\" alt=\"\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −4\">−4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 + (−2) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>4 + 0 + (−4) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 0 + (−1) = 2</b></div></div><p class=\"lv-combine\"><b>1 + 0 + 2 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7b5121489bd31f6.svg\"><img class=\"math display-math\" src=\"assets/equations/a9fce55fa8f0fbec.svg\" alt=\"R_1=(3)\\times(1)+(1)\\times(0)+(2)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2be91abc57b10ecb.svg\"><img class=\"math display-math\" src=\"assets/equations/b71bdd3aed98c346.svg\" alt=\"R_2=(2)\\times(2)+(1)\\times(0)+(2)\\times(-2)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e404b4617ef0e7d0.svg\"><img class=\"math display-math\" src=\"assets/equations/19fc18a5d8a877eb.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(0)+(1)\\times(-1)=2\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b108d091066c8f7c.svg\" alt=\"Y_{1,1}=(1)+(0)+(2)=3\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0\">0</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 + (−1) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>4 + 0 + 0 = 4</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>1 + 0 + (−1) = 0</b></div></div><p class=\"lv-combine\"><b>1 + 4 + 0 = 5</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa4766cd874d5e7f.svg\"><img class=\"math display-math\" src=\"assets/equations/eaf8c509090f51f1.svg\" alt=\"R_1=(2)\\times(1)+(2)\\times(0)+(1)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93a6f5b5b20f2f23.svg\"><img class=\"math display-math\" src=\"assets/equations/47348f4aaa64e235.svg\" alt=\"R_2=(2)\\times(2)+(1)\\times(0)+(0)\\times(-2)=4\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5f03457a49dcba68.svg\"><img class=\"math display-math\" src=\"assets/equations/91d68511c5df7991.svg\" alt=\"R_3=(1)\\times(1)+(0)\\times(0)+(1)\\times(-1)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd6e5a7547d2ee64.svg\" alt=\"Y_{1,2}=(1)+(4)+(0)=5\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0\">0</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 + (−1) = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>1 + 0 + 0 = 1</b></div></div><p class=\"lv-combine\"><b>2 + 0 + 1 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3a3d0394f9567ec.svg\"><img class=\"math display-math\" src=\"assets/equations/1f506dd6c963dbdb.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(0)+(1)\\times(-1)=2\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ab2e486b72e8236.svg\"><img class=\"math display-math\" src=\"assets/equations/7737415f7a101340.svg\" alt=\"R_2=(0)\\times(2)+(3)\\times(0)+(0)\\times(-2)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2dca2b82f9aac21.svg\"><img class=\"math display-math\" src=\"assets/equations/dbc9736155e0a1ec.svg\" alt=\"R_3=(1)\\times(1)+(1)\\times(0)+(0)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f077b3678b0e1f35.svg\" alt=\"Y_{2,1}=(2)+(0)+(1)=3\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −4\">−4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 + (−1) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 + (−4) = −4</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0 + 0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>0 + (−4) + (−3) = −7</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8247d99177a36658.svg\"><img class=\"math display-math\" src=\"assets/equations/bbe676b3e02a351a.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(0)+(1)\\times(-1)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/959c04625a9a0df4.svg\"><img class=\"math display-math\" src=\"assets/equations/b50d1e82d7e6e8b7.svg\" alt=\"R_2=(0)\\times(2)+(1)\\times(0)+(2)\\times(-2)=-4\" width=\"481.33\" height=\"24.43\" style=\"width:481.33px;height:24.43px;aspect-ratio:481.33/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/20986846d13e4484.svg\"><img class=\"math display-math\" src=\"assets/equations/369116c3da370aea.svg\" alt=\"R_3=(0)\\times(1)+(2)\\times(0)+(3)\\times(-1)=-3\" width=\"481.33\" height=\"24.43\" style=\"width:481.33px;height:24.43px;aspect-ratio:481.33/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:182.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec0342788a9224e.svg\"><img class=\"math display-math\" src=\"assets/equations/0984e17e87f9bbc9.svg\" alt=\"Y_{2,2}=(0)+(-4)+(-3)=-7\" width=\"326.14\" height=\"25.35\" style=\"width:326.14px;height:25.35px;aspect-ratio:326.14/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/3797d8870cefe33e.svg\" alt=\"\\begin{bmatrix}3 &amp; 5\\\\3 &amp; -7\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"kind":"practice","id":"mt2-c11-s6","search":"F25 Q6a **Question (10 marks).** Calculate every activation shape and trainable-parameter count for: Input 128 × 128 × 3. → Conv K = 3, filters = 16, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 3, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 240 units. → Dense 120 units. → Dense 5 units. Also convolve the input A with the kernel K shown below, valid padding and stride 2.\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 128 × 128 × 3.\n\nConv K = 3, filters = 16, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 3, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 240 units.\n\nDense 120 units.\n\nDense 5 units.\n\nAlso convolve the input A with the kernel K shown below, valid padding and stride 2.\n\n### To find\n\nFind every layer shape, its parameter count and the network total. Find every convolution output cell.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{128+2 \\times  0-3}{1}\\right\\rfloor+1\\) | 126 x 126 x 16 | 432 | 16 | 448 |\n| 2 pool | \\(\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1\\) | 63 x 63 x 16 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{63+2 \\times  0-3}{1}\\right\\rfloor+1\\) | 61 x 61 x 32 | 4,608 | 32 | 4,640 |\n| 4 pool | \\(\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1\\) | 30 x 30 x 32 | 0 | 0 | 0 |\n| 5 flat | 30 × 30 × 32 | 28800 | 0 | 0 | 0 |\n| 6 dense | 28800 → 240 | 240 | 6,912,000 | 240 | 6,912,240 |\n| 7 dense | 240 → 120 | 120 | 28,800 | 120 | 28,920 |\n| 8 dense | 120 → 5 | 5 | 600 | 5 | 605 |\n**Parameter substitutions, in layer order: **\nLayer 1: (3 x 3 x 3 + 1) x 16 = 448.\nLayer 3: (3 x 3 x 16 + 1) x 32 = 4,640.\nLayer 6: (28800 + 1) x 240 = 6,912,240.\nLayer 7: (240 + 1) x 120 = 28,920.\nLayer 8: (120 + 1) x 5 = 605.\n**Total: ** 448 + 4,640 + 6,912,240 + 28,920 + 605 = **6,946,853 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n**Separate convolution calculation: **\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{5+2 \\times  0"},{"title":"F25 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain hierarchical CNN feature extraction and the roles of convolution, pooling and fully connected layers. Why prefer CNNs over fully connected ANNs for images? Give medical-image and autonomous-vehicle applications and advantages.</p>"],"answer":["<p>A convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/convolution.svg\" aria-label=\"Enlarge diagram: One filter is reused at successive spatial positions\"><img src=\"assets/figures/convolution.svg\" alt=\"One filter is reused at successive spatial positions\" width=\"960\" height=\"630\" loading=\"lazy\"></button><figcaption>One filter is reused at successive spatial positions <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Convolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.</p>","<p>Compared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.</p>","<p>For medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.</p>"],"kind":"practice","id":"mt2-c11-s7","search":"F25 Q7b **Question (10 marks).** Explain hierarchical CNN feature extraction and the roles of convolution, pooling and fully connected layers. Why prefer CNNs over fully connected ANNs for images? Give medical-image and autonomous-vehicle applications and advantages.\n\n**Complete worked answer.**\nA convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.\n\nConvolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.\nCompared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.\nFor medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.\n\n\n"}]},{"n":12,"title":"R26 selected MT2 practice","sections":[{"title":"Start here","blocks":["<p>The source archive retains historical optimization, CNN and introductory RNN questions. Following the 12 October faculty update, the focused MT2 website presents the Unit 3–4 questions; retained RNN bookmarks lead to TEE. Original question IDs and marks are preserved. Full assessed tasks and numerical data are transcribed in readable language; worked solutions follow each question. This selection does not predict the paper.</p>"],"kind":"read","id":"mt2-c12-intro"},{"title":"R26 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Explain L1 and L2 regularization. Apply 50% dropout to outputs [0.8,−0.4,0.6,0.2] using an explicitly assumed mask.</p>"],"answer":["<h3>Given</h3>","<p>Activations = [0.8,−0.4,0.6,0.2]; dropout rate = 50%.</p>","<p>The worked example assumes mask [1,0,1,0] and uses inverted dropout.</p>","<p>No numerical weights or λ are supplied for the regularization explanation.</p>","<h3>To find</h3>","<p>Explain L1/L2 and calculate post-dropout activations under the stated mask.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>L2 penalty with a factor of one-half.</strong> This answer uses λ/2 times the sum of squared weights. Differentiating a square supplies a factor of 2, which cancels the one-half, so the added gradient is λw. Use this same convention in the explanation below.</p>","<p>λ = penalty strength; J_data = original data loss; wᵢ = weight i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e906f5f903db890.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac{\\lambda}{2}\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/919b9b7755f3c860.svg\" alt=\"\\frac{\\partial J}{\\partial w_i}=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"210.30\" height=\"54.60\" style=\"width:210.30px;height:54.60px;aspect-ratio:210.30/54.60\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L2 mein half diya hai: square ka 2 cancel, gradient mein lambda × weight.</p>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<h3>Solution — step by step</h3>","<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<h3>Numerical with one explicitly chosen mask</h3>","<p class=\"worked-step\"><strong>Step 1: convert dropout probability to keep probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39070c1933e29986.svg\" alt=\"q=1-0.5=0.5\" width=\"180.95\" height=\"21.02\" style=\"width:180.95px;height:21.02px;aspect-ratio:180.95/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: state a possible mask.</strong></p>","<p>Choose [1,0,1,0]; 1 means keep and 0 means drop. The question allows an assumed mask; others give different realizations.</p>","<p class=\"worked-step\"><strong>Step 3: multiply each activation by its mask entry.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:334.02px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ccd5e8324645240.svg\"><img class=\"math display-math\" src=\"assets/equations/11f3e40a403e55d3.svg\" alt=\"[0.8(1),(-0.4)(0),0.6(1),0.2(0)]=[0.8,0,0.6,0]\" width=\"499.67\" height=\"24.43\" style=\"width:499.67px;height:24.43px;aspect-ratio:499.67/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide the kept values by q for inverted dropout.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/552d192c8691910e.svg\" alt=\"0.8/0.5=1.6\" width=\"138.49\" height=\"24.43\" style=\"width:138.49px;height:24.43px;aspect-ratio:138.49/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2dc3409b6b4b5c.svg\" alt=\"0.6/0.5=1.2\" width=\"138.49\" height=\"24.43\" style=\"width:138.49px;height:24.43px;aspect-ratio:138.49/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: assemble the training output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e92cb4c6084d0ae8.svg\" alt=\"a_{\\mathrm{train}}=[1.6,0,1.2,0]\" width=\"217.16\" height=\"24.43\" style=\"width:217.16px;height:24.43px;aspect-ratio:217.16/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> simple masking gives [0.8,0,0.6,0]; inverted training dropout gives [1.6,0,1.2,0]. At inference inverted dropout is disabled.</p>"],"kind":"practice","id":"mt2-c12-s0","search":"R26 Q1c **Question (5 marks).** Explain L1 and L2 regularization. Apply 50% dropout to outputs [0.8,−0.4,0.6,0.2] using an explicitly assumed mask.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nActivations = [0.8,−0.4,0.6,0.2]; dropout rate = 50%.\n\nThe worked example assumes mask [1,0,1,0] and uses inverted dropout.\n\nNo numerical weights or λ are supplied for the regularization explanation.\n\n### To find\n\nExplain L1/L2 and calculate post-dropout activations under the stated mask.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**L2 penalty with a factor of one-half.** This answer uses λ/2 times the sum of squared weights. Differentiating a square supplies a factor of 2, which cancels the one-half, so the added gradient is λw. Use this same convention in the explanation below.\n\nλ = penalty strength; J_data = original data loss; wᵢ = weight i.\n\n\n\n\n\n**Yaad rakhne ka cue:** L2 mein half diya hai: square ka 2 cancel, gradient mein lambda × weight.\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n### Solution — step by step\n\n\n\n\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n### Numerical with one explicitly chosen mask\n\n**Step 1: convert dropout probability to keep probability.**\n\n\n\n\n\n\n\n**Step 2: state a possible mask.**\n\nChoose [1,0,1,0]; 1 means keep and 0 means drop. The question allows an assumed mask; others give different realizations.\n\n**Step 3: multiply each activation by its mask entry.**\n\n\n\n\n\n\n\n**Step 4: divide the kept values by q for inverted dropout.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 5: assemble the training output.**\n\n\n\n\n\n\n\n**Final answer:** simpl"},{"title":"R26 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Explain an RNN for positive, negative or neutral e-commerce review sentiment. Why are recurrence and word order relevant?</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p>For this task select a many-to-one output: tokenize and embed the full review, update the recurrent state across its words, and classify the final sequence representation with a three-unit softmax. Train using one-hot sentiment labels and categorical cross-entropy. “Not worth buying” and “worth buying” illustrate why negation and order matter.</p>"],"kind":"practice","id":"mt2-c12-s1","search":"R26 Q1d **Question (5 marks).** Explain an RNN for positive, negative or neutral e-commerce review sentiment. Why are recurrence and word order relevant?\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\nFor this task select a many-to-one output: tokenize and embed the full review, update the recurrent state across its words, and classify the final sequence representation with a three-unit softmax. Train using one-hot sentiment labels and categorical cross-entropy. “Not worth buying” and “worth buying” illustrate why negation and order matter.\n"},{"title":"R26 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain AlexNet regularization and training improvements; explain Inception multiscale features and 1 × 1 convolutions; recommend an architecture for large-scale image classification with justification.</p>"],"answer":["<p>AlexNet uses a sequence of convolutional layers followed by fully connected classification layers. Its influential design used ReLU activations, max pooling, dropout in the fully connected part, data augmentation and GPU training. ReLU&#x27;s positive derivative supports learning compared with heavily saturated sigmoid hidden units. Augmentation supplies varied training views; dropout reduces co-adaptation; GPU computation makes a large network practical to train.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/alexnet.svg\" aria-label=\"Enlarge diagram: The common classroom AlexNet layout contains five convolutions and three dense layers\"><img src=\"assets/figures/alexnet.svg\" alt=\"The common classroom AlexNet layout contains five convolutions and three dense layers\" width=\"960\" height=\"480\" loading=\"lazy\"></button><figcaption>The common classroom AlexNet layout contains five convolutions and three dense layers <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The common 227-pixel classroom layout is: Conv 11 stride 4 with 96 filters; pool 3 stride 2; Conv 5 padding 2 with 256 filters; pool 3 stride 2; three Conv 3 padding 1 layers with 384,384,256 filters; pool 3 stride 2; dense 4096; dense 4096; output 1000. Nonlinearities are applied between learned layers. Exact padding, grouping and input conventions must follow the question: the original model used channel groups in some layers, so parameter counts differ from a fully connected-channel simplification.</p>","<p>AlexNet follows a mainly sequential feature-extraction path. An Inception module processes several spatial scales in parallel and concatenates them, often using 1 × 1 bottlenecks to reduce cost. Neither architecture is universally best; the task, resource budget and validation performance determine the choice.</p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>","<p><strong>Recommendation: </strong> an Inception-family model is a defensible choice when varied object scales and computation efficiency matter, because parallel scales with bottlenecks provide diverse features at controlled cost. Compare held-out accuracy, latency and memory with available alternatives. This is a justified choice, not a claim that Inception always beats AlexNet on every dataset.</p>"],"kind":"practice","id":"mt2-c12-s2","search":"R26 Q2b **Question (10 marks).** Explain AlexNet regularization and training improvements; explain Inception multiscale features and 1 × 1 convolutions; recommend an architecture for large-scale image classification with justification.\n\n**Complete worked answer.**\nAlexNet uses a sequence of convolutional layers followed by fully connected classification layers. Its influential design used ReLU activations, max pooling, dropout in the fully connected part, data augmentation and GPU training. ReLU's positive derivative supports learning compared with heavily saturated sigmoid hidden units. Augmentation supplies varied training views; dropout reduces co-adaptation; GPU computation makes a large network practical to train.\n\nThe common 227-pixel classroom layout is: Conv 11 stride 4 with 96 filters; pool 3 stride 2; Conv 5 padding 2 with 256 filters; pool 3 stride 2; three Conv 3 padding 1 layers with 384,384,256 filters; pool 3 stride 2; dense 4096; dense 4096; output 1000. Nonlinearities are applied between learned layers. Exact padding, grouping and input conventions must follow the question: the original model used channel groups in some layers, so parameter counts differ from a fully connected-channel simplification.\nAlexNet follows a mainly sequential feature-extraction path. An Inception module processes several spatial scales in parallel and concatenates them, often using 1 × 1 bottlenecks to reduce cost. Neither architecture is universally best; the task, resource budget and validation performance determine the choice.\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\n**Recommendation: ** an Inception-family model is a defensible choice when varied object scales and computation efficiency matter, because parallel scales with bottlenecks provide diverse features at controlled cost. Compare held-out accuracy, latency and memory with available alternatives. This is a justified choice, not a claim that Inception always beats AlexNet on every dataset.\n"},{"title":"R26 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> How should CNN filter counts be selected? Explain effects on feature extraction, dimensionality, computation/memory, overfitting and hierarchical learning.</p>"],"answer":["<p>Choose filter counts as architecture hyperparameters using task complexity, available data, validation performance and resource limits. There is no universal correct count.</p>","<p>1. More filters can represent a wider variety of learned features at a layer; redundant filters do not automatically improve accuracy.</p>","<p>2. Cout filters produce Cout output channels; spatial height/width still follow kernel, padding and stride.</p>","<p>3. A K × K layer uses K²CinCout weights plus Cout biases. More output channels increase current activations and the input-channel cost of the next convolution.</p>","<p>4. Extra capacity can overfit limited data, so use validation, augmentation, transfer learning or regularization. Too few channels may underfit.</p>","<p>5. Later layers often use more channels after spatial downsampling, allowing complex feature combinations at a smaller spatial size. This is a common design choice, not a compulsory rule.</p>","<p>Example: a 3 × 3 layer with 16 input channels has (9 × 16+1) × 32 = 4,640 parameters for 32 filters, versus 9,280 for 64 filters. Output-channel count doubles while the same spatial-size formula applies.</p>"],"kind":"practice","id":"mt2-c12-s3","search":"R26 Q3b **Question (10 marks).** How should CNN filter counts be selected? Explain effects on feature extraction, dimensionality, computation/memory, overfitting and hierarchical learning.\n\n**Complete worked answer.**\nChoose filter counts as architecture hyperparameters using task complexity, available data, validation performance and resource limits. There is no universal correct count.\n1. More filters can represent a wider variety of learned features at a layer; redundant filters do not automatically improve accuracy.\n2. Cout filters produce Cout output channels; spatial height/width still follow kernel, padding and stride.\n3. A K × K layer uses K²CinCout weights plus Cout biases. More output channels increase current activations and the input-channel cost of the next convolution.\n4. Extra capacity can overfit limited data, so use validation, augmentation, transfer learning or regularization. Too few channels may underfit.\n5. Later layers often use more channels after spatial downsampling, allowing complex feature combinations at a smaller spatial size. This is a common design choice, not a compulsory rule.\nExample: a 3 × 3 layer with 16 input channels has (9 × 16+1) × 32 = 4,640 parameters for 32 filters, versus 9,280 for 64 filters. Output-channel count doubles while the same spatial-size formula applies.\n"},{"title":"R26 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Compare batch GD and SGD for loss oscillations with a graph, memory and large datasets. Discuss learning rate extremes. For J(θ) = 0.7 θ³, θ₀ = 1, η = 0.1, perform two iterations.</p>"],"answer":["<h3>Given</h3>","<p>J(θ) = 0.7θ³; θ₀ = 1; η = 0.1.</p>","<h3>To find</h3>","<p>Calculate the derivative and perform two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<p>The learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative full batch and stochastic traces distinguish smoothness from progress\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative full batch and stochastic traces distinguish smoothness from progress\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative full batch and stochastic traces distinguish smoothness from progress <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Batch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.</p>","<p>Momentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.</p>","<p>Diagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.</p>","<p class=\"worked-step\"><strong>Step 1: differentiate the objective before substituting.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaad5a7869c46a71.svg\" alt=\"J(\\theta)=0.7\\theta^3\" width=\"131.88\" height=\"27.69\" style=\"width:131.88px;height:27.69px;aspect-ratio:131.88/27.69\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2aadd5dc4445f1ba.svg\" alt=\"g(\\theta)=0.7(3)\\theta^2=2.1\\theta^2\" width=\"245.22\" height=\"27.70\" style=\"width:245.22px;height:27.70px;aspect-ratio:245.22/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate gradient at the original parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6e21de54ead2d325.svg\" alt=\"g_1=2.1(1)^2=2.1\" width=\"191.84\" height=\"27.70\" style=\"width:191.84px;height:27.70px;aspect-ratio:191.84/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the first gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3ed37be87afc8239.svg\" alt=\"0.1(2.1)=0.21\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: subtract to obtain the first update.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e9423903ada8f563.svg\" alt=\"\\theta_1=1-0.21=0.79\" width=\"216.27\" height=\"20.89\" style=\"width:216.27px;height:20.89px;aspect-ratio:216.27/20.89\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: square the changed parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c5b6ff4c2963f39a.svg\" alt=\"0.79^2=0.6241\" width=\"154.57\" height=\"23.60\" style=\"width:154.57px;height:23.60px;aspect-ratio:154.57/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: recalculate the gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c986b4d77e3de9d0.svg\" alt=\"g_2=2.1(0.6241)=1.31061\" width=\"285.70\" height=\"24.43\" style=\"width:285.70px;height:24.43px;aspect-ratio:285.70/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: scale the second gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f5b4b6bf69894db.svg\" alt=\"0.1(1.31061)=0.131061\" width=\"255.23\" height=\"24.43\" style=\"width:255.23px;height:24.43px;aspect-ratio:255.23/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: subtract from the first updated parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/11da355fe098969f.svg\"><img class=\"math display-math\" src=\"assets/equations/0d180bfeaebc1926.svg\" alt=\"\\theta_2=0.79-0.131061=0.658939\" width=\"345.23\" height=\"20.89\" style=\"width:345.23px;height:20.89px;aspect-ratio:345.23/20.89\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> θ₁ = 0.79; θ₂ = 0.658939. No individual samples are supplied, so these are the stated scalar gradient updates. The cubic is unbounded below; two steps are not a convergence proof.</p>"],"kind":"practice","id":"mt2-c12-s4","search":"R26 Q4a **Question (10 marks).** Compare batch GD and SGD for loss oscillations with a graph, memory and large datasets. Discuss learning rate extremes. For J(θ) = 0.7 θ³, θ₀ = 1, η = 0.1, perform two iterations.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nJ(θ) = 0.7θ³; θ₀ = 1; η = 0.1.\n\n### To find\n\nCalculate the derivative and perform two updates.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\nThe learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.\n\nBatch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.\nMomentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.\nDiagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.\n**Step 1: differentiate the objective before substituting.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 2: evaluate gradient at the original parameter.**\n\n\n\n\n\n\n\n**Step 3: scale the first gradient.**\n\n\n\n\n\n\n\n**Step 4: subtract to obtain the first update.**\n\n\n\n\n\n\n\n**Step 5: square the changed parameter.**\n\n\n\n\n\n\n\n**Step 6: recalculate the gradient.**\n\n\n\n\n\n\n\n**Step 7: scale the second gradient.**\n\n\n\n\n\n\n\n**Step 8: subtract from the first updated parameter.**\n\n\n\n\n\n\n\n**Final answer:** θ₁ = 0.79; θ₂ = 0.658939. No individual samples are supplied, so these are the stated scalar gradient updates. The cubic is unbounded below; two steps are not a convergence proof.\n"},{"title":"R26 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain feedforward limitations for sequential context and how recurrence helps. Calculate h using tanh for Wxh is shown below, Whh is shown below, x = [0,1], hprevious = [0,1], zero bias. Explain next-word probabilities.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_deac39f14c.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_deac39f14c.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Wxh and Whh are printed in the question; use their receiving-neuron rows.</p>","<p>Current input = [0,1]; previous hidden state = [0,1]; bias = 0.</p>","<p>Activation = tanh.</p>","<h3>To find</h3>","<p>Calculate both entries of the new hidden state. Output-layer weights are not supplied.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p class=\"worked-step\"><strong>Step 1: multiply the input vector into row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10e199f12bbe9b83.svg\"><img class=\"math display-math\" src=\"assets/equations/ae37ee7dd9298b47.svg\" alt=\"0.6(0)+0.4(1)=0+0.4=0.4\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: multiply the input vector into row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/360d1cebae87086f.svg\"><img class=\"math display-math\" src=\"assets/equations/0824814bcead44c1.svg\" alt=\"0.3(0)+0.7(1)=0+0.7=0.7\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: multiply previous state into recurrent row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7c5775eea93e5ad0.svg\"><img class=\"math display-math\" src=\"assets/equations/1ae989326f224964.svg\" alt=\"0.5(0)+0.3(1)=0+0.3=0.3\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: multiply previous state into recurrent row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/818979c823c2927e.svg\"><img class=\"math display-math\" src=\"assets/equations/cd403f4588367553.svg\" alt=\"0.2(0)+0.4(1)=0+0.4=0.4\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: combine contributions for hidden unit 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/01f98e63892e2cf5.svg\" alt=\"a_1=0.4+0.3+0=0.7\" width=\"254.40\" height=\"20.21\" style=\"width:254.40px;height:20.21px;aspect-ratio:254.40/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: combine contributions for hidden unit 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d5abcbc4ff3b8b0f.svg\" alt=\"a_2=0.7+0.4+0=1.1\" width=\"254.40\" height=\"20.21\" style=\"width:254.40px;height:20.21px;aspect-ratio:254.40/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: apply tanh separately to each complete sum.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc5f2bb1f8425e2b.svg\"><img class=\"math display-math\" src=\"assets/equations/644bf14870d92481.svg\" alt=\"h_1=\\tanh(0.7)\\approx0.604367777\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ceaf167b0d164375.svg\"><img class=\"math display-math\" src=\"assets/equations/f19c8c78d2c06e2b.svg\" alt=\"h_2=\\tanh(1.1)\\approx0.800499022\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> h ≈ [0.604367777,0.800499022]. The absent vocabulary output weights prevent calculating a numerical next-word probability list.</p>"],"kind":"practice","id":"mt2-c12-s5","search":"R26 Q5a **Question (10 marks).** Explain feedforward limitations for sequential context and how recurrence helps. Calculate h using tanh for Wxh is shown below, Whh is shown below, x = [0,1], hprevious = [0,1], zero bias. Explain next-word probabilities.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nWxh and Whh are printed in the question; use their receiving-neuron rows.\n\nCurrent input = [0,1]; previous hidden state = [0,1]; bias = 0.\n\nActivation = tanh.\n\n### To find\n\nCalculate both entries of the new hidden state. Output-layer weights are not supplied.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n**Step 1: multiply the input vector into row 1.**\n\n\n\n\n\n\n\n**Step 2: multiply the input vector into row 2.**\n\n\n\n\n\n\n\n**Step 3: multiply previous state into recurrent row 1.**\n\n\n\n\n\n\n\n**Step 4: multiply previous state into recurrent row 2.**\n\n\n\n\n\n\n\n**Step 5: combine contributions for hidden unit 1.**\n\n\n\n\n\n\n\n**Step 6: combine contributions for hidden unit 2.**\n\n\n\n\n\n\n\n**Step 7: apply tanh separately to each complete sum.**\n\n\n\n\n\n\n\n\n\n\n\n**Final answer:** h ≈ [0.604367777,0.800499022]. The absent vocabulary output weights prevent calculating a numerical next-word probability list.\n"},{"title":"R26 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain RMSProp, its update rule and accumulated squared gradients. Give advantages and disadvantages relative to SGD.</p>"],"answer":["<p>RMSProp keeps an exponentially weighted average of squared gradients, instead of AdaGrad&#x27;s ever-growing sum. For each parameter, initialize s₀ = 0 and use:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.46px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/459c86785f7d6c4f.svg\"><img class=\"math display-math\" src=\"assets/equations/914e44e2b8e8e8f9.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"483.06\" height=\"52.24\" style=\"width:483.06px;height:52.24px;aspect-ratio:483.06/52.24\" loading=\"lazy\"></picture></div>","<p>ρ controls how strongly earlier squared gradients are retained. A large average magnitude produces a larger denominator and a smaller step. A small average magnitude produces a relatively larger step. Squaring happens before averaging; averaging signed gradients instead would allow cancellation and would not be RMSProp.</p>","<p>Example: θ₀ = 1, η = 0.1, ρ = 0.9, s₀ = 0, g₁ = 2. Then s₁ = 0.9 × 0+0.1 × 4 = 0.4. θ₁ = 1−0.2/√0.4 = 0.683772234 when ε is negligible. If g₂ = 1, s₂ = 0.9 × 0.4+0.1 × 1 = 0.46 and θ₂ = 0.683772234−0.1/√0.46 = 0.536330278.</p>","<p>Benefits include adapting to different coordinate scales and avoiding AdaGrad&#x27;s permanent accumulation of all past squared gradients. Costs include extra state memory and tuning η, ρ and ε; noisy or badly chosen settings can still produce poor training. Unlike standard SGD it rescales each coordinate; unlike Adam it does not include a separate first-moment estimate in this basic form.</p>"],"kind":"practice","id":"mt2-c12-s6","search":"R26 Q5b **Question (10 marks).** Explain RMSProp, its update rule and accumulated squared gradients. Give advantages and disadvantages relative to SGD.\n\n**Complete worked answer.**\nRMSProp keeps an exponentially weighted average of squared gradients, instead of AdaGrad's ever-growing sum. For each parameter, initialize s₀ = 0 and use:\n\nρ controls how strongly earlier squared gradients are retained. A large average magnitude produces a larger denominator and a smaller step. A small average magnitude produces a relatively larger step. Squaring happens before averaging; averaging signed gradients instead would allow cancellation and would not be RMSProp.\nExample: θ₀ = 1, η = 0.1, ρ = 0.9, s₀ = 0, g₁ = 2. Then s₁ = 0.9 × 0+0.1 × 4 = 0.4. θ₁ = 1−0.2/√0.4 = 0.683772234 when ε is negligible. If g₂ = 1, s₂ = 0.9 × 0.4+0.1 × 1 = 0.46 and θ₂ = 0.683772234−0.1/√0.46 = 0.536330278.\nBenefits include adapting to different coordinate scales and avoiding AdaGrad's permanent accumulation of all past squared gradients. Costs include extra state memory and tuning η, ρ and ε; noisy or badly chosen settings can still produce poor training. Unlike standard SGD it rescales each coordinate; unlike Adam it does not include a separate first-moment estimate in this basic form.\n"},{"title":"R26 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For the binary CNN below, calculate output dimensions and trainable parameters after every layer. Input 256 × 256 × 3. → Conv K = 5, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 128, stride = 1, padding = 1. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 84 units. → Dense 32 units. → Dense 1 units. The printed output size is unspecified; assume one sigmoid output. Unspecified convolution padding is taken as valid.</p>"],"answer":["<h3>Given</h3>","<p>Input 256 × 256 × 3.</p>","<p>Conv K = 5, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 64, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 128, stride = 1, padding = 1.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 84 units.</p>","<p>Dense 32 units.</p>","<p>Dense 1 units.</p>","<p>assume one sigmoid output.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">256 × 256 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">252 × 252 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">2,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">2,432</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>256 × 256 × 3</strong>. Use 32 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f4b85116af3d067a.svg\"><img class=\"math display-math\" src=\"assets/equations/fd4c812f057cfbdc.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{256+2(0)-5}{1}\\right\\rfloor+1=252\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>252 × 252 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/963130ef1e615735.svg\"><img class=\"math display-math\" src=\"assets/equations/ab73b23ba038b015.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times3\\times32=2{,}400\" width=\"349.90\" height=\"23.91\" style=\"width:349.90px;height:23.91px;aspect-ratio:349.90/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/113b757e4d085763.svg\" alt=\"P_1=2{,}400+32=2{,}432\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">252 × 252 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">126 × 126 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>252 × 252 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3083aa89c3311d57.svg\"><img class=\"math display-math\" src=\"assets/equations/ea4835a0c4e1225d.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{252-2}{2}\\right\\rfloor+1=126\" width=\"308.50\" height=\"58.62\" style=\"width:308.50px;height:58.62px;aspect-ratio:308.50/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>126 × 126 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">126 × 126 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">64 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">122 × 122 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">51,200</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">64</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">51,264</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>126 × 126 × 32</strong>. Use 64 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/991cd2a9cf06a3a0.svg\"><img class=\"math display-math\" src=\"assets/equations/8f94d1b01f536cf3.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{126+2(0)-5}{1}\\right\\rfloor+1=122\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>122 × 122 × 64</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 32 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a22447ce668f8dbf.svg\"><img class=\"math display-math\" src=\"assets/equations/5b861b3fc768032c.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times32\\times64=51{,}200\" width=\"374.33\" height=\"23.91\" style=\"width:374.33px;height:23.91px;aspect-ratio:374.33/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc3a74202b89cbd8.svg\" alt=\"N_{\\mathrm{biases}}=64\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/101c0d0d89af6010.svg\" alt=\"P_3=51{,}200+64=51{,}264\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">122 × 122 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">61 × 61 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>122 × 122 × 64</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5f058816466e626.svg\"><img class=\"math display-math\" src=\"assets/equations/61527941fb172a39.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{122-2}{2}\\right\\rfloor+1=61\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>61 × 61 × 64</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">61 × 61 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">128 filters · 5 × 5 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">59 × 59 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">204,800</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">128</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">204,928</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>61 × 61 × 64</strong>. Use 128 filters of spatial size 5 × 5, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8321e7609e3b2886.svg\"><img class=\"math display-math\" src=\"assets/equations/b9ff7e28d1cec2ae.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{61+2(1)-5}{1}\\right\\rfloor+1=59\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>59 × 59 × 128</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 64 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c52ed6d2bdad242d.svg\"><img class=\"math display-math\" src=\"assets/equations/2b0e3ca2da50e61a.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times64\\times128=204{,}800\" width=\"398.77\" height=\"23.91\" style=\"width:398.77px;height:23.91px;aspect-ratio:398.77/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf36568f06144792.svg\" alt=\"N_{\\mathrm{biases}}=128\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f00380ddc73ffc90.svg\"><img class=\"math display-math\" src=\"assets/equations/81ad3f9ee9d3ccc2.svg\" alt=\"P_5=204{,}800+128=204{,}928\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">59 × 59 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">29 × 29 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>59 × 59 × 128</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c7e04e5a610fd348.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{59-2}{2}\\right\\rfloor+1=29\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>29 × 29 × 128</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 28.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 7 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">29 × 29 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">107,648</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>29 × 29 × 128</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.99px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4f51a385169358d4.svg\"><img class=\"math display-math\" src=\"assets/equations/d04e40df15cb4a0b.svg\" alt=\"n_{\\mathrm{flat}}=29\\times29\\times128=107{,}648\" width=\"332.66\" height=\"21.29\" style=\"width:332.66px;height:21.29px;aspect-ratio:332.66/21.29\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>107,648 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">107,648</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">84 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">9,042,432</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">84</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">9,042,516</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>107,648 features</strong>. Output: <strong>84 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3496f06ddb91fc91.svg\"><img class=\"math display-math\" src=\"assets/equations/63fdb30c55665f91.svg\" alt=\"N_{\\mathrm{weights}}=107{,}648\\times84=9{,}042{,}432\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec58135349b68114.svg\" alt=\"N_{\\mathrm{biases}}=84\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.35px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a73b69ea184fcd0.svg\"><img class=\"math display-math\" src=\"assets/equations/868b3136771d3432.svg\" alt=\"P_8=9{,}042{,}432+84=9{,}042{,}516\" width=\"344.03\" height=\"21.43\" style=\"width:344.03px;height:21.43px;aspect-ratio:344.03/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 9 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">32 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">32</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">2,688</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">2,720</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>84 features</strong>. Output: <strong>32 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6439e320bc2235fb.svg\" alt=\"N_{\\mathrm{weights}}=84\\times32=2{,}688\" width=\"277.94\" height=\"23.91\" style=\"width:277.94px;height:23.91px;aspect-ratio:277.94/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737742757d7487f8.svg\" alt=\"P_9=2{,}688+32=2{,}720\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">32</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">1 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">33</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>32 features</strong>. Output: <strong>1 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/63bcab1d4c5ad97d.svg\" alt=\"N_{\\mathrm{weights}}=32\\times1=32\" width=\"234.50\" height=\"23.91\" style=\"width:234.50px;height:23.91px;aspect-ratio:234.50/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9172e32c44e88eec.svg\" alt=\"N_{\\mathrm{biases}}=1\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6095954f97f48924.svg\" alt=\"P_10=32+1=33\" width=\"194.69\" height=\"20.36\" style=\"width:194.69px;height:20.36px;aspect-ratio:194.69/20.36\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/6723e51cb832856a.svg\" alt=\"\\left\\lfloor\\frac{256+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>252 x 252 x 32</td><td>2,400</td><td>32</td><td>2,432</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/88e7931306349767.svg\" alt=\"\\left\\lfloor\\frac{252-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>126 x 126 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5b79f5df9ff78236.svg\" alt=\"\\left\\lfloor\\frac{126+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>122 x 122 x 64</td><td>51,200</td><td>64</td><td>51,264</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/8713b9890edc970c.svg\" alt=\"\\left\\lfloor\\frac{122-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>61 x 61 x 64</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/54ee85e0468271d4.svg\" alt=\"\\left\\lfloor\\frac{61+2 \\times  1-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>59 x 59 x 128</td><td>204,800</td><td>128</td><td>204,928</td></tr><tr><td>6 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e80bd4fe22509760.svg\" alt=\"\\left\\lfloor\\frac{59-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>29 x 29 x 128</td><td>0</td><td>0</td><td>0</td></tr><tr><td>7 flat</td><td>29 × 29 × 128</td><td>107648</td><td>0</td><td>0</td><td>0</td></tr><tr><td>8 dense</td><td>107648 → 84</td><td>84</td><td>9,042,432</td><td>84</td><td>9,042,516</td></tr><tr><td>9 dense</td><td>84 → 32</td><td>32</td><td>2,688</td><td>32</td><td>2,720</td></tr><tr><td>10 dense</td><td>32 → 1</td><td>1</td><td>32</td><td>1</td><td>33</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (5 x 5 x 3 + 1) x 32 = 2,432.</p>","<p>Layer 3: (5 x 5 x 32 + 1) x 64 = 51,264.</p>","<p>Layer 5: (5 x 5 x 64 + 1) x 128 = 204,928.</p>","<p>Layer 8: (107648 + 1) x 84 = 9,042,516.</p>","<p>Layer 9: (84 + 1) x 32 = 2,720.</p>","<p>Layer 10: (32 + 1) x 1 = 33.</p>","<p><strong>Total: </strong> 2,432 + 51,264 + 204,928 + 9,042,516 + 2,720 + 33 = <strong>9,303,893 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p><strong>Correction: </strong> Conv 3 has (5 × 5 × 64+1) × 128 = <strong>204,928</strong> parameters, not 73,856 as printed in the key. Correct total is <strong>9,303,893</strong>. If binary classification is instead implemented with two softmax outputs, the last dense layer has(32+1) × 2 = 66 parameters and the total becomes 9,303,926; explicitly state the output convention.</p>"],"kind":"practice","id":"mt2-c12-s7","search":"R26 Q6a **Question (10 marks).** For the binary CNN below, calculate output dimensions and trainable parameters after every layer. Input 256 × 256 × 3. → Conv K = 5, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 128, stride = 1, padding = 1. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 84 units. → Dense 32 units. → Dense 1 units. The printed output size is unspecified; assume one sigmoid output. Unspecified convolution padding is taken as valid.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 256 × 256 × 3.\n\nConv K = 5, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 64, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 128, stride = 1, padding = 1.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 84 units.\n\nDense 32 units.\n\nDense 1 units.\n\nassume one sigmoid output.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{256+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 252 x 252 x 32 | 2,400 | 32 | 2,432 |\n| 2 pool | \\(\\left\\lfloor\\frac{252-2}{2}\\right\\rfloor+1\\) | 126 x 126 x 32 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{126+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 122 x 122 x 64 | 51,200 | 64 | 51,264 |\n| 4 pool | \\(\\left\\lfloor\\frac{122-2}{2}\\right\\rfloor+1\\) | 61 x 61 x 64 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{61+2 \\times  1-5}{1}\\right\\rfloor+1\\) | 59 x 59 x 128 | 204,800 | 128 | 204,928 |\n| 6 pool | \\(\\left\\lfloor\\frac{59-2}{2}\\right\\rfloor+1\\) | 29 x 29 x 128 | 0 | 0 | 0 |\n| 7 flat | 29 × 29 × 128 | 107648 | 0 | 0 | 0 |\n| 8 dense | 107648 → 84 | 84 | 9,042,432 | 84 | 9,042,516 |\n| 9 dense | 84 → 32 | 32 | 2,688 | 32 | 2,720 |\n| 10 dense | 32 → 1 | 1 | 32 | 1 | 33 |\n**Parameter substitutions, in layer order: **\nLayer 1: (5 x 5 x 3 + 1) x 32 = 2,432.\nLayer 3: (5 x 5 x 32 + 1) x 64 = 51,264.\nLayer 5: (5 x 5 x 64 + 1) x 128 = 204,928.\nLayer 8: (107648 + 1) x 84 = 9,042,516.\nLayer 9: (84 + 1) x 32 = 2,720.\nLayer 10: (32 + 1) x 1 = 33.\n**Total: ** 2,432 + 51,264 + 204,928 + 9,042,516 + 2,720 + 33 = **9,303,893 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n**Correction: ** Conv 3 has (5 × 5 × 64+1) × 128 = **204,928** parameters, not 73,856 as printed in the key. Correct total is "},{"title":"R26 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain transfer learning with CNNs and how to adapt a pretrained model to a new image classification task, including an example model.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>","<p><strong>Concrete example: </strong> replace the 1000-class head of a pretrained ResNet with a 10-class vegetable head. Train the new head with the base frozen, then optionally fine-tune late residual blocks at a smaller rate. Input preprocessing must match the pretrained model. The 10 output probabilities sum to 1 for mutually exclusive classes.</p>"],"kind":"practice","id":"mt2-c12-s8","search":"R26 Q7b **Question (10 marks).** Explain transfer learning with CNNs and how to adapt a pretrained model to a new image classification task, including an example model.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n**Concrete example: ** replace the 1000-class head of a pretrained ResNet with a 10-class vegetable head. Train the new head with the base frozen, then optionally fine-tune late residual blocks at a smaller rate. Input preprocessing must match the pretrained model. The 10 output probabilities sum to 1 for mutually exclusive classes.\n\n\n"}]},{"n":13,"title":"F23 selected MT2 practice","sections":[{"title":"Start here","blocks":["<p>The source archive retains historical optimization, CNN and introductory RNN questions. Following the 12 October faculty update, the focused MT2 website presents the Unit 3–4 questions; retained RNN bookmarks lead to TEE. Original question IDs and marks are preserved. Full assessed tasks and numerical data are transcribed in readable language; worked solutions follow each question. This selection does not predict the paper.</p>"],"kind":"read","id":"mt2-c13-intro"},{"title":"F23 Q1b","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Identify the hyperparameters to tune when training an ANN and explain their significance.</p>"],"answer":["<p>Hyperparameters are chosen outside the ordinary weight-gradient updates. Learning rate controls step size; number of layers and units controls capacity; activation determines nonlinear behavior; batch size controls the data used per update and memory demand; epochs control training duration. Regularization strength, dropout rate and early-stopping patience affect generalization. Optimizer-specific choices include momentum β or Adam β₁, β₂,ε. Tune using validation data while keeping the final test set separate. Weights and biases are learned parameters; they are not hyperparameters merely because their initial values must be selected.</p>"],"kind":"practice","id":"mt2-c13-s0","search":"F23 Q1b **Question (5 marks).** Identify the hyperparameters to tune when training an ANN and explain their significance.\n\n**Complete worked answer.**\nHyperparameters are chosen outside the ordinary weight-gradient updates. Learning rate controls step size; number of layers and units controls capacity; activation determines nonlinear behavior; batch size controls the data used per update and memory demand; epochs control training duration. Regularization strength, dropout rate and early-stopping patience affect generalization. Optimizer-specific choices include momentum β or Adam β₁, β₂,ε. Tune using validation data while keeping the final test set separate. Weights and biases are learned parameters; they are not hyperparameters merely because their initial values must be selected.\n"},{"title":"F23 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 1; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.</p>","<h3>To find</h3>","<p>Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/451621c0173b1850.svg\" alt=\"\\left\\lfloor\\frac{4+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 14\">14</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>10 + 9 + 5 = 24</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>5 + 14 + 6 = 25</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 3 + 2 = 8</b></div></div><p class=\"lv-combine\"><b>24 + 25 + 8 = 57</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fe1b0c406527aa8.svg\"><img class=\"math display-math\" src=\"assets/equations/17e6fe356ebb57a3.svg\" alt=\"R_1=(10)\\times(1)+(9)\\times(1)+(5)\\times(1)=24\" width=\"467.75\" height=\"24.43\" style=\"width:467.75px;height:24.43px;aspect-ratio:467.75/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dec76766281c84de.svg\"><img class=\"math display-math\" src=\"assets/equations/4ae5e24b45a652e7.svg\" alt=\"R_2=(5)\\times(1)+(7)\\times(2)+(6)\\times(1)=25\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/612c6e731f469d2a.svg\"><img class=\"math display-math\" src=\"assets/equations/640dbb668111d247.svg\" alt=\"R_3=(3)\\times(1)+(3)\\times(1)+(2)\\times(1)=8\" width=\"443.31\" height=\"24.43\" style=\"width:443.31px;height:24.43px;aspect-ratio:443.31/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.75px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b718b308893f322.svg\"><img class=\"math display-math\" src=\"assets/equations/572c32730d6fe617.svg\" alt=\"Y_{1,1}=(24)+(25)+(8)=57\" width=\"305.76\" height=\"25.35\" style=\"width:305.76px;height:25.35px;aspect-ratio:305.76/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>2–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 9\">9</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 6\">6</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 7\">7</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 12\">12</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 7\">7</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 8\">8</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>9 + 5 + 6 = 20</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>7 + 12 + 7 = 26</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 2 + 8 = 13</b></div></div><p class=\"lv-combine\"><b>20 + 26 + 13 = 59</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c760b3950eb840ed.svg\"><img class=\"math display-math\" src=\"assets/equations/227f73214fffc2b3.svg\" alt=\"R_1=(9)\\times(1)+(5)\\times(1)+(6)\\times(1)=20\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/16eb873463fe23bb.svg\"><img class=\"math display-math\" src=\"assets/equations/5e2ed47a500a084d.svg\" alt=\"R_2=(7)\\times(1)+(6)\\times(2)+(7)\\times(1)=26\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/17c18e38643140f3.svg\"><img class=\"math display-math\" src=\"assets/equations/adea8f6e7cdc7e9c.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(1)+(8)\\times(1)=13\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.65px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f077bed2b9d89eff.svg\"><img class=\"math display-math\" src=\"assets/equations/b674e79df8f34858.svg\" alt=\"Y_{1,2}=(20)+(26)+(13)=59\" width=\"317.98\" height=\"25.35\" style=\"width:317.98px;height:25.35px;aspect-ratio:317.98/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–4</b>, columns <b>1–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 5\">5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 7\">7</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 6\">6</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 6\">6</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 6\">6</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>5 + 7 + 6 = 18</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>3 + 6 + 2 = 11</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 2 + 6 = 11</b></div></div><p class=\"lv-combine\"><b>18 + 11 + 11 = 40</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ba28bdc7c806323.svg\"><img class=\"math display-math\" src=\"assets/equations/a148f40de653ff23.svg\" alt=\"R_1=(5)\\times(1)+(7)\\times(1)+(6)\\times(1)=18\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5861059147729994.svg\"><img class=\"math display-math\" src=\"assets/equations/0bf1f6754ed5f9c0.svg\" alt=\"R_2=(3)\\times(1)+(3)\\times(2)+(2)\\times(1)=11\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c85bf61f7da39979.svg\"><img class=\"math display-math\" src=\"assets/equations/849173dcb9ca1a0f.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(1)+(6)\\times(1)=11\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.65px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ba895c690daff56.svg\"><img class=\"math display-math\" src=\"assets/equations/867dfee50107ebc8.svg\" alt=\"Y_{2,1}=(18)+(11)+(11)=40\" width=\"317.98\" height=\"25.35\" style=\"width:317.98px;height:25.35px;aspect-ratio:317.98/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–4</b>, columns <b>2–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 7\">7</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 6\">6</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 7\">7</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 8\">8</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 6\">6</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>7 + 6 + 7 = 20</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>3 + 4 + 8 = 15</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>2 + 6 + 7 = 15</b></div></div><p class=\"lv-combine\"><b>20 + 15 + 15 = 50</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/05ae17650121d076.svg\"><img class=\"math display-math\" src=\"assets/equations/9f8fed3c271dceb7.svg\" alt=\"R_1=(7)\\times(1)+(6)\\times(1)+(7)\\times(1)=20\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9dcb85c5c6766eb3.svg\"><img class=\"math display-math\" src=\"assets/equations/7daf395d533e53c4.svg\" alt=\"R_2=(3)\\times(1)+(2)\\times(2)+(8)\\times(1)=15\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2745b26251055027.svg\"><img class=\"math display-math\" src=\"assets/equations/0136802d6b00a2fe.svg\" alt=\"R_3=(2)\\times(1)+(6)\\times(1)+(7)\\times(1)=15\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.65px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90b52e79a3bf1954.svg\"><img class=\"math display-math\" src=\"assets/equations/9333688e57e199f1.svg\" alt=\"Y_{2,2}=(20)+(15)+(15)=50\" width=\"317.98\" height=\"25.35\" style=\"width:317.98px;height:25.35px;aspect-ratio:317.98/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/3c78c4fdcdcef59f.svg\" alt=\"\\begin{bmatrix}57 &amp; 59\\\\40 &amp; 50\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"kind":"practice","id":"mt2-c13-s1","search":"F23 Q1d **Question (5 marks).** Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nCompute the convolution using the input A and kernel K shown below using padding 0 and stride 1.\n\n### To find\n\nFind every convolution output cell.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{4+2 \\times  0-3}{1}\\right\\rfloor+1\\) = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.\n**Output (1,1): ** (10 × (1)) + (9 × (1)) + (5 × (1)) + (5 × (1)) + (7 × (2)) + (6 × (1)) + (3 × (1)) + (3 × (1)) + (2 × (1)) = **57**.\n**Output (1,2): ** (9 × (1)) + (5 × (1)) + (6 × (1)) + (7 × (1)) + (6 × (2)) + (7 × (1)) + (3 × (1)) + (2 × (1)) + (8 × (1)) = **59**.\n**Output (2,1): ** (5 × (1)) + (7 × (1)) + (6 × (1)) + (3 × (1)) + (3 × (2)) + (2 × (1)) + (3 × (1)) + (2 × (1)) + (6 × (1)) = **40**.\n**Output (2,2): ** (7 × (1)) + (6 × (1)) + (7 × (1)) + (3 × (1)) + (2 × (2)) + (8 × (1)) + (2 × (1)) + (6 × (1)) + (7 × (1)) = **50**.\n**Final output: ** . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.\n"},{"title":"F23 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain key advantages of Adam for ANN training and how it differs from SGD.</p>"],"answer":["<p>Adam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.71px;--narrow-height:202.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92678247acd594b0.svg\"><img class=\"math display-math\" src=\"assets/equations/c443fc0367c152b1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\widehat v_t=\\frac{v_t}{1-\\beta_2^t},\\quad\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"571.98\" height=\"66.85\" style=\"width:571.98px;height:66.85px;aspect-ratio:571.98/66.85\" loading=\"lazy\"></picture></div>","<p>Use update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.</p>","<p>For g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.</p>","<p>Compared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.</p>"],"kind":"practice","id":"mt2-c13-s2","search":"F23 Q3b **Question (10 marks).** Explain key advantages of Adam for ANN training and how it differs from SGD.\n\n**Complete worked answer.**\nAdam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.\n\n\nUse update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.\nFor g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.\nCompared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.\n"},{"title":"F23 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Determine feature-map dimensions and parameters at every layer of the pictured AlexNet-style CNN. The normalized architecture is Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.</p>"],"answer":["<h3>Given</h3>","<p>The normalized architecture is Input 227 × 227 × 3.</p>","<p>Conv K = 11, filters = 96, stride = 4, padding = 0.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 256, stride = 1, padding = 2.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 256, stride = 1, padding = 1.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Dense 4096 units.</p>","<p>Dense 4096 units.</p>","<p>Dense 1000 units.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">227 × 227 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">96 filters · 11 × 11 · S = 4 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">34,848</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">96</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">34,944</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>227 × 227 × 3</strong>. Use 96 filters of spatial size 11 × 11, stride 4, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.10px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/441a061296efda7a.svg\"><img class=\"math display-math\" src=\"assets/equations/1ca643e3f874dc98.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{227+2(0)-11}{4}\\right\\rfloor+1=55\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>55 × 55 × 96</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9a11e5db4a09d338.svg\"><img class=\"math display-math\" src=\"assets/equations/e8a26a7b03e38af6.svg\" alt=\"N_{\\mathrm{weights}}=11\\times11\\times3\\times96=34{,}848\" width=\"386.55\" height=\"23.91\" style=\"width:386.55px;height:23.91px;aspect-ratio:386.55/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3b19ed994769f54.svg\" alt=\"N_{\\mathrm{biases}}=96\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ae51bc20750a112f.svg\" alt=\"P_1=34{,}848+96=34{,}944\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>55 × 55 × 96</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d42806d80c07005c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1=27\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>27 × 27 × 96</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 5 × 5 · S = 1 · P = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">614,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">614,656</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>27 × 27 × 96</strong>. Use 256 filters of spatial size 5 × 5, stride 1, and padding 2 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f4e102905e6bf9f.svg\"><img class=\"math display-math\" src=\"assets/equations/da9a62eaf99ea1e8.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27+2(2)-5}{1}\\right\\rfloor+1=27\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>27 × 27 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 96 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b720c78ffc948913.svg\"><img class=\"math display-math\" src=\"assets/equations/05edf5328cb35876.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times96\\times256=614{,}400\" width=\"398.77\" height=\"23.91\" style=\"width:398.77px;height:23.91px;aspect-ratio:398.77/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29c935e56c01ee26.svg\"><img class=\"math display-math\" src=\"assets/equations/67ebf4d50d295918.svg\" alt=\"P_3=614{,}400+256=614{,}656\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>27 × 27 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ca522f15a3632877.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1=13\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">885,120</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 256 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/492d70515e0406f9.svg\"><img class=\"math display-math\" src=\"assets/equations/0f457ff5f3c6b74f.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times256\\times384=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e9338e40808aff5.svg\"><img class=\"math display-math\" src=\"assets/equations/0cca75bb5a08cdeb.svg\" alt=\"P_5=884{,}736+384=885{,}120\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">1,327,104</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">1,327,488</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3729f79bf2b69fab.svg\"><img class=\"math display-math\" src=\"assets/equations/a2fb560ecf5f18c3.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times384=1{,}327{,}104\" width=\"429.99\" height=\"23.91\" style=\"width:429.99px;height:23.91px;aspect-ratio:429.99/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4565bf3714918ad3.svg\"><img class=\"math display-math\" src=\"assets/equations/8d8b08cc6480d083.svg\" alt=\"P_6=1{,}327{,}104+384=1{,}327{,}488\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">884,992</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 256 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/be0b63ec1f7ffb8c.svg\"><img class=\"math display-math\" src=\"assets/equations/42a81620f94360dd.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times256=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c304d00633ff2322.svg\"><img class=\"math display-math\" src=\"assets/equations/a803766772104e69.svg\" alt=\"P_7=884{,}736+256=884{,}992\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/117abcc38db86957.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1=6\" width=\"271.85\" height=\"58.62\" style=\"width:271.85px;height:58.62px;aspect-ratio:271.85/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>6 × 6 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 9 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>6 × 6 × 256</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d9921c92554e599.svg\" alt=\"n_{\\mathrm{flat}}=6\\times6\\times256=9{,}216\" width=\"283.79\" height=\"21.02\" style=\"width:283.79px;height:21.02px;aspect-ratio:283.79/21.02\" loading=\"lazy\"></div>","<p>Output: a vector with <strong>9,216 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">37,748,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">37,752,832</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>9,216 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/253a54d671a02309.svg\"><img class=\"math display-math\" src=\"assets/equations/864d5792c1506a4b.svg\" alt=\"N_{\\mathrm{weights}}=9{,}216\\times4{,}096=37{,}748{,}736\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a6d14bbf5757207.svg\"><img class=\"math display-math\" src=\"assets/equations/42e41d5d625e4b33.svg\" alt=\"P_10=37{,}748{,}736+4{,}096=37{,}752{,}832\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 11 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 11: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">16,777,216</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">16,781,312</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe4cfd667cc7b7ce.svg\"><img class=\"math display-math\" src=\"assets/equations/37f33b938916c485.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times4{,}096=16{,}777{,}216\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3652163d527344ad.svg\"><img class=\"math display-math\" src=\"assets/equations/ca42e0122e881f05.svg\" alt=\"P_11=16{,}777{,}216+4{,}096=16{,}781{,}312\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 12 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 12: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">1,000 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">1,000</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,096,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">1,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,097,000</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>1,000 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3d7876f0d5fdb4fa.svg\"><img class=\"math display-math\" src=\"assets/equations/a47853490ec706c7.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times1{,}000=4{,}096{,}000\" width=\"383.84\" height=\"23.91\" style=\"width:383.84px;height:23.91px;aspect-ratio:383.84/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d0008f88a44995b2.svg\" alt=\"N_{\\mathrm{biases}}=1{,}000\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3adeefbc3dbe4d6b.svg\"><img class=\"math display-math\" src=\"assets/equations/91b7bd4147e4b8d6.svg\" alt=\"P_12=4{,}096{,}000+1{,}000=4{,}097{,}000\" width=\"387.48\" height=\"21.43\" style=\"width:387.48px;height:21.43px;aspect-ratio:387.48/21.43\" loading=\"lazy\"></picture></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/74235148b2b7312a.svg\" alt=\"\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\" width=\"199.47\" height=\"45.60\" style=\"width:199.47px;height:45.60px;aspect-ratio:199.47/45.60\" loading=\"lazy\"></span></td><td>55 x 55 x 96</td><td>34,848</td><td>96</td><td>34,944</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cdac8f1c682bc40a.svg\" alt=\"\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 96</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/71046f85d0cc0ca5.svg\" alt=\"\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 256</td><td>614,400</td><td>256</td><td>614,656</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/55802f10aac3668d.svg\" alt=\"\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>884,736</td><td>384</td><td>885,120</td></tr><tr><td>6 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>1,327,104</td><td>384</td><td>1,327,488</td></tr><tr><td>7 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>884,736</td><td>256</td><td>884,992</td></tr><tr><td>8 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/73ab07c24eb836b2.svg\" alt=\"\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>6 x 6 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>9 flat</td><td>6 × 6 × 256</td><td>9216</td><td>0</td><td>0</td><td>0</td></tr><tr><td>10 dense</td><td>9216 → 4096</td><td>4096</td><td>37,748,736</td><td>4,096</td><td>37,752,832</td></tr><tr><td>11 dense</td><td>4096 → 4096</td><td>4096</td><td>16,777,216</td><td>4,096</td><td>16,781,312</td></tr><tr><td>12 dense</td><td>4096 → 1000</td><td>1000</td><td>4,096,000</td><td>1,000</td><td>4,097,000</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (11 x 11 x 3 + 1) x 96 = 34,944.</p>","<p>Layer 3: (5 x 5 x 96 + 1) x 256 = 614,656.</p>","<p>Layer 5: (3 x 3 x 256 + 1) x 384 = 885,120.</p>","<p>Layer 6: (3 x 3 x 384 + 1) x 384 = 1,327,488.</p>","<p>Layer 7: (3 x 3 x 384 + 1) x 256 = 884,992.</p>","<p>Layer 10: (9216 + 1) x 4096 = 37,752,832.</p>","<p>Layer 11: (4096 + 1) x 4096 = 16,781,312.</p>","<p>Layer 12: (4096 + 1) x 1000 = 4,097,000.</p>","<p><strong>Total: </strong> 34,944 + 614,656 + 885,120 + 1,327,488 + 884,992 + 37,752,832 + 16,781,312 + 4,097,000 = <strong>62,378,344 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p>The count treats every listed convolution as connected to all input channels. Original grouped AlexNet implementations have different counts; do not insert grouping that is not shown in the question.</p>"],"kind":"practice","id":"mt2-c13-s3","search":"F23 Q4a **Question (10 marks).** Determine feature-map dimensions and parameters at every layer of the pictured AlexNet-style CNN. The normalized architecture is Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nThe normalized architecture is Input 227 × 227 × 3.\n\nConv K = 11, filters = 96, stride = 4, padding = 0.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 5, filters = 256, stride = 1, padding = 2.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 256, stride = 1, padding = 1.\n\nPool K = 3, stride = 2, padding = 0.\n\nDense 4096 units.\n\nDense 4096 units.\n\nDense 1000 units.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\\) | 55 x 55 x 96 | 34,848 | 96 | 34,944 |\n| 2 pool | \\(\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\\) | 27 x 27 x 96 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\\) | 27 x 27 x 256 | 614,400 | 256 | 614,656 |\n| 4 pool | \\(\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\\) | 13 x 13 x 256 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 884,736 | 384 | 885,120 |\n| 6 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 1,327,104 | 384 | 1,327,488 |\n| 7 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 256 | 884,736 | 256 | 884,992 |\n| 8 pool | \\(\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\\) | 6 x 6 x 256 | 0 | 0 | 0 |\n| 9 flat | 6 × 6 × 256 | 9216 | 0 | 0 | 0 |\n| 10 dense | 9216 → 4096 | 4096 | 37,748,736 | 4,096 | 37,752,832 |\n| 11 dense | 4096 → 4096 | 4096 | 16,777,216 | 4,096 | 16,781,312 |\n| 12 dense | 4096 → 1000 | 1000 | 4,096,000 | 1,000 | 4,097,000 |\n**Parameter substitutions, in layer order: **\nLayer 1: (11 x 11 x 3 + 1) x 96 = 34,944.\nLayer 3: (5 x 5 x 96 + 1) x 256 = 614,656.\nLayer 5: (3 x 3 x 256 + 1) x 384 = 885,120.\nLayer 6: (3 x"},{"title":"F23 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For Inception V 1, justify different kernel sizes in one block, explain 1 × 1 convolutions and sketch one block.</p>"],"answer":["<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>"],"kind":"practice","id":"mt2-c13-s4","search":"F23 Q5a **Question (10 marks).** For Inception V 1, justify different kernel sizes in one block, explain 1 × 1 convolutions and sketch one block.\n\n**Complete worked answer.**\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\n"},{"title":"F23 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain how ResNet addresses vanishing gradients. Compare a block output with and without a residual connection.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>"],"kind":"practice","id":"mt2-c13-s5","search":"F23 Q6b **Question (10 marks).** Explain how ResNet addresses vanishing gradients. Compare a block output with and without a residual connection.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\n"},{"title":"F23 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design and sketch a sentiment-analysis model whose input is a small paragraph. Explain how its output is generated.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p><strong>Concrete many-to-one design: </strong> tokenize paragraph → embeddings → vanilla RNN sequence processor → final hidden state → dense 3 → softmax for positive/neutral/negative. If the task specifies only two labels, use one sigmoid or two softmax outputs instead. Train with the matching cross-entropy. Keep token order, handle padding/masks consistently and evaluate held-out reviews.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: Sentiment uses the many-to-one pattern\"><img src=\"assets/figures/sequences.svg\" alt=\"Sentiment uses the many-to-one pattern\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>Sentiment uses the many-to-one pattern <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"mt2-c13-s6","search":"F23 Q7a **Question (10 marks).** Design and sketch a sentiment-analysis model whose input is a small paragraph. Explain how its output is generated.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n**Concrete many-to-one design: ** tokenize paragraph → embeddings → vanilla RNN sequence processor → final hidden state → dense 3 → softmax for positive/neutral/negative. If the task specifies only two labels, use one sigmoid or two softmax outputs instead. Train with the matching cross-entropy. Keep token order, handle padding/masks consistently and evaluate held-out reviews.\n\n"},{"title":"F23 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain the bias-variance tradeoff. Fill effects on bias and variance for weight regularization, more hidden units, dropout and more training data from the same distribution.</p>"],"answer":["<p>Bias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/overfitting.svg\" aria-label=\"Enlarge diagram: Validation behavior distinguishes useful fitting from prolonged fitting to training details\"><img src=\"assets/figures/overfitting.svg\" alt=\"Validation behavior distinguishes useful fitting from prolonged fitting to training details\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Validation behavior distinguishes useful fitting from prolonged fitting to training details <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Increasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model&#x27;s approximation bias much. These are typical trends, not unconditional numerical laws.</p>","<p>Underfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.</p>","<p>Training and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Change</th><th>Typical bias</th><th>Typical variance</th></tr></thead><tbody><tr><td>Stronger weight regularization</td><td>Increases</td><td>Decreases</td></tr><tr><td>More hidden units</td><td>Decreases</td><td>Increases</td></tr><tr><td>Dropout during training</td><td>Increases</td><td>Decreases</td></tr><tr><td>More same-distribution training data</td><td>Approximately no change</td><td>Decreases</td></tr></tbody></table></div>","<p>These are the conventional exam trends, assuming other conditions are comparable. They are not guarantees for every training run.</p>"],"kind":"practice","id":"mt2-c13-s7","search":"F23 Q7b **Question (10 marks).** Explain the bias-variance tradeoff. Fill effects on bias and variance for weight regularization, more hidden units, dropout and more training data from the same distribution.\n\n**Complete worked answer.**\nBias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.\n\nIncreasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model's approximation bias much. These are typical trends, not unconditional numerical laws.\nUnderfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.\nTraining and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.\n| Change | Typical bias | Typical variance |\n| Stronger weight regularization | Increases | Decreases |\n| More hidden units | Decreases | Increases |\n| Dropout during training | Increases | Decreases |\n| More same-distribution training data | Approximately no change | Decreases |\nThese are the conventional exam trends, assuming other conditions are comparable. They are not guarantees for every training run.\n\n\n"}]},{"n":14,"title":"R24 selected MT2 practice","sections":[{"title":"Start here","blocks":["<p>The source archive retains historical optimization, CNN and introductory RNN questions. Following the 12 October faculty update, the focused MT2 website presents the Unit 3–4 questions; retained RNN bookmarks lead to TEE. Original question IDs and marks are preserved. Full assessed tasks and numerical data are transcribed in readable language; worked solutions follow each question. This selection does not predict the paper.</p>"],"kind":"read","id":"mt2-c14-intro"},{"title":"R24 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> A deep network strongly overfits its training set and performs poorly on unseen data. Explain remedies.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<p>Use a representative validation set to choose the remedy. Also inspect leakage, label quality and distribution mismatch. If the final test set was repeatedly used to tune changes, reserve a fresh untouched set for final reporting.</p>"],"kind":"practice","id":"mt2-c14-s0","search":"R24 Q1c **Question (5 marks).** A deep network strongly overfits its training set and performs poorly on unseen data. Explain remedies.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\nUse a representative validation set to choose the remedy. Also inspect leakage, label quality and distribution mismatch. If the final test set was repeatedly used to tune changes, reserve a fresh untouched set for final reporting.\n"},{"title":"R24 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> For feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_915e1db14b.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_915e1db14b.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"405\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>For feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.</p>","<h3>To find</h3>","<p>Find the requested pooled output(s).</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ad46d0c1b3646c71.svg\" alt=\"\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[21, 11, 12, 9]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>21 + 11 + 12 + 9 = 53</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>53/4 = <strong>13.25</strong>. Maximum = <strong>21</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[15, 10, 10, 11]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>15 + 10 + 10 + 11 = 46</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>46/4 = <strong>11.5</strong>. Maximum = <strong>15</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[11, 13, 7, 4]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>11 + 13 + 7 + 4 = 35</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>35/4 = <strong>8.75</strong>. Maximum = <strong>13</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[18, 12, 15, 12]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>18 + 12 + 15 + 12 = 57</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>57/4 = <strong>14.25</strong>. Maximum = <strong>18</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/94682b0fab3f0b97.svg\" alt=\"\\begin{bmatrix}13.25 &amp; 11.5\\\\8.75 &amp; 14.25\\end{bmatrix}\" width=\"125.66\" height=\"45.61\" style=\"width:125.66px;height:45.61px;aspect-ratio:125.66/45.61\" loading=\"lazy\"></span>. <strong>Max output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/89ec596cf1c6ec68.svg\" alt=\"\\begin{bmatrix}21 &amp; 15\\\\13 &amp; 18\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>"],"kind":"practice","id":"mt2-c14-s1","search":"R24 Q1d **Question (5 marks).** For feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nFor feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.\n\n### To find\n\nFind the requested pooled output(s).\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n\n\n**Shape: ** \\(\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\\) = 2 on each axis; channels stay unchanged.\n### Pooling window (1,1)\n\n**Step 1: select the entries.**\n\n[21, 11, 12, 9]\n\n**Step 2: add all selected entries.**\n\n21 + 11 + 12 + 9 = 53\n\n**Step 3: divide by the 4 entries in this window.**\n\n53/4 = **13.25**. Maximum = **21**\n\n\n### Pooling window (1,2)\n\n**Step 1: select the entries.**\n\n[15, 10, 10, 11]\n\n**Step 2: add all selected entries.**\n\n15 + 10 + 10 + 11 = 46\n\n**Step 3: divide by the 4 entries in this window.**\n\n46/4 = **11.5**. Maximum = **15**\n\n\n### Pooling window (2,1)\n\n**Step 1: select the entries.**\n\n[11, 13, 7, 4]\n\n**Step 2: add all selected entries.**\n\n11 + 13 + 7 + 4 = 35\n\n**Step 3: divide by the 4 entries in this window.**\n\n35/4 = **8.75**. Maximum = **13**\n\n\n### Pooling window (2,2)\n\n**Step 1: select the entries.**\n\n[18, 12, 15, 12]\n\n**Step 2: add all selected entries.**\n\n18 + 12 + 15 + 12 = 57\n\n**Step 3: divide by the 4 entries in this window.**\n\n57/4 = **14.25**. Maximum = **18**\n\n\n**Average output: ** . **Max output: ** . Pooling normally has zero trainable parameters and reduces spatial dimensions.\n"},{"title":"R24 Q2b","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare standard momentum and Nesterov accelerated gradient using their gradient-evaluation points and update equations. Explain what may happen when momentum is extremely close to 1, for example 0.9999.</p>","<p><strong>Syllabus-aligned extract:</strong> source R24 Q2b. The current-syllabus optimizer comparison and high-momentum discussion are retained; marks for this extract are not separately stated.</p>"],"answer":["<p>Use signed velocity. Standard momentum evaluates g at current θ: vnew = βv−ηg(θ), θ new = θ+vnew. Nesterov evaluates at a look-ahead point: θ look = θ+βv; vnew = βv−ηg(θ look); θ new = θ+vnew. Thus the gradient can correct a direction after anticipating part of the momentum move. Nesterov often reduces overshoot in suitable settings, but it is not universally faster for every neural network.</p>","<p>With β = 0.9999, old velocity decays very slowly. The method can respond sluggishly to direction changes, overshoot or oscillate, particularly with a large learning rate. An approximate memory scale 1/(1−β) = 10,000 steps illustrates the long persistence; it is not an exact convergence time.</p>"],"kind":"practice","id":"mt2-c14-s2","search":"R24 Q2b **Question.** Compare standard momentum and Nesterov accelerated gradient using their gradient-evaluation points and update equations. Explain what may happen when momentum is extremely close to 1, for example 0.9999.\n\n**Syllabus-aligned extract:** source R24 Q2b. The current-syllabus optimizer comparison and high-momentum discussion are retained; marks for this extract are not separately stated.\n\n**Complete worked answer.**\nUse signed velocity. Standard momentum evaluates g at current θ: vnew = βv−ηg(θ), θ new = θ+vnew. Nesterov evaluates at a look-ahead point: θ look = θ+βv; vnew = βv−ηg(θ look); θ new = θ+vnew. Thus the gradient can correct a direction after anticipating part of the momentum move. Nesterov often reduces overshoot in suitable settings, but it is not universally faster for every neural network.\nWith β = 0.9999, old velocity decays very slowly. The method can respond sluggishly to direction changes, overshoot or oscillate, particularly with a large learning rate. An approximate memory scale 1/(1−β) = 10,000 steps illustrates the long persistence; it is not an exact convergence time.\n"},{"title":"R24 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain why regularization matters, list techniques and elaborate one.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<p><strong>Elaborating L2: </strong> add(λ/2)Σw² to the data loss. For weight w = .5, data gradient.2, λ = .1, η = .1, total gradient = .2+.1 × .5 = .25, so wnew = .5−.1 × .25 = .475. Relative to the data-only update.48, the penalty pulls the weight further toward 0. Too large λ can remove useful signal, so tune on validation data.</p>"],"kind":"practice","id":"mt2-c14-s3","search":"R24 Q3b **Question (10 marks).** Explain why regularization matters, list techniques and elaborate one.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n**Elaborating L2: ** add(λ/2)Σw² to the data loss. For weight w = .5, data gradient.2, λ = .1, η = .1, total gradient = .2+.1 × .5 = .25, so wnew = .5−.1 × .25 = .475. Relative to the data-only update.48, the penalty pulls the weight further toward 0. Too large λ can remove useful signal, so tune on validation data.\n"},{"title":"R24 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Calculate weights, biases and feature-map sizes of the CNN: Input 227 × 227 × 3. → Conv K = 9, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 120 units. → Dense 84 units. → Dense 10 units.</p>"],"answer":["<h3>Given</h3>","<p>Input 227 × 227 × 3.</p>","<p>Conv K = 9, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 64, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 64, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 120 units.</p>","<p>Dense 84 units.</p>","<p>Dense 10 units.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">227 × 227 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 9 × 9 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">219 × 219 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">7,776</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">7,808</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>227 × 227 × 3</strong>. Use 32 filters of spatial size 9 × 9, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0d078197de388e4c.svg\"><img class=\"math display-math\" src=\"assets/equations/d3b5ab84e61f126d.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{227+2(0)-9}{1}\\right\\rfloor+1=219\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>219 × 219 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90e2d92ad9867cbd.svg\"><img class=\"math display-math\" src=\"assets/equations/c97378e50b8b5ac8.svg\" alt=\"N_{\\mathrm{weights}}=9\\times9\\times3\\times32=7{,}776\" width=\"349.90\" height=\"23.91\" style=\"width:349.90px;height:23.91px;aspect-ratio:349.90/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/59616c98ab8fffe7.svg\" alt=\"P_1=7{,}776+32=7{,}808\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">219 × 219 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">109 × 109 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>219 × 219 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3f1c898ff7560508.svg\"><img class=\"math display-math\" src=\"assets/equations/73ff985869e15a08.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{219-2}{2}\\right\\rfloor+1=109\" width=\"308.50\" height=\"58.62\" style=\"width:308.50px;height:58.62px;aspect-ratio:308.50/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>109 × 109 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 108.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">109 × 109 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">64 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">105 × 105 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">51,200</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">64</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">51,264</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>109 × 109 × 32</strong>. Use 64 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2cc5fced7b8ab11.svg\"><img class=\"math display-math\" src=\"assets/equations/fc0be4ce48988be6.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{109+2(0)-5}{1}\\right\\rfloor+1=105\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>105 × 105 × 64</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 32 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a22447ce668f8dbf.svg\"><img class=\"math display-math\" src=\"assets/equations/5b861b3fc768032c.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times32\\times64=51{,}200\" width=\"374.33\" height=\"23.91\" style=\"width:374.33px;height:23.91px;aspect-ratio:374.33/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc3a74202b89cbd8.svg\" alt=\"N_{\\mathrm{biases}}=64\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/101c0d0d89af6010.svg\" alt=\"P_3=51{,}200+64=51{,}264\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">105 × 105 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">52 × 52 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>105 × 105 × 64</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/616d6791b658eeb9.svg\"><img class=\"math display-math\" src=\"assets/equations/c5c0ee2fb6dc698d.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{105-2}{2}\\right\\rfloor+1=52\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>52 × 52 × 64</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 51.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">52 × 52 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">64 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">48 × 48 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">102,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">64</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">102,464</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>52 × 52 × 64</strong>. Use 64 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/58a6dd2bccbabd6a.svg\"><img class=\"math display-math\" src=\"assets/equations/87809c641f196e58.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{52+2(0)-5}{1}\\right\\rfloor+1=48\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>48 × 48 × 64</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 64 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c1baccc90afa895b.svg\"><img class=\"math display-math\" src=\"assets/equations/3a9b9e818c6252de.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times64\\times64=102{,}400\" width=\"386.55\" height=\"23.91\" style=\"width:386.55px;height:23.91px;aspect-ratio:386.55/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc3a74202b89cbd8.svg\" alt=\"N_{\\mathrm{biases}}=64\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bf8643a16a94e64.svg\"><img class=\"math display-math\" src=\"assets/equations/be86652891fb9307.svg\" alt=\"P_5=102{,}400+64=102{,}464\" width=\"306.02\" height=\"21.43\" style=\"width:306.02px;height:21.43px;aspect-ratio:306.02/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">48 × 48 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">24 × 24 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>48 × 48 × 64</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64a91a8e536e0765.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{48-2}{2}\\right\\rfloor+1=24\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>24 × 24 × 64</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 7 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">24 × 24 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">36,864</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>24 × 24 × 64</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5ee055840a7e6f06.svg\"><img class=\"math display-math\" src=\"assets/equations/d2c7c9ed057461d8.svg\" alt=\"n_{\\mathrm{flat}}=24\\times24\\times64=36{,}864\" width=\"308.23\" height=\"21.29\" style=\"width:308.23px;height:21.29px;aspect-ratio:308.23/21.29\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>36,864 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">36,864</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,423,680</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,423,800</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>36,864 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b963fc1e5d67938a.svg\"><img class=\"math display-math\" src=\"assets/equations/3d52ede2004cebfb.svg\" alt=\"N_{\\mathrm{weights}}=36{,}864\\times120=4{,}423{,}680\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99a27e646d35bbda.svg\"><img class=\"math display-math\" src=\"assets/equations/c09e1443401b8c28.svg\" alt=\"P_8=4{,}423{,}680+120=4{,}423{,}800\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 9 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">84 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">10,080</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">84</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">10,164</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>84 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.92px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4874c9639ae8a286.svg\"><img class=\"math display-math\" src=\"assets/equations/0b5956346ee0f9d2.svg\" alt=\"N_{\\mathrm{weights}}=120\\times84=10{,}080\" width=\"302.38\" height=\"23.91\" style=\"width:302.38px;height:23.91px;aspect-ratio:302.38/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec58135349b68114.svg\" alt=\"N_{\\mathrm{biases}}=84\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cfadc0698f826a8.svg\" alt=\"P_9=10{,}080+84=10{,}164\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">10 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">10</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">840</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">10</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">850</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>84 features</strong>. Output: <strong>10 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/995f161a94dc7ae1.svg\" alt=\"N_{\\mathrm{weights}}=84\\times10=840\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8203d983cccce3a9.svg\" alt=\"N_{\\mathrm{biases}}=10\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be85fac4796ebc34.svg\" alt=\"P_10=840+10=850\" width=\"231.35\" height=\"20.36\" style=\"width:231.35px;height:20.36px;aspect-ratio:231.35/20.36\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/8a2a9eb5376c2557.svg\" alt=\"\\left\\lfloor\\frac{227+2 \\times  0-9}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>219 x 219 x 32</td><td>7,776</td><td>32</td><td>7,808</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4185cd16a03f14e2.svg\" alt=\"\\left\\lfloor\\frac{219-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>109 x 109 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e91c4793e36ecf45.svg\" alt=\"\\left\\lfloor\\frac{109+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>105 x 105 x 64</td><td>51,200</td><td>64</td><td>51,264</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/02f6d3536f89b2ae.svg\" alt=\"\\left\\lfloor\\frac{105-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>52 x 52 x 64</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/6619d9b65db6ea0f.svg\" alt=\"\\left\\lfloor\\frac{52+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>48 x 48 x 64</td><td>102,400</td><td>64</td><td>102,464</td></tr><tr><td>6 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b6ef920332c6684a.svg\" alt=\"\\left\\lfloor\\frac{48-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>24 x 24 x 64</td><td>0</td><td>0</td><td>0</td></tr><tr><td>7 flat</td><td>24 × 24 × 64</td><td>36864</td><td>0</td><td>0</td><td>0</td></tr><tr><td>8 dense</td><td>36864 → 120</td><td>120</td><td>4,423,680</td><td>120</td><td>4,423,800</td></tr><tr><td>9 dense</td><td>120 → 84</td><td>84</td><td>10,080</td><td>84</td><td>10,164</td></tr><tr><td>10 dense</td><td>84 → 10</td><td>10</td><td>840</td><td>10</td><td>850</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (9 x 9 x 3 + 1) x 32 = 7,808.</p>","<p>Layer 3: (5 x 5 x 32 + 1) x 64 = 51,264.</p>","<p>Layer 5: (5 x 5 x 64 + 1) x 64 = 102,464.</p>","<p>Layer 8: (36864 + 1) x 120 = 4,423,800.</p>","<p>Layer 9: (120 + 1) x 84 = 10,164.</p>","<p>Layer 10: (84 + 1) x 10 = 850.</p>","<p><strong>Total: </strong> 7,808 + 51,264 + 102,464 + 4,423,800 + 10,164 + 850 = <strong>4,596,350 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>"],"kind":"practice","id":"mt2-c14-s4","search":"R24 Q4b **Question (10 marks).** Calculate weights, biases and feature-map sizes of the CNN: Input 227 × 227 × 3. → Conv K = 9, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 120 units. → Dense 84 units. → Dense 10 units.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 227 × 227 × 3.\n\nConv K = 9, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 64, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 64, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 120 units.\n\nDense 84 units.\n\nDense 10 units.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{227+2 \\times  0-9}{1}\\right\\rfloor+1\\) | 219 x 219 x 32 | 7,776 | 32 | 7,808 |\n| 2 pool | \\(\\left\\lfloor\\frac{219-2}{2}\\right\\rfloor+1\\) | 109 x 109 x 32 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{109+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 105 x 105 x 64 | 51,200 | 64 | 51,264 |\n| 4 pool | \\(\\left\\lfloor\\frac{105-2}{2}\\right\\rfloor+1\\) | 52 x 52 x 64 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{52+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 48 x 48 x 64 | 102,400 | 64 | 102,464 |\n| 6 pool | \\(\\left\\lfloor\\frac{48-2}{2}\\right\\rfloor+1\\) | 24 x 24 x 64 | 0 | 0 | 0 |\n| 7 flat | 24 × 24 × 64 | 36864 | 0 | 0 | 0 |\n| 8 dense | 36864 → 120 | 120 | 4,423,680 | 120 | 4,423,800 |\n| 9 dense | 120 → 84 | 84 | 10,080 | 84 | 10,164 |\n| 10 dense | 84 → 10 | 10 | 840 | 10 | 850 |\n**Parameter substitutions, in layer order: **\nLayer 1: (9 x 9 x 3 + 1) x 32 = 7,808.\nLayer 3: (5 x 5 x 32 + 1) x 64 = 51,264.\nLayer 5: (5 x 5 x 64 + 1) x 64 = 102,464.\nLayer 8: (36864 + 1) x 120 = 4,423,800.\nLayer 9: (120 + 1) x 84 = 10,164.\nLayer 10: (84 + 1) x 10 = 850.\n**Total: ** 7,808 + 51,264 + 102,464 + 4,423,800 + 10,164 + 850 = **4,596,350 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n"},{"title":"R24 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A GoogLeNet classifier trains slowly and vanishing gradients are suspected. Suggest an architecture change and explain its important features.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>A ResNet is a suitable architecture to investigate because skip additions provide shorter gradient paths. First verify the diagnosis with gradients and training curves; slow training alone does not establish vanishing gradients. Match projection shortcuts when spatial size/channels change and compare validation performance after the redesign.</p>"],"kind":"practice","id":"mt2-c14-s5","search":"R24 Q5a **Question (10 marks).** A GoogLeNet classifier trains slowly and vanishing gradients are suspected. Suggest an architecture change and explain its important features.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nA ResNet is a suitable architecture to investigate because skip additions provide shorter gradient paths. First verify the diagnosis with gradients and training curves; slow training alone does not establish vanishing gradients. Match projection shortcuts when spatial size/channels change and compare validation performance after the redesign.\n"},{"title":"R24 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A supermarket vegetable classifier has 10 classes but few examples per class and limited training resources. Explain different ways to use a pretrained model.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>","<p>For vegetables, replace the source head with 10 softmax outputs. Strategy 1: freeze the base and train only this head. Strategy 2: initialize from the same pretrained model and fine-tune selected later blocks at a small rate after head training. The first is cheaper and less prone to fitting all parameters from limited examples; the second can adapt features more closely to vegetables when validation supports it.</p>"],"kind":"practice","id":"mt2-c14-s6","search":"R24 Q6b **Question (10 marks).** A supermarket vegetable classifier has 10 classes but few examples per class and limited training resources. Explain different ways to use a pretrained model.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\nFor vegetables, replace the source head with 10 softmax outputs. Strategy 1: freeze the base and train only this head. Strategy 2: initialize from the same pretrained model and fine-tune selected later blocks at a small rate after head training. The first is cheaper and less prone to fitting all parameters from limited examples; the second can adapt features more closely to vegetables when validation supports it.\n"},{"title":"R24 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain different RNN input/output sequence types with architecture sketches.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: One-to-many many-to-one and two many-to-many arrangements\"><img src=\"assets/figures/sequences.svg\" alt=\"One-to-many many-to-one and two many-to-many arrangements\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>One-to-many many-to-one and two many-to-many arrangements <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>One-to-many: one image representation generates a caption. Many-to-one: a review produces one sentiment. Aligned many-to-many: each video frame receives a label. Unaligned many-to-many: an encoder reads a source sentence and a decoder generates a translation of possibly different length. Specify which outputs carry losses during training; variable lengths do not require new weights for each position.</p>"],"kind":"practice","id":"mt2-c14-s7","search":"R24 Q7b **Question (10 marks).** Explain different RNN input/output sequence types with architecture sketches.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n\nOne-to-many: one image representation generates a caption. Many-to-one: a review produces one sentiment. Aligned many-to-many: each video frame receives a label. Unaligned many-to-many: an encoder reads a source sentence and a decoder generates a translation of possibly different length. Specify which outputs carry losses during training; variable lengths do not require new weights for each position.\n\n\n"}]},{"n":15,"title":"F22 selected MT2 practice","sections":[{"title":"Start here","blocks":["<p>The source archive retains historical optimization, CNN and introductory RNN questions. Following the 12 October faculty update, the focused MT2 website presents the Unit 3–4 questions; retained RNN bookmarks lead to TEE. Original question IDs and marks are preserved. Full assessed tasks and numerical data are transcribed in readable language; worked solutions follow each question. This selection does not predict the paper.</p>"],"kind":"read","id":"mt2-c15-intro"},{"title":"F22 Q1a","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> A normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3]. Convolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding. Compute the output and identify the feature.</p>"],"answer":["<h3>Given</h3>","<p>A normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3].</p>","<p>Convolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding.</p>","<h3>To find</h3>","<p>Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/966c8fb493880239.svg\" alt=\"\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.5 + 0 + (−0.3) = 0.2</b></div></div><p class=\"lv-combine\"><b>0.2 + 0.2 + 0.2 = 0.6</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46893fc8d069d1a9.svg\"><img class=\"math display-math\" src=\"assets/equations/27b98fade189b3cb.svg\" alt=\"R_1=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a410c53ff471ca9.svg\"><img class=\"math display-math\" src=\"assets/equations/227859c9722c8d9d.svg\" alt=\"R_2=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c0f1258f7cc1b3a.svg\"><img class=\"math display-math\" src=\"assets/equations/23643e567273ca91.svg\" alt=\"R_3=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.24px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb7d1b049e078f58.svg\"><img class=\"math display-math\" src=\"assets/equations/c15a1021698c03e8.svg\" alt=\"Y_{1,1}=(0.2)+(0.2)+(0.2)=0.6\" width=\"345.16\" height=\"25.35\" style=\"width:345.16px;height:25.35px;aspect-ratio:345.16/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.3\">0.3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.3\">0.3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.3\">0.3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.3 + 0 + (−0.3) = 0</b></div></div><p class=\"lv-combine\"><b>0 + 0 + 0 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8fffc5f555fb2f95.svg\"><img class=\"math display-math\" src=\"assets/equations/54a80ceab4517447.svg\" alt=\"R_1=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a27c355bf724dc1d.svg\"><img class=\"math display-math\" src=\"assets/equations/4f1d831d541f9cae.svg\" alt=\"R_2=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9405479984ca544c.svg\"><img class=\"math display-math\" src=\"assets/equations/41420636bdf1878d.svg\" alt=\"R_3=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a79dadbe7e581b.svg\" alt=\"Y_{1,2}=(0)+(0)+(0)=0\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.5 + 0 + (−0.3) = 0.2</b></div></div><p class=\"lv-combine\"><b>0.2 + 0.2 + 0.2 = 0.6</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46893fc8d069d1a9.svg\"><img class=\"math display-math\" src=\"assets/equations/27b98fade189b3cb.svg\" alt=\"R_1=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a410c53ff471ca9.svg\"><img class=\"math display-math\" src=\"assets/equations/227859c9722c8d9d.svg\" alt=\"R_2=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c0f1258f7cc1b3a.svg\"><img class=\"math display-math\" src=\"assets/equations/23643e567273ca91.svg\" alt=\"R_3=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.24px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e16ceceb6a0a438.svg\"><img class=\"math display-math\" src=\"assets/equations/32aaa578d4b2a675.svg\" alt=\"Y_{2,1}=(0.2)+(0.2)+(0.2)=0.6\" width=\"345.16\" height=\"25.35\" style=\"width:345.16px;height:25.35px;aspect-ratio:345.16/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.3\">0.3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.3\">0.3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.3\">0.3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.3 + 0 + (−0.3) = 0</b></div></div><p class=\"lv-combine\"><b>0 + 0 + 0 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8fffc5f555fb2f95.svg\"><img class=\"math display-math\" src=\"assets/equations/54a80ceab4517447.svg\" alt=\"R_1=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a27c355bf724dc1d.svg\"><img class=\"math display-math\" src=\"assets/equations/4f1d831d541f9cae.svg\" alt=\"R_2=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9405479984ca544c.svg\"><img class=\"math display-math\" src=\"assets/equations/41420636bdf1878d.svg\" alt=\"R_3=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d6dfc0f38e45b75.svg\" alt=\"Y_{2,2}=(0)+(0)+(0)=0\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/14d5a1ec1325dcc6.svg\" alt=\"\\begin{bmatrix}0.6 &amp; 0\\\\0.6 &amp; 0\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>","<p>The filter compares left and right neighborhoods and responds to a vertical brightness boundary. Inputs are already normalized. No additional output-normalization rule is supplied, so the determined convolution is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/14d5a1ec1325dcc6.svg\" alt=\"\\begin{bmatrix}0.6 &amp; 0\\\\0.6 &amp; 0\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. If an examiner explicitly requests min-max normalization of this result, divide by 0.6 to obtain <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/40c2bacd9336c7bb.svg\" alt=\"\\begin{bmatrix}1 &amp; 0\\\\1 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>; that is a separate stated operation.</p>"],"kind":"practice","id":"mt2-c15-s0","search":"F22 Q1a **Question (4 marks).** A normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3]. Convolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding. Compute the output and identify the feature.\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nA normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3].\n\nConvolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding.\n\n### To find\n\nFind every convolution output cell.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\\) = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.\n**Output (1,1): ** (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) = **0.6**.\n**Output (1,2): ** (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) = **0**.\n**Output (2,1): ** (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) = **0.6**.\n**Output (2,2): ** (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) = **0**.\n**Final output: ** . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.\nThe filter compares left and right neighborhoods and responds to a vertical brightness boundary. Inputs are already normalized. No additional output-normalization rule is supplied, so the determined convolution is . If an examiner explicitly requests min-max normalization of this result, divide by 0.6 to obtain ; that is a separate stated operation.\n"},{"title":"F22 Q1b","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Weights are 0.55 and 0.65; their gradients are+0.3 and−0.25. With η = 0.1, compute gradient-descent changes and new weights.</p>"],"answer":["<h3>Given</h3>","<p>Old weights = [0.55,0.65].</p>","<p>Corresponding supplied gradients = [0.3,−0.25]; η = 0.1.</p>","<h3>To find</h3>","<p>Calculate the signed weight changes and both new weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the change in weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaf1d1bad63a2309.svg\" alt=\"\\Delta w_1=-0.1(0.3)=-0.03\" width=\"276.61\" height=\"24.43\" style=\"width:276.61px;height:24.43px;aspect-ratio:276.61/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add that change to old weight 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.64px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278794747f889246.svg\"><img class=\"math display-math\" src=\"assets/equations/c5de9a5a93170dac.svg\" alt=\"w_1^{\\mathrm{new}}=0.55+(-0.03)=0.52\" width=\"312.67\" height=\"24.43\" style=\"width:312.67px;height:24.43px;aspect-ratio:312.67/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the change in weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1c844e3b7026fa3a.svg\"><img class=\"math display-math\" src=\"assets/equations/43503938e7c174a7.svg\" alt=\"\\Delta w_2=-0.1(-0.25)=0.025\" width=\"301.05\" height=\"24.43\" style=\"width:301.05px;height:24.43px;aspect-ratio:301.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: add that change to old weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.84px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99431f20567e072c.svg\"><img class=\"math display-math\" src=\"assets/equations/2bfe89025b1bd27a.svg\" alt=\"w_2^{\\mathrm{new}}=0.65+0.025=0.675\" width=\"299.08\" height=\"23.87\" style=\"width:299.08px;height:23.87px;aspect-ratio:299.08/23.87\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> changes = [−0.03, +0.025]; new weights = [0.52, 0.675]. A negative gradient increases its weight under descent.</p>"],"kind":"practice","id":"mt2-c15-s1","search":"F22 Q1b **Question (4 marks).** Weights are 0.55 and 0.65; their gradients are+0.3 and−0.25. With η = 0.1, compute gradient-descent changes and new weights.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nOld weights = [0.55,0.65].\n\nCorresponding supplied gradients = [0.3,−0.25]; η = 0.1.\n\n### To find\n\nCalculate the signed weight changes and both new weights.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: calculate the change in weight 1.**\n\n\n\n\n\n\n\n**Step 2: add that change to old weight 1.**\n\n\n\n\n\n\n\n**Step 3: calculate the change in weight 2.**\n\n\n\n\n\n\n\n**Step 4: add that change to old weight 2.**\n\n\n\n\n\n\n\n**Final answer:** changes = [−0.03, +0.025]; new weights = [0.52, 0.675]. A negative gradient increases its weight under descent.\n"},{"title":"F22 Q1e","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Suggest and sketch an RNN architecture for image captioning.</p>"],"answer":["<p>Use a CNN encoder to map the image to a visual representation and a recurrent decoder (vanilla RNN) to generate words one at a time. Condition the decoder’s initial state or its inputs on image features. At each step, vocabulary softmax predicts the next word based on the image and earlier words. Train using correct next-word targets and cross-entropy; stop generation at an end token. This is a one-to-many mapping from one image to a caption sequence.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: The one-to-many pattern models image captioning\"><img src=\"assets/figures/sequences.svg\" alt=\"The one-to-many pattern models image captioning\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>The one-to-many pattern models image captioning <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"mt2-c15-s2","search":"F22 Q1e **Question (4 marks).** Suggest and sketch an RNN architecture for image captioning.\n\n**Complete worked answer.**\nUse a CNN encoder to map the image to a visual representation and a recurrent decoder (vanilla RNN) to generate words one at a time. Condition the decoder’s initial state or its inputs on image features. At each step, vocabulary softmax predicts the next word based on the image and earlier words. Train using correct next-word targets and cross-entropy; stop generation at an end token. This is a one-to-many mapping from one image to a caption sequence.\n\n"},{"title":"F22 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain bias, variance, underfitting and overfitting. A four-feature product-texture classifier has four grades including reject. Choose output activation/loss. Diagnose training error 15% and validation error 18% and suggest remedies.</p>"],"answer":["<p>Bias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/overfitting.svg\" aria-label=\"Enlarge diagram: Validation behavior distinguishes useful fitting from prolonged fitting to training details\"><img src=\"assets/figures/overfitting.svg\" alt=\"Validation behavior distinguishes useful fitting from prolonged fitting to training details\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Validation behavior distinguishes useful fitting from prolonged fitting to training details <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Increasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model&#x27;s approximation bias much. These are typical trends, not unconditional numerical laws.</p>","<p>Underfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.</p>","<p>Training and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.</p>","<p><strong>Classifier: </strong> four mutually exclusive grades require 4 output scores, softmax probabilities and categorical cross-entropy. A reject class is still a labeled class in this formulation.</p>","<p><strong>Diagnosis: </strong> a modest 3 percentage-point gap with both errors appreciable suggests underfitting/high bias if a much better attainable baseline exists. Confirm learning curves and label quality. Improve relevant features or model capacity, train sufficiently, tune the optimizer and reduce excessive regularization. The percentages alone do not prove the cause.</p>"],"kind":"practice","id":"mt2-c15-s3","search":"F22 Q3a **Question (10 marks).** Explain bias, variance, underfitting and overfitting. A four-feature product-texture classifier has four grades including reject. Choose output activation/loss. Diagnose training error 15% and validation error 18% and suggest remedies.\n\n**Complete worked answer.**\nBias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.\n\nIncreasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model's approximation bias much. These are typical trends, not unconditional numerical laws.\nUnderfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.\nTraining and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.\n**Classifier: ** four mutually exclusive grades require 4 output scores, softmax probabilities and categorical cross-entropy. A reject class is still a labeled class in this formulation.\n**Diagnosis: ** a modest 3 percentage-point gap with both errors appreciable suggests underfitting/high bias if a much better attainable baseline exists. Confirm learning curves and label quality. Improve relevant features or model capacity, train sufficiently, tune the optimizer and reduce excessive regularization. The percentages alone do not prove the cause.\n"},{"title":"F22 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Count trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2; convolution 5 × 5: 16 filters, pooling 2; dense 120, dense 84, softmax 10. Use the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.</p>"],"answer":["<h3>Given</h3>","<p>Count trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2.</p>","<p>convolution 5 × 5: 16 filters, pooling 2.</p>","<p>dense 120, dense 84, softmax 10.</p>","<p>Use the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">32 × 32 × 1</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">6 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">28 × 28 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">150</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">6</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">156</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>32 × 32 × 1</strong>. Use 6 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a58485fe718e957c.svg\"><img class=\"math display-math\" src=\"assets/equations/b2fe45e42e65423c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{32+2(0)-5}{1}\\right\\rfloor+1=28\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>28 × 28 × 6</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 1 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.44px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4503fe259db6cc31.svg\"><img class=\"math display-math\" src=\"assets/equations/d75bc00144d70f4e.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times1\\times6=150\" width=\"318.68\" height=\"23.91\" style=\"width:318.68px;height:23.91px;aspect-ratio:318.68/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07df0417eea506bc.svg\" alt=\"N_{\\mathrm{biases}}=6\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60d683ee579f75b5.svg\" alt=\"P_1=150+6=156\" width=\"206.92\" height=\"20.36\" style=\"width:206.92px;height:20.36px;aspect-ratio:206.92/20.36\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">28 × 28 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">14 × 14 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>28 × 28 × 6</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d66b872d3a8b7d76.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{28-2}{2}\\right\\rfloor+1=14\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>14 × 14 × 6</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">14 × 14 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">16 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">10 × 10 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">2,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">16</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">2,416</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>14 × 14 × 6</strong>. Use 16 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/85506bf5dfa9eb3a.svg\"><img class=\"math display-math\" src=\"assets/equations/44a93c57d72f0b31.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{14+2(0)-5}{1}\\right\\rfloor+1=10\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>10 × 10 × 16</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 6 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/95205b29ca5fb5db.svg\"><img class=\"math display-math\" src=\"assets/equations/5d2e007b43373429.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times6\\times16=2{,}400\" width=\"349.90\" height=\"23.91\" style=\"width:349.90px;height:23.91px;aspect-ratio:349.90/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc0c940eb69b41c0.svg\" alt=\"N_{\\mathrm{biases}}=16\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0985f033fb9785fd.svg\" alt=\"P_3=2{,}400+16=2{,}416\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">10 × 10 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">5 × 5 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>10 × 10 × 16</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c2393768f5c7cc6f.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{10-2}{2}\\right\\rfloor+1=5\" width=\"271.85\" height=\"58.62\" style=\"width:271.85px;height:58.62px;aspect-ratio:271.85/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>5 × 5 × 16</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">5 × 5 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">400</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>5 × 5 × 16</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b7fdfd1b9a608954.svg\" alt=\"n_{\\mathrm{flat}}=5\\times5\\times16=400\" width=\"252.57\" height=\"20.40\" style=\"width:252.57px;height:20.40px;aspect-ratio:252.57/20.40\" loading=\"lazy\"></div>","<p>Output: a vector with <strong>400 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 6 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">400</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">48,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">48,120</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>400 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.13px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/142c2516a0279849.svg\"><img class=\"math display-math\" src=\"assets/equations/19a0a131878ed831.svg\" alt=\"N_{\\mathrm{weights}}=400\\times120=48{,}000\" width=\"314.59\" height=\"23.91\" style=\"width:314.59px;height:23.91px;aspect-ratio:314.59/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee00c5a42d90e348.svg\"><img class=\"math display-math\" src=\"assets/equations/fd12e231aa432c56.svg\" alt=\"P_6=48{,}000+120=48{,}120\" width=\"293.80\" height=\"21.43\" style=\"width:293.80px;height:21.43px;aspect-ratio:293.80/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">84 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">10,080</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">84</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">10,164</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>84 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.92px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4874c9639ae8a286.svg\"><img class=\"math display-math\" src=\"assets/equations/0b5956346ee0f9d2.svg\" alt=\"N_{\\mathrm{weights}}=120\\times84=10{,}080\" width=\"302.38\" height=\"23.91\" style=\"width:302.38px;height:23.91px;aspect-ratio:302.38/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec58135349b68114.svg\" alt=\"N_{\\mathrm{biases}}=84\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c9fa89f780aa10aa.svg\" alt=\"P_7=10{,}080+84=10{,}164\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">10 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">10</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">840</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">10</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">850</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>84 features</strong>. Output: <strong>10 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/995f161a94dc7ae1.svg\" alt=\"N_{\\mathrm{weights}}=84\\times10=840\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8203d983cccce3a9.svg\" alt=\"N_{\\mathrm{biases}}=10\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b9609ba48ce42f1.svg\" alt=\"P_8=840+10=850\" width=\"219.13\" height=\"20.74\" style=\"width:219.13px;height:20.74px;aspect-ratio:219.13/20.74\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/77e2ec6d75d55591.svg\" alt=\"\\left\\lfloor\\frac{32+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>28 x 28 x 6</td><td>150</td><td>6</td><td>156</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/0f4985548e8cd39b.svg\" alt=\"\\left\\lfloor\\frac{28-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>14 x 14 x 6</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/104aadf49e642e25.svg\" alt=\"\\left\\lfloor\\frac{14+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>10 x 10 x 16</td><td>2,400</td><td>16</td><td>2,416</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/0c637a47bfb54036.svg\" alt=\"\\left\\lfloor\\frac{10-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>5 x 5 x 16</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 flat</td><td>5 × 5 × 16</td><td>400</td><td>0</td><td>0</td><td>0</td></tr><tr><td>6 dense</td><td>400 → 120</td><td>120</td><td>48,000</td><td>120</td><td>48,120</td></tr><tr><td>7 dense</td><td>120 → 84</td><td>84</td><td>10,080</td><td>84</td><td>10,164</td></tr><tr><td>8 dense</td><td>84 → 10</td><td>10</td><td>840</td><td>10</td><td>850</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (5 x 5 x 1 + 1) x 6 = 156.</p>","<p>Layer 3: (5 x 5 x 6 + 1) x 16 = 2,416.</p>","<p>Layer 6: (400 + 1) x 120 = 48,120.</p>","<p>Layer 7: (120 + 1) x 84 = 10,164.</p>","<p>Layer 8: (84 + 1) x 10 = 850.</p>","<p><strong>Total: </strong> 156 + 2,416 + 48,120 + 10,164 + 850 = <strong>61,706 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p>This is the standard classroom full-channel interpretation with nontrainable pooling and a dense 10-class softmax. The historical original LeNet used partial channel connections and other details, so its published parameter count need not equal this diagram-based count. If an input label is read as 28, the stated later 28 map after valid 5 × 5 convolution is inconsistent; record the 32 input assumption rather than silently ignoring the mismatch.</p>"],"kind":"practice","id":"mt2-c15-s4","search":"F22 Q3b **Question (10 marks).** Count trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2; convolution 5 × 5: 16 filters, pooling 2; dense 120, dense 84, softmax 10. Use the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nCount trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2.\n\nconvolution 5 × 5: 16 filters, pooling 2.\n\ndense 120, dense 84, softmax 10.\n\nUse the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{32+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 28 x 28 x 6 | 150 | 6 | 156 |\n| 2 pool | \\(\\left\\lfloor\\frac{28-2}{2}\\right\\rfloor+1\\) | 14 x 14 x 6 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{14+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 10 x 10 x 16 | 2,400 | 16 | 2,416 |\n| 4 pool | \\(\\left\\lfloor\\frac{10-2}{2}\\right\\rfloor+1\\) | 5 x 5 x 16 | 0 | 0 | 0 |\n| 5 flat | 5 × 5 × 16 | 400 | 0 | 0 | 0 |\n| 6 dense | 400 → 120 | 120 | 48,000 | 120 | 48,120 |\n| 7 dense | 120 → 84 | 84 | 10,080 | 84 | 10,164 |\n| 8 dense | 84 → 10 | 10 | 840 | 10 | 850 |\n**Parameter substitutions, in layer order: **\nLayer 1: (5 x 5 x 1 + 1) x 6 = 156.\nLayer 3: (5 x 5 x 6 + 1) x 16 = 2,416.\nLayer 6: (400 + 1) x 120 = 48,120.\nLayer 7: (120 + 1) x 84 = 10,164.\nLayer 8: (84 + 1) x 10 = 850.\n**Total: ** 156 + 2,416 + 48,120 + 10,164 + 850 = **61,706 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\nThis is the standard classroom full-channel interpretation with nontrainable pooling and a dense 10-class softmax. The historical original LeNet used partial channel connections and other details, so its published parameter count need not equal this diagram-based count. If an input label is read as 28, the stated later 28 map after valid 5 × 5 convolution is inconsistent; record the 32 input assumption rather than silently ignoring the mismatch.\n"},{"title":"F22 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> An Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved. Compute operations and explain 1 × 1 convolution.</p>"],"answer":["<h3>Given</h3>","<p>An Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved.</p>","<h3>To find</h3>","<p>Find direct and bottleneck computation counts and the requested saving.</p>","<h3>Formula — which one and why</h3>","<p><strong>Multiply–accumulate count.</strong> Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.</p>","<p>H_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output cell ka kaam × kitne output cells.</p>","<h3>Solution — step by step</h3>","<h3>Direct path</h3>","<p class=\"worked-step\"><strong>Step 2: direct path.</strong></p>","<p>output stays 28 × 28 with 32 channels.</p>","<p class=\"worked-step\"><strong>Step 3: direct path.</strong></p>","<p>MACs = 28 × 28 × 192 × 32 × 5 × 5 = <strong>120,422,400</strong>.</p>","<h3>Bottleneck path with 16 reduction channels</h3>","<p class=\"worked-step\"><strong>Step 4: bottleneck path with 16 reduction channels.</strong></p>","<p>1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.</p>","<p class=\"worked-step\"><strong>Step 5: bottleneck path with 16 reduction channels.</strong></p>","<p>The 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.</p>","<p class=\"worked-step\"><strong>Step 6: bottleneck path with 16 reduction channels.</strong></p>","<p>Total = <strong>12,443,648</strong>.</p>","<h3>Saving</h3>","<p class=\"worked-step\"><strong>Step 7: saving.</strong></p>","<p>120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = <strong>89.666667%</strong>. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = <strong>777,728r</strong></p>","<p class=\"worked-step\"><strong>Step 8: saving.</strong></p>","<p>there is no unique numeric bottleneck cost until r is chosen.</p>","<p class=\"worked-step\"><strong>Step 9: calculate this quantity.</strong></p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 10: calculate this quantity.</strong></p>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>"],"kind":"practice","id":"mt2-c15-s5","search":"F22 Q4a **Question (10 marks).** An Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved. Compute operations and explain 1 × 1 convolution.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nAn Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved.\n\n### To find\n\nFind direct and bottleneck computation counts and the requested saving.\n\n### Formula — which one and why\n\n**Multiply–accumulate count.** Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.\n\nH_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har output cell ka kaam × kitne output cells.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n\n\n### Direct path\n\n**Step 2: direct path.**\n\noutput stays 28 × 28 with 32 channels.\n\n**Step 3: direct path.**\n\nMACs = 28 × 28 × 192 × 32 × 5 × 5 = **120,422,400**.\n\n### Bottleneck path with 16 reduction channels\n\n**Step 4: bottleneck path with 16 reduction channels.**\n\n1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.\n\n**Step 5: bottleneck path with 16 reduction channels.**\n\nThe 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.\n\n**Step 6: bottleneck path with 16 reduction channels.**\n\nTotal = **12,443,648**.\n\n### Saving\n\n**Step 7: saving.**\n\n120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = **89.666667%**. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = **777,728r**\n\n**Step 8: saving.**\n\nthere is no unique numeric bottleneck cost until r is chosen.\n\n**Step 9: calculate this quantity.**\n\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\n\n\n**Step 10: calculate this quantity.**\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\n\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\n"},{"title":"F22 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Draw a 6-input, two-hidden-layer network with 5 neurons each and 4 classes, trained by AdaGrad. Identify learned parameters and tunable hyperparameters; no input-layer weights or biases.</p>"],"answer":["<h3>Given</h3>","<p>6 inputs → hidden 5 → hidden 5 → 4 output classes.</p>","<p>AdaGrad is the specified training algorithm; one bias per receiving neuron.</p>","<h3>To find</h3>","<p>Draw the architecture and count its learned weights/biases. The optimizer name does not change the count.</p>","<h3>Formula — which one and why</h3>","<p><strong>Dense-layer parameters.</strong> Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.</p>","<p>n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/494312d0893d20d2.svg\" alt=\"P=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"184.79\" height=\"24.43\" style=\"width:184.79px;height:24.43px;aspect-ratio:184.79/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output ke liye saare inputs plus ek bias.</p>","<h3>Solution — step by step</h3>","<p>Architecture: 6 → 5 → 5 → 4. Each non-input neuron has one bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/dense_6_5_5_4.svg\" aria-label=\"Enlarge diagram: F22 Q4b the input has six features and the output has four classes\"><img src=\"assets/figures/dense_6_5_5_4.svg\" alt=\"F22 Q4b the input has six features and the output has four classes\" width=\"960\" height=\"495\" loading=\"lazy\"></button><figcaption>F22 Q4b the input has six features and the output has four classes <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Layer 6 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9aa0cefe0fe7172a.svg\" alt=\"6(5)=30\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e27ba4eb6d98f55b.svg\" alt=\"30+5=35\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d16b109d87f9088b.svg\" alt=\"5(5)=25\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/862c71dcbfedc68d.svg\" alt=\"25+5=30\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 4</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b06f6eedc0b0c61f.svg\" alt=\"5(4)=20\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 4 receiving neurons, so 4 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/92df7685dd83d921.svg\" alt=\"20+4=24\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<p><strong>Total = 89</strong>. Input values and activations are not trainable parameters.</p>","<p>The learned parameters are input-to-hidden, hidden-to-hidden and hidden-to-output weights plus biases at receiving neurons. AdaGrad accumulators are optimizer state, not additional predictive weights. Hyperparameters include hidden widths/depth, learning rate η,ε, batch size, epochs, activations and regularization settings. Use 4-class softmax with categorical cross-entropy.</p>","<p>AdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p>Frequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.</p>","<p>Example with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.</p>","<p>Advantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.</p>"],"kind":"practice","id":"mt2-c15-s6","search":"F22 Q4b **Question (10 marks).** Draw a 6-input, two-hidden-layer network with 5 neurons each and 4 classes, trained by AdaGrad. Identify learned parameters and tunable hyperparameters; no input-layer weights or biases.\n\n**Complete worked answer.**\n\n\n\n### Given\n\n6 inputs → hidden 5 → hidden 5 → 4 output classes.\n\nAdaGrad is the specified training algorithm; one bias per receiving neuron.\n\n### To find\n\nDraw the architecture and count its learned weights/biases. The optimizer name does not change the count.\n\n### Formula — which one and why\n\n**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\nn_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.\n\n\n\n**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.\n\n### Solution — step by step\n\n\n\n\nArchitecture: 6 → 5 → 5 → 4. Each non-input neuron has one bias.\n\n### Layer 6 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 4\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 4 receiving neurons, so 4 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n**Total = 89**. Input values and activations are not trainable parameters.\nThe learned parameters are input-to-hidden, hidden-to-hidden and hidden-to-output weights plus biases at receiving neurons. AdaGrad accumulators are optimizer state, not additional predictive weights. Hyperparameters include hidden widths/depth, learning rate η,ε, batch size, epochs, activations and regularization settings. Use 4-class softmax with categorical cross-entropy.\nAdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:\n\nFrequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.\nExample with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.\nAdvantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.\n"},{"title":"F22 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain DL optimization challenges and the advantage of momentum over plain mini-batch gradient descent.</p>"],"answer":["<p>The learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative full batch and stochastic traces distinguish smoothness from progress\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative full batch and stochastic traces distinguish smoothness from progress\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative full batch and stochastic traces distinguish smoothness from progress <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Batch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.</p>","<p>Momentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.</p>","<p>Diagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.</p>","<p>Momentum uses vnew = βv−ηg and θ new = θ+vnew; consistent gradients accumulate direction, whereas some alternating components cancel. Plain mini-batch descent uses only the current batch gradient. Both can be combined: momentum with mini-batch gradients is a standard coherent choice.</p>"],"kind":"practice","id":"mt2-c15-s7","search":"F22 Q5b **Question (10 marks).** Explain DL optimization challenges and the advantage of momentum over plain mini-batch gradient descent.\n\n**Complete worked answer.**\nThe learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.\n\nBatch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.\nMomentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.\nDiagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.\nMomentum uses vnew = βv−ηg and θ new = θ+vnew; consistent gradients accumulate direction, whereas some alternating components cancel. Plain mini-batch descent uses only the current batch gradient. Both can be combined: momentum with mini-batch gradients is a standard coherent choice.\n"},{"title":"F22 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A CNN image classifier performs poorly because of vanishing gradients. Explain remedies.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>Also inspect saturated sigmoid/tanh hidden units, initialization and gradient magnitudes. Appropriate ReLU-family activations and initialization can help preserve usable gradients. Residual blocks require shape-compatible additions or projections. Verify that the diagnosis is correct; additional training time alone cannot repair gradients that are consistently negligible.</p>"],"kind":"practice","id":"mt2-c15-s8","search":"F22 Q6a **Question (10 marks).** A CNN image classifier performs poorly because of vanishing gradients. Explain remedies.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nAlso inspect saturated sigmoid/tanh hidden units, initialization and gradient magnitudes. Appropriate ReLU-family activations and initialization can help preserve usable gradients. Residual blocks require shape-compatible additions or projections. Verify that the diagnosis is correct; additional training time alone cannot repair gradients that are consistently negligible.\n"},{"title":"F22 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design a clothes classifier for 250,000 six-dimensional samples,6 classes and 2 hidden layers. Give train/validation/test split, activations/loss, actions for 15% training 20% validation error, interpret improvement to 1%/1.5%, then address 15% test error.</p>"],"answer":["<p><strong>One explicit design: </strong>6 → 16 → 8 → 6, ReLU hidden layers,6-unit softmax output, categorical cross-entropy. The hidden widths are chosen assumptions, not supplied numerical requirements.</p>","<p>Architecture: 6 → 16 → 8 → 6. Each non-input neuron has one bias.</p>","<h3>Layer 6 → 16</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35a3fea4574170f0.svg\" alt=\"6(16)=96\" width=\"112.68\" height=\"24.43\" style=\"width:112.68px;height:24.43px;aspect-ratio:112.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 16 receiving neurons, so 16 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/77dd73646865b98e.svg\" alt=\"96+16=112\" width=\"147.97\" height=\"18.27\" style=\"width:147.97px;height:18.27px;aspect-ratio:147.97/18.27\" loading=\"lazy\"></div>","<h3>Layer 16 → 8</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3a81b7540b48b829.svg\" alt=\"16(8)=128\" width=\"124.90\" height=\"24.43\" style=\"width:124.90px;height:24.43px;aspect-ratio:124.90/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 8 receiving neurons, so 8 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c4ed13ec1c4089a9.svg\" alt=\"128+8=136\" width=\"147.97\" height=\"18.27\" style=\"width:147.97px;height:18.27px;aspect-ratio:147.97/18.27\" loading=\"lazy\"></div>","<h3>Layer 8 → 6</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42c41d8c1f1be799.svg\" alt=\"8(6)=48\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 6 receiving neurons, so 6 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/935190190dc4ddae.svg\" alt=\"48+6=54\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<p><strong>Total = 302</strong>. Input values and activations are not trainable parameters.</p>","<p><strong>Split: </strong> a stratified 70/15/15 split gives 175,000 training,37,500 validation,37,500 test samples. Fit preprocessing on training data only and keep related duplicates within a single split.</p>","<p><strong>15%/20%: </strong> inspect learning curves and baseline difficulty. Substantial training error suggests capacity/optimization or data-quality issues; the 5 point gap also suggests a generalization issue. Improve training fit, tune regularization and collect useful representative data instead of blindly increasing capacity.</p>","<p><strong>1%/1.5%: </strong> good comparable-set results with a small gap are encouraging; verify that validation has not leaked into training.</p>","<p><strong>15% test: </strong> inspect distribution shift, preprocessing differences, label quality, leakage or repeated validation overfitting. Compare per-class errors and collection conditions. Address the actual cause and collect representative data if necessary. If test results guide retuning, use a fresh untouched final test set.</p>"],"kind":"practice","id":"mt2-c15-s9","search":"F22 Q6b **Question (10 marks).** Design a clothes classifier for 250,000 six-dimensional samples,6 classes and 2 hidden layers. Give train/validation/test split, activations/loss, actions for 15% training 20% validation error, interpret improvement to 1%/1.5%, then address 15% test error.\n\n**Complete worked answer.**\n**One explicit design: **6 → 16 → 8 → 6, ReLU hidden layers,6-unit softmax output, categorical cross-entropy. The hidden widths are chosen assumptions, not supplied numerical requirements.\nArchitecture: 6 → 16 → 8 → 6. Each non-input neuron has one bias.\n### Layer 6 → 16\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 16 receiving neurons, so 16 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 16 → 8\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 8 receiving neurons, so 8 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 8 → 6\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 6 receiving neurons, so 6 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n**Total = 302**. Input values and activations are not trainable parameters.\n**Split: ** a stratified 70/15/15 split gives 175,000 training,37,500 validation,37,500 test samples. Fit preprocessing on training data only and keep related duplicates within a single split.\n**15%/20%: ** inspect learning curves and baseline difficulty. Substantial training error suggests capacity/optimization or data-quality issues; the 5 point gap also suggests a generalization issue. Improve training fit, tune regularization and collect useful representative data instead of blindly increasing capacity.\n**1%/1.5%: ** good comparable-set results with a small gap are encouraging; verify that validation has not leaked into training.\n**15% test: ** inspect distribution shift, preprocessing differences, label quality, leakage or repeated validation overfitting. Compare per-class errors and collection conditions. Address the actual cause and collect representative data if necessary. If test results guide retuning, use a fresh untouched final test set.\n\n"}]},{"n":16,"title":"R23 selected MT2 practice","sections":[{"title":"Start here","blocks":["<p>The source archive retains historical optimization, CNN and introductory RNN questions. Following the 12 October faculty update, the focused MT2 website presents the Unit 3–4 questions; retained RNN bookmarks lead to TEE. Original question IDs and marks are preserved. Full assessed tasks and numerical data are transcribed in readable language; worked solutions follow each question. This selection does not predict the paper.</p>"],"kind":"read","id":"mt2-c16-intro"},{"title":"R23 Q1a","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Suggest and sketch an RNN architecture to synthesize a musical tune.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p>Represent notes as discrete tokens or suitable pitch-duration vectors. Train a recurrent decoder to predict the next note from preceding notes. A vocabulary softmax handles discrete note tokens; repeatedly feed generated notes to continue the tune until a stop condition. This is autoregressive sequence generation, typically a many-to-many next-token training pattern.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: Music generation can predict a next note at every recurrent step\"><img src=\"assets/figures/sequences.svg\" alt=\"Music generation can predict a next note at every recurrent step\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>Music generation can predict a next note at every recurrent step <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"mt2-c16-s0","search":"R23 Q1a **Question (4 marks).** Suggest and sketch an RNN architecture to synthesize a musical tune.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\nRepresent notes as discrete tokens or suitable pitch-duration vectors. Train a recurrent decoder to predict the next note from preceding notes. A vocabulary softmax handles discrete note tokens; repeatedly feed generated notes to continue the tune until a stop condition. This is autoregressive sequence generation, typically a many-to-many next-token training pattern.\n\n"},{"title":"R23 Q1b","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Apply 3 × 3 average pooling with stride 2 to Matrix 1 shown below. Give the output and justify pooling.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_847554ea0e.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_847554ea0e.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"470\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Apply 3 × 3 average pooling with stride 2 to Matrix 1 shown below.</p>","<h3>To find</h3>","<p>Find the requested pooled output(s).</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cc7bf1ef4d7c44f8.svg\" alt=\"\\left\\lfloor\\frac{5-3}{2}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[1, 2, 3, 5, 3, 4, 7, 4, 8]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>1 + 2 + 3 + 5 + 3 + 4 + 7 + 4 + 8 = 37</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>37/9 = <strong>4.111111111</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[3, 2, 5, 4, 6, 3, 8, 5, 9]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>3 + 2 + 5 + 4 + 6 + 3 + 8 + 5 + 9 = 45</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>45/9 = <strong>5</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[7, 4, 8, 8, 5, 10, 9, 10, 3]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>7 + 4 + 8 + 8 + 5 + 10 + 9 + 10 + 3 = 64</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>64/9 = <strong>7.111111111</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[8, 5, 9, 10, 4, 2, 3, 4, 3]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>8 + 5 + 9 + 10 + 4 + 2 + 3 + 4 + 3 = 48</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>48/9 = <strong>5.333333333</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/072844f2570c1168.svg\" alt=\"\\begin{bmatrix}4.111111111 &amp; 5\\\\7.111111111 &amp; 5.333333333\\end{bmatrix}\" width=\"239.69\" height=\"45.61\" style=\"width:239.69px;height:45.61px;aspect-ratio:239.69/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>"],"kind":"practice","id":"mt2-c16-s1","search":"R23 Q1b **Question (4 marks).** Apply 3 × 3 average pooling with stride 2 to Matrix 1 shown below. Give the output and justify pooling.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nApply 3 × 3 average pooling with stride 2 to Matrix 1 shown below.\n\n### To find\n\nFind the requested pooled output(s).\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n**Shape: ** \\(\\left\\lfloor\\frac{5-3}{2}\\right\\rfloor+1\\) = 2 on each axis; channels stay unchanged.\n### Pooling window (1,1)\n\n**Step 1: select the entries.**\n\n[1, 2, 3, 5, 3, 4, 7, 4, 8]\n\n**Step 2: add all selected entries.**\n\n1 + 2 + 3 + 5 + 3 + 4 + 7 + 4 + 8 = 37\n\n**Step 3: divide by the 9 entries in this window.**\n\n37/9 = **4.111111111**\n\n\n### Pooling window (1,2)\n\n**Step 1: select the entries.**\n\n[3, 2, 5, 4, 6, 3, 8, 5, 9]\n\n**Step 2: add all selected entries.**\n\n3 + 2 + 5 + 4 + 6 + 3 + 8 + 5 + 9 = 45\n\n**Step 3: divide by the 9 entries in this window.**\n\n45/9 = **5**\n\n\n### Pooling window (2,1)\n\n**Step 1: select the entries.**\n\n[7, 4, 8, 8, 5, 10, 9, 10, 3]\n\n**Step 2: add all selected entries.**\n\n7 + 4 + 8 + 8 + 5 + 10 + 9 + 10 + 3 = 64\n\n**Step 3: divide by the 9 entries in this window.**\n\n64/9 = **7.111111111**\n\n\n### Pooling window (2,2)\n\n**Step 1: select the entries.**\n\n[8, 5, 9, 10, 4, 2, 3, 4, 3]\n\n**Step 2: add all selected entries.**\n\n8 + 5 + 9 + 10 + 4 + 2 + 3 + 4 + 3 = 48\n\n**Step 3: divide by the 9 entries in this window.**\n\n48/9 = **5.333333333**\n\n\n**Average output: ** . Pooling normally has zero trainable parameters and reduces spatial dimensions.\n"},{"title":"R23 Q1d","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Evaluate how mini-batch size affects optimization and parallel processing.</p>"],"answer":["<p>A mini-batch forms one gradient from B examples. Smaller B usually gives noisier gradients, lower activation memory and more updates per epoch. Larger B averages more examples, often uses vectorized hardware more efficiently up to resource limits, but needs more memory and gives fewer updates per epoch. N examples produce ceil(N/B) updates if the last partial batch is kept. Too-large B does not guarantee faster wall-clock progress or better generalization. Tune batch size with learning rate and resource constraints. Computation within a batch can be parallelized; successive optimizer steps remain dependent on the updated parameters.</p>"],"kind":"practice","id":"mt2-c16-s2","search":"R23 Q1d **Question (4 marks).** Evaluate how mini-batch size affects optimization and parallel processing.\n\n**Complete worked answer.**\nA mini-batch forms one gradient from B examples. Smaller B usually gives noisier gradients, lower activation memory and more updates per epoch. Larger B averages more examples, often uses vectorized hardware more efficiently up to resource limits, but needs more memory and gives fewer updates per epoch. N examples produce ceil(N/B) updates if the last partial batch is kept. Too-large B does not guarantee faster wall-clock progress or better generalization. Tune batch size with learning rate and resource constraints. Computation within a batch can be parallelized; successive optimizer steps remain dependent on the updated parameters.\n"},{"title":"R23 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A CNN with convolution, pooling, dense and output layers receives 127 × 127 images for 5 classes and trains with Adam. Identify learned parameters and tunable hyperparameters.</p>"],"answer":["<p>Convolutional kernel entries and filter biases are learned parameters. Dense weight matrices and biases are learned parameters. Pooling, flattening and ordinary activations have no learned weights. The output has 5 class scores and usually softmax with categorical cross-entropy. Adam’s m, v are running optimizer states, not extra predictive parameters.</p>","<p>Hyperparameters include kernel sizes, filter counts, strides, padding, pooling configuration, dense widths, activations, learning rate, Adam β₁/β₂/ε, batch size, epochs and regularization. Architecture choices control representation capacity and resource demand; optimizer settings control update behavior. No filter counts or dense widths are specified, so a unique numerical parameter total cannot be calculated from 127 × 127 and 5 classes alone.</p>","<p>Adam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.71px;--narrow-height:202.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92678247acd594b0.svg\"><img class=\"math display-math\" src=\"assets/equations/c443fc0367c152b1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\widehat v_t=\\frac{v_t}{1-\\beta_2^t},\\quad\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"571.98\" height=\"66.85\" style=\"width:571.98px;height:66.85px;aspect-ratio:571.98/66.85\" loading=\"lazy\"></picture></div>","<p>Use update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.</p>","<p>For g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.</p>","<p>Compared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.</p>"],"kind":"practice","id":"mt2-c16-s3","search":"R23 Q2a **Question (10 marks).** A CNN with convolution, pooling, dense and output layers receives 127 × 127 images for 5 classes and trains with Adam. Identify learned parameters and tunable hyperparameters.\n\n**Complete worked answer.**\nConvolutional kernel entries and filter biases are learned parameters. Dense weight matrices and biases are learned parameters. Pooling, flattening and ordinary activations have no learned weights. The output has 5 class scores and usually softmax with categorical cross-entropy. Adam’s m, v are running optimizer states, not extra predictive parameters.\nHyperparameters include kernel sizes, filter counts, strides, padding, pooling configuration, dense widths, activations, learning rate, Adam β₁/β₂/ε, batch size, epochs and regularization. Architecture choices control representation capacity and resource demand; optimizer settings control update behavior. No filter counts or dense widths are specified, so a unique numerical parameter total cannot be calculated from 127 × 127 and 5 classes alone.\nAdam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.\n\n\nUse update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.\nFor g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.\nCompared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.\n"},{"title":"R23 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Justify ReLU over sigmoid/tanh for deep hidden layers. For predicting brand ratings on a scale of 10, choose output activation and loss. Diagnose 2% training versus 18% validation error and suggest remedies.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>","<p><strong>Rating regression: </strong> for a continuous score, one linear output with MSE is a standard baseline. If strict 0–10 bounds are required, use 10 × sigmoid(z) and the matching regression loss, noting saturation near the endpoints. If labels are categorical rating bins, a categorical formulation would be different; state the continuous-score assumption.</p>","<p><strong>2% versus 18%: </strong> if errors use the same comparable metric and distribution, this large generalization gap strongly suggests overfitting. Use appropriate regularization, early stopping, more representative data and possibly a smaller model; inspect leakage and preprocessing too.</p>","<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>"],"kind":"practice","id":"mt2-c16-s4","search":"R23 Q2b **Question (10 marks).** Justify ReLU over sigmoid/tanh for deep hidden layers. For predicting brand ratings on a scale of 10, choose output activation and loss. Diagnose 2% training versus 18% validation error and suggest remedies.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n**Rating regression: ** for a continuous score, one linear output with MSE is a standard baseline. If strict 0–10 bounds are required, use 10 × sigmoid(z) and the matching regression loss, noting saturation near the endpoints. If labels are categorical rating bins, a categorical formulation would be different; state the continuous-score assumption.\n**2% versus 18%: ** if errors use the same comparable metric and distribution, this large generalization gap strongly suggests overfitting. Use appropriate regularization, early stopping, more representative data and possibly a smaller model; inspect leakage and preprocessing too.\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of u"},{"title":"R23 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design employee face-recognition attendance using a CNN with too few training images. Explain solutions.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>"],"kind":"practice","id":"mt2-c16-s5","search":"R23 Q4a **Question (10 marks).** Design employee face-recognition attendance using a CNN with too few training images. Explain solutions.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n"},{"title":"R23 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Estimate parameters of the AlexNet diagram. Use Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.</p>"],"answer":["<h3>Given</h3>","<p>Use Input 227 × 227 × 3.</p>","<p>Conv K = 11, filters = 96, stride = 4, padding = 0.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 256, stride = 1, padding = 2.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 256, stride = 1, padding = 1.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Dense 4096 units.</p>","<p>Dense 4096 units.</p>","<p>Dense 1000 units.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">227 × 227 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">96 filters · 11 × 11 · S = 4 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">34,848</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">96</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">34,944</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>227 × 227 × 3</strong>. Use 96 filters of spatial size 11 × 11, stride 4, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.10px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/441a061296efda7a.svg\"><img class=\"math display-math\" src=\"assets/equations/1ca643e3f874dc98.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{227+2(0)-11}{4}\\right\\rfloor+1=55\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>55 × 55 × 96</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9a11e5db4a09d338.svg\"><img class=\"math display-math\" src=\"assets/equations/e8a26a7b03e38af6.svg\" alt=\"N_{\\mathrm{weights}}=11\\times11\\times3\\times96=34{,}848\" width=\"386.55\" height=\"23.91\" style=\"width:386.55px;height:23.91px;aspect-ratio:386.55/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3b19ed994769f54.svg\" alt=\"N_{\\mathrm{biases}}=96\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ae51bc20750a112f.svg\" alt=\"P_1=34{,}848+96=34{,}944\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>55 × 55 × 96</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d42806d80c07005c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1=27\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>27 × 27 × 96</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 5 × 5 · S = 1 · P = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">614,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">614,656</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>27 × 27 × 96</strong>. Use 256 filters of spatial size 5 × 5, stride 1, and padding 2 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f4e102905e6bf9f.svg\"><img class=\"math display-math\" src=\"assets/equations/da9a62eaf99ea1e8.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27+2(2)-5}{1}\\right\\rfloor+1=27\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>27 × 27 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 96 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b720c78ffc948913.svg\"><img class=\"math display-math\" src=\"assets/equations/05edf5328cb35876.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times96\\times256=614{,}400\" width=\"398.77\" height=\"23.91\" style=\"width:398.77px;height:23.91px;aspect-ratio:398.77/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29c935e56c01ee26.svg\"><img class=\"math display-math\" src=\"assets/equations/67ebf4d50d295918.svg\" alt=\"P_3=614{,}400+256=614{,}656\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>27 × 27 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ca522f15a3632877.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1=13\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">885,120</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 256 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/492d70515e0406f9.svg\"><img class=\"math display-math\" src=\"assets/equations/0f457ff5f3c6b74f.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times256\\times384=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e9338e40808aff5.svg\"><img class=\"math display-math\" src=\"assets/equations/0cca75bb5a08cdeb.svg\" alt=\"P_5=884{,}736+384=885{,}120\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">1,327,104</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">1,327,488</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3729f79bf2b69fab.svg\"><img class=\"math display-math\" src=\"assets/equations/a2fb560ecf5f18c3.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times384=1{,}327{,}104\" width=\"429.99\" height=\"23.91\" style=\"width:429.99px;height:23.91px;aspect-ratio:429.99/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4565bf3714918ad3.svg\"><img class=\"math display-math\" src=\"assets/equations/8d8b08cc6480d083.svg\" alt=\"P_6=1{,}327{,}104+384=1{,}327{,}488\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">884,992</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 256 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/be0b63ec1f7ffb8c.svg\"><img class=\"math display-math\" src=\"assets/equations/42a81620f94360dd.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times256=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c304d00633ff2322.svg\"><img class=\"math display-math\" src=\"assets/equations/a803766772104e69.svg\" alt=\"P_7=884{,}736+256=884{,}992\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/117abcc38db86957.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1=6\" width=\"271.85\" height=\"58.62\" style=\"width:271.85px;height:58.62px;aspect-ratio:271.85/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>6 × 6 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 9 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>6 × 6 × 256</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d9921c92554e599.svg\" alt=\"n_{\\mathrm{flat}}=6\\times6\\times256=9{,}216\" width=\"283.79\" height=\"21.02\" style=\"width:283.79px;height:21.02px;aspect-ratio:283.79/21.02\" loading=\"lazy\"></div>","<p>Output: a vector with <strong>9,216 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">37,748,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">37,752,832</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>9,216 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/253a54d671a02309.svg\"><img class=\"math display-math\" src=\"assets/equations/864d5792c1506a4b.svg\" alt=\"N_{\\mathrm{weights}}=9{,}216\\times4{,}096=37{,}748{,}736\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a6d14bbf5757207.svg\"><img class=\"math display-math\" src=\"assets/equations/42e41d5d625e4b33.svg\" alt=\"P_10=37{,}748{,}736+4{,}096=37{,}752{,}832\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 11 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 11: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">16,777,216</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">16,781,312</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe4cfd667cc7b7ce.svg\"><img class=\"math display-math\" src=\"assets/equations/37f33b938916c485.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times4{,}096=16{,}777{,}216\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3652163d527344ad.svg\"><img class=\"math display-math\" src=\"assets/equations/ca42e0122e881f05.svg\" alt=\"P_11=16{,}777{,}216+4{,}096=16{,}781{,}312\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 12 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 12: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">1,000 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">1,000</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,096,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">1,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,097,000</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>1,000 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3d7876f0d5fdb4fa.svg\"><img class=\"math display-math\" src=\"assets/equations/a47853490ec706c7.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times1{,}000=4{,}096{,}000\" width=\"383.84\" height=\"23.91\" style=\"width:383.84px;height:23.91px;aspect-ratio:383.84/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d0008f88a44995b2.svg\" alt=\"N_{\\mathrm{biases}}=1{,}000\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3adeefbc3dbe4d6b.svg\"><img class=\"math display-math\" src=\"assets/equations/91b7bd4147e4b8d6.svg\" alt=\"P_12=4{,}096{,}000+1{,}000=4{,}097{,}000\" width=\"387.48\" height=\"21.43\" style=\"width:387.48px;height:21.43px;aspect-ratio:387.48/21.43\" loading=\"lazy\"></picture></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/74235148b2b7312a.svg\" alt=\"\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\" width=\"199.47\" height=\"45.60\" style=\"width:199.47px;height:45.60px;aspect-ratio:199.47/45.60\" loading=\"lazy\"></span></td><td>55 x 55 x 96</td><td>34,848</td><td>96</td><td>34,944</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cdac8f1c682bc40a.svg\" alt=\"\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 96</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/71046f85d0cc0ca5.svg\" alt=\"\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 256</td><td>614,400</td><td>256</td><td>614,656</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/55802f10aac3668d.svg\" alt=\"\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>884,736</td><td>384</td><td>885,120</td></tr><tr><td>6 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>1,327,104</td><td>384</td><td>1,327,488</td></tr><tr><td>7 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>884,736</td><td>256</td><td>884,992</td></tr><tr><td>8 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/73ab07c24eb836b2.svg\" alt=\"\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>6 x 6 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>9 flat</td><td>6 × 6 × 256</td><td>9216</td><td>0</td><td>0</td><td>0</td></tr><tr><td>10 dense</td><td>9216 → 4096</td><td>4096</td><td>37,748,736</td><td>4,096</td><td>37,752,832</td></tr><tr><td>11 dense</td><td>4096 → 4096</td><td>4096</td><td>16,777,216</td><td>4,096</td><td>16,781,312</td></tr><tr><td>12 dense</td><td>4096 → 1000</td><td>1000</td><td>4,096,000</td><td>1,000</td><td>4,097,000</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (11 x 11 x 3 + 1) x 96 = 34,944.</p>","<p>Layer 3: (5 x 5 x 96 + 1) x 256 = 614,656.</p>","<p>Layer 5: (3 x 3 x 256 + 1) x 384 = 885,120.</p>","<p>Layer 6: (3 x 3 x 384 + 1) x 384 = 1,327,488.</p>","<p>Layer 7: (3 x 3 x 384 + 1) x 256 = 884,992.</p>","<p>Layer 10: (9216 + 1) x 4096 = 37,752,832.</p>","<p>Layer 11: (4096 + 1) x 4096 = 16,781,312.</p>","<p>Layer 12: (4096 + 1) x 1000 = 4,097,000.</p>","<p><strong>Total: </strong> 34,944 + 614,656 + 885,120 + 1,327,488 + 884,992 + 37,752,832 + 16,781,312 + 4,097,000 = <strong>62,378,344 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p>The diagram labels its final pooled map 6 × 6 × 256; a 3 × 3, stride 2 pool from 13 × 13 produces 6. If a small printed stride label is read as 3, it conflicts with the shown 6 × 6 map. The answer uses the consistent classic stride 2 interpretation. Original grouped AlexNet counts are a different architecture assumption.</p>"],"kind":"practice","id":"mt2-c16-s6","search":"R23 Q4b **Question (10 marks).** Estimate parameters of the AlexNet diagram. Use Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nUse Input 227 × 227 × 3.\n\nConv K = 11, filters = 96, stride = 4, padding = 0.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 5, filters = 256, stride = 1, padding = 2.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 256, stride = 1, padding = 1.\n\nPool K = 3, stride = 2, padding = 0.\n\nDense 4096 units.\n\nDense 4096 units.\n\nDense 1000 units.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\\) | 55 x 55 x 96 | 34,848 | 96 | 34,944 |\n| 2 pool | \\(\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\\) | 27 x 27 x 96 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\\) | 27 x 27 x 256 | 614,400 | 256 | 614,656 |\n| 4 pool | \\(\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\\) | 13 x 13 x 256 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 884,736 | 384 | 885,120 |\n| 6 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 1,327,104 | 384 | 1,327,488 |\n| 7 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 256 | 884,736 | 256 | 884,992 |\n| 8 pool | \\(\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\\) | 6 x 6 x 256 | 0 | 0 | 0 |\n| 9 flat | 6 × 6 × 256 | 9216 | 0 | 0 | 0 |\n| 10 dense | 9216 → 4096 | 4096 | 37,748,736 | 4,096 | 37,752,832 |\n| 11 dense | 4096 → 4096 | 4096 | 16,777,216 | 4,096 | 16,781,312 |\n| 12 dense | 4096 → 1000 | 1000 | 4,096,000 | 1,000 | 4,097,000 |\n**Parameter substitutions, in layer order: **\nLayer 1: (11 x 11 x 3 + 1) x 96 = 34,944.\nLayer 3: (5 x 5 x 96 + 1) x 256 = 614,656.\nLayer 5: (3 x 3 x 256 + 1) x 384 = 885,120.\nLayer 6: (3 x 3 x 384 + 1) x 384 = 1,327,488.\nLayer 7: (3 x 3 x 384 + 1) x 256 = 884,992.\nLayer 10: (9216 + 1) x 4096 = 3"},{"title":"R23 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Suggest and justify remedies when (1) loss does not minimize after many epochs, (2) gradients are noisy and loss oscillates, (3) loss falls then rises because updates miss a minimum.</p>"],"answer":["<p>The learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative full batch and stochastic traces distinguish smoothness from progress\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative full batch and stochastic traces distinguish smoothness from progress\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative full batch and stochastic traces distinguish smoothness from progress <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Batch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.</p>","<p>Momentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.</p>","<p>Diagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.</p>","<p><strong>Scenario 1: </strong> check correctness and gradient magnitudes, then tune learning rate, activation, initialization or optimizer. <strong>Scenario 2: </strong> consider an appropriate larger mini-batch or momentum; distinguish ordinary stochastic noise from divergence. <strong>Scenario 3: </strong> reduce learning rate or use a schedule; momentum/Nesterov can help but excessive momentum can worsen overshoot. Judge training and validation curves separately.</p>"],"kind":"practice","id":"mt2-c16-s7","search":"R23 Q6a **Question (10 marks).** Suggest and justify remedies when (1) loss does not minimize after many epochs, (2) gradients are noisy and loss oscillates, (3) loss falls then rises because updates miss a minimum.\n\n**Complete worked answer.**\nThe learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.\n\nBatch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.\nMomentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.\nDiagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.\n**Scenario 1: ** check correctness and gradient magnitudes, then tune learning rate, activation, initialization or optimizer. **Scenario 2: ** consider an appropriate larger mini-batch or momentum; distinguish ordinary stochastic noise from divergence. **Scenario 3: ** reduce learning rate or use a schedule; momentum/Nesterov can help but excessive momentum can worsen overshoot. Judge training and validation curves separately.\n"},{"title":"R23 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A 28 × 28 × 192 input is convolved with 32 same-padded 5 × 5 filters to produce 28 × 28 × 32. Count computations. What happens if a 1 × 1 convolution precedes it? The reduction-channel count is not supplied.</p>"],"answer":["<h3>Given</h3>","<p>Input = 28 × 28 × 192; 32 same-padded 5 × 5 filters.</p>","<p>A preceding 1 × 1 convolution would reduce to C channels.</p>","<p>C is not supplied, so first give the symbolic bottleneck count; 16 channels is only an illustrative assumption.</p>","<h3>To find</h3>","<p>Calculate direct cost and express bottleneck cost in C; explain when the bottleneck saves computation.</p>","<h3>Formula — which one and why</h3>","<p><strong>Multiply–accumulate count.</strong> Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.</p>","<p>H_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output cell ka kaam × kitne output cells.</p>","<h3>Solution — step by step</h3>","<h3>Direct path</h3>","<p class=\"worked-step\"><strong>Step 2: direct path.</strong></p>","<p>output stays 28 × 28 with 32 channels.</p>","<p class=\"worked-step\"><strong>Step 3: direct path.</strong></p>","<p>MACs = 28 × 28 × 192 × 32 × 5 × 5 = <strong>120,422,400</strong>.</p>","<h3>Bottleneck path with 16 reduction channels</h3>","<p class=\"worked-step\"><strong>Step 4: bottleneck path with 16 reduction channels.</strong></p>","<p>1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.</p>","<p class=\"worked-step\"><strong>Step 5: bottleneck path with 16 reduction channels.</strong></p>","<p>The 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.</p>","<p class=\"worked-step\"><strong>Step 6: bottleneck path with 16 reduction channels.</strong></p>","<p>Total = <strong>12,443,648</strong>.</p>","<h3>Saving</h3>","<p class=\"worked-step\"><strong>Step 7: saving.</strong></p>","<p>120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = <strong>89.666667%</strong>. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = <strong>777,728r</strong></p>","<p class=\"worked-step\"><strong>Step 8: saving.</strong></p>","<p>there is no unique numeric bottleneck cost until r is chosen.</p>","<p>The 16-channel bottleneck is an explicitly chosen illustrative value, consistent with a related paper; the symbolic 777,728 r answer is required when r has not been specified.</p>","<p class=\"worked-step\"><strong>Step 9: calculate this quantity.</strong></p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 10: calculate this quantity.</strong></p>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>"],"kind":"practice","id":"mt2-c16-s8","search":"R23 Q6b **Question (10 marks).** A 28 × 28 × 192 input is convolved with 32 same-padded 5 × 5 filters to produce 28 × 28 × 32. Count computations. What happens if a 1 × 1 convolution precedes it? The reduction-channel count is not supplied.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput = 28 × 28 × 192; 32 same-padded 5 × 5 filters.\n\nA preceding 1 × 1 convolution would reduce to C channels.\n\nC is not supplied, so first give the symbolic bottleneck count; 16 channels is only an illustrative assumption.\n\n### To find\n\nCalculate direct cost and express bottleneck cost in C; explain when the bottleneck saves computation.\n\n### Formula — which one and why\n\n**Multiply–accumulate count.** Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.\n\nH_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har output cell ka kaam × kitne output cells.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n\n\n### Direct path\n\n**Step 2: direct path.**\n\noutput stays 28 × 28 with 32 channels.\n\n**Step 3: direct path.**\n\nMACs = 28 × 28 × 192 × 32 × 5 × 5 = **120,422,400**.\n\n### Bottleneck path with 16 reduction channels\n\n**Step 4: bottleneck path with 16 reduction channels.**\n\n1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.\n\n**Step 5: bottleneck path with 16 reduction channels.**\n\nThe 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.\n\n**Step 6: bottleneck path with 16 reduction channels.**\n\nTotal = **12,443,648**.\n\n### Saving\n\n**Step 7: saving.**\n\n120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = **89.666667%**. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = **777,728r**\n\n**Step 8: saving.**\n\nthere is no unique numeric bottleneck cost until r is chosen.\n\nThe 16-channel bottleneck is an explicitly chosen illustrative value, consistent with a related paper; the symbolic 777,728 r answer is required when r has not been specified.\n\n**Step 9: calculate this quantity.**\n\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\n\n\n**Step 10: calculate this quantity.**\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\n\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kern"},{"title":"R23 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Training performance is good but unseen-data performance degrades. Identify the issue and explain ways to improve it.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<p>A comparable-distribution train/unseen gap suggests overfitting. Also check whether the new data have shifted, preprocessing differs or labels are inconsistent. Select regularization using validation performance, not final-test tuning. Improvement must be demonstrated on representative held-out examples.</p>"],"kind":"practice","id":"mt2-c16-s9","search":"R23 Q7b **Question (10 marks).** Training performance is good but unseen-data performance degrades. Identify the issue and explain ways to improve it.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\nA comparable-distribution train/unseen gap suggests overfitting. Also check whether the new data have shifted, preprocessing differs or labels are inconsistent. Select regularization using validation performance, not final-test tuning. Improvement must be demonstrated on representative held-out examples.\n\n\n"}]},{"n":17,"title":"MT2 numerical practice from direct to mixed","sections":[{"title":"Start here","blocks":["<p>These 45 original drills cover the required maths, neuron/gradient prerequisites, optimization, regularization, CNNs and basic RNN forward passes. Each has a full solution. They are practice questions, not predictions.</p>","<p>First learn the method, then cover the answer and solve. Start with drills 4–6, 11, 14–39, then the mixed drills 40–45. Use the earlier arithmetic drills whenever a sign, bracket or calculator entry blocks you.</p>"],"kind":"read","id":"mt2-c17-intro"},{"title":"How to solve a mixed numerical without guessing","blocks":["<p>A mixed question is a chain of familiar operations. First circle the requested final quantity. Underline the given activation, loss, padding, stride, threshold, learning rate and any fixed parameters. Draw a small box for each stage. Write the output of one box as the input to the next. Never skip a stage because its title looks unfamiliar.</p>","<p><strong>If the question says output or prediction:</strong> do only the forward chain, unless training is separately requested. For a neuron, multiply and add before activating. For a CNN, determine spatial shapes before flattening. For an RNN, carry the previous state into the next time step.</p>","<p><strong>If it says train or update:</strong> finish the entire old forward pass, calculate the stated loss derivative, move backward, store every gradient, then update together. If there are several output branches, add their effects at the shared hidden unit. For a batch, follow the stated sum or mean loss before updating.</p>","<p><strong>If it mixes dropout and a loss:</strong> apply the given training mask and scaling first; then predict from the resulting activations. The gradient to a dropped path is zero for that mask. If it also specifies L2, add its gradient to the data gradient before the optimizer step. If it also specifies momentum or Adam, carry their stored states as well as the parameter.</p>","<p><strong>If it mixes convolution, pooling and a dense classifier:</strong> output shape → next layer input shape → flatten length → dense scores → activation → loss. Count learned parameters separately from output values. Pooling and flattening have zero learned parameters in these questions.</p>","<p><strong>If it changes a familiar problem:</strong> an extra input adds another product; an extra output adds another backward path; a new channel adds another kernel sum; a new time step adds another shared-state calculation. The method stays the same. The drills below deliberately change signs, targets, loss scales and layer combinations.</p>","<p><strong>Your completion rule:</strong> solve a representative problem today without the answer, repeat it after several hours, then solve a changed-number or mixed version tomorrow. Mark the exact line where your reasoning failed. Correcting that line is what builds reliable recall; reading an open solution does not test it.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c17-s0","search":"How to solve a mixed numerical without guessing A mixed question is a chain of familiar operations. First circle the requested final quantity. Underline the given activation, loss, padding, stride, threshold, learning rate and any fixed parameters. Draw a small box for each stage. Write the output of one box as the input to the next. Never skip a stage because its title looks unfamiliar.\n**If the question says output or prediction:** do only the forward chain, unless training is separately requested. For a neuron, multiply and add before activating. For a CNN, determine spatial shapes before flattening. For an RNN, carry the previous state into the next time step.\n**If it says train or update:** finish the entire old forward pass, calculate the stated loss derivative, move backward, store every gradient, then update together. If there are several output branches, add their effects at the shared hidden unit. For a batch, follow the stated sum or mean loss before updating.\n**If it mixes dropout and a loss:** apply the given training mask and scaling first; then predict from the resulting activations. The gradient to a dropped path is zero for that mask. If it also specifies L2, add its gradient to the data gradient before the optimizer step. If it also specifies momentum or Adam, carry their stored states as well as the parameter.\n**If it mixes convolution, pooling and a dense classifier:** output shape → next layer input shape → flatten length → dense scores → activation → loss. Count learned parameters separately from output values. Pooling and flattening have zero learned parameters in these questions.\n**If it changes a familiar problem:** an extra input adds another product; an extra output adds another backward path; a new channel adds another kernel sum; a new time step adds another shared-state calculation. The method stays the same. The drills below deliberately change signs, targets, loss scales and layer combinations.\n**Your completion rule:** solve a representative problem today without the answer, repeat it after several hours, then solve a changed-number or mixed version tomorrow. Mark the exact line where your reasoning failed. Correcting that line is what builds reliable recall; reading an open solution does not test it.\n"},{"title":"Drill 1 Signs and brackets","question":["<p class=\"inline-question\"><strong>Question.</strong> Evaluate 2−0.1 × (−3), then (2−0.1) × (−3). Explain why they differ.</p>"],"answer":["<h3>Given</h3>","<p>Expressions: 2−0.1×(−3) and (2−0.1)×(−3).</p>","<h3>To find</h3>","<p>Evaluate both and explain the effect of grouping.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the calculation</h3>","<p>A minus sign can mean subtraction or a negative number. Brackets tell us which part belongs together. These two expressions have different brackets, so they describe different calculations.</p>","<h3>Rule used</h3>","<p>Do brackets first, then multiplication, then addition or subtraction. Subtracting a negative number means adding its positive size.</p>","<p class=\"worked-step\"><strong>Step 1: First expression: multiply before subtracting.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5b11a126e768858f.svg\" alt=\"2-0.1\\times(-3)\" width=\"153.42\" height=\"24.43\" style=\"width:153.42px;height:24.43px;aspect-ratio:153.42/24.43\" loading=\"lazy\"></div>","<p>First multiply: a positive number times a negative number is negative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/189f052516957693.svg\" alt=\"0.1\\times(-3)=-0.3\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<p>Put this complete result back into the expression. Keep its negative sign inside brackets.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2d796303b17c0e32.svg\" alt=\"2-(-0.3)=2+0.3=2.3\" width=\"281.05\" height=\"24.43\" style=\"width:281.05px;height:24.43px;aspect-ratio:281.05/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Second expression: finish the bracket first.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26a467850584ea86.svg\" alt=\"2-0.1=1.9\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p>Now multiply the whole bracket result by negative 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f4e294dd1ab7a8aa.svg\" alt=\"1.9\\times(-3)=-5.7\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> first expression = 2.3; second expression = −5.7. In a weight update, multiply learning rate by gradient first, then subtract that product from the old weight.</p>"],"kind":"practice","id":"mt2-c17-s1","search":"Drill 1 Signs and brackets **Question.** Evaluate 2−0.1 × (−3), then (2−0.1) × (−3). Explain why they differ.\n\n**Full solution.**\n\n\n\n### Given\n\nExpressions: 2−0.1×(−3) and (2−0.1)×(−3).\n\n### To find\n\nEvaluate both and explain the effect of grouping.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the calculation\nA minus sign can mean subtraction or a negative number. Brackets tell us which part belongs together. These two expressions have different brackets, so they describe different calculations.\n### Rule used\nDo brackets first, then multiplication, then addition or subtraction. Subtracting a negative number means adding its positive size.\n**Step 1: First expression: multiply before subtracting.**\n\nFirst multiply: a positive number times a negative number is negative.\n\nPut this complete result back into the expression. Keep its negative sign inside brackets.\n\n**Step 2: Second expression: finish the bracket first.**\n\nNow multiply the whole bracket result by negative 3.\n\n**Final answer:** first expression = 2.3; second expression = −5.7. In a weight update, multiply learning rate by gradient first, then subtract that product from the old weight.\n"},{"title":"Drill 2 Half sum versus mean","question":["<p class=\"inline-question\"><strong>Question.</strong> Predictions = [0.2,0.7,0.4], targets = [0,1,1]. Find SSE, half SSE and MSE.</p>"],"answer":["<h3>Given</h3>","<p>Predictions = [0.2, 0.7, 0.4].</p>","<p>Targets = [0, 1, 1]; number of outputs n = 3.</p>","<h3>To find</h3>","<p>Find SSE, half SSE, MSE and the prediction gradients requested in the question.</p>","<h3>Formula — which one and why</h3>","<p><strong>Squared-error objectives.</strong> Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.</p>","<p>ŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle error square; phir question ke hisaab se sum, half ya mean.</p>","<h3>Solution — step by step</h3>","<h3>Given values and loss definitions</h3>","<p>There are n = 3 prediction–target pairs. Use the supplied predictions directly; no rounding to class labels is required. Let eᵢ = ŷᵢ − yᵢ be the signed residual for pair i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5312f21f7180b663.svg\" alt=\"\\mathrm{SSE}=\\sum_{i=1}^{n}e_i^2\" width=\"137.81\" height=\"68.62\" style=\"width:137.81px;height:68.62px;aspect-ratio:137.81/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8370703d0e22f365.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_{i=1}^{n}e_i^2=\\frac{\\mathrm{SSE}}2\" width=\"256.33\" height=\"68.62\" style=\"width:256.33px;height:68.62px;aspect-ratio:256.33/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bde24be7fa074ec1.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_{i=1}^{n}e_i^2=\\frac{\\mathrm{SSE}}n\" width=\"263.26\" height=\"68.62\" style=\"width:263.26px;height:68.62px;aspect-ratio:263.26/68.62\" loading=\"lazy\"></div>","<p>SSE is the sum of squared errors. Half SSE and MSE rescale that same sum by different denominators: 2 and n, respectively.</p>","<h3>Step 1: calculate each residual and its square</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Pair</th><th>Prediction ŷᵢ</th><th>Target yᵢ</th><th>Residual ŷᵢ − yᵢ</th><th>Squared residual</th></tr></thead><tbody><tr><td>1</td><td>0.2</td><td>0</td><td>0.2 − 0 = 0.2</td><td>(0.2)² = 0.04</td></tr><tr><td>2</td><td>0.7</td><td>1</td><td>0.7 − 1 = −0.3</td><td>(−0.3)² = 0.09</td></tr><tr><td>3</td><td>0.4</td><td>1</td><td>0.4 − 1 = −0.6</td><td>(−0.6)² = 0.36</td></tr></tbody></table></div>","<h3>Step 2: sum the squared residuals</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4890329b3b657194.svg\"><img class=\"math display-math\" src=\"assets/equations/36128683498bbba3.svg\" alt=\"\\mathrm{SSE}=0.04+0.09+0.36=0.49\" width=\"342.50\" height=\"19.23\" style=\"width:342.50px;height:19.23px;aspect-ratio:342.50/19.23\" loading=\"lazy\"></picture></div>","<p>Square each residual before summing. Squaring the sum of signed residuals would be a different quantity, because positive and negative residuals could cancel.</p>","<h3>Step 3: apply each requested normalization</h3>","<p>For half SSE, the denominator is 2:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3d10f476bd1cf13c.svg\" alt=\"L_{\\mathrm{half}}=\\frac{0.49}{2}=0.245\" width=\"223.17\" height=\"49.82\" style=\"width:223.17px;height:49.82px;aspect-ratio:223.17/49.82\" loading=\"lazy\"></div>","<p>For MSE, the denominator is the number of pairs, n = 3:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.26px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4cd1db7c5158eb6.svg\"><img class=\"math display-math\" src=\"assets/equations/2f7b20630e72d239.svg\" alt=\"\\mathrm{MSE}=\\frac{0.49}{3}=0.163333333\\ldots\" width=\"333.67\" height=\"50.36\" style=\"width:333.67px;height:50.36px;aspect-ratio:333.67/50.36\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> SSE = 0.49; half SSE = 0.245; MSE ≈ 0.163333. They represent the same residuals at different scales. Half SSE and MSE coincide when n = 2; they do not coincide for these three nonzero residuals. No derivative is required by this question.</p>"],"kind":"practice","id":"mt2-c17-s2","search":"Drill 2 Half sum versus mean \n**Question.** Predictions = [0.2,0.7,0.4], targets = [0,1,1]. Find SSE, half SSE and MSE.\n\n**Full solution.**\n\n\n\n### Given\n\nPredictions = [0.2, 0.7, 0.4].\n\nTargets = [0, 1, 1]; number of outputs n = 3.\n\n### To find\n\nFind SSE, half SSE, MSE and the prediction gradients requested in the question.\n\n### Formula — which one and why\n\n**Squared-error objectives.** Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.\n\nŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle error square; phir question ke hisaab se sum, half ya mean.\n\n### Solution — step by step\n\n\n\n\n\n### Given values and loss definitions\nThere are n = 3 prediction–target pairs. Use the supplied predictions directly; no rounding to class labels is required. Let eᵢ = ŷᵢ − yᵢ be the signed residual for pair i.\n\n\n\nSSE is the sum of squared errors. Half SSE and MSE rescale that same sum by different denominators: 2 and n, respectively.\n\n### Step 1: calculate each residual and its square\n| Pair | Prediction ŷᵢ | Target yᵢ | Residual ŷᵢ − yᵢ | Squared residual |\n| 1 | 0.2 | 0 | 0.2 − 0 = 0.2 | (0.2)² = 0.04 |\n| 2 | 0.7 | 1 | 0.7 − 1 = −0.3 | (−0.3)² = 0.09 |\n| 3 | 0.4 | 1 | 0.4 − 1 = −0.6 | (−0.6)² = 0.36 |\n\n### Step 2: sum the squared residuals\n\nSquare each residual before summing. Squaring the sum of signed residuals would be a different quantity, because positive and negative residuals could cancel.\n\n### Step 3: apply each requested normalization\nFor half SSE, the denominator is 2:\n\nFor MSE, the denominator is the number of pairs, n = 3:\n\n\n**Final answer:** SSE = 0.49; half SSE = 0.245; MSE ≈ 0.163333. They represent the same residuals at different scales. Half SSE and MSE coincide when n = 2; they do not coincide for these three nonzero residuals. No derivative is required by this question.\n\n"},{"title":"Drill 3 Natural log and probability","question":["<p class=\"inline-question\"><strong>Question.</strong> Compute −ln(0.9),−ln(0.1), and <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b7f5712356b73942.svg\" alt=\"e^{-\\ln 2}\" width=\"43.29\" height=\"17.39\" style=\"width:43.29px;height:17.39px;aspect-ratio:43.29/17.39\" loading=\"lazy\"></span>.</p>"],"answer":["<h3>Given</h3>","<p>Probabilities: 0.9 and 0.1.</p>","<p>Exponential expression: exp(−ln 2).</p>","<h3>To find</h3>","<p>Find −ln(0.9), −ln(0.1) and exp(−ln 2).</p>","<h3>Formula — which one and why</h3>","<p><strong>Natural logarithms.</strong> The natural logarithm reverses the exponential. A negative log turns a small correct-class probability into a larger positive loss.</p>","<p>ln uses base e ≈ 2.71828. exp(a) means e raised to the power a. Keep the minus outside ln when the question says −ln(p).</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/45890ca9be189629.svg\" alt=\"-\\ln p=\\ln\\frac1p\" width=\"139.90\" height=\"54.29\" style=\"width:139.90px;height:54.29px;aspect-ratio:139.90/54.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/04d92df0f222846e.svg\" alt=\"e^{\\ln a}=a\" width=\"85.35\" height=\"24.08\" style=\"width:85.35px;height:24.08px;aspect-ratio:85.35/24.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5953def5a7690c0e.svg\" alt=\"e^{-\\ln a}=\\frac1a\" width=\"112.43\" height=\"49.80\" style=\"width:112.43px;height:49.80px;aspect-ratio:112.43/49.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> exp banata hai power; ln us power ko wapas nikaalta hai.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The natural logarithm ln tells us the power of e needed to obtain a number. It reverses the exponential operation. A calculator evaluates ln; it is not ordinary division.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:114.24px;--narrow-height:106.38px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/794f58bf694147ad.svg\"><img class=\"math display-math\" src=\"assets/equations/16ba8aa03cb4b3ca.svg\" alt=\"\\ln(e^a)=a,\\qquad e^{\\ln a}=a\\quad(a&gt;0)\" width=\"353.71\" height=\"28.19\" style=\"width:353.71px;height:28.19px;aspect-ratio:353.71/28.19\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ee2a4da74df0c61.svg\" alt=\"e^{-a}=\\frac1{e^a}\" width=\"101.89\" height=\"49.82\" style=\"width:101.89px;height:49.82px;aspect-ratio:101.89/49.82\" loading=\"lazy\"></div>","<h3>Step 1: calculate the first logarithm, then its minus sign</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5deadd8f45d24fdd.svg\" alt=\"\\ln(0.9)\\approx-0.105360516\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.58px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b17db90c0b1eab0.svg\"><img class=\"math display-math\" src=\"assets/equations/a07489f729a63131.svg\" alt=\"-\\ln(0.9)=-(-0.105360516)=0.105360516\" width=\"473.83\" height=\"24.43\" style=\"width:473.83px;height:24.43px;aspect-ratio:473.83/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: calculate the second logarithm</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ccbedb0aa22add9.svg\" alt=\"\\ln(0.1)\\approx-2.302585093\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.58px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc081502a0ccb2a9.svg\"><img class=\"math display-math\" src=\"assets/equations/63eac781aee3c744.svg\" alt=\"-\\ln(0.1)=-(-2.302585093)=2.302585093\" width=\"473.83\" height=\"24.43\" style=\"width:473.83px;height:24.43px;aspect-ratio:473.83/24.43\" loading=\"lazy\"></picture></div>","<p>When these are correct-class probabilities, 0.1 represents a worse prediction than 0.9, so its negative-log loss is larger.</p>","<h3>Step 3: simplify the exponential using the inverse rule</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b612f5289fa6fa44.svg\" alt=\"e^{-\\ln2}=\\frac1{e^{\\ln2}}=\\frac12=0.5\" width=\"257.71\" height=\"51.14\" style=\"width:257.71px;height:51.14px;aspect-ratio:257.71/51.14\" loading=\"lazy\"></div>","<p><strong>Final answers:</strong> 0.105360516, 2.302585093 and 0.5. Use the ln key; base-10 log gives different first and second answers.</p>"],"kind":"practice","id":"mt2-c17-s3","search":"Drill 3 Natural log and probability **Question.** Compute −ln(0.9),−ln(0.1), and \\(e^{-\\ln 2}\\).\n\n**Full solution.**\n\n\n\n### Given\n\nProbabilities: 0.9 and 0.1.\n\nExponential expression: exp(−ln 2).\n\n### To find\n\nFind −ln(0.9), −ln(0.1) and exp(−ln 2).\n\n### Formula — which one and why\n\n**Natural logarithms.** The natural logarithm reverses the exponential. A negative log turns a small correct-class probability into a larger positive loss.\n\nln uses base e ≈ 2.71828. exp(a) means e raised to the power a. Keep the minus outside ln when the question says −ln(p).\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** exp banata hai power; ln us power ko wapas nikaalta hai.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe natural logarithm ln tells us the power of e needed to obtain a number. It reverses the exponential operation. A calculator evaluates ln; it is not ordinary division.\n\n\n### Step 1: calculate the first logarithm, then its minus sign\n\n\n### Step 2: calculate the second logarithm\n\n\nWhen these are correct-class probabilities, 0.1 represents a worse prediction than 0.9, so its negative-log loss is larger.\n### Step 3: simplify the exponential using the inverse rule\n\n**Final answers:** 0.105360516, 2.302585093 and 0.5. Use the ln key; base-10 log gives different first and second answers.\n"},{"title":"Drill 4 Dot product and bias","question":["<p class=\"inline-question\"><strong>Question.</strong> Find z for x = [2,−1,0.5], w = [0.3,0.4,−0.2], b = 0.1; then apply ReLU.</p>"],"answer":["<h3>Given</h3>","<p>Inputs x = [2, −1, 0.5].</p>","<p>Weights w = [0.3, 0.4, −0.2]; bias b = 0.1.</p>","<p>Activation: ReLU.</p>","<h3>To find</h3>","<p>Find the weighted sum z and ReLU output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>A dot product means multiply corresponding entries, then add the products. A bias is one extra value added after the sum. ReLU keeps a positive result and replaces a negative result with zero.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:179.43px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d429a2592c8f926e.svg\"><img class=\"math display-math\" src=\"assets/equations/d2b18ce5f8c75557.svg\" alt=\"z=w_1x_1+w_2x_2+w_3x_3+b,\\qquad a=\\max(0,z)\" width=\"506.63\" height=\"24.43\" style=\"width:506.63px;height:24.43px;aspect-ratio:506.63/24.43\" loading=\"lazy\"></picture></div>","<p>Here x contains inputs, w contains weights, b is bias, z is the weighted sum, and a is the activated output.</p>","<h3>Step 1: multiply the matching pairs</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6092f2a718fe356.svg\" alt=\"w_1x_1=0.3\\times2=0.6\" width=\"222.51\" height=\"19.94\" style=\"width:222.51px;height:19.94px;aspect-ratio:222.51/19.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d39443d0dbfaaa2b.svg\" alt=\"w_2x_2=0.4\\times(-1)=-0.4\" width=\"279.55\" height=\"24.43\" style=\"width:279.55px;height:24.43px;aspect-ratio:279.55/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6f257d4f869d8fa2.svg\"><img class=\"math display-math\" src=\"assets/equations/8173a34611c8e936.svg\" alt=\"w_3x_3=(-0.2)\\times0.5=-0.1\" width=\"298.56\" height=\"24.43\" style=\"width:298.56px;height:24.43px;aspect-ratio:298.56/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: add all products and add bias once</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72dd56dcc4bb45b6.svg\"><img class=\"math display-math\" src=\"assets/equations/aa77eba1df26bb28.svg\" alt=\"z=0.6+(-0.4)+(-0.1)+0.1\" width=\"334.51\" height=\"24.43\" style=\"width:334.51px;height:24.43px;aspect-ratio:334.51/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3991f5f0c7df172.svg\" alt=\"z=0.2-0.1+0.1=0.2\" width=\"261.18\" height=\"18.27\" style=\"width:261.18px;height:18.27px;aspect-ratio:261.18/18.27\" loading=\"lazy\"></div>","<h3>Step 3: apply the activation</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b62624e146d1934.svg\" alt=\"a=\\max(0,0.2)=0.2\" width=\"228.12\" height=\"24.43\" style=\"width:228.12px;height:24.43px;aspect-ratio:228.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> weighted sum z = 0.2; ReLU output a = 0.2. The two numbers happen to match because z is positive.</p>"],"kind":"practice","id":"mt2-c17-s4","search":"Drill 4 Dot product and bias **Question.** Find z for x = [2,−1,0.5], w = [0.3,0.4,−0.2], b = 0.1; then apply ReLU.\n\n**Full solution.**\n\n\n\n### Given\n\nInputs x = [2, −1, 0.5].\n\nWeights w = [0.3, 0.4, −0.2]; bias b = 0.1.\n\nActivation: ReLU.\n\n### To find\n\nFind the weighted sum z and ReLU output.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nA dot product means multiply corresponding entries, then add the products. A bias is one extra value added after the sum. ReLU keeps a positive result and replaces a negative result with zero.\n\nHere x contains inputs, w contains weights, b is bias, z is the weighted sum, and a is the activated output.\n### Step 1: multiply the matching pairs\n\n\n\n### Step 2: add all products and add bias once\n\n\n### Step 3: apply the activation\n\n**Final answer:** weighted sum z = 0.2; ReLU output a = 0.2. The two numbers happen to match because z is positive.\n"},{"title":"Drill 5 Matrix rows receive inputs","question":["<p class=\"inline-question\"><strong>Question.</strong> For the weight matrix W shown below, x = [2,1], b = [0.5,−0.5], find Wx+b and ReLU.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_ed1fcbfdf5.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_ed1fcbfdf5.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/47c671c1553de484.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\-1 &amp; 3\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>.</p>","<p>Input column x = [2,1]ᵀ; bias column b = [0.5,−0.5]ᵀ.</p>","<p>Activation: ReLU on each result.</p>","<h3>To find</h3>","<p>Find Wx+b and the activated output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Row–column multiplication.</strong> Each receiving neuron uses one weight row. Multiply that row by the input column, add the products, then add that neuron’s bias.</p>","<p>Wⱼᵢ = weight from input i to receiver j; xᵢ = input i; bⱼ = bias of receiver j; zⱼ = its preactivation. A superscript T means transpose: exchange rows and columns.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc40cdac8ad4c81c.svg\" alt=\"z_j=\\sum_i W_{ji}x_i+b_j\" width=\"202.09\" height=\"52.35\" style=\"width:202.09px;height:52.35px;aspect-ratio:202.09/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek row × poora input column = ek receiving neuron ka answer.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>Each row supplies the weights of one receiving neuron. Multiply that row by the input column, then add that neuron&#x27;s own bias. The two biases are separate; do not add both to every row.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.73px;--narrow-height:64.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa52f339dd0d5a91.svg\"><img class=\"math display-math\" src=\"assets/equations/6f48223c352868b0.svg\" alt=\"z=Wx+b,\\qquad a_j=\\max(0,z_j)\" width=\"346.35\" height=\"25.52\" style=\"width:346.35px;height:25.52px;aspect-ratio:346.35/25.52\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e990284b43290d2.svg\" alt=\"W=\\begin{bmatrix}1&amp;2\\\\-1&amp;3\\end{bmatrix},\\quad x=\\begin{bmatrix}2\\\\1\\end{bmatrix},\\quad b=\\begin{bmatrix}0.5\\\\-0.5\\end{bmatrix}\" width=\"426.16\" height=\"58.64\" style=\"width:426.16px;height:58.64px;aspect-ratio:426.16/58.64\" loading=\"lazy\"></div>","<h3>Step 1: calculate receiving neuron 1 from row 1</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eaa341baa6e16b1f.svg\"><img class=\"math display-math\" src=\"assets/equations/46e8f36136a4c4d2.svg\" alt=\"z_1=(1\\times2)+(2\\times1)+0.5\" width=\"292.20\" height=\"24.43\" style=\"width:292.20px;height:24.43px;aspect-ratio:292.20/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/50386fe91979c412.svg\" alt=\"z_1=2+2+0.5=4.5\" width=\"233.83\" height=\"20.21\" style=\"width:233.83px;height:20.21px;aspect-ratio:233.83/20.21\" loading=\"lazy\"></div>","<h3>Step 2: calculate receiving neuron 2 from row 2</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b0b4c769cba96d49.svg\"><img class=\"math display-math\" src=\"assets/equations/fe996afd770f8834.svg\" alt=\"z_2=((-1)\\times2)+(3\\times1)+(-0.5)\" width=\"368.25\" height=\"24.43\" style=\"width:368.25px;height:24.43px;aspect-ratio:368.25/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8bdba182228536bc.svg\" alt=\"z_2=-2+3-0.5=0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<h3>Step 3: apply ReLU to each entry</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/43cee11d40484528.svg\"><img class=\"math display-math\" src=\"assets/equations/e48d03ac9b49ea16.svg\" alt=\"a_1=\\max(0,4.5)=4.5,\\qquad a_2=\\max(0,0.5)=0.5\" width=\"537.30\" height=\"24.43\" style=\"width:537.30px;height:24.43px;aspect-ratio:537.30/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b93dfe6da27f9705.svg\" alt=\"z=\\begin{bmatrix}4.5\\\\0.5\\end{bmatrix},\\qquad a=\\begin{bmatrix}4.5\\\\0.5\\end{bmatrix}\" width=\"263.25\" height=\"58.64\" style=\"width:263.25px;height:58.64px;aspect-ratio:263.25/58.64\" loading=\"lazy\"></div>","<p>The shape is 2 rows by 1 column: one output for each receiving row.</p>"],"kind":"practice","id":"mt2-c17-s5","search":"Drill 5 Matrix rows receive inputs **Question.** For the weight matrix W shown below, x = [2,1], b = [0.5,−0.5], find Wx+b and ReLU.\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nW = .\n\nInput column x = [2,1]ᵀ; bias column b = [0.5,−0.5]ᵀ.\n\nActivation: ReLU on each result.\n\n### To find\n\nFind Wx+b and the activated output.\n\n### Formula — which one and why\n\n**Row–column multiplication.** Each receiving neuron uses one weight row. Multiply that row by the input column, add the products, then add that neuron’s bias.\n\nWⱼᵢ = weight from input i to receiver j; xᵢ = input i; bⱼ = bias of receiver j; zⱼ = its preactivation. A superscript T means transpose: exchange rows and columns.\n\n\n\n**Yaad rakhne ka cue:** Ek row × poora input column = ek receiving neuron ka answer.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nEach row supplies the weights of one receiving neuron. Multiply that row by the input column, then add that neuron's own bias. The two biases are separate; do not add both to every row.\n\n\n### Step 1: calculate receiving neuron 1 from row 1\n\n\n### Step 2: calculate receiving neuron 2 from row 2\n\n\n### Step 3: apply ReLU to each entry\n\n\nThe shape is 2 rows by 1 column: one output for each receiving row.\n"},{"title":"Drill 6 Chain rule on a tiny loss","question":["<p class=\"inline-question\"><strong>Question.</strong> Let o = wx+b, L = ½(o−y)², x = 3, w = 0.2, b = 0.1, y = 1. Find dL/dw, dL/db and update at η = 0.1.</p>"],"answer":["<h3>Given</h3>","<p>Model: o = wx+b; loss L = ½(o−y)².</p>","<p>x = 3; y = 1; w = 0.2; b = 0.1.</p>","<p>Learning rate η = 0.1.</p>","<h3>To find</h3>","<p>Find ∂L/∂w, ∂L/∂b and the updated weight and bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule for a linear neuron.</strong> The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.</p>","<p>z = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/00f49c1127dda70e.svg\" alt=\"z=wx+b\" width=\"115.77\" height=\"18.96\" style=\"width:115.77px;height:18.96px;aspect-ratio:115.77/18.96\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f50d7e1cde6462d5.svg\" alt=\"L=\\frac12(z-y)^2\" width=\"155.08\" height=\"49.55\" style=\"width:155.08px;height:49.55px;aspect-ratio:155.08/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/955c63d58ce8cb9b.svg\" alt=\"g_w=\\frac{\\partial L}{\\partial w}=(z-y)x\" width=\"219.49\" height=\"51.29\" style=\"width:219.49px;height:51.29px;aspect-ratio:219.49/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a5a6192e644e19b.svg\" alt=\"g_b=\\frac{\\partial L}{\\partial b}=z-y\" width=\"180.69\" height=\"51.29\" style=\"width:180.69px;height:51.29px;aspect-ratio:180.69/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33df8d5a70c57c14.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_w\" width=\"167.42\" height=\"19.53\" style=\"width:167.42px;height:19.53px;aspect-ratio:167.42/19.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c2843cb0410cd77b.svg\" alt=\"b_{\\mathrm{new}}=b-\\eta g_b\" width=\"148.44\" height=\"22.24\" style=\"width:148.44px;height:22.24px;aspect-ratio:148.44/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek path mein multiply; alag paths mil rahe hon toh add.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The output o is a linear prediction: no sigmoid or ReLU is specified. Changing w changes o, which changes L. The chain rule multiplies those linked effects.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:155.56px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90379cab01aa101e.svg\"><img class=\"math display-math\" src=\"assets/equations/e9fdca67a77fbb78.svg\" alt=\"o=wx+b,\\qquad L=\\frac12(o-y)^2\" width=\"331.56\" height=\"49.55\" style=\"width:331.56px;height:49.55px;aspect-ratio:331.56/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:134.29px;--narrow-height:183.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ae2da1d297dac40.svg\"><img class=\"math display-math\" src=\"assets/equations/ca7badc8e4620a3c.svg\" alt=\"\\frac{\\partial L}{\\partial o}=o-y,\\quad \\frac{\\partial o}{\\partial w}=x,\\quad \\frac{\\partial o}{\\partial b}=1\" width=\"367.97\" height=\"51.29\" style=\"width:367.97px;height:51.29px;aspect-ratio:367.97/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:168.13px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a63ae410089093d5.svg\"><img class=\"math display-math\" src=\"assets/equations/6ffe92ced0000c23.svg\" alt=\"\\frac{\\partial L}{\\partial w}=(o-y)x,\\qquad \\frac{\\partial L}{\\partial b}=o-y\" width=\"348.57\" height=\"51.29\" style=\"width:348.57px;height:51.29px;aspect-ratio:348.57/51.29\" loading=\"lazy\"></picture></div>","<p>The learning rate η says how much of the gradient to subtract.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.24px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9cca82416f4ee903.svg\"><img class=\"math display-math\" src=\"assets/equations/8c595e12402e35b1.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta\\frac{\\partial L}{\\partial w},\\qquad b_{\\mathrm{new}}=b-\\eta\\frac{\\partial L}{\\partial b}\" width=\"411.74\" height=\"51.29\" style=\"width:411.74px;height:51.29px;aspect-ratio:411.74/51.29\" loading=\"lazy\"></picture></div>","<h3>Step 1: obtain the current prediction and error</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.86px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d8d618e9d2cfc7d.svg\"><img class=\"math display-math\" src=\"assets/equations/259368438902dc69.svg\" alt=\"o=(0.2\\times3)+0.1=0.6+0.1=0.7\" width=\"386.58\" height=\"24.43\" style=\"width:386.58px;height:24.43px;aspect-ratio:386.58/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f0bd8184760ad600.svg\" alt=\"o-y=0.7-1=-0.3\" width=\"242.42\" height=\"21.52\" style=\"width:242.42px;height:21.52px;aspect-ratio:242.42/21.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.26px;--narrow-height:113.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/21397d642a37130f.svg\"><img class=\"math display-math\" src=\"assets/equations/6ccc7a83cb90d797.svg\" alt=\"L=\\frac12(-0.3)^2=\\frac12(0.09)=0.045\" width=\"358.35\" height=\"49.55\" style=\"width:358.35px;height:49.55px;aspect-ratio:358.35/49.55\" loading=\"lazy\"></picture></div>","<h3>Step 2: calculate both gradients from this same prediction</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ed97f79ab4475569.svg\" alt=\"\\frac{\\partial L}{\\partial w}=(-0.3)\\times3=-0.9\" width=\"268.81\" height=\"51.29\" style=\"width:268.81px;height:51.29px;aspect-ratio:268.81/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/80efe080f6cbf4d3.svg\" alt=\"\\frac{\\partial L}{\\partial b}=(-0.3)\\times1=-0.3\" width=\"267.96\" height=\"51.29\" style=\"width:267.96px;height:51.29px;aspect-ratio:267.96/51.29\" loading=\"lazy\"></div>","<h3>Step 3: update the weight</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/187fe0232f317977.svg\"><img class=\"math display-math\" src=\"assets/equations/c80322ecffe9a16b.svg\" alt=\"w_{\\mathrm{new}}=0.2-0.1(-0.9)=0.2-(-0.09)=0.29\" width=\"494.61\" height=\"24.43\" style=\"width:494.61px;height:24.43px;aspect-ratio:494.61/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 4: update the bias</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/15129640706302ac.svg\"><img class=\"math display-math\" src=\"assets/equations/c3e5531ea9063ace.svg\" alt=\"b_{\\mathrm{new}}=0.1-0.1(-0.3)=0.1-(-0.03)=0.13\" width=\"487.59\" height=\"24.43\" style=\"width:487.59px;height:24.43px;aspect-ratio:487.59/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> weight gradient −0.9; bias gradient −0.3; new weight 0.29; new bias 0.13. Both updates use the old forward pass.</p>"],"kind":"practice","id":"mt2-c17-s6","search":"Drill 6 Chain rule on a tiny loss **Question.** Let o = wx+b, L = ½(o−y)², x = 3, w = 0.2, b = 0.1, y = 1. Find dL/dw, dL/db and update at η = 0.1.\n\n**Full solution.**\n\n\n\n### Given\n\nModel: o = wx+b; loss L = ½(o−y)².\n\nx = 3; y = 1; w = 0.2; b = 0.1.\n\nLearning rate η = 0.1.\n\n### To find\n\nFind ∂L/∂w, ∂L/∂b and the updated weight and bias.\n\n### Formula — which one and why\n\n**Chain rule for a linear neuron.** The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.\n\nz = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.\n\n\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek path mein multiply; alag paths mil rahe hon toh add.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe output o is a linear prediction: no sigmoid or ReLU is specified. Changing w changes o, which changes L. The chain rule multiplies those linked effects.\n\n\n\nThe learning rate η says how much of the gradient to subtract.\n\n### Step 1: obtain the current prediction and error\n\n\n\n### Step 2: calculate both gradients from this same prediction\n\n\n### Step 3: update the weight\n\n### Step 4: update the bias\n\n**Final answer:** weight gradient −0.9; bias gradient −0.3; new weight 0.29; new bias 0.13. Both updates use the old forward pass.\n"},{"title":"Drill 7 Sigmoid with binary cross entropy","question":["<p class=\"inline-question\"><strong>Question.</strong> A binary classifier has logit z = 1, target 1. Find probability, BCE and the gradient with respect to z.</p>"],"answer":["<h3>Given</h3>","<p>Logit z = 1; binary target y = 1.</p>","<p>Output: sigmoid; loss: binary cross-entropy.</p>","<h3>To find</h3>","<p>Find probability, BCE and the loss derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Binary cross-entropy.</strong> For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.</p>","<p>y is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bbef5a5d1c7047f.svg\" alt=\"\\frac{\\partial L}{\\partial z}=p-y\" width=\"127.94\" height=\"51.29\" style=\"width:127.94px;height:51.29px;aspect-ratio:127.94/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>A logit is the raw score before sigmoid. Sigmoid converts it to a probability p. The target y = 1 says the positive class is correct. Binary cross-entropy measures how little probability the model assigned to the correct binary outcome.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06236932ea7e53d0.svg\" alt=\"p=\\frac1{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6b608fdfba7ba2f.svg\" alt=\"L=-\\left[y\\ln p+(1-y)\\ln(1-p)\\right]\" width=\"339.45\" height=\"24.43\" style=\"width:339.45px;height:24.43px;aspect-ratio:339.45/24.43\" loading=\"lazy\"></div>","<p>For sigmoid combined with this loss, the gradient with respect to the logit has the simplified form:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bbef5a5d1c7047f.svg\" alt=\"\\frac{\\partial L}{\\partial z}=p-y\" width=\"127.94\" height=\"51.29\" style=\"width:127.94px;height:51.29px;aspect-ratio:127.94/51.29\" loading=\"lazy\"></div>","<h3>Step 1: convert logit 1 into probability</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8b081af8baa5f1b.svg\" alt=\"e^{-1}\\approx0.367879441\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f1586fb666c5061e.svg\" alt=\"1+e^{-1}\\approx1.367879441\" width=\"239.13\" height=\"23.60\" style=\"width:239.13px;height:23.60px;aspect-ratio:239.13/23.60\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:184.59px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f55393e129c6628.svg\"><img class=\"math display-math\" src=\"assets/equations/6617ec66ea10120e.svg\" alt=\"p=\\frac1{1.367879441}\\approx0.731058579\" width=\"346.14\" height=\"50.09\" style=\"width:346.14px;height:50.09px;aspect-ratio:346.14/50.09\" loading=\"lazy\"></picture></div>","<h3>Step 2: substitute the target in the full loss formula</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fca94e6b25348fdc.svg\" alt=\"L=-\\left[1\\ln(0.731058579)+(1-1)\\ln(1-0.731058579)\\right]\" width=\"588.23\" height=\"24.43\" style=\"width:588.23px;height:24.43px;aspect-ratio:588.23/24.43\" loading=\"lazy\"></div>","<p>The second term has multiplier zero, so it contributes zero.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f41a1bed5052539d.svg\"><img class=\"math display-math\" src=\"assets/equations/36829459a4aa6b4b.svg\" alt=\"L=-\\ln(0.731058579)\\approx0.313261688\" width=\"402.21\" height=\"24.43\" style=\"width:402.21px;height:24.43px;aspect-ratio:402.21/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 3: calculate the combined gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.86px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d503567052ec89af.svg\"><img class=\"math display-math\" src=\"assets/equations/24cc736ea2ce6146.svg\" alt=\"\\frac{\\partial L}{\\partial z}=0.731058579-1=-0.268941421\" width=\"425.41\" height=\"51.29\" style=\"width:425.41px;height:51.29px;aspect-ratio:425.41/51.29\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> probability ≈ 0.731059; BCE ≈ 0.313262; logit gradient ≈ −0.268941. The simplified gradient already includes sigmoid&#x27;s effect. Multiplying by sigmoid&#x27;s slope again would apply it twice.</p>"],"kind":"practice","id":"mt2-c17-s7","search":"Drill 7 Sigmoid with binary cross entropy **Question.** A binary classifier has logit z = 1, target 1. Find probability, BCE and the gradient with respect to z.\n\n**Full solution.**\n\n\n\n### Given\n\nLogit z = 1; binary target y = 1.\n\nOutput: sigmoid; loss: binary cross-entropy.\n\n### To find\n\nFind probability, BCE and the loss derivative with respect to z.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Binary cross-entropy.** For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.\n\ny is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.\n\n\n\n\n\n**Yaad rakhne ka cue:** Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nA logit is the raw score before sigmoid. Sigmoid converts it to a probability p. The target y = 1 says the positive class is correct. Binary cross-entropy measures how little probability the model assigned to the correct binary outcome.\n\n\nFor sigmoid combined with this loss, the gradient with respect to the logit has the simplified form:\n\n### Step 1: convert logit 1 into probability\n\n\n\n### Step 2: substitute the target in the full loss formula\n\nThe second term has multiplier zero, so it contributes zero.\n\n### Step 3: calculate the combined gradient\n\n**Final answer:** probability ≈ 0.731059; BCE ≈ 0.313262; logit gradient ≈ −0.268941. The simplified gradient already includes sigmoid's effect. Multiplying by sigmoid's slope again would apply it twice.\n"},{"title":"Drill 8 Activation contrast","question":["<p class=\"inline-question\"><strong>Question.</strong> For z = [−3,0,2], find ReLU and Leaky ReLU with α = 0.1, and the sigmoid derivative at z = 0.</p>"],"answer":["<h3>Given</h3>","<p>Inputs z = [−3,0,2].</p>","<p>Leaky-ReLU negative slope α = 0.1.</p>","<p>For the sigmoid derivative, use z = 0.</p>","<h3>To find</h3>","<p>Find ReLU and Leaky-ReLU outputs and the sigmoid slope at zero.</p>","<h3>Formula — which one and why</h3>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<h3>Solution — step by step</h3>","<h3>Formulas and their meanings</h3>","<p>ReLU compares the input with zero and returns the larger value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<p>Leaky ReLU uses the input unchanged when nonnegative, and multiplies it by α when negative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<h3>Step 1: apply ReLU separately to all three inputs</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.46px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3202f6e374a86c4c.svg\"><img class=\"math display-math\" src=\"assets/equations/7a53989c39d25faa.svg\" alt=\"\\max(0,-3)=0,\\quad \\max(0,0)=0,\\quad \\max(0,2)=2\" width=\"523.36\" height=\"24.43\" style=\"width:523.36px;height:24.43px;aspect-ratio:523.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>ReLU output = [0, 0, 2].</strong></p>","<h3>Step 2: use α = 0.1 only on the negative input</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/189f052516957693.svg\" alt=\"0.1\\times(-3)=-0.3\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<p>The zero and positive entries remain 0 and 2. <strong>Leaky ReLU output = [−0.3, 0, 2].</strong></p>","<h3>Step 3: calculate sigmoid before its derivative</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.01px;--narrow-height:92.09px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7727ce70c548ec20.svg\"><img class=\"math display-math\" src=\"assets/equations/4a542f0b5de210cf.svg\" alt=\"\\sigma(z)=\\frac1{1+e^{-z}},\\qquad \\sigma&#x27;(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"452.38\" height=\"51.56\" style=\"width:452.38px;height:51.56px;aspect-ratio:452.38/51.56\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.29px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1ef72ba6a1deae0f.svg\"><img class=\"math display-math\" src=\"assets/equations/8b3dd0cfc097c6b9.svg\" alt=\"\\sigma(0)=\\frac1{1+e^0}=\\frac1{1+1}=0.5\" width=\"314.11\" height=\"52.39\" style=\"width:314.11px;height:52.39px;aspect-ratio:314.11/52.39\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.09px;--narrow-height:64.97px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c6f6bc13772ea829.svg\"><img class=\"math display-math\" src=\"assets/equations/20af7f249f7a71f8.svg\" alt=\"\\sigma&#x27;(0)=0.5(1-0.5)=0.5\\times0.5=0.25\" width=\"409.03\" height=\"25.88\" style=\"width:409.03px;height:25.88px;aspect-ratio:409.03/25.88\" loading=\"lazy\"></picture></div>","<p>The sigmoid <strong>value</strong> is 0.5 but its <strong>slope</strong> is 0.25. They are different quantities.</p>"],"kind":"practice","id":"mt2-c17-s8","search":"Drill 8 Activation contrast **Question.** For z = [−3,0,2], find ReLU and Leaky ReLU with α = 0.1, and the sigmoid derivative at z = 0.\n\n**Full solution.**\n\n\n\n### Given\n\nInputs z = [−3,0,2].\n\nLeaky-ReLU negative slope α = 0.1.\n\nFor the sigmoid derivative, use z = 0.\n\n### To find\n\nFind ReLU and Leaky-ReLU outputs and the sigmoid slope at zero.\n\n### Formula — which one and why\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and their meanings\nReLU compares the input with zero and returns the larger value.\n\nLeaky ReLU uses the input unchanged when nonnegative, and multiplies it by α when negative.\n\n### Step 1: apply ReLU separately to all three inputs\n\n**ReLU output = [0, 0, 2].**\n### Step 2: use α = 0.1 only on the negative input\n\nThe zero and positive entries remain 0 and 2. **Leaky ReLU output = [−0.3, 0, 2].**\n### Step 3: calculate sigmoid before its derivative\n\n\n\nThe sigmoid **value** is 0.5 but its **slope** is 0.25. They are different quantities.\n"},{"title":"Drill 9 Softmax and true class loss","question":["<p class=\"inline-question\"><strong>Question.</strong> Scores = [1,2,0], true one-hot class = [0,1,0]. Find probabilities and categorical cross-entropy.</p>"],"answer":["<h3>Given</h3>","<p>Logits = [1,2,0].</p>","<p>One-hot target = [0,1,0]: class 2 is correct.</p>","<h3>To find</h3>","<p>Find all three softmax probabilities and CCE.</p>","<h3>Formula — which one and why</h3>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The scores z are raw class scores. Softmax converts the whole group into class probabilities. The label [0,1,0] says class 2 is correct; it is not a set of predicted probabilities.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.27px;--narrow-height:118.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd0c8ddf71d7e5e7.svg\"><img class=\"math display-math\" src=\"assets/equations/b901ae0600ed0d36.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_jz_j\" width=\"324.43\" height=\"63.31\" style=\"width:324.43px;height:63.31px;aspect-ratio:324.43/63.31\" loading=\"lazy\"></picture></div>","<p>Subtracting the same c from every score keeps the probabilities unchanged and avoids very large exponentials.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a21d413c89b5a80.svg\" alt=\"L_{\\mathrm{CCE}}=-\\sum_i y_i\\ln p_i\" width=\"219.18\" height=\"52.35\" style=\"width:219.18px;height:52.35px;aspect-ratio:219.18/52.35\" loading=\"lazy\"></div>","<h3>Step 1: subtract the largest score</h3>","<p>The largest of [1,2,0] is 2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72ceba57b734c648.svg\"><img class=\"math display-math\" src=\"assets/equations/b6bd92da9301ed16.svg\" alt=\"[1-2,\\;2-2,\\;0-2]=[-1,0,-2]\" width=\"354.38\" height=\"24.43\" style=\"width:354.38px;height:24.43px;aspect-ratio:354.38/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: calculate the three exponentials</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:203.84px;--narrow-height:112.44px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b2c277f81e3d9881.svg\"><img class=\"math display-math\" src=\"assets/equations/c1751b34781aca62.svg\" alt=\"e^{-1}=0.367879441,\\quad e^0=1,\\quad e^{-2}=0.135335283\" width=\"531.54\" height=\"26.34\" style=\"width:531.54px;height:26.34px;aspect-ratio:531.54/26.34\" loading=\"lazy\"></picture></div>","<h3>Step 3: add them to get one common denominator</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.87px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc4d03dcae0355c5.svg\"><img class=\"math display-math\" src=\"assets/equations/95814cf2d0de3a7e.svg\" alt=\"D=0.367879441+1+0.135335283=1.503214724\" width=\"544.26\" height=\"18.69\" style=\"width:544.26px;height:18.69px;aspect-ratio:544.26/18.69\" loading=\"lazy\"></picture></div>","<h3>Step 4: divide each exponential by this denominator</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa686bb14848b0d1.svg\"><img class=\"math display-math\" src=\"assets/equations/55ba241642d89ad8.svg\" alt=\"p_1=\\frac{0.367879441}{1.503214724}=0.244728471\" width=\"356.81\" height=\"50.36\" style=\"width:356.81px;height:50.36px;aspect-ratio:356.81/50.36\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/361efa91829285c7.svg\"><img class=\"math display-math\" src=\"assets/equations/b2c010d4d592ad18.svg\" alt=\"p_2=\\frac{1}{1.503214724}=0.665240956\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/54c91e5ed1921172.svg\"><img class=\"math display-math\" src=\"assets/equations/8024840665a8cd1c.svg\" alt=\"p_3=\\frac{0.135335283}{1.503214724}=0.090030573\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p>The probabilities add to 1, apart from rounding. Class 2 has the highest score and the highest probability.</p>","<h3>Step 5: use the probability of the correct class in CCE</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:316.01px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cc77914badc24790.svg\"><img class=\"math display-math\" src=\"assets/equations/1e41b81b1fc86ad6.svg\" alt=\"L=-[0\\ln p_1+1\\ln p_2+0\\ln p_3]=-\\ln p_2\" width=\"435.73\" height=\"24.43\" style=\"width:435.73px;height:24.43px;aspect-ratio:435.73/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65db0db7f14d7ab8.svg\"><img class=\"math display-math\" src=\"assets/equations/c6ddf889d37419c3.svg\" alt=\"L=-\\ln(0.665240956)=0.407605964\" width=\"402.21\" height=\"24.43\" style=\"width:402.21px;height:24.43px;aspect-ratio:402.21/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> probabilities ≈ [0.244728, 0.665241, 0.090031]; CCE ≈ 0.407606.</p>"],"kind":"practice","id":"mt2-c17-s9","search":"Drill 9 Softmax and true class loss **Question.** Scores = [1,2,0], true one-hot class = [0,1,0]. Find probabilities and categorical cross-entropy.\n\n**Full solution.**\n\n\n\n### Given\n\nLogits = [1,2,0].\n\nOne-hot target = [0,1,0]: class 2 is correct.\n\n### To find\n\nFind all three softmax probabilities and CCE.\n\n### Formula — which one and why\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe scores z are raw class scores. Softmax converts the whole group into class probabilities. The label [0,1,0] says class 2 is correct; it is not a set of predicted probabilities.\n\nSubtracting the same c from every score keeps the probabilities unchanged and avoids very large exponentials.\n\n### Step 1: subtract the largest score\nThe largest of [1,2,0] is 2.\n\n### Step 2: calculate the three exponentials\n\n### Step 3: add them to get one common denominator\n\n### Step 4: divide each exponential by this denominator\n\n\n\nThe probabilities add to 1, apart from rounding. Class 2 has the highest score and the highest probability.\n### Step 5: use the probability of the correct class in CCE\n\n\n**Final answer:** probabilities ≈ [0.244728, 0.665241, 0.090031]; CCE ≈ 0.407606.\n"},{"title":"Drill 10 Sigmoid neuron gradient","question":["<p class=\"inline-question\"><strong>Question.</strong> x = 2, w = 0.5, b = 0, y = 1, half squared loss, η = 0.1. Find one weight and bias update.</p>"],"answer":["<h3>Given</h3>","<p>x = 2; w = 0.5; b = 0; target y = 1.</p>","<p>Activation: sigmoid; loss: half squared error.</p>","<p>Learning rate η = 0.1.</p>","<h3>To find</h3>","<p>Find the output, delta, weight/bias gradients and one update.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>Here the loss is half squared error. It is different from binary cross-entropy, so we include the sigmoid derivative explicitly.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:156.01px;--narrow-height:154.86px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72569e3d1cf18215.svg\"><img class=\"math display-math\" src=\"assets/equations/c39b7cba136e59b8.svg\" alt=\"z=wx+b,\\quad p=\\frac1{1+e^{-z}},\\quad L=\\frac12(p-y)^2\" width=\"474.97\" height=\"51.56\" style=\"width:474.97px;height:51.56px;aspect-ratio:474.97/51.56\" loading=\"lazy\"></picture></div>","<p>The symbol δ (delta) is a short name for the loss gradient with respect to the neuron&#x27;s raw score z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf8f40120fc7de9a.svg\" alt=\"\\delta=(p-y)p(1-p)\" width=\"202.25\" height=\"24.43\" style=\"width:202.25px;height:24.43px;aspect-ratio:202.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6678df97903ca342.svg\" alt=\"\\frac{\\partial L}{\\partial w}=\\delta x,\\quad \\frac{\\partial L}{\\partial b}=\\delta\" width=\"219.45\" height=\"51.29\" style=\"width:219.45px;height:51.29px;aspect-ratio:219.45/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.98px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e125df8665bd715.svg\"><img class=\"math display-math\" src=\"assets/equations/46cbd30453d64730.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta\\delta x,\\quad b_{\\mathrm{new}}=b-\\eta\\delta\" width=\"339.68\" height=\"22.80\" style=\"width:339.68px;height:22.80px;aspect-ratio:339.68/22.80\" loading=\"lazy\"></picture></div>","<h3>Step 1: weighted sum and sigmoid</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88322b08817273b7.svg\" alt=\"z=0.5\\times2+0=1\" width=\"204.15\" height=\"18.27\" style=\"width:204.15px;height:18.27px;aspect-ratio:204.15/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/496f72f75e4bdba9.svg\"><img class=\"math display-math\" src=\"assets/equations/d48b6096bc280c6f.svg\" alt=\"p=\\frac1{1+e^{-1}}=0.731058579\" width=\"294.75\" height=\"52.39\" style=\"width:294.75px;height:52.39px;aspect-ratio:294.75/52.39\" loading=\"lazy\"></picture></div>","<h3>Step 2: error and activation slope</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/95ba7a4e62bbaee0.svg\"><img class=\"math display-math\" src=\"assets/equations/8773c0aada00e672.svg\" alt=\"p-y=0.731058579-1=-0.268941421\" width=\"438.33\" height=\"21.55\" style=\"width:438.33px;height:21.55px;aspect-ratio:438.33/21.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.22px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe81a8ae8e93cc3b.svg\"><img class=\"math display-math\" src=\"assets/equations/116080684bb307ac.svg\" alt=\"p(1-p)=0.731058579\\times0.268941421=0.196611933\" width=\"567.62\" height=\"24.43\" style=\"width:567.62px;height:24.43px;aspect-ratio:567.62/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 3: multiply the linked effects to obtain delta</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.42px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca75a0d20742f652.svg\"><img class=\"math display-math\" src=\"assets/equations/c963a470be9b7811.svg\" alt=\"\\delta=(-0.268941421)\\times0.196611933=-0.052877093\" width=\"549.81\" height=\"24.43\" style=\"width:549.81px;height:24.43px;aspect-ratio:549.81/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 4: multiply delta by the input to each parameter</h3>","<p>The weight receives x = 2. The bias effectively receives the constant input 1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.65px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/909d6c4ba3b4dba5.svg\"><img class=\"math display-math\" src=\"assets/equations/904a6dac1e6b4e5a.svg\" alt=\"\\frac{\\partial L}{\\partial w}=(-0.052877093)\\times2=-0.105754186\" width=\"464.29\" height=\"51.29\" style=\"width:464.29px;height:51.29px;aspect-ratio:464.29/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/385f9ff4016d4aa5.svg\" alt=\"\\frac{\\partial L}{\\partial b}=-0.052877093\" width=\"221.78\" height=\"51.29\" style=\"width:221.78px;height:51.29px;aspect-ratio:221.78/51.29\" loading=\"lazy\"></div>","<h3>Step 5: subtract learning rate times each gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/48c8e5f15b7994a8.svg\"><img class=\"math display-math\" src=\"assets/equations/b4289d1b3f149e0a.svg\" alt=\"w_{\\mathrm{new}}=0.5-0.1(-0.105754186)=0.510575419\" width=\"502.72\" height=\"24.43\" style=\"width:502.72px;height:24.43px;aspect-ratio:502.72/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b7af577aaec3d7cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bc4fa856481c3256.svg\" alt=\"b_{\\mathrm{new}}=0-0.1(-0.052877093)=0.005287709\" width=\"476.69\" height=\"24.43\" style=\"width:476.69px;height:24.43px;aspect-ratio:476.69/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> new weight ≈ 0.510575419; new bias ≈ 0.005287709. Subtracting negative gradients increases both values here.</p>"],"kind":"practice","id":"mt2-c17-s10","search":"Drill 10 Sigmoid neuron gradient **Question.** x = 2, w = 0.5, b = 0, y = 1, half squared loss, η = 0.1. Find one weight and bias update.\n\n**Full solution.**\n\n\n\n### Given\n\nx = 2; w = 0.5; b = 0; target y = 1.\n\nActivation: sigmoid; loss: half squared error.\n\nLearning rate η = 0.1.\n\n### To find\n\nFind the output, delta, weight/bias gradients and one update.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nHere the loss is half squared error. It is different from binary cross-entropy, so we include the sigmoid derivative explicitly.\n\nThe symbol δ (delta) is a short name for the loss gradient with respect to the neuron's raw score z.\n\n\n\n### Step 1: weighted sum and sigmoid\n\n\n### Step 2: error and activation slope\n\n\n### Step 3: multiply the linked effects to obtain delta\n\n### Step 4: multiply delta by the input to each parameter\nThe weight receives x = 2. The bias effectively receives the constant input 1.\n\n\n### Step 5: subtract learning rate times each gradient\n\n\n**Final answer:** new weight ≈ 0.510575419; new bias ≈ 0.005287709. Subtracting negative gradients increases both values here.\n"},{"title":"Drill 11 Full ReLU backpropagation","question":["<p class=\"inline-question\"><strong>Question.</strong> Input x = [1, 2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.1. Use half squared loss and update all weights and biases.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_0601bfe757.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_0601bfe757.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_drill13.svg\" aria-label=\"Enlarge diagram: Worked example: all incoming weights and biases\"><img src=\"assets/figures/net_drill13.svg\" alt=\"Worked example: all incoming weights and biases\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>Worked example: all incoming weights and biases <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [1, 2].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.1].</p>","<p>Hidden and output activations are ReLU.</p>","<p>Target y = [1].</p>","<p>Learning rate η = 0.1.</p>","<p>Use half squared loss and update all weights and biases.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used before substituting numbers</h3>","<p>For every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.98px;--narrow-height:169.67px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc1bda021c501564.svg\"><img class=\"math display-math\" src=\"assets/equations/b6818e3243c5ede2.svg\" alt=\"z_j=\\sum_iw_{ji}a_i+b_j,\\quad a_j=f(z_j),\\quad L=\\frac12\\sum_k(o_k-y_k)^2\" width=\"590.65\" height=\"62.49\" style=\"width:590.65px;height:62.49px;aspect-ratio:590.65/62.49\" loading=\"lazy\"></picture></div>","<p>Delta means the loss gradient with respect to a neuron&#x27;s raw score. First calculate output deltas, then hidden deltas using every connected output path.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e56bc6ef11f21beb.svg\" alt=\"\\delta_{o_k}=(o_k-y_k)f&#x27;(z_{o_k})\" width=\"226.50\" height=\"26.16\" style=\"width:226.50px;height:26.16px;aspect-ratio:226.50/26.16\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6086310bbc701ed1.svg\" alt=\"\\delta_{h_j}=\\left(\\sum_kw_{kj}\\delta_{o_k}\\right)f&#x27;(z_{h_j})\" width=\"274.97\" height=\"73.28\" style=\"width:274.97px;height:73.28px;aspect-ratio:274.97/73.28\" loading=\"lazy\"></div>","<p>The gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f883fcc3e95816b.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i,\\qquad \\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"287.20\" height=\"57.94\" style=\"width:287.20px;height:57.94px;aspect-ratio:287.20/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.06px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7c0c7e8cef31635.svg\"><img class=\"math display-math\" src=\"assets/equations/289f74bc5d59b047.svg\" alt=\"w_{ji,\\mathrm{new}}=w_{ji}-\\eta\\delta_j a_i,\\quad b_{j,\\mathrm{new}}=b_j-\\eta\\delta_j\" width=\"418.98\" height=\"24.71\" style=\"width:418.98px;height:24.71px;aspect-ratio:418.98/24.71\" loading=\"lazy\"></picture></div>","<p>For sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d12052a5268cb30c.svg\"><img class=\"math display-math\" src=\"assets/equations/9b009885daaa5779.svg\" alt=\"z_{h_1} = (0.2 \\times  1) + (0.1 \\times  2) + (0.1) = 0.5\" width=\"421.90\" height=\"24.58\" style=\"width:421.90px;height:24.58px;aspect-ratio:421.90/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b78961f402336b21.svg\" alt=\"h_{1} = \\max(0,0.5) = 0.5\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0eb4dbe7db30c72c.svg\"><img class=\"math display-math\" src=\"assets/equations/840732725d47f1fe.svg\" alt=\"z_{h_2} = (0.3 \\times  1) + (-0.1 \\times  2) + (0.2) = 0.3\" width=\"440.92\" height=\"24.58\" style=\"width:440.92px;height:24.58px;aspect-ratio:440.92/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3ca4b1ac8771a1a8.svg\" alt=\"h_{2} = \\max(0,0.3) = 0.3\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/24202b454fb4dad2.svg\"><img class=\"math display-math\" src=\"assets/equations/f22e357a250f5762.svg\" alt=\"z_{o_1} = (0.4 \\times  0.5) + (0.5 \\times  0.3) + (0.1) = 0.45\" width=\"470.57\" height=\"24.58\" style=\"width:470.57px;height:24.58px;aspect-ratio:470.57/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6f7822c28a4fdd9.svg\" alt=\"o_{1} = \\max(0,0.45) = 0.45\" width=\"262.14\" height=\"24.43\" style=\"width:262.14px;height:24.43px;aspect-ratio:262.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.55]. Squared errors = [0.3025]. Half-sum squared loss = 0.15125; mean squared error = 0.3025. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/08c65e290585835f.svg\"><img class=\"math display-math\" src=\"assets/equations/e54a4bff1059c242.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.45-1) \\times  1 = -0.55\" width=\"345.14\" height=\"24.58\" style=\"width:345.14px;height:24.58px;aspect-ratio:345.14/24.58\" loading=\"lazy\"></picture></div>","<p>The ReLU derivative is 1 here because this preactivation is positive.</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.5</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.55</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.4275</strong></div></div><p>Subtract η × gradient = <b>−0.0275</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.92px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a95215144e52b49.svg\"><img class=\"math display-math\" src=\"assets/equations/1452e508c28a6d93.svg\" alt=\"g_{1,1}^{(2)}=(-0.55)\\times(0.5)\\approx -0.275\" width=\"337.18\" height=\"36.54\" style=\"width:337.18px;height:36.54px;aspect-ratio:337.18/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5bb285fe6a5d5ca6.svg\"><img class=\"math display-math\" src=\"assets/equations/c98fe26955db1400.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.4-0.1(-0.275)\\approx 0.4275\" width=\"400.79\" height=\"36.54\" style=\"width:400.79px;height:36.54px;aspect-ratio:400.79/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.3</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.55</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.165</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.5165</strong></div></div><p>Subtract η × gradient = <b>−0.0165</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.92px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9dd543c1a4cfe977.svg\"><img class=\"math display-math\" src=\"assets/equations/9325b59e9bc80f3d.svg\" alt=\"g_{1,2}^{(2)}=(-0.55)\\times(0.3)\\approx -0.165\" width=\"337.18\" height=\"36.54\" style=\"width:337.18px;height:36.54px;aspect-ratio:337.18/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6b95f80af95c8ca3.svg\"><img class=\"math display-math\" src=\"assets/equations/8b302d0b5078734a.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.5-0.1(-0.165)\\approx 0.5165\" width=\"400.79\" height=\"36.54\" style=\"width:400.79px;height:36.54px;aspect-ratio:400.79/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.22</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b6b2e13098fb66e7.svg\"><img class=\"math display-math\" src=\"assets/equations/a0677d80f1fb0659.svg\" alt=\"C_1=(0.4)\\times(-0.55)\\approx -0.22\" width=\"317.34\" height=\"24.43\" style=\"width:317.34px;height:24.43px;aspect-ratio:317.34/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b39852d5faaf11fb.svg\" alt=\"\\text{Sum}=C_1\\approx -0.22\" width=\"203.29\" height=\"20.89\" style=\"width:203.29px;height:20.89px;aspect-ratio:203.29/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f452f757c3f0207e.svg\" alt=\"\\delta_{h_1} = -0.22 \\times  1 = -0.22\" width=\"262.54\" height=\"23.78\" style=\"width:262.54px;height:23.78px;aspect-ratio:262.54/23.78\" loading=\"lazy\"></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.275</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7150a7153bb561f5.svg\"><img class=\"math display-math\" src=\"assets/equations/2daae1e05e9f3afa.svg\" alt=\"C_1=(0.5)\\times(-0.55)\\approx -0.275\" width=\"329.55\" height=\"24.43\" style=\"width:329.55px;height:24.43px;aspect-ratio:329.55/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d346b0df4b69bd95.svg\" alt=\"\\text{Sum}=C_1\\approx -0.275\" width=\"215.50\" height=\"20.89\" style=\"width:215.50px;height:20.89px;aspect-ratio:215.50/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7ad50eed6d4c12e2.svg\" alt=\"\\delta_{h_2} = -0.275 \\times  1 = -0.275\" width=\"286.97\" height=\"23.78\" style=\"width:286.97px;height:23.78px;aspect-ratio:286.97/23.78\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.222</strong></div></div><p>Subtract η × gradient = <b>−0.022</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.91px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c1b77c7df67c595.svg\"><img class=\"math display-math\" src=\"assets/equations/d2c8214211374554.svg\" alt=\"g_{1,1}^{(1)}=(-0.22)\\times(1)\\approx -0.22\" width=\"305.95\" height=\"36.54\" style=\"width:305.95px;height:36.54px;aspect-ratio:305.95/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e91b335304219c5c.svg\"><img class=\"math display-math\" src=\"assets/equations/1103f1b43164b612.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.2-0.1(-0.22)\\approx 0.222\" width=\"376.35\" height=\"36.54\" style=\"width:376.35px;height:36.54px;aspect-ratio:376.35/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.44</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.144</strong></div></div><p>Subtract η × gradient = <b>−0.044</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.91px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/828d4390f7c40527.svg\"><img class=\"math display-math\" src=\"assets/equations/7306e7ed77d36dd1.svg\" alt=\"g_{1,2}^{(1)}=(-0.22)\\times(2)\\approx -0.44\" width=\"305.95\" height=\"36.54\" style=\"width:305.95px;height:36.54px;aspect-ratio:305.95/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0bf76ef563b87e1.svg\"><img class=\"math display-math\" src=\"assets/equations/679cfd3e82742ab1.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.1-0.1(-0.44)\\approx 0.144\" width=\"376.35\" height=\"36.54\" style=\"width:376.35px;height:36.54px;aspect-ratio:376.35/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.3275</strong></div></div><p>Subtract η × gradient = <b>−0.0275</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.13px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a0689c05816a3a3a.svg\"><img class=\"math display-math\" src=\"assets/equations/efc4ca15325664fa.svg\" alt=\"g_{2,1}^{(1)}=(-0.275)\\times(1)\\approx -0.275\" width=\"330.38\" height=\"36.54\" style=\"width:330.38px;height:36.54px;aspect-ratio:330.38/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/950cba298eb25531.svg\"><img class=\"math display-math\" src=\"assets/equations/c874099b770b95c2.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.3-0.1(-0.275)\\approx 0.3275\" width=\"400.79\" height=\"36.54\" style=\"width:400.79px;height:36.54px;aspect-ratio:400.79/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.55</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.045</strong></div></div><p>Subtract η × gradient = <b>−0.055</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.13px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/27b6c549a9eafc2d.svg\"><img class=\"math display-math\" src=\"assets/equations/a96b50c26c1fb262.svg\" alt=\"g_{2,2}^{(1)}=(-0.275)\\times(2)\\approx -0.55\" width=\"318.17\" height=\"36.54\" style=\"width:318.17px;height:36.54px;aspect-ratio:318.17/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.81px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c7fab0773a9a18b8.svg\"><img class=\"math display-math\" src=\"assets/equations/3c1258873b38aaf8.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=-0.1-0.1(-0.55)\\approx -0.045\" width=\"414.37\" height=\"36.54\" style=\"width:414.37px;height:36.54px;aspect-ratio:414.37/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31940cedcf20decc.svg\"><img class=\"math display-math\" src=\"assets/equations/9f4d72c657ffcbf4.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.1-0.1(-0.220000000)=0.122000000\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6350b7de1a7fd962.svg\"><img class=\"math display-math\" src=\"assets/equations/a1c182cfafd9e6ab.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.2-0.1(-0.275000000)=0.227500000\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ce690df86543a5bc.svg\"><img class=\"math display-math\" src=\"assets/equations/42cf2912fda00eff.svg\" alt=\"b_{o_1,\\mathrm{new}}=0.1-0.1(-0.550000000)=0.155000000\" width=\"516.43\" height=\"25.35\" style=\"width:516.43px;height:25.35px;aspect-ratio:516.43/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>"],"kind":"practice","id":"mt2-c17-s11","search":"Drill 11 Full ReLU backpropagation **Question.** Input x = [1, 2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.1. Use half squared loss and update all weights and biases.\n\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput x = [1, 2].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.1].\n\nHidden and output activations are ReLU.\n\nTarget y = [1].\n\nLearning rate η = 0.1.\n\nUse half squared loss and update all weights and biases.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used before substituting numbers\nFor every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.\n\nDelta means the loss gradient with respect to a neuron's raw score. First calculate output deltas, then hidden deltas using every connected output path.\n\n\nThe gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.\n\n\nFor sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.55]."},{"title":"Drill 12 Two output sigmoid backpropagation","question":["<p class=\"inline-question\"><strong>Question.</strong> Input x = [0.2, 0.4]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.1]; W₂ is shown below; b₂ = [0, 0.1]. Hidden and output activations are sigmoid. Target y = [1, 0]. Learning rate η = 0.2. Use half summed squared loss and update all parameters.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_907c03b5dc.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_907c03b5dc.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_drill14.svg\" aria-label=\"Enlarge diagram: Worked example: both output paths must contribute to hidden gradients\"><img src=\"assets/figures/net_drill14.svg\" alt=\"Worked example: both output paths must contribute to hidden gradients\" width=\"960\" height=\"638\" loading=\"lazy\"></button><figcaption>Worked example: both output paths must contribute to hidden gradients <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [0.2, 0.4].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.1].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0, 0.1].</p>","<p>Hidden and output activations are sigmoid.</p>","<p>Target y = [1, 0].</p>","<p>Learning rate η = 0.2.</p>","<p>Use half summed squared loss and update all parameters.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used before substituting numbers</h3>","<p>For every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.98px;--narrow-height:169.67px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc1bda021c501564.svg\"><img class=\"math display-math\" src=\"assets/equations/b6818e3243c5ede2.svg\" alt=\"z_j=\\sum_iw_{ji}a_i+b_j,\\quad a_j=f(z_j),\\quad L=\\frac12\\sum_k(o_k-y_k)^2\" width=\"590.65\" height=\"62.49\" style=\"width:590.65px;height:62.49px;aspect-ratio:590.65/62.49\" loading=\"lazy\"></picture></div>","<p>Delta means the loss gradient with respect to a neuron&#x27;s raw score. First calculate output deltas, then hidden deltas using every connected output path.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e56bc6ef11f21beb.svg\" alt=\"\\delta_{o_k}=(o_k-y_k)f&#x27;(z_{o_k})\" width=\"226.50\" height=\"26.16\" style=\"width:226.50px;height:26.16px;aspect-ratio:226.50/26.16\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6086310bbc701ed1.svg\" alt=\"\\delta_{h_j}=\\left(\\sum_kw_{kj}\\delta_{o_k}\\right)f&#x27;(z_{h_j})\" width=\"274.97\" height=\"73.28\" style=\"width:274.97px;height:73.28px;aspect-ratio:274.97/73.28\" loading=\"lazy\"></div>","<p>The gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f883fcc3e95816b.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i,\\qquad \\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"287.20\" height=\"57.94\" style=\"width:287.20px;height:57.94px;aspect-ratio:287.20/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.06px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7c0c7e8cef31635.svg\"><img class=\"math display-math\" src=\"assets/equations/289f74bc5d59b047.svg\" alt=\"w_{ji,\\mathrm{new}}=w_{ji}-\\eta\\delta_j a_i,\\quad b_{j,\\mathrm{new}}=b_j-\\eta\\delta_j\" width=\"418.98\" height=\"24.71\" style=\"width:418.98px;height:24.71px;aspect-ratio:418.98/24.71\" loading=\"lazy\"></picture></div>","<p>For sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b34f23de35a7cf0c.svg\"><img class=\"math display-math\" src=\"assets/equations/c91412b204993ed6.svg\" alt=\"z_{h_1} = (0.1 \\times  0.2) + (0.2 \\times  0.4) + (0.1) = 0.2\" width=\"459.93\" height=\"24.58\" style=\"width:459.93px;height:24.58px;aspect-ratio:459.93/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/acdd5499eb345eef.svg\"><img class=\"math display-math\" src=\"assets/equations/94bdd56fd67f70d6.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(0.2)}}=0.549833997\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6178667245d07427.svg\"><img class=\"math display-math\" src=\"assets/equations/0c8577da1dc8776a.svg\" alt=\"z_{h_2} = (-0.2 \\times  0.2) + (0.3 \\times  0.4) + (0.1) = 0.18\" width=\"491.15\" height=\"24.58\" style=\"width:491.15px;height:24.58px;aspect-ratio:491.15/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.18px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/63a52c4f6d59b8f1.svg\"><img class=\"math display-math\" src=\"assets/equations/e227b5ddfa70fc91.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.18)}}=0.544878892\" width=\"342.73\" height=\"53.84\" style=\"width:342.73px;height:53.84px;aspect-ratio:342.73/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.95px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/897314316dee8982.svg\"><img class=\"math display-math\" src=\"assets/equations/e5fd2ad81db5cb12.svg\" alt=\"z_{o_1} = (0.2 \\times  0.549833997) + (-0.1 \\times  0.544878892) + (0) = 0.05547891\" width=\"739.35\" height=\"24.58\" style=\"width:739.35px;height:24.58px;aspect-ratio:739.35/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.80px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/247adbbc93580b44.svg\"><img class=\"math display-math\" src=\"assets/equations/4890faea42fbcddd.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.05547891)}}=0.513866171\" width=\"392.34\" height=\"53.84\" style=\"width:392.34px;height:53.84px;aspect-ratio:392.34/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0e0191df53ed3741.svg\"><img class=\"math display-math\" src=\"assets/equations/4e7177927a4b11d4.svg\" alt=\"z_{o_2} = (0.3 \\times  0.549833997) + (0.4 \\times  0.544878892) + (0.1) = 0.482901756\" width=\"751.56\" height=\"24.58\" style=\"width:751.56px;height:24.58px;aspect-ratio:751.56/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9a8b37a15ece040e.svg\"><img class=\"math display-math\" src=\"assets/equations/b4bdac71b195a0cc.svg\" alt=\"o_{2}=\\frac{1}{1+e^{-(0.482901756)}}=0.618432848\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.486133829, 0.618432848]. Squared errors = [0.2363261, 0.382459187]. Half-sum squared loss = 0.309392643; mean squared error = 0.309392643. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f1f5b1787fc59def.svg\"><img class=\"math display-math\" src=\"assets/equations/32cdbe21f65e2b06.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.513866171-1) \\times  0.249807729 = -0.121439988\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p><strong>Output delta 2:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6546421fef60e0c5.svg\"><img class=\"math display-math\" src=\"assets/equations/76cba5dae26e3af0.svg\" alt=\"\\delta_{o_2} = 1 \\times  (0.618432848-0) \\times  0.235973661 = 0.145933863\" width=\"613.92\" height=\"24.58\" style=\"width:613.92px;height:24.58px;aspect-ratio:613.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.549833997</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.121439988</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.066771834</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.213354367</strong></div></div><p>Subtract η × gradient = <b>−0.013354367</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8335141cc6234897.svg\"><img class=\"math display-math\" src=\"assets/equations/918d32ea9955cc69.svg\" alt=\"g_{1,1}^{(2)}=(-0.121439988)\\times(0.549833997)\\approx -0.066771834\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4c9c4df3cf58176a.svg\"><img class=\"math display-math\" src=\"assets/equations/f6338ce1a52bb766.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.2-0.2(-0.066771834)\\approx 0.213354367\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.544878892</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.121439988</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.066170086</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.086765983</strong></div></div><p>Subtract η × gradient = <b>−0.013234017</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e6cb2fb79ea00bc6.svg\"><img class=\"math display-math\" src=\"assets/equations/28a4d3d30f2657c9.svg\" alt=\"g_{1,2}^{(2)}=(-0.121439988)\\times(0.544878892)\\approx -0.066170086\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1f30020d32cef10b.svg\"><img class=\"math display-math\" src=\"assets/equations/c29bb818f965c973.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=-0.1-0.2(-0.066170086)\\approx -0.086765983\" width=\"573.19\" height=\"36.54\" style=\"width:573.19px;height:36.54px;aspect-ratio:573.19/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h1 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.549833997</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.145933863</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.080239399</strong><span class=\"lv-detail\">h1 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.28395212</strong></div></div><p>Subtract η × gradient = <b>0.01604788</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dde4ee7e9e8f997c.svg\" alt=\"g_{2,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,1}}=\\delta_{o_2}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/16c40d7d34614dcb.svg\"><img class=\"math display-math\" src=\"assets/equations/5b06ea5d37905422.svg\" alt=\"g_{2,1}^{(2)}=(0.145933863)\\times(0.549833997)\\approx 0.080239399\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5660f8c2c8b62a6f.svg\"><img class=\"math display-math\" src=\"assets/equations/d900aa21d0b17c7e.svg\" alt=\"W^{(2)}_{2,1,\\mathrm{new}}=0.3-0.2(0.080239399)\\approx 0.28395212\" width=\"503.95\" height=\"36.54\" style=\"width:503.95px;height:36.54px;aspect-ratio:503.95/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.544878892</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.145933863</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.079516282</strong><span class=\"lv-detail\">h2 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.384096744</strong></div></div><p>Subtract η × gradient = <b>0.015903256</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57d7e754e94fe533.svg\" alt=\"g_{2,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,2}}=\\delta_{o_2}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2bf8871d8771b0c8.svg\"><img class=\"math display-math\" src=\"assets/equations/ca3eeac86363862f.svg\" alt=\"g_{2,2}^{(2)}=(0.145933863)\\times(0.544878892)\\approx 0.079516282\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d6e1bdf461c23702.svg\"><img class=\"math display-math\" src=\"assets/equations/320cca8c034f0c86.svg\" alt=\"W^{(2)}_{2,2,\\mathrm{new}}=0.4-0.2(0.079516282)\\approx 0.384096744\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.121439988</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.024287998</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.145933863</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.043780159</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.019492161</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7be9181956492e01.svg\"><img class=\"math display-math\" src=\"assets/equations/da1d2225b6cf0b3e.svg\" alt=\"C_1=(0.2)\\times(-0.121439988)\\approx -0.024287998\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0025ef2e4f3926ed.svg\"><img class=\"math display-math\" src=\"assets/equations/01c7679493ca990b.svg\" alt=\"C_2=(0.3)\\times(0.145933863)\\approx 0.043780159\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6abb0857809f8db8.svg\"><img class=\"math display-math\" src=\"assets/equations/66b0d378cdd2503f.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.019492161\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3348b1ba7e091393.svg\"><img class=\"math display-math\" src=\"assets/equations/206e786abddd6488.svg\" alt=\"\\delta_{h_1} = 0.019492161 \\times  0.247516573 = 0.004824633\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.121439988</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.012143999</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.145933863</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.058373545</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.070517544</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/909a9296285664eb.svg\"><img class=\"math display-math\" src=\"assets/equations/7e59b3ad426aa9b6.svg\" alt=\"C_1=(-0.1)\\times(-0.121439988)\\approx 0.012143999\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/14154a8890e8abb8.svg\"><img class=\"math display-math\" src=\"assets/equations/b190ef59d9695988.svg\" alt=\"C_2=(0.4)\\times(0.145933863)\\approx 0.058373545\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1538baedb3bcff3c.svg\"><img class=\"math display-math\" src=\"assets/equations/41fc299f66c265e9.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.070517544\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b6511e93ffa2060f.svg\"><img class=\"math display-math\" src=\"assets/equations/d2104a629894d5d4.svg\" alt=\"\\delta_{h_2} = 0.070517544 \\times  0.247985885 = 0.017487356\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.004824633</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000964927</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.099807015</strong></div></div><p>Subtract η × gradient = <b>0.000192985</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a8abe88d39c4a4c9.svg\"><img class=\"math display-math\" src=\"assets/equations/1785a1b288336ba6.svg\" alt=\"g_{1,1}^{(1)}=(0.004824633)\\times(0.2)\\approx 0.000964927\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e34dab3cfb2bef31.svg\"><img class=\"math display-math\" src=\"assets/equations/429125d2eee69ed4.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.1-0.2(0.000964927)\\approx 0.099807015\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.004824633</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.001929853</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.199614029</strong></div></div><p>Subtract η × gradient = <b>0.000385971</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a45450793aa1fbee.svg\"><img class=\"math display-math\" src=\"assets/equations/fef8b9d9db76a45d.svg\" alt=\"g_{1,2}^{(1)}=(0.004824633)\\times(0.4)\\approx 0.001929853\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff165bc32cce96bf.svg\"><img class=\"math display-math\" src=\"assets/equations/86e7e16686d8ad69.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.2-0.2(0.001929853)\\approx 0.199614029\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.017487356</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.003497471</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.200699494</strong></div></div><p>Subtract η × gradient = <b>0.000699494</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5a519701097922e5.svg\"><img class=\"math display-math\" src=\"assets/equations/2c7569fc93ce3696.svg\" alt=\"g_{2,1}^{(1)}=(0.017487356)\\times(0.2)\\approx 0.003497471\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/251cd8c98d77e90c.svg\"><img class=\"math display-math\" src=\"assets/equations/d31db2b9d2bae391.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=-0.2-0.2(0.003497471)\\approx -0.200699494\" width=\"554.18\" height=\"36.54\" style=\"width:554.18px;height:36.54px;aspect-ratio:554.18/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.017487356</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.006994942</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.298601012</strong></div></div><p>Subtract η × gradient = <b>0.001398988</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/253913dce1e316cf.svg\"><img class=\"math display-math\" src=\"assets/equations/f1825dbaa53d6e64.svg\" alt=\"g_{2,2}^{(1)}=(0.017487356)\\times(0.4)\\approx 0.006994942\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30eae54a2d6333bf.svg\"><img class=\"math display-math\" src=\"assets/equations/f4cac41f24ea1d22.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.3-0.2(0.006994942)\\approx 0.298601012\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d95f499c8cf92af.svg\"><img class=\"math display-math\" src=\"assets/equations/fc185daa7ea868a7.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.1-0.2(0.004824633)=0.099035073\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/574987d80e93f51f.svg\"><img class=\"math display-math\" src=\"assets/equations/7e8c76ed543b6526.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.1-0.2(0.017487356)=0.096502529\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c0bf69b79bc6be7c.svg\"><img class=\"math display-math\" src=\"assets/equations/7f891f57c5f4c76f.svg\" alt=\"b_{o_1,\\mathrm{new}}=0-0.2(-0.121439988)=0.024287998\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ab34abf185daf06.svg\"><img class=\"math display-math\" src=\"assets/equations/54d821197ed88717.svg\" alt=\"b_{o_2,\\mathrm{new}}=0.1-0.2(0.145933863)=0.070813227\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>"],"kind":"practice","id":"mt2-c17-s12","search":"Drill 12 Two output sigmoid backpropagation **Question.** Input x = [0.2, 0.4]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.1]; W₂ is shown below; b₂ = [0, 0.1]. Hidden and output activations are sigmoid. Target y = [1, 0]. Learning rate η = 0.2. Use half summed squared loss and update all parameters.\n\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput x = [0.2, 0.4].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.1].\n\nW₂ is printed with the question.\n\nb₂ = [0, 0.1].\n\nHidden and output activations are sigmoid.\n\nTarget y = [1, 0].\n\nLearning rate η = 0.2.\n\nUse half summed squared loss and update all parameters.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used before substituting numbers\nFor every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.\n\nDelta means the loss gradient with respect to a neuron's raw score. First calculate output deltas, then hidden deltas using every connected output path.\n\n\nThe gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.\n\n\nFor sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.\n\n**Step 1 map the arrows.** Each row of W₁ receives all inputs; each "},{"title":"Drill 13 A negative ReLU blocks this path","question":["<p class=\"inline-question\"><strong>Question.</strong> x = 2, w1 = −0.4, b1 = 0.1, w2 = 0.5, b2 = 0.2; hidden ReLU, linear output, y = 1, half squared loss. Find dw 1 and dw 2.</p>"],"answer":["<h3>Given</h3>","<p>x = 2; w₁ = −0.4; b₁ = 0.1; w₂ = 0.5; b₂ = 0.2.</p>","<p>Hidden activation: ReLU; output activation: linear.</p>","<p>Target y = 1; loss: half squared error.</p>","<h3>To find</h3>","<p>Find the gradients of w₁ and w₂ and explain any zero gradients.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used</h3>","<p>The hidden neuron uses ReLU, but the output is linear. “Linear output” means its weighted sum is already its output.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.35px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2107914ba4f232f1.svg\"><img class=\"math display-math\" src=\"assets/equations/96964269705ef1b5.svg\" alt=\"z_h=w_1x+b_1,\\quad h=\\max(0,z_h),\\quad o=w_2h+b_2\" width=\"514.94\" height=\"24.43\" style=\"width:514.94px;height:24.43px;aspect-ratio:514.94/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.36px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/160d78635e6efcbf.svg\"><img class=\"math display-math\" src=\"assets/equations/e9baab27f7f33ee2.svg\" alt=\"L=\\frac12(o-y)^2,\\quad \\delta_o=o-y\" width=\"298.39\" height=\"49.55\" style=\"width:298.39px;height:49.55px;aspect-ratio:298.39/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.25px;--narrow-height:164.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a9eda432984ec8da.svg\"><img class=\"math display-math\" src=\"assets/equations/51a8b01e1bee8834.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=\\delta_o h,\\quad \\delta_h=\\delta_o w_2\\operatorname{ReLU}&#x27;(z_h),\\quad \\frac{\\partial L}{\\partial w_1}=\\delta_h x\" width=\"533.85\" height=\"54.41\" style=\"width:533.85px;height:54.41px;aspect-ratio:533.85/54.41\" loading=\"lazy\"></picture></div>","<h3>Step 1: hidden weighted sum and activation</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.36px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81ce8e4429aab67a.svg\"><img class=\"math display-math\" src=\"assets/equations/b94d4768d9ba8e6f.svg\" alt=\"z_h=(-0.4)\\times2+0.1=-0.8+0.1=-0.7\" width=\"455.10\" height=\"24.43\" style=\"width:455.10px;height:24.43px;aspect-ratio:455.10/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0f4049c82bf618fd.svg\" alt=\"h=\\max(0,-0.7)=0\" width=\"229.26\" height=\"24.43\" style=\"width:229.26px;height:24.43px;aspect-ratio:229.26/24.43\" loading=\"lazy\"></div>","<p>Because the raw hidden score is negative, ReLU&#x27;s derivative at this point is 0.</p>","<h3>Step 2: output prediction and output delta</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8775ad02ed7eaf6c.svg\" alt=\"o=0.5\\times0+0.2=0.2\" width=\"242.65\" height=\"18.27\" style=\"width:242.65px;height:18.27px;aspect-ratio:242.65/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ff295007085f430d.svg\" alt=\"\\delta_o=0.2-1=-0.8\" width=\"209.97\" height=\"21.37\" style=\"width:209.97px;height:21.37px;aspect-ratio:209.97/21.37\" loading=\"lazy\"></div>","<h3>Step 3: output weight gradient</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/400d3f8e82bf09fc.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=(-0.8)\\times0=0\" width=\"241.47\" height=\"54.41\" style=\"width:241.47px;height:54.41px;aspect-ratio:241.47/54.41\" loading=\"lazy\"></div>","<p>This is zero because the input to that connection, h, is zero.</p>","<h3>Step 4: hidden delta and input weight gradient</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1721f576f8f22211.svg\" alt=\"\\delta_h=(-0.8)\\times0.5\\times0=0\" width=\"272.65\" height=\"24.43\" style=\"width:272.65px;height:24.43px;aspect-ratio:272.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a131ac401273e09f.svg\" alt=\"\\frac{\\partial L}{\\partial w_1}=0\\times2=0\" width=\"184.43\" height=\"54.41\" style=\"width:184.43px;height:54.41px;aspect-ratio:184.43/54.41\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> both requested weight gradients are zero. The output bias gradient equals −0.8, so a zero weight gradient does not mean every parameter&#x27;s gradient is zero.</p>"],"kind":"practice","id":"mt2-c17-s13","search":"Drill 13 A negative ReLU blocks this path **Question.** x = 2, w1 = −0.4, b1 = 0.1, w2 = 0.5, b2 = 0.2; hidden ReLU, linear output, y = 1, half squared loss. Find dw 1 and dw 2.\n\n**Full solution.**\n\n\n\n### Given\n\nx = 2; w₁ = −0.4; b₁ = 0.1; w₂ = 0.5; b₂ = 0.2.\n\nHidden activation: ReLU; output activation: linear.\n\nTarget y = 1; loss: half squared error.\n\n### To find\n\nFind the gradients of w₁ and w₂ and explain any zero gradients.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used\nThe hidden neuron uses ReLU, but the output is linear. “Linear output” means its weighted sum is already its output.\n\n\n\n### Step 1: hidden weighted sum and activation\n\n\nBecause the raw hidden score is negative, ReLU's derivative at this point is 0.\n### Step 2: output prediction and output delta\n\n\n### Step 3: output weight gradient\n\nThis is zero because the input to that connection, h, is zero.\n### Step 4: hidden delta and input weight gradient\n\n\n**Final answer:** both requested weight gradients are zero. The output bias gradient equals −0.8, so a zero weight gradient does not mean every parameter's gradient is zero.\n"},{"title":"Drill 14 Batch and sequential SGD","question":["<p class=\"inline-question\"><strong>Question.</strong> ŷ = wx, start w = 0, η = 0.1, data(1,1), (2,2). Use mean half squared loss for a batch. Compare one batch update with one sequential SGD epoch.</p>"],"answer":["<h3>Given</h3>","<p>Model ŷ = wx; initial w = 0; η = 0.1.</p>","<p>Samples in order: (x,y) = (1,1), then (2,2).</p>","<p>Batch objective: mean half squared loss.</p>","<h3>To find</h3>","<p>Compare the weight after one batch update and one sequential SGD epoch.</p>","<h3>Formula — which one and why</h3>","<p><strong>Batch mean versus sequential SGD.</strong> A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.</p>","<p>B = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/657f63b5043d3907.svg\" alt=\"g_{\\mathrm{batch}}=\\frac1B\\sum_i g_i\" width=\"180.88\" height=\"61.92\" style=\"width:180.88px;height:61.92px;aspect-ratio:180.88/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0b4939a48933eb0a.svg\" alt=\"g_i=(wx_i-y_i)x_i\" width=\"182.50\" height=\"24.43\" style=\"width:182.50px;height:24.43px;aspect-ratio:182.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Batch: same old weight par average; SGD: har sample ke baad weight change.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>For one sample, x is the input, y is the target, and w is the weight. Batch GD averages gradients evaluated at the <strong>same old weight</strong>. Sequential SGD updates after each sample and uses that new weight for the next sample.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.48px;--narrow-height:130.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e02d92789136f341.svg\"><img class=\"math display-math\" src=\"assets/equations/00e3dff87be9cc8c.svg\" alt=\"\\hat y=wx,\\quad L=\\frac12(\\hat y-y)^2,\\quad g=(\\hat y-y)x\" width=\"433.35\" height=\"49.55\" style=\"width:433.35px;height:49.55px;aspect-ratio:433.35/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.57px;--narrow-height:86.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7783293f367f0a09.svg\"><img class=\"math display-math\" src=\"assets/equations/070a9c1b54d9ac42.svg\" alt=\"g_{\\mathrm{batch}}=\\frac{g_1+g_2}{2},\\qquad w_{\\mathrm{new}}=w-\\eta g\" width=\"386.53\" height=\"47.52\" style=\"width:386.53px;height:47.52px;aspect-ratio:386.53/47.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Part A: one batch update from w = 0.</strong></p>","<p>For sample (1,1), prediction = 0 × 1 = 0, so:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/65b3616ae354de6a.svg\" alt=\"g_1=(0-1)\\times1=-1\" width=\"234.12\" height=\"24.43\" style=\"width:234.12px;height:24.43px;aspect-ratio:234.12/24.43\" loading=\"lazy\"></div>","<p>For sample (2,2), keep the same weight 0. Prediction = 0 × 2 = 0, so:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5e54f46939905d8.svg\" alt=\"g_2=(0-2)\\times2=-4\" width=\"234.12\" height=\"24.43\" style=\"width:234.12px;height:24.43px;aspect-ratio:234.12/24.43\" loading=\"lazy\"></div>","<p>Average these two gradients, then update once.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.60px;--narrow-height:91.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ae3a9f41f9f31680.svg\"><img class=\"math display-math\" src=\"assets/equations/6159bfc1e25aba9f.svg\" alt=\"g_{\\mathrm{batch}}=\\frac{-1+(-4)}2=-2.5\" width=\"293.41\" height=\"52.43\" style=\"width:293.41px;height:52.43px;aspect-ratio:293.41/52.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.91px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/568002eaa70aedb2.svg\"><img class=\"math display-math\" src=\"assets/equations/a5ec534d58a905c7.svg\" alt=\"w_{\\mathrm{batch}}=0-0.1(-2.5)=0.25\" width=\"312.94\" height=\"24.43\" style=\"width:312.94px;height:24.43px;aspect-ratio:312.94/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Part B: one SGD epoch, restarting at w = 0.</strong></p>","<p>The first sample has gradient −1, just as above.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2b5721e0e1c67b4.svg\" alt=\"w_1=0-0.1(-1)=0.1\" width=\"248.11\" height=\"24.43\" style=\"width:248.11px;height:24.43px;aspect-ratio:248.11/24.43\" loading=\"lazy\"></div>","<p>For the second sample use this new weight, so prediction is:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/905f0951780ee22a.svg\" alt=\"\\hat y_2=0.1\\times2=0.2\" width=\"192.35\" height=\"24.80\" style=\"width:192.35px;height:24.80px;aspect-ratio:192.35/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.74px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f262bc5d6c22d8bb.svg\"><img class=\"math display-math\" src=\"assets/equations/4c4f586bc3f0f97e.svg\" alt=\"g_2=(0.2-2)\\times2=(-1.8)\\times2=-3.6\" width=\"416.06\" height=\"24.43\" style=\"width:416.06px;height:24.43px;aspect-ratio:416.06/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.32px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f8c5ce8387c2e254.svg\"><img class=\"math display-math\" src=\"assets/equations/ff99526a93e31696.svg\" alt=\"w_2=0.1-0.1(-3.6)=0.1+0.36=0.46\" width=\"435.48\" height=\"24.43\" style=\"width:435.48px;height:24.43px;aspect-ratio:435.48/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> batch result 0.25; sequential SGD result 0.46. The difference comes from the timing of the updates.</p>"],"kind":"practice","id":"mt2-c17-s14","search":"Drill 14 Batch and sequential SGD **Question.** ŷ = wx, start w = 0, η = 0.1, data(1,1), (2,2). Use mean half squared loss for a batch. Compare one batch update with one sequential SGD epoch.\n\n**Full solution.**\n\n\n\n### Given\n\nModel ŷ = wx; initial w = 0; η = 0.1.\n\nSamples in order: (x,y) = (1,1), then (2,2).\n\nBatch objective: mean half squared loss.\n\n### To find\n\nCompare the weight after one batch update and one sequential SGD epoch.\n\n### Formula — which one and why\n\n**Batch mean versus sequential SGD.** A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.\n\nB = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Batch: same old weight par average; SGD: har sample ke baad weight change.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nFor one sample, x is the input, y is the target, and w is the weight. Batch GD averages gradients evaluated at the **same old weight**. Sequential SGD updates after each sample and uses that new weight for the next sample.\n\n\n**Step 1: Part A: one batch update from w = 0.**\nFor sample (1,1), prediction = 0 × 1 = 0, so:\n\nFor sample (2,2), keep the same weight 0. Prediction = 0 × 2 = 0, so:\n\nAverage these two gradients, then update once.\n\n\n**Step 2: Part B: one SGD epoch, restarting at w = 0.**\nThe first sample has gradient −1, just as above.\n\nFor the second sample use this new weight, so prediction is:\n\n\n\n**Final answer:** batch result 0.25; sequential SGD result 0.46. The difference comes from the timing of the updates.\n"},{"title":"Drill 15 Incomplete mini batch","question":["<p class=\"inline-question\"><strong>Question.</strong> N = 103, B = 20, epochs = 3. Count updates for batch GD, SGD, mini-batch keeping the remainder, and mini-batch dropping it.</p>"],"answer":["<h3>Given</h3>","<p>N = 103 samples; B = 20 samples per mini-batch.</p>","<p>E = 3 epochs.</p>","<p>Compare both remainder policies: keep or drop the final 3 examples.</p>","<h3>To find</h3>","<p>Find total updates for full-batch GD, SGD, and both mini-batch policies.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>An epoch means one pass through the dataset. An update happens once per batch used. N is the number of samples, B is the chosen batch size, and E is the number of epochs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:128.03px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e0f5f4a6b7d3af9c.svg\"><img class=\"math display-math\" src=\"assets/equations/9c0c1479389c6c19.svg\" alt=\"U_{\\mathrm{batch}}=E,\\qquad U_{\\mathrm{SGD}}=NE\" width=\"299.98\" height=\"21.43\" style=\"width:299.98px;height:21.43px;aspect-ratio:299.98/21.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:175.85px;--narrow-height:131.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/147e19d72acc4203.svg\"><img class=\"math display-math\" src=\"assets/equations/a6ec99ec225775f5.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil,\\qquad U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"398.39\" height=\"58.62\" style=\"width:398.39px;height:58.62px;aspect-ratio:398.39/58.62\" loading=\"lazy\"></picture></div>","<p>Ceiling rounds up to the next integer; floor rounds down. The final incomplete batch needs an update only if it is retained.</p>","<h3>Step 1: batch GD</h3>","<p>All 103 samples form one batch per epoch.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11f14a41e22f1916.svg\" alt=\"U_{\\mathrm{batch}}=3\\times1=3\" width=\"192.65\" height=\"20.54\" style=\"width:192.65px;height:20.54px;aspect-ratio:192.65/20.54\" loading=\"lazy\"></div>","<h3>Step 2: SGD</h3>","<p>Each sample gets its own update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4c08a8b839ca4b99.svg\" alt=\"U_{\\mathrm{SGD}}=103\\times3=309\" width=\"235.65\" height=\"20.74\" style=\"width:235.65px;height:20.74px;aspect-ratio:235.65/20.74\" loading=\"lazy\"></div>","<h3>Step 3: mini-batches with the remainder</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7600fce77b11dfac.svg\" alt=\"103=5\\times20+3\" width=\"177.84\" height=\"18.27\" style=\"width:177.84px;height:18.27px;aspect-ratio:177.84/18.27\" loading=\"lazy\"></div>","<p>The batch sizes are 20, 20, 20, 20, 20 and 3. Six batches per epoch give:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64422d140052bf5c.svg\" alt=\"U_{\\mathrm{keep}}=6\\times3=18\" width=\"196.70\" height=\"23.71\" style=\"width:196.70px;height:23.71px;aspect-ratio:196.70/23.71\" loading=\"lazy\"></div>","<h3>Step 4: mini-batches without the remainder</h3>","<p>Only the five complete batches are used each epoch.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b34106919fd6639.svg\" alt=\"U_{\\mathrm{drop}}=5\\times3=15\" width=\"197.25\" height=\"23.71\" style=\"width:197.25px;height:23.71px;aspect-ratio:197.25/23.71\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 3, 309, 18 and 15 updates respectively.</p>"],"kind":"practice","id":"mt2-c17-s15","search":"Drill 15 Incomplete mini batch **Question.** N = 103, B = 20, epochs = 3. Count updates for batch GD, SGD, mini-batch keeping the remainder, and mini-batch dropping it.\n\n**Full solution.**\n\n\n\n### Given\n\nN = 103 samples; B = 20 samples per mini-batch.\n\nE = 3 epochs.\n\nCompare both remainder policies: keep or drop the final 3 examples.\n\n### To find\n\nFind total updates for full-batch GD, SGD, and both mini-batch policies.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nAn epoch means one pass through the dataset. An update happens once per batch used. N is the number of samples, B is the chosen batch size, and E is the number of epochs.\n\n\nCeiling rounds up to the next integer; floor rounds down. The final incomplete batch needs an update only if it is retained.\n### Step 1: batch GD\nAll 103 samples form one batch per epoch.\n\n### Step 2: SGD\nEach sample gets its own update.\n\n### Step 3: mini-batches with the remainder\n\nThe batch sizes are 20, 20, 20, 20, 20 and 3. Six batches per epoch give:\n\n### Step 4: mini-batches without the remainder\nOnly the five complete batches are used each epoch.\n\n**Final answer:** 3, 309, 18 and 15 updates respectively.\n"},{"title":"Drill 16 GD variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two GD updates.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½θ².</p>","<p>Initial θ₀ = 1; η = 0.1; two iterations.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec670e56abfcf00.svg\"><img class=\"math display-math\" src=\"assets/equations/ad9f147031605f82.svg\" alt=\"J(\\theta)=\\frac12(\\theta-0)^2,\\qquad J\\prime(\\theta)=\\theta-0\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.</p>","<h3>Update formulas</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:156.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b3d142fa7d569702.svg\"><img class=\"math display-math\" src=\"assets/equations/1fa856180f9f092b.svg\" alt=\"g_t=J\\prime(\\theta_{t-1}),\\quad \\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"326.86\" height=\"24.43\" style=\"width:326.86px;height:24.43px;aspect-ratio:326.86/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51e0e1de442cadbf.svg\" alt=\"g_1=1-(0)=1\" width=\"173.03\" height=\"24.43\" style=\"width:173.03px;height:24.43px;aspect-ratio:173.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1f113e7fc6ecc1f4.svg\" alt=\"\\theta_1=1-0.1(1)=0.9\" width=\"223.06\" height=\"24.43\" style=\"width:223.06px;height:24.43px;aspect-ratio:223.06/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/acfaeec4e6af0c51.svg\" alt=\"g_2=0.9-(0)=0.9\" width=\"211.04\" height=\"24.43\" style=\"width:211.04px;height:24.43px;aspect-ratio:211.04/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1708353d6ee40680.svg\" alt=\"\\theta_2=0.9-0.1(0.9)=0.81\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Final parameter after two updates: 0.81.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"mt2-c17-s16","search":"Drill 16 GD variation 1 **Question.** J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two GD updates. \n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½θ².\n\nInitial θ₀ = 1; η = 0.1; two iterations.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.\n### Update formulas\n\n**Step 1: Update 1.**\n\n\n**Step 2: Update 2.**\n\n\n**Final parameter after two updates: 0.81.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 17 GD variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two GD updates.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½(θ−1)².</p>","<p>Initial θ₀ = −0.5; η = 0.1; two iterations.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e49b01175757fe7.svg\"><img class=\"math display-math\" src=\"assets/equations/d9f043ffb887fd14.svg\" alt=\"J(\\theta)=\\frac12(\\theta-1)^2,\\qquad J\\prime(\\theta)=\\theta-1\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.</p>","<h3>Update formulas</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:156.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b3d142fa7d569702.svg\"><img class=\"math display-math\" src=\"assets/equations/1fa856180f9f092b.svg\" alt=\"g_t=J\\prime(\\theta_{t-1}),\\quad \\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"326.86\" height=\"24.43\" style=\"width:326.86px;height:24.43px;aspect-ratio:326.86/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce4034cb1a64ebf6.svg\" alt=\"g_1=-0.5-(1)=-1.5\" width=\"249.06\" height=\"24.43\" style=\"width:249.06px;height:24.43px;aspect-ratio:249.06/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c2dd4efda1f26eb.svg\"><img class=\"math display-math\" src=\"assets/equations/e397e226e8c7c566.svg\" alt=\"\\theta_1=-0.5-0.1(-1.5)=-0.35\" width=\"330.33\" height=\"24.43\" style=\"width:330.33px;height:24.43px;aspect-ratio:330.33/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e8a70b34a625603.svg\" alt=\"g_2=-0.35-(1)=-1.35\" width=\"273.50\" height=\"24.43\" style=\"width:273.50px;height:24.43px;aspect-ratio:273.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/354b5f7978875963.svg\"><img class=\"math display-math\" src=\"assets/equations/b21cdf85d50680f5.svg\" alt=\"\\theta_2=-0.35-0.1(-1.35)=-0.215\" width=\"366.98\" height=\"24.43\" style=\"width:366.98px;height:24.43px;aspect-ratio:366.98/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: -0.215.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"mt2-c17-s17","search":"Drill 17 GD variation 2 **Question.** J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two GD updates. \n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½(θ−1)².\n\nInitial θ₀ = −0.5; η = 0.1; two iterations.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.\n### Update formulas\n\n**Step 1: Update 1.**\n\n\n**Step 2: Update 2.**\n\n\n**Final parameter after two updates: -0.215.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 18 Momentum variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½θ².</p>","<p>Initial θ₀ = 1; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec670e56abfcf00.svg\"><img class=\"math display-math\" src=\"assets/equations/ad9f147031605f82.svg\" alt=\"J(\\theta)=\\frac12(\\theta-0)^2,\\qquad J\\prime(\\theta)=\\theta-0\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51e0e1de442cadbf.svg\" alt=\"g_1=1-(0)=1\" width=\"173.03\" height=\"24.43\" style=\"width:173.03px;height:24.43px;aspect-ratio:173.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/acfaeec4e6af0c51.svg\" alt=\"g_2=0.9-(0)=0.9\" width=\"211.04\" height=\"24.43\" style=\"width:211.04px;height:24.43px;aspect-ratio:211.04/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.38px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0143acec3cdc1b06.svg\"><img class=\"math display-math\" src=\"assets/equations/9d76f7ff1692b41e.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.9)=-0.18\" width=\"361.95\" height=\"24.43\" style=\"width:361.95px;height:24.43px;aspect-ratio:361.95/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Final parameter after two updates: 0.72.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"mt2-c17-s18","search":"Drill 18 Momentum variation 1 **Question.** J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½θ².\n\nInitial θ₀ = 1; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n**Step 2: Update 2.**\n\n\n\n**Final parameter after two updates: 0.72.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 19 Momentum variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½(θ−1)².</p>","<p>Initial θ₀ = −0.5; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e49b01175757fe7.svg\"><img class=\"math display-math\" src=\"assets/equations/d9f043ffb887fd14.svg\" alt=\"J(\\theta)=\\frac12(\\theta-1)^2,\\qquad J\\prime(\\theta)=\\theta-1\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce4034cb1a64ebf6.svg\" alt=\"g_1=-0.5-(1)=-1.5\" width=\"249.06\" height=\"24.43\" style=\"width:249.06px;height:24.43px;aspect-ratio:249.06/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.90px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e63b276a509c75c.svg\"><img class=\"math display-math\" src=\"assets/equations/2679c9e024274dac.svg\" alt=\"v_1=0.9(0)-0.1(-1.5)=0.15\" width=\"323.92\" height=\"24.43\" style=\"width:323.92px;height:24.43px;aspect-ratio:323.92/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3de31f4085d1f9eb.svg\"><img class=\"math display-math\" src=\"assets/equations/76cd873d8955bf17.svg\" alt=\"\\theta_1=-0.5+(0.15)=-0.35\" width=\"292.31\" height=\"24.43\" style=\"width:292.31px;height:24.43px;aspect-ratio:292.31/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e8a70b34a625603.svg\" alt=\"g_2=-0.35-(1)=-1.35\" width=\"273.50\" height=\"24.43\" style=\"width:273.50px;height:24.43px;aspect-ratio:273.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.59px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b81155b82e98b2d.svg\"><img class=\"math display-math\" src=\"assets/equations/23765d6232402c77.svg\" alt=\"v_2=0.9(0.15)-0.1(-1.35)=0.27\" width=\"367.37\" height=\"24.43\" style=\"width:367.37px;height:24.43px;aspect-ratio:367.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5bc5d38d05f5667.svg\"><img class=\"math display-math\" src=\"assets/equations/035af79f7cb5dc94.svg\" alt=\"\\theta_2=-0.35+(0.27)=-0.08\" width=\"304.53\" height=\"24.43\" style=\"width:304.53px;height:24.43px;aspect-ratio:304.53/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: -0.08.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"mt2-c17-s19","search":"Drill 19 Momentum variation 2 **Question.** J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½(θ−1)².\n\nInitial θ₀ = −0.5; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n**Step 2: Update 2.**\n\n\n\n**Final parameter after two updates: -0.08.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 20 Nesterov variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½θ².</p>","<p>Initial θ₀ = 1; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Nesterov lookahead.</strong> First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.</p>","<p>θ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d83df079bf260cc.svg\" alt=\"g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"138.39\" height=\"24.43\" style=\"width:138.39px;height:24.43px;aspect-ratio:138.39/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle look ahead; gradient wahan; update original position se.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec670e56abfcf00.svg\"><img class=\"math display-math\" src=\"assets/equations/ad9f147031605f82.svg\" alt=\"J(\\theta)=\\frac12(\\theta-0)^2,\\qquad J\\prime(\\theta)=\\theta-0\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/122d449c66d53648.svg\"><img class=\"math display-math\" src=\"assets/equations/eebc0b956dd1a540.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1},\\quad g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"378.67\" height=\"24.43\" style=\"width:378.67px;height:24.43px;aspect-ratio:378.67/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44a5155fc196e4c6.svg\" alt=\"\\theta_{\\mathrm{look}}=1+0.9(0)=1\" width=\"226.62\" height=\"24.43\" style=\"width:226.62px;height:24.43px;aspect-ratio:226.62/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51e0e1de442cadbf.svg\" alt=\"g_1=1-(0)=1\" width=\"173.03\" height=\"24.43\" style=\"width:173.03px;height:24.43px;aspect-ratio:173.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.84px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f8c51c39237a8f3.svg\"><img class=\"math display-math\" src=\"assets/equations/e3234cc25d1508de.svg\" alt=\"\\theta_{\\mathrm{look}}=0.9+0.9(-0.1)=0.81\" width=\"314.87\" height=\"24.43\" style=\"width:314.87px;height:24.43px;aspect-ratio:314.87/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f61619e280f936a0.svg\" alt=\"g_2=0.81-(0)=0.81\" width=\"235.47\" height=\"24.43\" style=\"width:235.47px;height:24.43px;aspect-ratio:235.47/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35f06a75a728a22a.svg\"><img class=\"math display-math\" src=\"assets/equations/e92dee4c49c58b06.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.81)=-0.171\" width=\"386.38\" height=\"24.43\" style=\"width:386.38px;height:24.43px;aspect-ratio:386.38/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b7b6422b337bab9.svg\"><img class=\"math display-math\" src=\"assets/equations/2c96483424ef8929.svg\" alt=\"\\theta_2=0.9+(-0.171)=0.729\" width=\"297.73\" height=\"24.43\" style=\"width:297.73px;height:24.43px;aspect-ratio:297.73/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: 0.729.</strong> The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.</p>"],"kind":"practice","id":"mt2-c17-s20","search":"Drill 20 Nesterov variation 1 **Question.** J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½θ².\n\nInitial θ₀ = 1; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Nesterov lookahead.** First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.\n\nθ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle look ahead; gradient wahan; update original position se.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n\n**Step 2: Update 2.**\n\n\n\n\n**Final parameter after two updates: 0.729.** The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.\n"},{"title":"Drill 21 Nesterov variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½(θ−1)².</p>","<p>Initial θ₀ = −0.5; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Nesterov lookahead.</strong> First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.</p>","<p>θ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d83df079bf260cc.svg\" alt=\"g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"138.39\" height=\"24.43\" style=\"width:138.39px;height:24.43px;aspect-ratio:138.39/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle look ahead; gradient wahan; update original position se.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e49b01175757fe7.svg\"><img class=\"math display-math\" src=\"assets/equations/d9f043ffb887fd14.svg\" alt=\"J(\\theta)=\\frac12(\\theta-1)^2,\\qquad J\\prime(\\theta)=\\theta-1\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/122d449c66d53648.svg\"><img class=\"math display-math\" src=\"assets/equations/eebc0b956dd1a540.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1},\\quad g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"378.67\" height=\"24.43\" style=\"width:378.67px;height:24.43px;aspect-ratio:378.67/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.83px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a4363d91dbba8cc0.svg\"><img class=\"math display-math\" src=\"assets/equations/f19658c31004feb6.svg\" alt=\"\\theta_{\\mathrm{look}}=-0.5+0.9(0)=-0.5\" width=\"302.66\" height=\"24.43\" style=\"width:302.66px;height:24.43px;aspect-ratio:302.66/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce4034cb1a64ebf6.svg\" alt=\"g_1=-0.5-(1)=-1.5\" width=\"249.06\" height=\"24.43\" style=\"width:249.06px;height:24.43px;aspect-ratio:249.06/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.90px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e63b276a509c75c.svg\"><img class=\"math display-math\" src=\"assets/equations/2679c9e024274dac.svg\" alt=\"v_1=0.9(0)-0.1(-1.5)=0.15\" width=\"323.92\" height=\"24.43\" style=\"width:323.92px;height:24.43px;aspect-ratio:323.92/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3de31f4085d1f9eb.svg\"><img class=\"math display-math\" src=\"assets/equations/76cd873d8955bf17.svg\" alt=\"\\theta_1=-0.5+(0.15)=-0.35\" width=\"292.31\" height=\"24.43\" style=\"width:292.31px;height:24.43px;aspect-ratio:292.31/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f623b6f68ec5b35a.svg\"><img class=\"math display-math\" src=\"assets/equations/dade5906dabc1018.svg\" alt=\"\\theta_{\\mathrm{look}}=-0.35+0.9(0.15)=-0.215\" width=\"370.54\" height=\"24.43\" style=\"width:370.54px;height:24.43px;aspect-ratio:370.54/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.67px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f77fca68d44fde4d.svg\"><img class=\"math display-math\" src=\"assets/equations/b8b2f5a400acaace.svg\" alt=\"g_2=-0.215-(1)=-1.215\" width=\"297.93\" height=\"24.43\" style=\"width:297.93px;height:24.43px;aspect-ratio:297.93/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/afa161b36559b605.svg\"><img class=\"math display-math\" src=\"assets/equations/e1b4633f6988ed67.svg\" alt=\"v_2=0.9(0.15)-0.1(-1.215)=0.2565\" width=\"404.03\" height=\"24.43\" style=\"width:404.03px;height:24.43px;aspect-ratio:404.03/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cc919e70a6113df8.svg\"><img class=\"math display-math\" src=\"assets/equations/7e5dfb5f2581a338.svg\" alt=\"\\theta_2=-0.35+(0.2565)=-0.0935\" width=\"353.40\" height=\"24.43\" style=\"width:353.40px;height:24.43px;aspect-ratio:353.40/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: -0.0935.</strong> The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.</p>"],"kind":"practice","id":"mt2-c17-s21","search":"Drill 21 Nesterov variation 2 **Question.** J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½(θ−1)².\n\nInitial θ₀ = −0.5; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Nesterov lookahead.** First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.\n\nθ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle look ahead; gradient wahan; update original position se.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n\n**Step 2: Update 2.**\n\n\n\n\n**Final parameter after two updates: -0.0935.** The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.\n"},{"title":"Drill 22 AdaGrad variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = 1; η = 0.1.</p>","<p>Supplied gradients: [2,1].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p>","<p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>G is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/49a0512d42c905d8.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\varepsilon}\" width=\"224.31\" height=\"52.24\" style=\"width:224.31px;height:52.24px;aspect-ratio:224.31/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient 2.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a2f78c9b3d52d653.svg\" alt=\"G_1=0+(2)^2=4\" width=\"191.24\" height=\"27.70\" style=\"width:191.24px;height:27.70px;aspect-ratio:191.24/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7923d1e84dd761ae.svg\" alt=\"\\sqrt{G_1}=\\sqrt{4}=2\" width=\"165.24\" height=\"30.79\" style=\"width:165.24px;height:30.79px;aspect-ratio:165.24/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1122171b0bd236e.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{4}}=0.9\" width=\"263.68\" height=\"60.60\" style=\"width:263.68px;height:60.60px;aspect-ratio:263.68/60.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 1.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd892c081c748bf2.svg\" alt=\"G_2=4+(1)^2=5\" width=\"191.24\" height=\"27.70\" style=\"width:191.24px;height:27.70px;aspect-ratio:191.24/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33c414269f4796af.svg\" alt=\"\\sqrt{G_2}=\\sqrt{5}=2.236067977\" width=\"281.99\" height=\"30.79\" style=\"width:281.99px;height:30.79px;aspect-ratio:281.99/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.88px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2a79e598e1b306b.svg\"><img class=\"math display-math\" src=\"assets/equations/0919f3ad17401c14.svg\" alt=\"\\theta_2=0.9-\\frac{0.1\\times(1)}{\\sqrt{5}}=0.85527864\" width=\"368.22\" height=\"60.60\" style=\"width:368.22px;height:60.60px;aspect-ratio:368.22/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"mt2-c17-s22","search":"Drill 22 AdaGrad variation 1 **Question.** θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = 1; η = 0.1.\n\nSupplied gradients: [2,1].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**AdaGrad.** Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.\n\nG = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.\n\n\n\n\n\n**Yaad rakhne ka cue:** Square karo, purane sum mein jodo, root se scale karo.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nG is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient 2.**\nAdd the new squared gradient to all previous squares.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 1.**\nAdd the new squared gradient to all previous squares.\n\n\n\n"},{"title":"Drill 23 AdaGrad variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = −0.5; η = 0.1.</p>","<p>Supplied gradients: [−1,2].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p>","<p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>G is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/49a0512d42c905d8.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\varepsilon}\" width=\"224.31\" height=\"52.24\" style=\"width:224.31px;height:52.24px;aspect-ratio:224.31/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient -1.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bba453205f160315.svg\" alt=\"G_1=0+(-1)^2=1\" width=\"210.25\" height=\"27.70\" style=\"width:210.25px;height:27.70px;aspect-ratio:210.25/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1112f0b4d6224a38.svg\" alt=\"\\sqrt{G_1}=\\sqrt{1}=1\" width=\"165.24\" height=\"30.79\" style=\"width:165.24px;height:30.79px;aspect-ratio:165.24/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.90px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37395f4e33d5e1e8.svg\"><img class=\"math display-math\" src=\"assets/equations/771de6f5ff86a0f6.svg\" alt=\"\\theta_1=-0.5-\\frac{0.1\\times(-1)}{\\sqrt{1}}=-0.4\" width=\"339.72\" height=\"60.60\" style=\"width:339.72px;height:60.60px;aspect-ratio:339.72/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 2.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e7c36432792b91c.svg\" alt=\"G_2=1+(2)^2=5\" width=\"191.24\" height=\"27.70\" style=\"width:191.24px;height:27.70px;aspect-ratio:191.24/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33c414269f4796af.svg\" alt=\"\\sqrt{G_2}=\\sqrt{5}=2.236067977\" width=\"281.99\" height=\"30.79\" style=\"width:281.99px;height:30.79px;aspect-ratio:281.99/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.89px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1161742779014e25.svg\"><img class=\"math display-math\" src=\"assets/equations/cb523a64bc5840f4.svg\" alt=\"\\theta_2=-0.4-\\frac{0.1\\times(2)}{\\sqrt{5}}=-0.489442719\" width=\"418.46\" height=\"60.60\" style=\"width:418.46px;height:60.60px;aspect-ratio:418.46/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"mt2-c17-s23","search":"Drill 23 AdaGrad variation 2 **Question.** θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = −0.5; η = 0.1.\n\nSupplied gradients: [−1,2].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**AdaGrad.** Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.\n\nG = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.\n\n\n\n\n\n**Yaad rakhne ka cue:** Square karo, purane sum mein jodo, root se scale karo.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nG is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient -1.**\nAdd the new squared gradient to all previous squares.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 2.**\nAdd the new squared gradient to all previous squares.\n\n\n\n"},{"title":"Drill 24 RMSProp variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = 1; η = 0.1.</p>","<p>Supplied gradients: [2,1].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>ρ = 0.9.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p>","<p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>s is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient 2.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a0575b9596aea909.svg\" alt=\"s_1=0.9(0)+0.1(2)^2=0.4\" width=\"283.96\" height=\"27.70\" style=\"width:283.96px;height:27.70px;aspect-ratio:283.96/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8724fbf30b88d3b5.svg\"><img class=\"math display-math\" src=\"assets/equations/ffb5003b52e07ea4.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.4}=0.632455532\" width=\"289.17\" height=\"30.34\" style=\"width:289.17px;height:30.34px;aspect-ratio:289.17/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.88px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/84ca434a6eea16db.svg\"><img class=\"math display-math\" src=\"assets/equations/a1a1a24a56913ad6.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{0.4}}=0.683772234\" width=\"361.42\" height=\"60.60\" style=\"width:361.42px;height:60.60px;aspect-ratio:361.42/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 1.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99dd3340957517b7.svg\"><img class=\"math display-math\" src=\"assets/equations/ec584873dea573e6.svg\" alt=\"s_2=0.9(0.4)+0.1(1)^2=0.46\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7bc15fc56ff7b9f2.svg\"><img class=\"math display-math\" src=\"assets/equations/d68789eef851ad06.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.46}=0.678232998\" width=\"301.38\" height=\"30.34\" style=\"width:301.38px;height:30.34px;aspect-ratio:301.38/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.68px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dec405b6648724b8.svg\"><img class=\"math display-math\" src=\"assets/equations/555de02648791e71.svg\" alt=\"\\theta_2=0.683772234-\\frac{0.1\\times(1)}{\\sqrt{0.46}}=0.536330278\" width=\"478.17\" height=\"60.60\" style=\"width:478.17px;height:60.60px;aspect-ratio:478.17/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"mt2-c17-s24","search":"Drill 24 RMSProp variation 1 **Question.** θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = 1; η = 0.1.\n\nSupplied gradients: [2,1].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nρ = 0.9.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**RMSProp.** Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.\n\ns = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.\n\n\n\n\n\n**Yaad rakhne ka cue:** Saare purane squares nahi—unki fading average.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\ns is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient 2.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 1.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n"},{"title":"Drill 25 RMSProp variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = −0.5; η = 0.1.</p>","<p>Supplied gradients: [−1,2].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>ρ = 0.9.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p>","<p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>s is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient -1.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81d06c696eada47a.svg\"><img class=\"math display-math\" src=\"assets/equations/859c9536cc17d749.svg\" alt=\"s_1=0.9(0)+0.1(-1)^2=0.1\" width=\"302.98\" height=\"27.70\" style=\"width:302.98px;height:27.70px;aspect-ratio:302.98/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.57px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8e43eda4dcf6bcb7.svg\"><img class=\"math display-math\" src=\"assets/equations/8a4a542960803c14.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.1}=0.316227766\" width=\"289.17\" height=\"30.20\" style=\"width:289.17px;height:30.20px;aspect-ratio:289.17/30.20\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.90px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1da7d1cdeda02890.svg\"><img class=\"math display-math\" src=\"assets/equations/3d6651cada170e8a.svg\" alt=\"\\theta_1=-0.5-\\frac{0.1\\times(-1)}{\\sqrt{0.1}}=-0.183772234\" width=\"437.46\" height=\"60.60\" style=\"width:437.46px;height:60.60px;aspect-ratio:437.46/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 2.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c7113e75687c23e.svg\"><img class=\"math display-math\" src=\"assets/equations/6351a5fcafc4c5e8.svg\" alt=\"s_2=0.9(0.1)+0.1(2)^2=0.49\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e14a6fd4eb271def.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.49}=0.7\" width=\"203.66\" height=\"30.34\" style=\"width:203.66px;height:30.34px;aspect-ratio:203.66/30.34\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.68px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dbbd9b6c37d99e9e.svg\"><img class=\"math display-math\" src=\"assets/equations/8c6d3f7be7bc6289.svg\" alt=\"\\theta_2=-0.183772234-\\frac{0.1\\times(2)}{\\sqrt{0.49}}=-0.46948652\" width=\"503.97\" height=\"60.60\" style=\"width:503.97px;height:60.60px;aspect-ratio:503.97/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"mt2-c17-s25","search":"Drill 25 RMSProp variation 2 **Question.** θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = −0.5; η = 0.1.\n\nSupplied gradients: [−1,2].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nρ = 0.9.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**RMSProp.** Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.\n\ns = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.\n\n\n\n\n\n**Yaad rakhne ka cue:** Saare purane squares nahi—unki fading average.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\ns is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient -1.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 2.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n"},{"title":"Drill 26 Adam variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = 1; η = 0.1.</p>","<p>Supplied gradients: [2,1].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>β₁ = 0.9; β₂ = 0.999; use bias correction.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Adam with bias correction.</strong> Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.</p>","<p>m = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1b0801ea4c5e3b1.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\epsilon}\" width=\"219.18\" height=\"66.12\" style=\"width:219.18px;height:66.12px;aspect-ratio:219.18/66.12\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Direction memory + square memory; hats lagao, phir update.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>m remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/cc72454f862696ef.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad \\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"329.41\" height=\"53.28\" style=\"width:329.41px;height:53.28px;aspect-ratio:329.41/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient 2.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ac027abcdfcdb75.svg\" alt=\"m_1=0.9(0)+0.1(2)=0.2\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b00fce2cf8ae5a5b.svg\"><img class=\"math display-math\" src=\"assets/equations/5ddaed21d0d6628c.svg\" alt=\"v_1=0.999(0)+0.001(2)^2=0.004\" width=\"357.66\" height=\"27.70\" style=\"width:357.66px;height:27.70px;aspect-ratio:357.66/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8975b50fed0845b.svg\" alt=\"\\widehat m_1=\\frac{0.2}{1-0.9^{1}}=2\" width=\"204.24\" height=\"54.93\" style=\"width:204.24px;height:54.93px;aspect-ratio:204.24/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f16a835e4241c7ed.svg\" alt=\"\\widehat v_1=\\frac{0.004}{1-0.999^{1}}=4\" width=\"219.07\" height=\"55.20\" style=\"width:219.07px;height:55.20px;aspect-ratio:219.07/55.20\" loading=\"lazy\"></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1122171b0bd236e.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{4}}=0.9\" width=\"263.68\" height=\"60.60\" style=\"width:263.68px;height:60.60px;aspect-ratio:263.68/60.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 1.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6a9a858d7c18aeb.svg\"><img class=\"math display-math\" src=\"assets/equations/4f47b7aabd4f81c4.svg\" alt=\"m_2=0.9(0.2)+0.1(1)=0.28\" width=\"314.52\" height=\"24.43\" style=\"width:314.52px;height:24.43px;aspect-ratio:314.52/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.32px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/308792cf26a22040.svg\"><img class=\"math display-math\" src=\"assets/equations/a1ecf2cf2c6e9e7e.svg\" alt=\"v_2=0.999(0.004)+0.001(1)^2=0.004996\" width=\"437.76\" height=\"27.70\" style=\"width:437.76px;height:27.70px;aspect-ratio:437.76/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2b1a3823c4815fe2.svg\"><img class=\"math display-math\" src=\"assets/equations/62512ed956356eba.svg\" alt=\"\\widehat m_2=\\frac{0.28}{1-0.9^{2}}=1.473684211\" width=\"320.99\" height=\"54.93\" style=\"width:320.99px;height:54.93px;aspect-ratio:320.99/54.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.27px;--narrow-height:94.29px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3922f5c0c13f3037.svg\"><img class=\"math display-math\" src=\"assets/equations/4ae265791f4d129d.svg\" alt=\"\\widehat v_2=\\frac{0.004996}{1-0.999^{2}}=2.499249625\" width=\"335.82\" height=\"55.20\" style=\"width:335.82px;height:55.20px;aspect-ratio:335.82/55.20\" loading=\"lazy\"></picture></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.70px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d6c4212f9eead9c.svg\"><img class=\"math display-math\" src=\"assets/equations/da23812bc6e746bd.svg\" alt=\"\\theta_2=0.9-\\frac{0.1\\times(1.473684211)}{\\sqrt{2.499249625}}=0.806782036\" width=\"497.18\" height=\"60.60\" style=\"width:497.18px;height:60.60px;aspect-ratio:497.18/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"mt2-c17-s26","search":"Drill 26 Adam variation 1 **Question.** θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = 1; η = 0.1.\n\nSupplied gradients: [2,1].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nβ₁ = 0.9; β₂ = 0.999; use bias correction.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Adam with bias correction.** Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.\n\nm = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Direction memory + square memory; hats lagao, phir update.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nm remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.\n\n\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient 2.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n**Step 2: Iteration 2 with supplied gradient 1.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n"},{"title":"Drill 27 Adam variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = −0.5; η = 0.1.</p>","<p>Supplied gradients: [−1,2].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>β₁ = 0.9; β₂ = 0.999; use bias correction.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Adam with bias correction.</strong> Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.</p>","<p>m = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1b0801ea4c5e3b1.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\epsilon}\" width=\"219.18\" height=\"66.12\" style=\"width:219.18px;height:66.12px;aspect-ratio:219.18/66.12\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Direction memory + square memory; hats lagao, phir update.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>m remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/cc72454f862696ef.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad \\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"329.41\" height=\"53.28\" style=\"width:329.41px;height:53.28px;aspect-ratio:329.41/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient -1.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff0acbc11515087e.svg\"><img class=\"math display-math\" src=\"assets/equations/8cb1bdd325f9978f.svg\" alt=\"m_1=0.9(0)+0.1(-1)=-0.1\" width=\"321.31\" height=\"24.43\" style=\"width:321.31px;height:24.43px;aspect-ratio:321.31/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:234.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e44b2300355f9498.svg\"><img class=\"math display-math\" src=\"assets/equations/d05bfcaee435c205.svg\" alt=\"v_1=0.999(0)+0.001(-1)^2=0.001\" width=\"376.67\" height=\"27.70\" style=\"width:376.67px;height:27.70px;aspect-ratio:376.67/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/721803042ed359b9.svg\" alt=\"\\widehat m_1=\\frac{-0.1}{1-0.9^{1}}=-1\" width=\"223.25\" height=\"54.93\" style=\"width:223.25px;height:54.93px;aspect-ratio:223.25/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4d865fbfcf2b328.svg\" alt=\"\\widehat v_1=\\frac{0.001}{1-0.999^{1}}=1\" width=\"219.07\" height=\"54.93\" style=\"width:219.07px;height:54.93px;aspect-ratio:219.07/54.93\" loading=\"lazy\"></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.90px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37395f4e33d5e1e8.svg\"><img class=\"math display-math\" src=\"assets/equations/771de6f5ff86a0f6.svg\" alt=\"\\theta_1=-0.5-\\frac{0.1\\times(-1)}{\\sqrt{1}}=-0.4\" width=\"339.72\" height=\"60.60\" style=\"width:339.72px;height:60.60px;aspect-ratio:339.72/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 2.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/89d9785f6f04be8b.svg\"><img class=\"math display-math\" src=\"assets/equations/dc1a680eebaa1164.svg\" alt=\"m_2=0.9(-0.1)+0.1(2)=0.11\" width=\"333.54\" height=\"24.43\" style=\"width:333.54px;height:24.43px;aspect-ratio:333.54/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.32px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0838089126c8ebdc.svg\"><img class=\"math display-math\" src=\"assets/equations/6ffede766a41d6bd.svg\" alt=\"v_2=0.999(0.001)+0.001(2)^2=0.004999\" width=\"437.76\" height=\"27.70\" style=\"width:437.76px;height:27.70px;aspect-ratio:437.76/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e970513a5c078389.svg\"><img class=\"math display-math\" src=\"assets/equations/bee1e67cf69a8631.svg\" alt=\"\\widehat m_2=\\frac{0.11}{1-0.9^{2}}=0.578947368\" width=\"320.99\" height=\"54.93\" style=\"width:320.99px;height:54.93px;aspect-ratio:320.99/54.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.27px;--narrow-height:94.29px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6410e8fada39e27.svg\"><img class=\"math display-math\" src=\"assets/equations/998deb4908102974.svg\" alt=\"\\widehat v_2=\\frac{0.004999}{1-0.999^{2}}=2.500750375\" width=\"335.82\" height=\"55.20\" style=\"width:335.82px;height:55.20px;aspect-ratio:335.82/55.20\" loading=\"lazy\"></picture></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.70px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3e2be14fb02aba94.svg\"><img class=\"math display-math\" src=\"assets/equations/fc06a7b542215246.svg\" alt=\"\\theta_2=-0.4-\\frac{0.1\\times(0.578947368)}{\\sqrt{2.500750375}}=-0.436610353\" width=\"535.20\" height=\"60.60\" style=\"width:535.20px;height:60.60px;aspect-ratio:535.20/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"mt2-c17-s27","search":"Drill 27 Adam variation 2 **Question.** θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = −0.5; η = 0.1.\n\nSupplied gradients: [−1,2].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nβ₁ = 0.9; β₂ = 0.999; use bias correction.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Adam with bias correction.** Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.\n\nm = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Direction memory + square memory; hats lagao, phir update.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nm remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.\n\n\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient -1.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n**Step 2: Iteration 2 with supplied gradient 2.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n"},{"title":"Drill 28 Regularized objective","question":["<p class=\"inline-question\"><strong>Question.</strong> Data loss = 0.4, w = [−2,1,0.5], λ = 0.1. Calculate L1 objective and L2 objective using (λ/2)Σw².</p>"],"answer":["<h3>Given</h3>","<p>Data loss = 0.4; weights = [−2,1,0.5]; λ = 0.1.</p>","<p>For L2, the question includes the factor ½.</p>","<h3>To find</h3>","<p>Find each penalty and the total L1/L2 objective.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>L2 penalty with a factor of one-half.</strong> Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.</p>","<p>λ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29419cadd5578572.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc02963f72332f.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"179.88\" height=\"23.98\" style=\"width:179.88px;height:23.98px;aspect-ratio:179.88/23.98\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/616c8cbb90430248.svg\" alt=\"w_i^{\\mathrm{new}}=w_i-\\eta g_i\" width=\"169.00\" height=\"24.06\" style=\"width:169.00px;height:24.06px;aspect-ratio:169.00/24.06\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half wala L2 derivative mein lambda × weight deta hai.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The data loss measures prediction error. A regularization penalty adds a cost for large weights. The objective J is the total being minimized. λ sets the strength of the penalty.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14053316f92ab54d.svg\" alt=\"J_{L1}=L_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"247.46\" height=\"52.35\" style=\"width:247.46px;height:52.35px;aspect-ratio:247.46/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3cf9af2ddfa197c.svg\" alt=\"J_{L2}=L_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"247.31\" height=\"62.61\" style=\"width:247.31px;height:62.61px;aspect-ratio:247.31/62.61\" loading=\"lazy\"></div>","<p>Absolute value means ignore the sign. Squaring means multiply the number by itself. These are different operations.</p>","<p class=\"worked-step\"><strong>Step 1: Part A: L1 objective.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:108.63px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcceddf63f9341b2.svg\"><img class=\"math display-math\" src=\"assets/equations/9936fa64e265469b.svg\" alt=\"|-2|=2,\\quad |1|=1,\\quad |0.5|=0.5\" width=\"350.30\" height=\"24.41\" style=\"width:350.30px;height:24.41px;aspect-ratio:350.30/24.41\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.48px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb36584739f81886.svg\"><img class=\"math display-math\" src=\"assets/equations/2a71081b4845e558.svg\" alt=\"\\sum_i|w_i|=2+1+0.5=3.5\" width=\"290.22\" height=\"52.35\" style=\"width:290.22px;height:52.35px;aspect-ratio:290.22/52.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.95px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc6e588ea36fd61a.svg\"><img class=\"math display-math\" src=\"assets/equations/e5d16adbe508b8b5.svg\" alt=\"\\text{L1 penalty}=0.1\\times3.5=0.35\" width=\"313.97\" height=\"21.95\" style=\"width:313.97px;height:21.95px;aspect-ratio:313.97/21.95\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3ee4cac7da2daf6.svg\" alt=\"J_{L1}=0.4+0.35=0.75\" width=\"249.15\" height=\"20.36\" style=\"width:249.15px;height:20.36px;aspect-ratio:249.15/20.36\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Part B: L2 objective with the given half.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:117.93px;--narrow-height:112.44px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ef16358fc81a0cdc.svg\"><img class=\"math display-math\" src=\"assets/equations/f1d2b6bccfe10f10.svg\" alt=\"(-2)^2=4,\\quad 1^2=1,\\quad 0.5^2=0.25\" width=\"361.92\" height=\"27.70\" style=\"width:361.92px;height:27.70px;aspect-ratio:361.92/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.79px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/18bd7cc9173340e8.svg\"><img class=\"math display-math\" src=\"assets/equations/ae0c24324eadcb63.svg\" alt=\"\\sum_iw_i^2=4+1+0.25=5.25\" width=\"303.75\" height=\"52.35\" style=\"width:303.75px;height:52.35px;aspect-ratio:303.75/52.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/482c5bfd76d38e6c.svg\" alt=\"\\frac\\lambda2=\\frac{0.1}2=0.05\" width=\"175.59\" height=\"50.24\" style=\"width:175.59px;height:50.24px;aspect-ratio:175.59/50.24\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.06px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/722ddb9c14ea7480.svg\"><img class=\"math display-math\" src=\"assets/equations/785c143e9ad28b18.svg\" alt=\"\\text{L2 penalty}=0.05\\times5.25=0.2625\" width=\"362.84\" height=\"21.95\" style=\"width:362.84px;height:21.95px;aspect-ratio:362.84/21.95\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6399f9c64b91d83f.svg\"><img class=\"math display-math\" src=\"assets/equations/318e776fa7639b85.svg\" alt=\"J_{L2}=0.4+0.2625=0.6625\" width=\"298.02\" height=\"20.36\" style=\"width:298.02px;height:20.36px;aspect-ratio:298.02/20.36\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> L1 objective 0.75; L2 objective 0.6625. These are total objectives, not just penalty values.</p>"],"kind":"practice","id":"mt2-c17-s28","search":"Drill 28 Regularized objective **Question.** Data loss = 0.4, w = [−2,1,0.5], λ = 0.1. Calculate L1 objective and L2 objective using (λ/2)Σw².\n\n**Full solution.**\n\n\n\n### Given\n\nData loss = 0.4; weights = [−2,1,0.5]; λ = 0.1.\n\nFor L2, the question includes the factor ½.\n\n### To find\n\nFind each penalty and the total L1/L2 objective.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**L2 penalty with a factor of one-half.** Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.\n\nλ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Half wala L2 derivative mein lambda × weight deta hai.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe data loss measures prediction error. A regularization penalty adds a cost for large weights. The objective J is the total being minimized. λ sets the strength of the penalty.\n\n\nAbsolute value means ignore the sign. Squaring means multiply the number by itself. These are different operations.\n**Step 1: Part A: L1 objective.**\n\n\n\n\n**Step 2: Part B: L2 objective with the given half.**\n\n\n\n\n\n**Final answer:** L1 objective 0.75; L2 objective 0.6625. These are total objectives, not just penalty values.\n"},{"title":"Drill 29 L1 update on positive and negative weights","question":["<p class=\"inline-question\"><strong>Question.</strong> w = [−0.5,0.3], data gradients = [0.2,−0.1], λ = 0.1, η = 0.2. Use L1 and ordinary gradient descent away from zero.</p>"],"answer":["<h3>Given</h3>","<p>Old weights = [−0.5,0.3].</p>","<p>Data gradients = [0.2,−0.1]; λ = 0.1; η = 0.2.</p>","<h3>To find</h3>","<p>Find total gradients and the two updated weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>The supplied data gradient is only one part of the total gradient. L1 adds λ times the sign of the old weight. Sign is −1 for a negative weight and +1 for a positive weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:152.92px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/edfc42b95078bb2c.svg\"><img class=\"math display-math\" src=\"assets/equations/9bff63bbdd0e51df.svg\" alt=\"g_{j,\\mathrm{total}}=g_{j,\\mathrm{data}}+\\lambda\\operatorname{sign}(w_j)\" width=\"288.99\" height=\"25.52\" style=\"width:288.99px;height:25.52px;aspect-ratio:288.99/25.52\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8e2c2fa59e985f4e.svg\" alt=\"w_{j,\\mathrm{new}}=w_j-\\eta g_{j,\\mathrm{total}}\" width=\"223.56\" height=\"21.44\" style=\"width:223.56px;height:21.44px;aspect-ratio:223.56/21.44\" loading=\"lazy\"></div>","<p>Both weights here are nonzero, so the ambiguous derivative of absolute value at zero is not needed.</p>","<p class=\"worked-step\"><strong>Step 1: Weight 1: old value −0.5.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:243.83px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/56f95d7675b65e54.svg\"><img class=\"math display-math\" src=\"assets/equations/ebeb8e1558332839.svg\" alt=\"\\lambda\\operatorname{sign}(-0.5)=0.1(-1)=-0.1\" width=\"326.66\" height=\"24.43\" style=\"width:326.66px;height:24.43px;aspect-ratio:326.66/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.58px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee9041d822361870.svg\"><img class=\"math display-math\" src=\"assets/equations/7626b740cec3ed4d.svg\" alt=\"g_{1,\\mathrm{total}}=0.2+(-0.1)=0.1\" width=\"289.39\" height=\"25.35\" style=\"width:289.39px;height:25.35px;aspect-ratio:289.39/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.88px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6d4d841ab160b740.svg\"><img class=\"math display-math\" src=\"assets/equations/49b338a1efee1ae5.svg\" alt=\"w_{1,\\mathrm{new}}=-0.5-0.2(0.1)=-0.5-0.02=-0.52\" width=\"508.04\" height=\"25.35\" style=\"width:508.04px;height:25.35px;aspect-ratio:508.04/25.35\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Weight 2: old value 0.3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cce8304f0261d4a5.svg\" alt=\"\\lambda\\operatorname{sign}(0.3)=0.1(1)=0.1\" width=\"269.63\" height=\"24.43\" style=\"width:269.63px;height:24.43px;aspect-ratio:269.63/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/09ef0e91f63c60f6.svg\" alt=\"g_{2,\\mathrm{total}}=-0.1+0.1=0\" width=\"251.37\" height=\"23.30\" style=\"width:251.37px;height:23.30px;aspect-ratio:251.37/23.30\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39fa74bf610f2797.svg\" alt=\"w_{2,\\mathrm{new}}=0.3-0.2(0)=0.3\" width=\"282.67\" height=\"25.35\" style=\"width:282.67px;height:25.35px;aspect-ratio:282.67/25.35\" loading=\"lazy\"></div>","<p><strong>Final answer: [−0.52, 0.3].</strong> L1&#x27;s own contribution pulls toward zero, but the combined data-plus-penalty update can move a weight away from zero.</p>"],"kind":"practice","id":"mt2-c17-s29","search":"Drill 29 L1 update on positive and negative weights **Question.** w = [−0.5,0.3], data gradients = [0.2,−0.1], λ = 0.1, η = 0.2. Use L1 and ordinary gradient descent away from zero.\n\n**Full solution.**\n\n\n\n### Given\n\nOld weights = [−0.5,0.3].\n\nData gradients = [0.2,−0.1]; λ = 0.1; η = 0.2.\n\n### To find\n\nFind total gradients and the two updated weights.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nThe supplied data gradient is only one part of the total gradient. L1 adds λ times the sign of the old weight. Sign is −1 for a negative weight and +1 for a positive weight.\n\n\nBoth weights here are nonzero, so the ambiguous derivative of absolute value at zero is not needed.\n**Step 1: Weight 1: old value −0.5.**\n\n\n\n**Step 2: Weight 2: old value 0.3.**\n\n\n\n**Final answer: [−0.52, 0.3].** L1's own contribution pulls toward zero, but the combined data-plus-penalty update can move a weight away from zero.\n"},{"title":"Drill 30 L2 update","question":["<p class=\"inline-question\"><strong>Question.</strong> w = [0.5,−0.2], data gradients = [0.1,0.3], λ = 0.2, η = 0.1. Use(λ/2)Σw².</p>"],"answer":["<h3>Given</h3>","<p>Old weights = [0.5,−0.2]; data gradients = [0.1,0.3].</p>","<p>λ = 0.2; η = 0.1; penalty = (λ/2)Σw².</p>","<h3>To find</h3>","<p>Find penalty gradients, total gradients and updated weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>L2 penalty with a factor of one-half.</strong> Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.</p>","<p>λ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29419cadd5578572.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc02963f72332f.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"179.88\" height=\"23.98\" style=\"width:179.88px;height:23.98px;aspect-ratio:179.88/23.98\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/616c8cbb90430248.svg\" alt=\"w_i^{\\mathrm{new}}=w_i-\\eta g_i\" width=\"169.00\" height=\"24.06\" style=\"width:169.00px;height:24.06px;aspect-ratio:169.00/24.06\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half wala L2 derivative mein lambda × weight deta hai.</p>","<h3>Solution — step by step</h3>","<h3>Formula and its reason</h3>","<p>The derivative of (λ/2)w² is λw: the 2 from the square cancels the half. Add that regularization gradient to the given data gradient before updating.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6dece7c528660c2d.svg\" alt=\"g_{j,\\mathrm{total}}=g_{j,\\mathrm{data}}+\\lambda w_j\" width=\"223.68\" height=\"24.15\" style=\"width:223.68px;height:24.15px;aspect-ratio:223.68/24.15\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8e2c2fa59e985f4e.svg\" alt=\"w_{j,\\mathrm{new}}=w_j-\\eta g_{j,\\mathrm{total}}\" width=\"223.56\" height=\"21.44\" style=\"width:223.56px;height:21.44px;aspect-ratio:223.56/21.44\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 1: Weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26564fe78f783309.svg\" alt=\"\\lambda w_1=0.2\\times0.5=0.1\" width=\"231.13\" height=\"20.63\" style=\"width:231.13px;height:20.63px;aspect-ratio:231.13/20.63\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e611707728d90ba8.svg\" alt=\"g_{1,\\mathrm{total}}=0.1+0.1=0.2\" width=\"251.37\" height=\"23.30\" style=\"width:251.37px;height:23.30px;aspect-ratio:251.37/23.30\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.86px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/86b47a5bd5373b33.svg\"><img class=\"math display-math\" src=\"assets/equations/055c0eb9628a74ae.svg\" alt=\"w_{1,\\mathrm{new}}=0.5-0.1(0.2)=0.48\" width=\"313.89\" height=\"25.35\" style=\"width:313.89px;height:25.35px;aspect-ratio:313.89/25.35\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d1d1a2ba29bb3862.svg\"><img class=\"math display-math\" src=\"assets/equations/469562aa281fbfba.svg\" alt=\"\\lambda w_2=0.2\\times(-0.2)=-0.04\" width=\"300.37\" height=\"24.43\" style=\"width:300.37px;height:24.43px;aspect-ratio:300.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.79px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eeb80cfd582d91ed.svg\"><img class=\"math display-math\" src=\"assets/equations/0590c2b0e0fd2940.svg\" alt=\"g_{2,\\mathrm{total}}=0.3+(-0.04)=0.26\" width=\"313.83\" height=\"25.35\" style=\"width:313.83px;height:25.35px;aspect-ratio:313.83/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b559be4dc46e47e0.svg\"><img class=\"math display-math\" src=\"assets/equations/7c525ffa9dc17255.svg\" alt=\"w_{2,\\mathrm{new}}=-0.2-0.1(0.26)=-0.226\" width=\"376.35\" height=\"25.35\" style=\"width:376.35px;height:25.35px;aspect-ratio:376.35/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final answer: [0.48, −0.226].</strong> The second data gradient dominates the regularization term, explaining why that negative weight becomes more negative.</p>"],"kind":"practice","id":"mt2-c17-s30","search":"Drill 30 L2 update **Question.** w = [0.5,−0.2], data gradients = [0.1,0.3], λ = 0.2, η = 0.1. Use(λ/2)Σw².\n\n**Full solution.**\n\n\n\n### Given\n\nOld weights = [0.5,−0.2]; data gradients = [0.1,0.3].\n\nλ = 0.2; η = 0.1; penalty = (λ/2)Σw².\n\n### To find\n\nFind penalty gradients, total gradients and updated weights.\n\n### Formula — which one and why\n\n**L2 penalty with a factor of one-half.** Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.\n\nλ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Half wala L2 derivative mein lambda × weight deta hai.\n\n### Solution — step by step\n\n\n\n\n\n### Formula and its reason\nThe derivative of (λ/2)w² is λw: the 2 from the square cancels the half. Add that regularization gradient to the given data gradient before updating.\n\n\n**Step 1: Weight 1.**\n\n\n\n**Step 2: Weight 2.**\n\n\n\n**Final answer: [0.48, −0.226].** The second data gradient dominates the regularization term, explaining why that negative weight becomes more negative.\n"},{"title":"Drill 31 Inverted dropout","question":["<p class=\"inline-question\"><strong>Question.</strong> Activations = [2,−1,0,3], keep probability 0.75, mask = [1,0,1,1]. Find training outputs and explain inference.</p>"],"answer":["<h3>Given</h3>","<p>Activations = [2,−1,0,3].</p>","<p>Keep probability q = 0.75; keep mask = [1,0,1,1].</p>","<h3>To find</h3>","<p>Find training outputs and state the inference rule.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>The mask entry m is 1 when an activation is kept and 0 when dropped. The keep probability q is 0.75. Inverted dropout divides the kept activations by q during training so that their expected value is preserved.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4210eb7af01249ba.svg\" alt=\"a&#x27;_j=\\frac{m_j a_j}{q}\" width=\"118.08\" height=\"50.73\" style=\"width:118.08px;height:50.73px;aspect-ratio:118.08/50.73\" loading=\"lazy\"></div>","<p>The multiplication is entry by entry; there is no dot-product sum.</p>","<h3>Step 1: apply the mask</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:259.35px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f0ff08cea46f6163.svg\"><img class=\"math display-math\" src=\"assets/equations/0a3991790719d436.svg\" alt=\"[1(2),\\;0(-1),\\;1(0),\\;1(3)]=[2,0,0,3]\" width=\"386.99\" height=\"24.43\" style=\"width:386.99px;height:24.43px;aspect-ratio:386.99/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: divide each result by 0.75</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4257cce51e38bfe0.svg\" alt=\"a&#x27;_1=\\frac2{0.75}=2.666666667\" width=\"271.92\" height=\"50.09\" style=\"width:271.92px;height:50.09px;aspect-ratio:271.92/50.09\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.97px;--narrow-height:114.84px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93312a45b7b42272.svg\"><img class=\"math display-math\" src=\"assets/equations/f7f43ac5cd2d312a.svg\" alt=\"a&#x27;_2=\\frac0{0.75}=0,\\qquad a&#x27;_3=\\frac0{0.75}=0\" width=\"370.08\" height=\"50.09\" style=\"width:370.08px;height:50.09px;aspect-ratio:370.08/50.09\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d5f3e01a5c059a83.svg\" alt=\"a&#x27;_4=\\frac3{0.75}=4\" width=\"155.17\" height=\"50.07\" style=\"width:155.17px;height:50.07px;aspect-ratio:155.17/50.07\" loading=\"lazy\"></div>","<p><strong>Training output = [2.666666667, 0, 0, 4].</strong> A kept activation that was already zero stays zero.</p>","<h3>During inference</h3>","<p>Disable the random mask and the division. If the incoming activations are the same [2,−1,0,3], they pass through unchanged. The scaling has already been accounted for during training.</p>"],"kind":"practice","id":"mt2-c17-s31","search":"Drill 31 Inverted dropout **Question.** Activations = [2,−1,0,3], keep probability 0.75, mask = [1,0,1,1]. Find training outputs and explain inference.\n\n**Full solution.**\n\n\n\n### Given\n\nActivations = [2,−1,0,3].\n\nKeep probability q = 0.75; keep mask = [1,0,1,1].\n\n### To find\n\nFind training outputs and state the inference rule.\n\n### Formula — which one and why\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nThe mask entry m is 1 when an activation is kept and 0 when dropped. The keep probability q is 0.75. Inverted dropout divides the kept activations by q during training so that their expected value is preserved.\n\nThe multiplication is entry by entry; there is no dot-product sum.\n### Step 1: apply the mask\n\n### Step 2: divide each result by 0.75\n\n\n\n**Training output = [2.666666667, 0, 0, 4].** A kept activation that was already zero stays zero.\n### During inference\nDisable the random mask and the division. If the incoming activations are the same [2,−1,0,3], they pass through unchanged. The scaling has already been accounted for during training.\n"},{"title":"Drill 32 Convolution with a negative coefficient","question":["<p class=\"inline-question\"><strong>Question.</strong> Use the input A and kernel K shown below, stride 1, padding 0. Compute all outputs.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 1; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Input A and kernel K are printed with the question.</p>","<p>Stride S = 1; padding P = 0; bias = 0.</p>","<p>Use the kernel without flipping it.</p>","<h3>To find</h3>","<p>Calculate all nine output cells.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<h3>Formulas and the operation we are performing</h3>","<p>A filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:281.49px;--narrow-height:152.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1a1aa2b10ea1816e.svg\"><img class=\"math display-math\" src=\"assets/equations/33407dafb559f8d6.svg\" alt=\"Y_{ij}=\\sum_{u=0}^{K_h-1}\\sum_{v=0}^{K_w-1}X_{iS+u,jS+v}K_{uv}+b\" width=\"351.15\" height=\"73.34\" style=\"width:351.15px;height:73.34px;aspect-ratio:351.15/73.34\" loading=\"lazy\"></picture></div>","<p>Here i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.</p>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/99ba828c16946a06.svg\" alt=\"\\left\\lfloor\\frac{4+2 \\times  0-2}{1}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 3 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + (−2) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 1 = 1</b></div></div><p class=\"lv-combine\"><b>(−1) + 1 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0c50421371c4116.svg\"><img class=\"math display-math\" src=\"assets/equations/62842635b6eb75f8.svg\" alt=\"R_1=(1)\\times(1)+(2)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8c103dd6ecdec24c.svg\"><img class=\"math display-math\" src=\"assets/equations/d060bcb31ccbcc5c.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(1)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23722ac152853b27.svg\" alt=\"Y_{1,1}=(-1)+(1)=0\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 3 = 3</b></div></div><p class=\"lv-combine\"><b>2 + 3 = 5</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92e95617002bb2ff.svg\"><img class=\"math display-math\" src=\"assets/equations/65b69a57c4f3db18.svg\" alt=\"R_1=(2)\\times(1)+(0)\\times(-1)=2\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/89af9e3096091f5c.svg\"><img class=\"math display-math\" src=\"assets/equations/651ec43291a6ceee.svg\" alt=\"R_2=(1)\\times(0)+(3)\\times(1)=3\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e073412e219f2310.svg\" alt=\"Y_{1,2}=(2)+(3)=5\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + (−1) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 2 = 2</b></div></div><p class=\"lv-combine\"><b>(−1) + 2 = 1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37f1662710810d02.svg\"><img class=\"math display-math\" src=\"assets/equations/4bff5878f34559b0.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1986dc904d99f31e.svg\"><img class=\"math display-math\" src=\"assets/equations/e54c044f72c7530b.svg\" alt=\"R_2=(3)\\times(0)+(2)\\times(1)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48b778ac3ad46a58.svg\" alt=\"Y_{1,3}=(-1)+(2)=1\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + (−1) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 1 = 1</b></div></div><p class=\"lv-combine\"><b>(−1) + 1 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37f1662710810d02.svg\"><img class=\"math display-math\" src=\"assets/equations/4bff5878f34559b0.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e63832c06fcb7aed.svg\"><img class=\"math display-math\" src=\"assets/equations/bd0efbee152c1e5c.svg\" alt=\"R_2=(2)\\times(0)+(1)\\times(1)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cb2a77b737bf455.svg\" alt=\"Y_{2,1}=(-1)+(1)=0\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −3\">−3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + (−3) = −2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>(−2) + 0 = −2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/540cabd018cf9dd5.svg\"><img class=\"math display-math\" src=\"assets/equations/ad79fb60fa82034f.svg\" alt=\"R_1=(1)\\times(1)+(3)\\times(-1)=-2\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75388bfbb51edc5c.svg\"><img class=\"math display-math\" src=\"assets/equations/b595ad69d60edb10.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(1)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a1f7599e33d0692.svg\" alt=\"Y_{2,2}=(-2)+(0)=-2\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + (−2) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 1 = 1</b></div></div><p class=\"lv-combine\"><b>1 + 1 = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/941c8bddd3a4fd90.svg\"><img class=\"math display-math\" src=\"assets/equations/142f16f0e77fc1bc.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(-1)=1\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8c103dd6ecdec24c.svg\"><img class=\"math display-math\" src=\"assets/equations/d060bcb31ccbcc5c.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(1)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba68e9967c8a5ec6.svg\" alt=\"Y_{2,3}=(1)+(1)=2\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + (−1) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>1 + 0 = 1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ed9de22182a739e4.svg\"><img class=\"math display-math\" src=\"assets/equations/271ba4631f61b76a.svg\" alt=\"R_1=(2)\\times(1)+(1)\\times(-1)=1\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75388bfbb51edc5c.svg\"><img class=\"math display-math\" src=\"assets/equations/b595ad69d60edb10.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(1)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/108e2edb8fe7afbe.svg\" alt=\"Y_{3,1}=(1)+(0)=1\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 2 = 2</b></div></div><p class=\"lv-combine\"><b>1 + 2 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/248757728423ee8c.svg\"><img class=\"math display-math\" src=\"assets/equations/56ab2f7173dad1a0.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(-1)=1\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8b2b9a5baccb2ea6.svg\"><img class=\"math display-math\" src=\"assets/equations/925c2ca7e5d512dc.svg\" alt=\"R_2=(0)\\times(0)+(2)\\times(1)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/50d4d84e0be67f18.svg\" alt=\"Y_{3,2}=(1)+(2)=3\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + (−1) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 3 = 3</b></div></div><p class=\"lv-combine\"><b>(−1) + 3 = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37f1662710810d02.svg\"><img class=\"math display-math\" src=\"assets/equations/4bff5878f34559b0.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c18dea868e99c1c8.svg\"><img class=\"math display-math\" src=\"assets/equations/410d185792d0d4e1.svg\" alt=\"R_2=(2)\\times(0)+(3)\\times(1)=3\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5248561d79f5d37a.svg\" alt=\"Y_{3,3}=(-1)+(3)=2\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/1659d27513ae9f09.svg\" alt=\"\\begin{bmatrix}0 &amp; 5 &amp; 1\\\\0 &amp; -2 &amp; 2\\\\1 &amp; 3 &amp; 2\\end{bmatrix}\" width=\"106.65\" height=\"72.21\" style=\"width:106.65px;height:72.21px;aspect-ratio:106.65/72.21\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"kind":"practice","id":"mt2-c17-s32","search":"Drill 32 Convolution with a negative coefficient **Question.** Use the input A and kernel K shown below, stride 1, padding 0. Compute all outputs.\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput A and kernel K are printed with the question.\n\nStride S = 1; padding P = 0; bias = 0.\n\nUse the kernel without flipping it.\n\n### To find\n\nCalculate all nine output cells.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and the operation we are performing\nA filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.\n\nHere i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.\n\nN is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.\n\n\n\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{4+2 \\times  0-2}{1}\\right\\rfloor+1\\) = 3 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.\n**Output (1,1): ** (1 × (1)) + (2 × (-1)) + (0 × (0)) + (1 × (1)) = **0**.\n**Output (1,2): ** (2 × (1)) + (0 × (-1)) + (1 × (0)) + (3 × (1)) = **5**.\n**Output (1,3): ** (0 × (1)) + (1 × (-1)) + (3 × (0)) + (2 × (1)) = **1**.\n**Output (2,1): ** (0 × (1)) + (1 × (-1)) + (2 × (0)) + (1 × (1)) = **0**.\n**Output (2,2): ** (1 × (1)) + (3 × (-1)) + (1 × (0)) + (0 × (1)) = **-2**.\n**Output (2,3): ** (3 × (1)) + (2 × (-1)) + (0 × (0)) + (1 × (1)) = **2**.\n**Output (3,1): ** (2 × (1)) + (1 × (-1)) + (1 × (0)) + (0 × (1)) = **1**.\n**Output (3,2): ** (1 × (1)) + (0 × (-1)) + (0 × (0)) + (2 × (1)) = **3**.\n**Output (3,3): ** (0 × (1)) + (1 × (-1)) + (2 × (0)) + (3 × (1)) = **2**.\n**Final output: ** . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.\n"},{"title":"Drill 33 Padding stride and channels","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 31 × 31 × 3; 5 × 5 convolution,8 filters, stride 2, padding 1. Find shape, weights, biases, total.</p>"],"answer":["<h3>Given</h3>","<p>Input shape = 31 × 31 × 3.</p>","<p>Filter size = 5 × 5; number of filters = 8.</p>","<p>Stride S = 2; padding P = 1 per side; one bias per filter.</p>","<h3>To find</h3>","<p>Find output shape, weights, biases and total parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of each given value</h3>","<p>The input has height 31, width 31 and 3 channels. K = 5 is the filter width/height; S = 2 is the stride; P = 1 is padding on each side. Eight filters create eight output channels.</p>","<h3>Formulas used</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.63px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4fb085a2eda022c5.svg\"><img class=\"math display-math\" src=\"assets/equations/391b54fdb0c0ef2b.svg\" alt=\"\\text{weights}=K^2C_{\\mathrm{in}}C_{\\mathrm{out}},\\quad \\text{biases}=C_{\\mathrm{out}}\" width=\"399.88\" height=\"26.63\" style=\"width:399.88px;height:26.63px;aspect-ratio:399.88/26.63\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35882bbb02ddb8aa.svg\"><img class=\"math display-math\" src=\"assets/equations/37224dd4ef25f22f.svg\" alt=\"\\text{parameters}=\\text{weights}+\\text{biases}\" width=\"323.73\" height=\"21.99\" style=\"width:323.73px;height:21.99px;aspect-ratio:323.73/21.99\" loading=\"lazy\"></picture></div>","<h3>Step 1: find the output height and width</h3>","<p>Padding adds one cell on each side, so the padded width is 31 + 2 × 1 = 33.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:97.97px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f73307dcf9d893e8.svg\"><img class=\"math display-math\" src=\"assets/equations/a4fa49b6e311d65e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{31+2(1)-5}{2}\\right\\rfloor+1\" width=\"300.36\" height=\"58.87\" style=\"width:300.36px;height:58.87px;aspect-ratio:300.36/58.87\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.98px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c0ed9983d10f2a99.svg\"><img class=\"math display-math\" src=\"assets/equations/70537488f5dc8b8a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{28}{2}\\right\\rfloor+1=14+1=15\" width=\"341.09\" height=\"58.62\" style=\"width:341.09px;height:58.62px;aspect-ratio:341.09/58.62\" loading=\"lazy\"></picture></div>","<p>The height uses the same calculation. <strong>Output shape = 15 × 15 × 8.</strong></p>","<h3>Step 2: count weights in one filter</h3>","<p>Each filter covers 5 × 5 positions in each of 3 channels.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ce380d19eaf1a9e.svg\"><img class=\"math display-math\" src=\"assets/equations/56e79229382e122b.svg\" alt=\"5\\times5\\times3=75\\text{ weights per filter}\" width=\"336.96\" height=\"22.26\" style=\"width:336.96px;height:22.26px;aspect-ratio:336.96/22.26\" loading=\"lazy\"></picture></div>","<h3>Step 3: count all filters and their biases</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/19223176d175b12b.svg\" alt=\"\\text{weights}=75\\times8=600\" width=\"248.56\" height=\"21.99\" style=\"width:248.56px;height:21.99px;aspect-ratio:248.56/21.99\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e580536b54e8c233.svg\"><img class=\"math display-math\" src=\"assets/equations/311dd5c76d87d54c.svg\" alt=\"\\text{biases}=8,\\qquad \\text{total}=600+8=608\" width=\"398.03\" height=\"21.70\" style=\"width:398.03px;height:21.70px;aspect-ratio:398.03/21.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> shape 15 × 15 × 8; 600 weights; 8 biases; 608 parameters. The 15 × 15 output locations reuse those weights.</p>"],"kind":"practice","id":"mt2-c17-s33","search":"Drill 33 Padding stride and channels **Question.** Input 31 × 31 × 3; 5 × 5 convolution,8 filters, stride 2, padding 1. Find shape, weights, biases, total.\n\n**Full solution.**\n\n\n\n### Given\n\nInput shape = 31 × 31 × 3.\n\nFilter size = 5 × 5; number of filters = 8.\n\nStride S = 2; padding P = 1 per side; one bias per filter.\n\n### To find\n\nFind output shape, weights, biases and total parameters.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of each given value\nThe input has height 31, width 31 and 3 channels. K = 5 is the filter width/height; S = 2 is the stride; P = 1 is padding on each side. Eight filters create eight output channels.\n### Formulas used\n\n\n\n### Step 1: find the output height and width\nPadding adds one cell on each side, so the padded width is 31 + 2 × 1 = 33.\n\n\nThe height uses the same calculation. **Output shape = 15 × 15 × 8.**\n### Step 2: count weights in one filter\nEach filter covers 5 × 5 positions in each of 3 channels.\n\n### Step 3: count all filters and their biases\n\n\n**Final answer:** shape 15 × 15 × 8; 600 weights; 8 biases; 608 parameters. The 15 × 15 output locations reuse those weights.\n"},{"title":"Drill 34 Max and average pooling","question":["<p class=\"inline-question\"><strong>Question.</strong> Pool the input A shown below with 2 × 2 windows and stride 2. Find max and average outputs.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_563e4ee8f7.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_563e4ee8f7.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"405\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input A is printed with the question.</p>","<p>Window size = 2 × 2; stride = 2; no padding.</p>","<h3>To find</h3>","<p>Find the complete max-pooling and average-pooling outputs.</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<h3>Formulas and meaning</h3>","<p>Each 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/870fc5e76c2ff285.svg\" alt=\"p_{\\mathrm{max}}=\\max(a_1,a_2,a_3,a_4)\" width=\"270.51\" height=\"24.43\" style=\"width:270.51px;height:24.43px;aspect-ratio:270.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf572bd2a565d88a.svg\" alt=\"p_{\\mathrm{avg}}=\\frac{a_1+a_2+a_3+a_4}{4}\" width=\"268.03\" height=\"47.52\" style=\"width:268.03px;height:47.52px;aspect-ratio:268.03/47.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.64px;--narrow-height:98.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a9854190bb7c9a.svg\"><img class=\"math display-math\" src=\"assets/equations/bd33b42a8814468f.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"300.97\" height=\"58.62\" style=\"width:300.97px;height:58.62px;aspect-ratio:300.97/58.62\" loading=\"lazy\"></picture></div>","<p>Use the input size at the pooling layer. The output keeps the same channel count.</p>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ad46d0c1b3646c71.svg\" alt=\"\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[1, 4, 0, 2]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>1 + 4 + 0 + 2 = 7</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>7/4 = <strong>1.75</strong>. Maximum = <strong>4</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[2, 3, 5, 1]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>2 + 3 + 5 + 1 = 11</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>11/4 = <strong>2.75</strong>. Maximum = <strong>5</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[6, 3, 1, 7]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>6 + 3 + 1 + 7 = 17</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>17/4 = <strong>4.25</strong>. Maximum = <strong>7</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[2, 0, 4, 8]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>2 + 0 + 4 + 8 = 14</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>14/4 = <strong>3.5</strong>. Maximum = <strong>8</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c4e510493e329d60.svg\" alt=\"\\begin{bmatrix}1.75 &amp; 2.75\\\\4.25 &amp; 3.5\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>. <strong>Max output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/71895dac90bdedf0.svg\" alt=\"\\begin{bmatrix}4 &amp; 5\\\\7 &amp; 8\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>"],"kind":"practice","id":"mt2-c17-s34","search":"Drill 34 Max and average pooling **Question.** Pool the input A shown below with 2 × 2 windows and stride 2. Find max and average outputs.\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput A is printed with the question.\n\nWindow size = 2 × 2; stride = 2; no padding.\n\n### To find\n\nFind the complete max-pooling and average-pooling outputs.\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and meaning\nEach 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.\n\n\n\nUse the input size at the pooling layer. The output keeps the same channel count.\n\n**Shape: ** \\(\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\\) = 2 on each axis; channels stay unchanged.\n### Pooling window (1,1)\n\n**Step 1: select the entries.**\n\n[1, 4, 0, 2]\n\n**Step 2: add all selected entries.**\n\n1 + 4 + 0 + 2 = 7\n\n**Step 3: divide by the 4 entries in this window.**\n\n7/4 = **1.75**. Maximum = **4**\n\n\n### Pooling window (1,2)\n\n**Step 1: select the entries.**\n\n[2, 3, 5, 1]\n\n**Step 2: add all selected entries.**\n\n2 + 3 + 5 + 1 = 11\n\n**Step 3: divide by the 4 entries in this window.**\n\n11/4 = **2.75**. Maximum = **5**\n\n\n### Pooling window (2,1)\n\n**Step 1: select the entries.**\n\n[6, 3, 1, 7]\n\n**Step 2: add all selected entries.**\n\n6 + 3 + 1 + 7 = 17\n\n**Step 3: divide by the 4 entries in this window.**\n\n17/4 = **4.25**. Maximum = **7**\n\n\n### Pooling window (2,2)\n\n**Step 1: select the entries.**\n\n[2, 0, 4, 8]\n\n**Step 2: add all selected entries.**\n\n2 + 0 + 4 + 8 = 14\n\n**Step 3: divide by the 4 entries in this window.**\n\n14/4 = **3.5**. Maximum = **8**\n\n\n**Average output: ** . **Max output: ** . Pooling normally has zero trainable parameters and reduces spatial dimensions.\n"},{"title":"Drill 35 Complete small CNN","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 10 × 10 × 1 → Conv 3 × 3,4 filters, stride 1, valid → Pool 2 stride 2 → Flatten → Dense 3. Find all shapes and parameters.</p>"],"answer":["<h3>Given</h3>","<p>Input = 10 × 10 × 1.</p>","<p>Conv: 3 × 3, 4 filters, stride 1, valid padding.</p>","<p>Pool: 2 × 2, stride 2; then flatten and dense layer with 3 outputs.</p>","<p>Include one bias per filter/dense neuron.</p>","<h3>To find</h3>","<p>Find all output shapes, layer parameter counts and their sum.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<h3>Formulas and assumptions</h3>","<p>“Valid” means zero padding. The convolution and dense layers each have one bias per receiving filter or neuron. Pooling and flattening have no learned parameters.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4064c7b5aff30cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bf6a8c697b8e11ab.svg\" alt=\"n_{\\mathrm{flat}}=HWC,\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"425.84\" height=\"24.43\" style=\"width:425.84px;height:24.43px;aspect-ratio:425.84/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 1: convolution shape</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.72px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/79853ff0cb463822.svg\"><img class=\"math display-math\" src=\"assets/equations/7bc6460a33d41247.svg\" alt=\"N_{\\mathrm{conv}}=\\frac{10+0-3}{1}+1=7+1=8\" width=\"382.41\" height=\"49.55\" style=\"width:382.41px;height:49.55px;aspect-ratio:382.41/49.55\" loading=\"lazy\"></picture></div>","<p>Four filters produce four channels: <strong>8 × 8 × 4</strong>.</p>","<h3>Step 2: convolution parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.28px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d2206cecca6115a8.svg\"><img class=\"math display-math\" src=\"assets/equations/04061505b018b4db.svg\" alt=\"\\text{weights}=3\\times3\\times1\\times4=36\" width=\"308.30\" height=\"21.99\" style=\"width:308.30px;height:21.99px;aspect-ratio:308.30/21.99\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d97de20b29f5a9fb.svg\"><img class=\"math display-math\" src=\"assets/equations/76ea5b945615119b.svg\" alt=\"\\text{biases}=4,\\qquad P_{\\mathrm{conv}}=36+4=40\" width=\"376.11\" height=\"21.70\" style=\"width:376.11px;height:21.70px;aspect-ratio:376.11/21.70\" loading=\"lazy\"></picture></div>","<h3>Step 3: pooling shape</h3>","<p>Pooling now receives size 8, not the original size 10.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.55px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4578ff92c09a54ec.svg\"><img class=\"math display-math\" src=\"assets/equations/66d12a448520cead.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{8-2}{2}\\right\\rfloor+1=3+1=4\" width=\"353.25\" height=\"58.62\" style=\"width:353.25px;height:58.62px;aspect-ratio:353.25/58.62\" loading=\"lazy\"></picture></div>","<p>Channels remain 4: <strong>4 × 4 × 4</strong>. Pooling parameters = 0.</p>","<h3>Step 4: flatten</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b42325b09a6929a4.svg\" alt=\"n_{\\mathrm{flat}}=4\\times4\\times4=64\" width=\"228.13\" height=\"20.40\" style=\"width:228.13px;height:20.40px;aspect-ratio:228.13/20.40\" loading=\"lazy\"></div>","<p>Flatten creates a vector of 64 numbers. It rearranges values, so its parameter count is 0.</p>","<h3>Step 5: dense layer with 3 outputs</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/738d2c475096e79a.svg\" alt=\"\\text{weights}=64\\times3=192\" width=\"248.56\" height=\"21.99\" style=\"width:248.56px;height:21.99px;aspect-ratio:248.56/21.99\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.64px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f927a7fa1a913d20.svg\"><img class=\"math display-math\" src=\"assets/equations/5b290fab1b1da9d6.svg\" alt=\"\\text{biases}=3,\\qquad P_{\\mathrm{dense}}=192+3=195\" width=\"406.87\" height=\"21.70\" style=\"width:406.87px;height:21.70px;aspect-ratio:406.87/21.70\" loading=\"lazy\"></picture></div>","<h3>Step 6: add learned parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.43px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/468553004a2eb33c.svg\"><img class=\"math display-math\" src=\"assets/equations/2c4f62d57a39f2bf.svg\" alt=\"P_{\\mathrm{total}}=40+0+0+195=235\" width=\"330.19\" height=\"20.54\" style=\"width:330.19px;height:20.54px;aspect-ratio:330.19/20.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> shapes 8 × 8 × 4 → 4 × 4 × 4 → 64 → 3; total 235 parameters.</p>"],"kind":"practice","id":"mt2-c17-s35","search":"Drill 35 Complete small CNN **Question.** Input 10 × 10 × 1 → Conv 3 × 3,4 filters, stride 1, valid → Pool 2 stride 2 → Flatten → Dense 3. Find all shapes and parameters.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 10 × 10 × 1.\n\nConv: 3 × 3, 4 filters, stride 1, valid padding.\n\nPool: 2 × 2, stride 2; then flatten and dense layer with 3 outputs.\n\nInclude one bias per filter/dense neuron.\n\n### To find\n\nFind all output shapes, layer parameter counts and their sum.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and assumptions\n“Valid” means zero padding. The convolution and dense layers each have one bias per receiving filter or neuron. Pooling and flattening have no learned parameters.\n\n\n\n### Step 1: convolution shape\n\nFour filters produce four channels: **8 × 8 × 4**.\n### Step 2: convolution parameters\n\n\n### Step 3: pooling shape\nPooling now receives size 8, not the original size 10.\n\nChannels remain 4: **4 × 4 × 4**. Pooling parameters = 0.\n### Step 4: flatten\n\nFlatten creates a vector of 64 numbers. It rearranges values, so its parameter count is 0.\n### Step 5: dense layer with 3 outputs\n\n\n### Step 6: add learned parameters\n\n**Final answer:** shapes 8 × 8 × 4 → 4 × 4 × 4 → 64 → 3; total 235 parameters.\n"},{"title":"Drill 36 Reverse a spatial formula","question":["<p class=\"inline-question\"><strong>Question.</strong> A stride-1, valid 3 × 3 convolution outputs 18 × 18 × 12. What input spatial size is needed? Is input channel count determined?</p>"],"answer":["<h3>Given</h3>","<p>Output shape = 18 × 18 × 12.</p>","<p>Kernel = 3 × 3; stride = 1; valid padding P = 0.</p>","<p>Input channel count is not supplied.</p>","<h3>To find</h3>","<p>Solve for input height/width; state whether input channels and parameter count are uniquely determined.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Formula used</h3>","<p>For stride 1 and valid padding, the output width is input width minus kernel width plus one.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6074916da488a8bc.svg\" alt=\"N_{\\mathrm{out}}=N-K+1\" width=\"194.57\" height=\"20.54\" style=\"width:194.57px;height:20.54px;aspect-ratio:194.57/20.54\" loading=\"lazy\"></div>","<h3>Step 1: substitute the known output and kernel sizes</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73b9e54fad32ca52.svg\" alt=\"18=N-3+1=N-2\" width=\"259.26\" height=\"18.69\" style=\"width:259.26px;height:18.69px;aspect-ratio:259.26/18.69\" loading=\"lazy\"></div>","<h3>Step 2: isolate the unknown input size</h3>","<p>Add 2 to both sides. Doing the same operation to both sides preserves the equality.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cfbfbce776e71cb1.svg\" alt=\"18+2=N-2+2\" width=\"204.97\" height=\"18.69\" style=\"width:204.97px;height:18.69px;aspect-ratio:204.97/18.69\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c758e056cb2f1688.svg\" alt=\"N=20\" width=\"78.72\" height=\"18.69\" style=\"width:78.72px;height:18.69px;aspect-ratio:78.72/18.69\" loading=\"lazy\"></div>","<h3>Step 3: interpret the channel information</h3>","<p>The 12 output channels tell us there are 12 filters. They do not say how many channels the input has. An RGB input and a many-channel intermediate map could both feed 12 filters.</p>","<p>With one bias per filter, the parameter formula would be:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f0b530e411679c54.svg\" alt=\"P=(3\\times3\\times C_{\\mathrm{in}}+1)\\times12\" width=\"284.42\" height=\"24.43\" style=\"width:284.42px;height:24.43px;aspect-ratio:284.42/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> input spatial shape 20 × 20; input channel count is undetermined from these givens.</p>"],"kind":"practice","id":"mt2-c17-s36","search":"Drill 36 Reverse a spatial formula **Question.** A stride-1, valid 3 × 3 convolution outputs 18 × 18 × 12. What input spatial size is needed? Is input channel count determined?\n\n**Full solution.**\n\n\n\n### Given\n\nOutput shape = 18 × 18 × 12.\n\nKernel = 3 × 3; stride = 1; valid padding P = 0.\n\nInput channel count is not supplied.\n\n### To find\n\nSolve for input height/width; state whether input channels and parameter count are uniquely determined.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Formula used\nFor stride 1 and valid padding, the output width is input width minus kernel width plus one.\n\n### Step 1: substitute the known output and kernel sizes\n\n### Step 2: isolate the unknown input size\nAdd 2 to both sides. Doing the same operation to both sides preserves the equality.\n\n\n### Step 3: interpret the channel information\nThe 12 output channels tell us there are 12 filters. They do not say how many channels the input has. An RGB input and a many-channel intermediate map could both feed 12 filters.\nWith one bias per filter, the parameter formula would be:\n\n**Final answer:** input spatial shape 20 × 20; input channel count is undetermined from these givens.\n"},{"title":"Drill 37 Bottleneck cost with new values","question":["<p class=\"inline-question\"><strong>Question.</strong> A 16 × 16 × 64 map feeds 32 same-padded 3 × 3 filters. Compare direct MACs with an 8-channel 1 × 1 bottleneck first.</p>"],"answer":["<h3>Given</h3>","<p>Input = 16 × 16 × 64.</p>","<p>Direct branch: 32 same-padded 3 × 3 filters.</p>","<p>Alternative: 1 × 1 reduction to 8 channels, then the same 32-filter 3 × 3 layer.</p>","<p>Spatial size remains 16 × 16; exclude bias additions.</p>","<h3>To find</h3>","<p>Find both MAC counts, absolute saving and percentage saving.</p>","<h3>Formula — which one and why</h3>","<p><strong>Multiply–accumulate count.</strong> Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.</p>","<p>H_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output cell ka kaam × kitne output cells.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>A MAC is one multiply–accumulate operation. For the convention used here, count the weight–input products over every output location. Bias additions are omitted. A 1 × 1 bottleneck reduces channels before the expensive 3 × 3 layer.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<h3>Step 1: direct 3 × 3 convolution</h3>","<p>Each output uses 3 × 3 × 64 = 576 weight–input pairs. There are 16 × 16 × 32 = 8,192 outputs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.21px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/673cd31676ab87d1.svg\"><img class=\"math display-math\" src=\"assets/equations/660ea75dfc92d56c.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=8192\\times576=4{,}718{,}592\" width=\"392.94\" height=\"22.24\" style=\"width:392.94px;height:22.24px;aspect-ratio:392.94/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 2: 1 × 1 reduction from 64 to 8 channels</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bcc137de649f71d.svg\"><img class=\"math display-math\" src=\"assets/equations/07ded70ae81c3cd5.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=16\\times16\\times8\\times1\\times1\\times64=131{,}072\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 3: 3 × 3 convolution now receives only 8 channels</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.07px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/da27ae2a69680cb6.svg\"><img class=\"math display-math\" src=\"assets/equations/798ae9e57f70e0ad.svg\" alt=\"\\mathrm{MACs}_{3\\times3}=16\\times16\\times32\\times3\\times3\\times8=589{,}824\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 4: add the two bottleneck stages</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/741f21ae6e5bfc83.svg\"><img class=\"math display-math\" src=\"assets/equations/ec8abadaa9257a67.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=131{,}072+589{,}824=720{,}896\" width=\"483.59\" height=\"22.24\" style=\"width:483.59px;height:22.24px;aspect-ratio:483.59/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 5: calculate the saving</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/005360b3f69dc10a.svg\"><img class=\"math display-math\" src=\"assets/equations/03fa81b05dc71237.svg\" alt=\"\\mathrm{saving}=4{,}718{,}592-720{,}896=3{,}997{,}696\" width=\"440.68\" height=\"21.58\" style=\"width:440.68px;height:21.58px;aspect-ratio:440.68/21.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.96px;--narrow-height:132.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2a96913f36caca06.svg\"><img class=\"math display-math\" src=\"assets/equations/46344c94632c2247.svg\" alt=\"\\mathrm{saving\\ percent}=\\frac{3{,}997{,}696}{4{,}718{,}592}\\times100=84.722222\\%\" width=\"518.68\" height=\"54.54\" style=\"width:518.68px;height:54.54px;aspect-ratio:518.68/54.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> direct 4,718,592 MACs; bottleneck 720,896 MACs; approximately 84.72% fewer. The output shape stays 16 × 16 × 32.</p>"],"kind":"practice","id":"mt2-c17-s37","search":"Drill 37 Bottleneck cost with new values **Question.** A 16 × 16 × 64 map feeds 32 same-padded 3 × 3 filters. Compare direct MACs with an 8-channel 1 × 1 bottleneck first.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 16 × 16 × 64.\n\nDirect branch: 32 same-padded 3 × 3 filters.\n\nAlternative: 1 × 1 reduction to 8 channels, then the same 32-filter 3 × 3 layer.\n\nSpatial size remains 16 × 16; exclude bias additions.\n\n### To find\n\nFind both MAC counts, absolute saving and percentage saving.\n\n### Formula — which one and why\n\n**Multiply–accumulate count.** Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.\n\nH_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har output cell ka kaam × kitne output cells.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nA MAC is one multiply–accumulate operation. For the convention used here, count the weight–input products over every output location. Bias additions are omitted. A 1 × 1 bottleneck reduces channels before the expensive 3 × 3 layer.\n\n### Step 1: direct 3 × 3 convolution\nEach output uses 3 × 3 × 64 = 576 weight–input pairs. There are 16 × 16 × 32 = 8,192 outputs.\n\n### Step 2: 1 × 1 reduction from 64 to 8 channels\n\n### Step 3: 3 × 3 convolution now receives only 8 channels\n\n### Step 4: add the two bottleneck stages\n\n### Step 5: calculate the saving\n\n\n**Final answer:** direct 4,718,592 MACs; bottleneck 720,896 MACs; approximately 84.72% fewer. The output shape stays 16 × 16 × 32.\n"},{"title":"Drill 38 Residual addition","question":["<p class=\"inline-question\"><strong>Question.</strong> x = [2,−3,1], F(x) = [−1,1,0.5]. Calculate residual output before and after ReLU and compare the plain block.</p>"],"answer":["<h3>Given</h3>","<p>x = [2,−3,1]; F(x) = [−1,1,0.5].</p>","<h3>To find</h3>","<p>Find x+F(x), apply ReLU, and compare with ReLU(F(x)).</p>","<h3>Formula — which one and why</h3>","<p><strong>Residual addition.</strong> Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.</p>","<p>x = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec48bb473e2d7934.svg\" alt=\"y=x+F(x)\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position ke numbers add; shape same rehni chahiye.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The main branch produces F(x). The shortcut carries x. A residual join adds matching entries from these equally sized vectors. ReLU is a separate operation after that join.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.19px;--narrow-height:64.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/78deb7e05ee3749d.svg\"><img class=\"math display-math\" src=\"assets/equations/16339c457d56baab.svg\" alt=\"H(x)=x+F(x),\\qquad a_j=\\max(0,H_j)\" width=\"413.81\" height=\"25.52\" style=\"width:413.81px;height:25.52px;aspect-ratio:413.81/25.52\" loading=\"lazy\"></picture></div>","<h3>Step 1: add each pair</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a26d4fa253f0177.svg\" alt=\"H_1=2+(-1)=1\" width=\"200.69\" height=\"24.43\" style=\"width:200.69px;height:24.43px;aspect-ratio:200.69/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b33025f78e725f0.svg\" alt=\"H_2=-3+1=-2\" width=\"200.69\" height=\"20.36\" style=\"width:200.69px;height:20.36px;aspect-ratio:200.69/20.36\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f50029ce8c5be41.svg\" alt=\"H_3=1+0.5=1.5\" width=\"200.69\" height=\"20.74\" style=\"width:200.69px;height:20.74px;aspect-ratio:200.69/20.74\" loading=\"lazy\"></div>","<p>The residual output before ReLU is <strong>[1, −2, 1.5]</strong>.</p>","<h3>Step 2: apply ReLU</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:372.69px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/09e521346431d0a8.svg\"><img class=\"math display-math\" src=\"assets/equations/78b039e2c7b066b2.svg\" alt=\"[\\max(0,1),\\max(0,-2),\\max(0,1.5)]=[1,0,1.5]\" width=\"496.24\" height=\"24.43\" style=\"width:496.24px;height:24.43px;aspect-ratio:496.24/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 3: compare with the plain branch</h3>","<p>Without a shortcut, the raw output is just F(x) = [−1, 1, 0.5]. Its ReLU output is <strong>[0, 1, 0.5]</strong>.</p>","<p>Residual addition keeps three entries. Concatenation would join the vectors into six entries and is a different operation.</p>"],"kind":"practice","id":"mt2-c17-s38","search":"Drill 38 Residual addition **Question.** x = [2,−3,1], F(x) = [−1,1,0.5]. Calculate residual output before and after ReLU and compare the plain block.\n\n**Full solution.**\n\n\n\n### Given\n\nx = [2,−3,1]; F(x) = [−1,1,0.5].\n\n### To find\n\nFind x+F(x), apply ReLU, and compare with ReLU(F(x)).\n\n### Formula — which one and why\n\n**Residual addition.** Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.\n\nx = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.\n\n\n\n**Yaad rakhne ka cue:** Same position ke numbers add; shape same rehni chahiye.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe main branch produces F(x). The shortcut carries x. A residual join adds matching entries from these equally sized vectors. ReLU is a separate operation after that join.\n\n### Step 1: add each pair\n\n\n\nThe residual output before ReLU is **[1, −2, 1.5]**.\n### Step 2: apply ReLU\n\n### Step 3: compare with the plain branch\nWithout a shortcut, the raw output is just F(x) = [−1, 1, 0.5]. Its ReLU output is **[0, 1, 0.5]**.\nResidual addition keeps three entries. Concatenation would join the vectors into six entries and is a different operation.\n"},{"title":"Drill 39 Two RNN steps","question":["<p class=\"inline-question\"><strong>Question.</strong> h₀ = 0, Wxh = 0.5, Whh = 0.2, b = 0, x₁ = 1, x₂ = 2, tanh activation. Find h₁, h₂.</p>"],"answer":["<h3>Given</h3>","<p>Initial h₀ = 0; input weight Wxh = 0.5; recurrent weight Whh = 0.2; b = 0.</p>","<p>Inputs: x₁ = 1, x₂ = 2; activation: tanh.</p>","<h3>To find</h3>","<p>Calculate h₁, then use it to calculate h₂.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>At time t, the RNN combines the current input xₜ and the previous hidden state hₜ₋₁. The same two weights are reused at both times.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/53aa19b3509081a2.svg\"><img class=\"math display-math\" src=\"assets/equations/1a9a9845cda07cae.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b,\\qquad h_t=\\tanh(a_t)\" width=\"484.34\" height=\"24.43\" style=\"width:484.34px;height:24.43px;aspect-ratio:484.34/24.43\" loading=\"lazy\"></picture></div>","<p>The raw sum a is not the hidden state. Tanh converts that sum into the state that is carried forward.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/994b9a9f57dad438.svg\" alt=\"\\tanh(a)=\\frac{e^{2a}-1}{e^{2a}+1}\" width=\"197.45\" height=\"56.48\" style=\"width:197.45px;height:56.48px;aspect-ratio:197.45/56.48\" loading=\"lazy\"></div>","<h3>Step 1: calculate the first raw sum</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.04px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a11d26405f8ffbf6.svg\"><img class=\"math display-math\" src=\"assets/equations/6d7c2d3322af892b.svg\" alt=\"a_1=0.5(1)+0.2(0)+0=0.5\" width=\"316.85\" height=\"24.43\" style=\"width:316.85px;height:24.43px;aspect-ratio:316.85/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: activate it to obtain the first state</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a56af3f825290564.svg\" alt=\"h_1=\\tanh(0.5)=\\frac{e^1-1}{e^1+1}\" width=\"263.93\" height=\"56.48\" style=\"width:263.93px;height:56.48px;aspect-ratio:263.93/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.13px;--narrow-height:90.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8658aac9b96930a3.svg\"><img class=\"math display-math\" src=\"assets/equations/50c20979a353d66c.svg\" alt=\"h_1=\\frac{2.718281828-1}{2.718281828+1}=0.462117157\" width=\"400.68\" height=\"51.80\" style=\"width:400.68px;height:51.80px;aspect-ratio:400.68/51.80\" loading=\"lazy\"></picture></div>","<h3>Step 3: use that state in the second raw sum</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/05a3c9bcda834dc2.svg\"><img class=\"math display-math\" src=\"assets/equations/a620346ee9bd0632.svg\" alt=\"a_2=0.5(2)+0.2(0.462117157)+0\" width=\"369.79\" height=\"24.43\" style=\"width:369.79px;height:24.43px;aspect-ratio:369.79/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.23px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7019e7bc4f1316c8.svg\"><img class=\"math display-math\" src=\"assets/equations/dd63fd4bc0c56e9d.svg\" alt=\"a_2=1+0.092423431=1.092423431\" width=\"388.78\" height=\"20.21\" style=\"width:388.78px;height:20.21px;aspect-ratio:388.78/20.21\" loading=\"lazy\"></picture></div>","<h3>Step 4: activate the second sum</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.19px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1963e3f6225d34f.svg\"><img class=\"math display-math\" src=\"assets/equations/b65e6ee603919e32.svg\" alt=\"h_2=\\tanh(1.092423431)=0.797760954\" width=\"415.75\" height=\"24.43\" style=\"width:415.75px;height:24.43px;aspect-ratio:415.75/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> h₁ ≈ 0.462117157; h₂ ≈ 0.797760954. Pass h₁ to the next step, not the unactivated value 0.5.</p>"],"kind":"practice","id":"mt2-c17-s39","search":"Drill 39 Two RNN steps **Question.** h₀ = 0, Wxh = 0.5, Whh = 0.2, b = 0, x₁ = 1, x₂ = 2, tanh activation. Find h₁, h₂.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial h₀ = 0; input weight Wxh = 0.5; recurrent weight Whh = 0.2; b = 0.\n\nInputs: x₁ = 1, x₂ = 2; activation: tanh.\n\n### To find\n\nCalculate h₁, then use it to calculate h₂.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nAt time t, the RNN combines the current input xₜ and the previous hidden state hₜ₋₁. The same two weights are reused at both times.\n\nThe raw sum a is not the hidden state. Tanh converts that sum into the state that is carried forward.\n\n### Step 1: calculate the first raw sum\n\n### Step 2: activate it to obtain the first state\n\n\n### Step 3: use that state in the second raw sum\n\n\n### Step 4: activate the second sum\n\n**Final answer:** h₁ ≈ 0.462117157; h₂ ≈ 0.797760954. Pass h₁ to the next step, not the unactivated value 0.5.\n"},{"title":"Drill 40 Mixed convolution pool dense and loss","question":["<p class=\"inline-question\"><strong>Question.</strong> A is shown below, kernel Matrix 2 shown below, stride 1, valid. Apply ReLU, then 2 × 2 max pool stride 1. Flatten rowwise, use weight vector [0.1,0.2,0.3,0.4], bias 0, sigmoid output, target 1. Find all stages and BCE.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K · Matrix 2</div><table class=\"lv-matrix\" aria-label=\"Kernel K · Matrix 2\"><caption>Kernel K · Matrix 2</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 1; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Input A and kernel Matrix 2 are printed with the question.</p>","<p>Conv: stride 1, valid padding; follow with ReLU.</p>","<p>Max pool: 2 × 2, stride 1; flatten row by row.</p>","<p>Dense weights = [0.1,0.2,0.3,0.4]; bias = 0; sigmoid output.</p>","<p>Binary target = 1.</p>","<h3>To find</h3>","<p>Find convolution, activated map, pooled map, flattened values, prediction and BCE.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Binary cross-entropy.</strong> For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.</p>","<p>y is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bbef5a5d1c7047f.svg\" alt=\"\\frac{\\partial L}{\\partial z}=p-y\" width=\"127.94\" height=\"51.29\" style=\"width:127.94px;height:51.29px;aspect-ratio:127.94/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).</p>","<h3>Solution — step by step</h3>","<h3>Formulas and the operation we are performing</h3>","<p>A filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:281.49px;--narrow-height:152.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1a1aa2b10ea1816e.svg\"><img class=\"math display-math\" src=\"assets/equations/33407dafb559f8d6.svg\" alt=\"Y_{ij}=\\sum_{u=0}^{K_h-1}\\sum_{v=0}^{K_w-1}X_{iS+u,jS+v}K_{uv}+b\" width=\"351.15\" height=\"73.34\" style=\"width:351.15px;height:73.34px;aspect-ratio:351.15/73.34\" loading=\"lazy\"></picture></div>","<p>Here i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.</p>","<h3>Formulas and meaning</h3>","<p>Each 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/870fc5e76c2ff285.svg\" alt=\"p_{\\mathrm{max}}=\\max(a_1,a_2,a_3,a_4)\" width=\"270.51\" height=\"24.43\" style=\"width:270.51px;height:24.43px;aspect-ratio:270.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf572bd2a565d88a.svg\" alt=\"p_{\\mathrm{avg}}=\\frac{a_1+a_2+a_3+a_4}{4}\" width=\"268.03\" height=\"47.52\" style=\"width:268.03px;height:47.52px;aspect-ratio:268.03/47.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.64px;--narrow-height:98.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a9854190bb7c9a.svg\"><img class=\"math display-math\" src=\"assets/equations/bd33b42a8814468f.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"300.97\" height=\"58.62\" style=\"width:300.97px;height:58.62px;aspect-ratio:300.97/58.62\" loading=\"lazy\"></picture></div>","<p>Use the input size at the pooling layer. The output keeps the same channel count.</p>","<h3>Completing the network after pooling</h3>","<p>Flatten row by row. Multiply the resulting entries by the dense weights and add bias. Apply sigmoid to produce p. For target 1, binary cross-entropy is minus ln(p).</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.90px;--narrow-height:157.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a593381e0c37ce0b.svg\"><img class=\"math display-math\" src=\"assets/equations/2a2f870df03533ca.svg\" alt=\"z=\\sum_iw_ix_i+b,\\qquad p=\\frac1{1+e^{-z}},\\qquad L=-\\ln p\" width=\"532.22\" height=\"61.92\" style=\"width:532.22px;height:61.92px;aspect-ratio:532.22/61.92\" loading=\"lazy\"></picture></div>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/99ba828c16946a06.svg\" alt=\"\\left\\lfloor\\frac{4+2 \\times  0-2}{1}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 3 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−1) = −1</b></div></div><p class=\"lv-combine\"><b>1 + (−1) = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10a146899dccf86a.svg\"><img class=\"math display-math\" src=\"assets/equations/029ae836b8cf695f.svg\" alt=\"R_1=(1)\\times(1)+(2)\\times(0)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a91d42dac9ba1633.svg\"><img class=\"math display-math\" src=\"assets/equations/d7380bbaffbc2948.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/059edda10c2ac26e.svg\" alt=\"Y_{1,1}=(1)+(-1)=0\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>2 + (−3) = −1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/13b97b59677316ed.svg\"><img class=\"math display-math\" src=\"assets/equations/11fea4ed5b78299e.svg\" alt=\"R_1=(2)\\times(1)+(0)\\times(0)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9cf98567181f7899.svg\"><img class=\"math display-math\" src=\"assets/equations/59a1357910dce5f4.svg\" alt=\"R_2=(1)\\times(0)+(3)\\times(-1)=-3\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6828ab91aa100a9.svg\" alt=\"Y_{1,2}=(2)+(-3)=-1\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−2) = −2</b></div></div><p class=\"lv-combine\"><b>0 + (−2) = −2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9602643188947584.svg\"><img class=\"math display-math\" src=\"assets/equations/38b1e54a3b119ea9.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(0)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/49c3d4aac1f50f22.svg\"><img class=\"math display-math\" src=\"assets/equations/893c6acf067ed4a9.svg\" alt=\"R_2=(3)\\times(0)+(2)\\times(-1)=-2\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/77839b654a5d343b.svg\" alt=\"Y_{1,3}=(0)+(-2)=-2\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−1) = −1</b></div></div><p class=\"lv-combine\"><b>0 + (−1) = −1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9602643188947584.svg\"><img class=\"math display-math\" src=\"assets/equations/38b1e54a3b119ea9.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(0)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/825cd1ca9fbe27a2.svg\"><img class=\"math display-math\" src=\"assets/equations/ee2b941345fd8cb4.svg\" alt=\"R_2=(2)\\times(0)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74f7aefb8b0d75bd.svg\" alt=\"Y_{2,1}=(0)+(-1)=-1\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>1 + 0 = 1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/50ba62bd05697a22.svg\"><img class=\"math display-math\" src=\"assets/equations/c318e658016b1fbd.svg\" alt=\"R_1=(1)\\times(1)+(3)\\times(0)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f7d66e56559f9de7.svg\"><img class=\"math display-math\" src=\"assets/equations/88c7ac8976f026b8.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(-1)=0\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e353ed5c5344d9f0.svg\" alt=\"Y_{2,2}=(1)+(0)=1\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 = 3</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−1) = −1</b></div></div><p class=\"lv-combine\"><b>3 + (−1) = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/239b4ccf3eb098a0.svg\"><img class=\"math display-math\" src=\"assets/equations/9fed257738d47bdb.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(0)=3\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a91d42dac9ba1633.svg\"><img class=\"math display-math\" src=\"assets/equations/d7380bbaffbc2948.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc81876afa80a85e.svg\" alt=\"Y_{2,3}=(3)+(-1)=2\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>2 + 0 = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca82f5af7cbb2e71.svg\"><img class=\"math display-math\" src=\"assets/equations/c8ce43d27f6afa3e.svg\" alt=\"R_1=(2)\\times(1)+(1)\\times(0)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f7d66e56559f9de7.svg\"><img class=\"math display-math\" src=\"assets/equations/88c7ac8976f026b8.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(-1)=0\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3322f48fabaf515.svg\" alt=\"Y_{3,1}=(2)+(0)=2\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−2) = −2</b></div></div><p class=\"lv-combine\"><b>1 + (−2) = −1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b9538ffab8a7d30.svg\"><img class=\"math display-math\" src=\"assets/equations/206ee4c111bd14b3.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(0)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1baae78cba2e069c.svg\"><img class=\"math display-math\" src=\"assets/equations/03bf601080143dcc.svg\" alt=\"R_2=(0)\\times(0)+(2)\\times(-1)=-2\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/43f244bc80788fd1.svg\" alt=\"Y_{3,2}=(1)+(-2)=-1\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>0 + (−3) = −3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9602643188947584.svg\"><img class=\"math display-math\" src=\"assets/equations/38b1e54a3b119ea9.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(0)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/04e972a19789fc08.svg\"><img class=\"math display-math\" src=\"assets/equations/4b10b62665a7718a.svg\" alt=\"R_2=(2)\\times(0)+(3)\\times(-1)=-3\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73f07f2c01400713.svg\" alt=\"Y_{3,3}=(0)+(-3)=-3\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/78836b0ad068fd57.svg\" alt=\"\\begin{bmatrix}0 &amp; -1 &amp; -2\\\\-1 &amp; 1 &amp; 2\\\\2 &amp; -1 &amp; -3\\end{bmatrix}\" width=\"136.22\" height=\"72.21\" style=\"width:136.22px;height:72.21px;aspect-ratio:136.22/72.21\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>","<p>ReLU turns negative entries into 0: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5203ca394b677586.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 1 &amp; 2\\\\2 &amp; 0 &amp; 0\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>.</p>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/65d999fa66cd37e1.svg\" alt=\"\\left\\lfloor\\frac{3-2}{1}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[0, 0, 0, 1]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>0 + 0 + 0 + 1 = 1</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>1/4 = <strong>0.25</strong>. Maximum = <strong>1</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[0, 0, 1, 2]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>0 + 0 + 1 + 2 = 3</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>3/4 = <strong>0.75</strong>. Maximum = <strong>2</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[0, 1, 2, 0]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>0 + 1 + 2 + 0 = 3</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>3/4 = <strong>0.75</strong>. Maximum = <strong>2</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[1, 2, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>1 + 2 + 0 + 0 = 3</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>3/4 = <strong>0.75</strong>. Maximum = <strong>2</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/386a0646a3bb55b5.svg\" alt=\"\\begin{bmatrix}0.25 &amp; 0.75\\\\0.75 &amp; 0.75\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>. <strong>Max output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4fb14ffabb3fef49.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\2 &amp; 2\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>","<p>Use MAX output and flatten rowwise: [1, 2, 2, 2]. Dense z = 0.1 × 1 + 0.2 × 2 + 0.3 × 2 + 0.4 × 2 = 1.9. p = σ(1.9) = 0.869891526. BCE = −ln(p) = <strong>0.139386758</strong>. Average pool values were computed for contrast; the question requires max pool.</p>"],"kind":"practice","id":"mt2-c17-s40","search":"Drill 40 Mixed convolution pool dense and loss **Question.** A is shown below, kernel Matrix 2 shown below, stride 1, valid. Apply ReLU, then 2 × 2 max pool stride 1. Flatten rowwise, use weight vector [0.1,0.2,0.3,0.4], bias 0, sigmoid output, target 1. Find all stages and BCE.\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput A and kernel Matrix 2 are printed with the question.\n\nConv: stride 1, valid padding; follow with ReLU.\n\nMax pool: 2 × 2, stride 1; flatten row by row.\n\nDense weights = [0.1,0.2,0.3,0.4]; bias = 0; sigmoid output.\n\nBinary target = 1.\n\n### To find\n\nFind convolution, activated map, pooled map, flattened values, prediction and BCE.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Binary cross-entropy.** For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.\n\ny is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.\n\n\n\n\n\n**Yaad rakhne ka cue:** Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and the operation we are performing\nA filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.\n\nHere i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.\n\nN is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.\n### Formulas and meaning\nEach 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the g"},{"title":"Drill 41 Mixed backpropagation and L2","question":["<p class=\"inline-question\"><strong>Question.</strong> Single linear neuron ŷ = wx, x = 2, w = 0.4, y = 1. Objective J = ½(ŷ−y)²+(λ/2)w², λ = 0.1, η = 0.2. Find loss, gradient, new weight.</p>"],"answer":["<h3>Given</h3>","<p>Prediction ŷ = wx; x = 2; w = 0.4; target y = 1.</p>","<p>Data loss = ½(ŷ−y)²; penalty = (λ/2)w².</p>","<p>λ = 0.1; η = 0.2.</p>","<h3>To find</h3>","<p>Find total objective, its weight gradient and the new weight.</p>","<h3>Formula — which one and why</h3>","<p><strong>L2 penalty with a factor of one-half.</strong> Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.</p>","<p>λ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29419cadd5578572.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc02963f72332f.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"179.88\" height=\"23.98\" style=\"width:179.88px;height:23.98px;aspect-ratio:179.88/23.98\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/616c8cbb90430248.svg\" alt=\"w_i^{\\mathrm{new}}=w_i-\\eta g_i\" width=\"169.00\" height=\"24.06\" style=\"width:169.00px;height:24.06px;aspect-ratio:169.00/24.06\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half wala L2 derivative mein lambda × weight deta hai.</p>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>This objective contains both prediction error and a weight penalty. Its gradient also has two parts. Compute both at the old weight, add them, then update once.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.54px;--narrow-height:90.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9807919ec463b336.svg\"><img class=\"math display-math\" src=\"assets/equations/f7ed754c852735b2.svg\" alt=\"\\hat y=wx,\\qquad J=\\frac12(\\hat y-y)^2+\\frac\\lambda2w^2\" width=\"373.30\" height=\"50.24\" style=\"width:373.30px;height:50.24px;aspect-ratio:373.30/50.24\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.87px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fccbb24d2fd5ed97.svg\"><img class=\"math display-math\" src=\"assets/equations/3a34fcc434834bc2.svg\" alt=\"\\frac{\\partial J}{\\partial w}=(\\hat y-y)x+\\lambda w,\\qquad w_{\\mathrm{new}}=w-\\eta\\frac{\\partial J}{\\partial w}\" width=\"466.25\" height=\"51.29\" style=\"width:466.25px;height:51.29px;aspect-ratio:466.25/51.29\" loading=\"lazy\"></picture></div>","<h3>Step 1: prediction and error</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:242.54px;--narrow-height:66.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3414961b88098bc1.svg\"><img class=\"math display-math\" src=\"assets/equations/2cdfc715227663d5.svg\" alt=\"\\hat y=0.4\\times2=0.8,\\qquad \\hat y-y=0.8-1=-0.2\" width=\"483.95\" height=\"24.80\" style=\"width:483.95px;height:24.80px;aspect-ratio:483.95/24.80\" loading=\"lazy\"></picture></div>","<h3>Step 2: data loss</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.03px;--narrow-height:113.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f025cfcfa02c965d.svg\"><img class=\"math display-math\" src=\"assets/equations/5140459142337abc.svg\" alt=\"L_{\\mathrm{data}}=\\frac12(-0.2)^2=\\frac12(0.04)=0.02\" width=\"381.78\" height=\"49.55\" style=\"width:381.78px;height:49.55px;aspect-ratio:381.78/49.55\" loading=\"lazy\"></picture></div>","<h3>Step 3: regularization penalty and total objective</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.72px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c4fc429067a3f156.svg\"><img class=\"math display-math\" src=\"assets/equations/61163a2b02bc5b66.svg\" alt=\"R=\\frac{0.1}{2}(0.4)^2=0.05(0.16)=0.008\" width=\"380.74\" height=\"49.55\" style=\"width:380.74px;height:49.55px;aspect-ratio:380.74/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/72c65e08a565a4c1.svg\" alt=\"J=0.02+0.008=0.028\" width=\"265.27\" height=\"18.69\" style=\"width:265.27px;height:18.69px;aspect-ratio:265.27/18.69\" loading=\"lazy\"></div>","<h3>Step 4: calculate the two gradient contributions</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/20e7a6699528fa05.svg\" alt=\"g_{\\mathrm{data}}=(-0.2)\\times2=-0.4\" width=\"274.03\" height=\"24.43\" style=\"width:274.03px;height:24.43px;aspect-ratio:274.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ed23175a058690ac.svg\" alt=\"g_{\\mathrm{penalty}}=0.1\\times0.4=0.04\" width=\"270.79\" height=\"23.73\" style=\"width:270.79px;height:23.73px;aspect-ratio:270.79/23.73\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c43044f63438eb7.svg\"><img class=\"math display-math\" src=\"assets/equations/b422d0258ed7d40f.svg\" alt=\"g_{\\mathrm{total}}=-0.4+0.04=-0.36\" width=\"300.38\" height=\"21.55\" style=\"width:300.38px;height:21.55px;aspect-ratio:300.38/21.55\" loading=\"lazy\"></picture></div>","<h3>Step 5: update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.65px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93c291aebdd73770.svg\"><img class=\"math display-math\" src=\"assets/equations/f4be65ea94b49c52.svg\" alt=\"w_{\\mathrm{new}}=0.4-0.2(-0.36)=0.4+0.072=0.472\" width=\"493.24\" height=\"24.43\" style=\"width:493.24px;height:24.43px;aspect-ratio:493.24/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> total loss 0.028; gradient −0.36; new weight 0.472.</p>"],"kind":"practice","id":"mt2-c17-s41","search":"Drill 41 Mixed backpropagation and L2 **Question.** Single linear neuron ŷ = wx, x = 2, w = 0.4, y = 1. Objective J = ½(ŷ−y)²+(λ/2)w², λ = 0.1, η = 0.2. Find loss, gradient, new weight.\n\n**Full solution.**\n\n\n\n### Given\n\nPrediction ŷ = wx; x = 2; w = 0.4; target y = 1.\n\nData loss = ½(ŷ−y)²; penalty = (λ/2)w².\n\nλ = 0.1; η = 0.2.\n\n### To find\n\nFind total objective, its weight gradient and the new weight.\n\n### Formula — which one and why\n\n**L2 penalty with a factor of one-half.** Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.\n\nλ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Half wala L2 derivative mein lambda × weight deta hai.\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThis objective contains both prediction error and a weight penalty. Its gradient also has two parts. Compute both at the old weight, add them, then update once.\n\n\n### Step 1: prediction and error\n\n### Step 2: data loss\n\n### Step 3: regularization penalty and total objective\n\n\n### Step 4: calculate the two gradient contributions\n\n\n\n### Step 5: update\n\n**Final answer:** total loss 0.028; gradient −0.36; new weight 0.472.\n"},{"title":"Drill 42 Mixed dropout and a momentum update","question":["<p class=\"inline-question\"><strong>Question.</strong> Hidden activations [1,2], inverted dropout q = 0.5, mask [1,0]. Linear output weights [0.2,0.3], bias 0, target 1, half squared loss. Update only output weights with momentum β = 0.9, old velocity [0.1,−0.1], η = 0.1.</p>"],"answer":["<h3>Given</h3>","<p>Hidden activations = [1,2]; mask = [1,0]; keep probability q = 0.5.</p>","<p>Linear-output weights = [0.2,0.3]; bias = 0; target = 1.</p>","<p>Half squared loss; update only the output weights.</p>","<p>Old signed velocity = [0.1,−0.1]; β = 0.9; η = 0.1.</p>","<h3>To find</h3>","<p>Find dropped/scaled activations, prediction, gradients, new velocities and new output weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used</h3>","<p>Dropout changes the inputs received by the output neuron. Use those changed inputs in both its forward calculation and its weight gradients.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:179.65px;--narrow-height:165.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0da6165a5d02d6ea.svg\"><img class=\"math display-math\" src=\"assets/equations/efaf3726aa8b79f8.svg\" alt=\"a&#x27;_j=\\frac{m_ja_j}{q},\\quad o=\\sum_jw_ja&#x27;_j+b,\\quad g_j=(o-y)a&#x27;_j\" width=\"509.70\" height=\"61.69\" style=\"width:509.70px;height:61.69px;aspect-ratio:509.70/61.69\" loading=\"lazy\"></picture></div>","<p>The signed-velocity momentum convention is:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.43px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc93fbe5bcc88056.svg\"><img class=\"math display-math\" src=\"assets/equations/b4d3d4646fcd808d.svg\" alt=\"v_{j,\\mathrm{new}}=\\beta v_{j,\\mathrm{old}}-\\eta g_j,\\qquad w_{j,\\mathrm{new}}=w_j+v_{j,\\mathrm{new}}\" width=\"479.21\" height=\"24.42\" style=\"width:479.21px;height:24.42px;aspect-ratio:479.21/24.42\" loading=\"lazy\"></picture></div>","<h3>Step 1: apply inverted dropout</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.83px;--narrow-height:114.84px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/446657a723f0a489.svg\"><img class=\"math display-math\" src=\"assets/equations/2b32d1a861daf9ff.svg\" alt=\"a&#x27;_1=\\frac{1\\times1}{0.5}=2,\\qquad a&#x27;_2=\\frac{0\\times2}{0.5}=0\" width=\"391.80\" height=\"50.09\" style=\"width:391.80px;height:50.09px;aspect-ratio:391.80/50.09\" loading=\"lazy\"></picture></div>","<h3>Step 2: prediction and error</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a323109c2640591d.svg\"><img class=\"math display-math\" src=\"assets/equations/d947f0c3c40b6311.svg\" alt=\"o=0.2(2)+0.3(0)+0=0.4\" width=\"305.11\" height=\"24.43\" style=\"width:305.11px;height:24.43px;aspect-ratio:305.11/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e63213278aa7de98.svg\" alt=\"o-y=0.4-1=-0.6\" width=\"242.42\" height=\"21.55\" style=\"width:242.42px;height:21.55px;aspect-ratio:242.42/21.55\" loading=\"lazy\"></div>","<h3>Step 3: current weight gradients</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.00px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f44ece1dbabee9e.svg\"><img class=\"math display-math\" src=\"assets/equations/f17168c45fd84cbe.svg\" alt=\"g_1=(-0.6)(2)=-1.2,\\qquad g_2=(-0.6)(0)=0\" width=\"498.12\" height=\"24.43\" style=\"width:498.12px;height:24.43px;aspect-ratio:498.12/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 4: remembered movement plus new correction</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.38px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6463456a76ac5311.svg\"><img class=\"math display-math\" src=\"assets/equations/afa6505a2a4ce39d.svg\" alt=\"v_{1,\\mathrm{new}}=0.9(0.1)-0.1(-1.2)=0.09+0.12=0.21\" width=\"526.83\" height=\"25.35\" style=\"width:526.83px;height:25.35px;aspect-ratio:526.83/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.13px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/66eba48d514886f3.svg\"><img class=\"math display-math\" src=\"assets/equations/896aef66e0912dce.svg\" alt=\"v_{2,\\mathrm{new}}=0.9(-0.1)-0.1(0)=-0.09\" width=\"377.49\" height=\"25.35\" style=\"width:377.49px;height:25.35px;aspect-ratio:377.49/25.35\" loading=\"lazy\"></picture></div>","<h3>Step 5: add velocities to old weights</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad8445391f1a6df2.svg\" alt=\"w_{1,\\mathrm{new}}=0.2+0.21=0.41\" width=\"275.88\" height=\"23.55\" style=\"width:275.88px;height:23.55px;aspect-ratio:275.88/23.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dc7d2ca77c91e6c.svg\" alt=\"w_{2,\\mathrm{new}}=0.3-0.09=0.21\" width=\"275.88\" height=\"23.30\" style=\"width:275.88px;height:23.30px;aspect-ratio:275.88/23.30\" loading=\"lazy\"></div>","<p><strong>Final answer: [0.41, 0.21].</strong> The second weight moves even with zero current gradient because its old momentum is nonzero.</p>"],"kind":"practice","id":"mt2-c17-s42","search":"Drill 42 Mixed dropout and a momentum update **Question.** Hidden activations [1,2], inverted dropout q = 0.5, mask [1,0]. Linear output weights [0.2,0.3], bias 0, target 1, half squared loss. Update only output weights with momentum β = 0.9, old velocity [0.1,−0.1], η = 0.1.\n\n**Full solution.**\n\n\n\n### Given\n\nHidden activations = [1,2]; mask = [1,0]; keep probability q = 0.5.\n\nLinear-output weights = [0.2,0.3]; bias = 0; target = 1.\n\nHalf squared loss; update only the output weights.\n\nOld signed velocity = [0.1,−0.1]; β = 0.9; η = 0.1.\n\n### To find\n\nFind dropped/scaled activations, prediction, gradients, new velocities and new output weights.\n\n### Formula — which one and why\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used\nDropout changes the inputs received by the output neuron. Use those changed inputs in both its forward calculation and its weight gradients.\n\nThe signed-velocity momentum convention is:\n\n### Step 1: apply inverted dropout\n\n### Step 2: prediction and error\n\n\n### Step 3: current weight gradients\n\n### Step 4: remembered movement plus new correction\n\n\n### Step 5: add velocities to old weights\n\n\n**Final answer: [0.41, 0.21].** The second weight moves even with zero current gradient because its old momentum is nonzero.\n"},{"title":"Drill 43 Mixed CNN dimensions softmax and loss","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 8 × 8 × 3 → Conv 3, stride 1, padding 1, 2 filters → Pool 2, stride 2 → Flatten → Dense 3. Logits [0,1,−1], true class is the second class (one-hot target [0,1,0]). Find shapes, parameters, probabilities and CCE.</p>"],"answer":["<h3>Given</h3>","<p>Input = 8 × 8 × 3.</p>","<p>Conv: kernel 3, stride 1, padding 1, 2 filters.</p>","<p>Pool: kernel 2, stride 2; flatten; dense layer with 3 outputs.</p>","<p>Logits = [0,1,−1]; true class is the second class (one-hot target [0,1,0]).</p>","<h3>To find</h3>","<p>Find shapes, parameter counts, probabilities and CCE.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used</h3>","<p>Separate shape from learned parameter count. H, W and C mean height, width and channels. K, P and S mean filter size, padding per side and stride.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4064c7b5aff30cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bf6a8c697b8e11ab.svg\" alt=\"n_{\\mathrm{flat}}=HWC,\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"425.84\" height=\"24.43\" style=\"width:425.84px;height:24.43px;aspect-ratio:425.84/24.43\" loading=\"lazy\"></picture></div>","<p>The +1 counts one bias per receiving filter or neuron. Pooling and flattening add no learned parameters. Softmax converts scores to probabilities; CCE uses the probability of the correct class.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.99px;--narrow-height:157.13px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1ffdc701f4381a15.svg\"><img class=\"math display-math\" src=\"assets/equations/e3c5269ae1be7e5e.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\quad c=\\max_jz_j,\\quad L=-\\ln p_{\\mathrm{correct}}\" width=\"498.29\" height=\"63.31\" style=\"width:498.29px;height:63.31px;aspect-ratio:498.29/63.31\" loading=\"lazy\"></picture></div>","<p>Conv size = (8+2−3)+1 = 8; output 8 × 8 × 2; parameters = (3 × 3 × 3+1) × 2 = 56. Pool 4 × 4 × 2; parameters 0. Flatten 32. Dense 3 parameters = (32+1) × 3 = 99. Total = <strong>155</strong>.</p>","<p class=\"worked-step\"><strong>Step 1 stabilize: </strong> subtract the largest logit 1 from every value: [-1, 0, -2]. This does not change softmax.</p>","<p class=\"worked-step\"><strong>Step 2 exponentiate: </strong> exp values = [0.367879441, 1, 0.135335283].</p>","<p class=\"worked-step\"><strong>Step 3 denominator: </strong> sum = 1.503214724.</p>","<p class=\"worked-step\"><strong>Step 4 divide each value by this same sum: </strong> probabilities = <strong>[0.244728471, 0.665240956, 0.090030573]</strong>. <strong>Check: </strong> all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.</p>","<p>Correct class probability = 0.665240956; CCE = −ln(0.665240956) = <strong>0.407605964</strong>.</p>"],"kind":"practice","id":"mt2-c17-s43","search":"Drill 43 Mixed CNN dimensions softmax and loss **Question.** Input 8 × 8 × 3 → Conv 3, stride 1, padding 1, 2 filters → Pool 2, stride 2 → Flatten → Dense 3. Logits [0,1,−1], true class is the second class (one-hot target [0,1,0]). Find shapes, parameters, probabilities and CCE.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 8 × 8 × 3.\n\nConv: kernel 3, stride 1, padding 1, 2 filters.\n\nPool: kernel 2, stride 2; flatten; dense layer with 3 outputs.\n\nLogits = [0,1,−1]; true class is the second class (one-hot target [0,1,0]).\n\n### To find\n\nFind shapes, parameter counts, probabilities and CCE.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used\nSeparate shape from learned parameter count. H, W and C mean height, width and channels. K, P and S mean filter size, padding per side and stride.\n\n\n\nThe +1 counts one bias per receiving filter or neuron. Pooling and flattening add no learned parameters. Softmax converts scores to probabilities; CCE uses the probability of the correct class.\n\n\nConv size = (8+2−3)+1 = 8; output 8 × 8 × 2; parameters = (3 × 3 × 3+1) × 2 = 56. Pool 4 × 4 × 2; parameters 0. Flatten 32. Dense 3 parameters = (32+1) × 3 = 99. Total = **155**.\n**Step 1 stabilize: ** subtract the largest logit 1 from every value: [-1, 0, -2]. This does not change softmax.\n\n**Step 2 exponentiate: ** exp values = [0.367879441, 1, 0.135335283].\n\n**Step 3 denominator: ** sum = 1.503214724.\n\n**Step 4 divide each value by this same sum: ** probabilities = **[0.244728471, 0.665240956, 0.090030573]**. **Check: ** all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.\nCorrect class probability = 0.665240956; CCE = −ln(0.665240956) = **0.407605964**.\n"},{"title":"Drill 44 Inception concatenation and parameter count","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 10 × 10 × 8. Parallel branches: A uses 1 × 1 conv 4 filters ; B uses 3 × 3 same Conv 6 filters; C max pool 3 same, stride 1 then 1 × 1 conv 2 filters. Find combined shape and trainable parameters.</p>"],"answer":["<h3>Given</h3>","<p>Input = 10 × 10 × 8.</p>","<p>Branch A: 1 × 1 convolution, 4 filters.</p>","<p>Branch B: 3 × 3 same convolution, 6 filters.</p>","<p>Branch C: 3 × 3 same max pool with stride 1, then 1 × 1 convolution, 2 filters.</p>","<h3>To find</h3>","<p>Find each branch shape and parameters, then the concatenated shape and total parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inception channel concatenation.</strong> Parallel branches retain their separate features. Add their channel counts while keeping the common height and width. Add trainable parameters across branches.</p>","<p>C₁,C₂,… = branch output channels. Concatenation requires matching spatial dimensions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5fcf90049e052b72.svg\" alt=\"C_{\\mathrm{out}}=\\sum_k C_k\" width=\"144.90\" height=\"52.91\" style=\"width:144.90px;height:52.91px;aspect-ratio:144.90/52.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c6958d2f8ded49d5.svg\" alt=\"P_{\\mathrm{total}}=\\sum_k P_k\" width=\"151.89\" height=\"52.91\" style=\"width:151.89px;height:52.91px;aspect-ratio:151.89/52.91\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Channels jodo; height-width same rakho.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>Each parallel branch receives the same original 10 × 10 × 8 input. “Same” with stride 1 preserves height and width. Concatenation joins the channel lists without adding the feature values.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2245536fdd10a080.svg\" alt=\"C_{\\mathrm{combined}}=C_A+C_B+C_C\" width=\"281.51\" height=\"21.28\" style=\"width:281.51px;height:21.28px;aspect-ratio:281.51/21.28\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<p>Assume one bias per filter. Pooling has no learned parameters.</p>","<p class=\"worked-step\"><strong>Step 1: Branch A.</strong></p>","<p>Its 4 filters produce shape 10 × 10 × 4.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.74px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff251b0ed25a7ae7.svg\"><img class=\"math display-math\" src=\"assets/equations/baf7f3bc0580d3c4.svg\" alt=\"P_A=(1\\times1\\times8+1)\\times4=9\\times4=36\" width=\"406.74\" height=\"24.43\" style=\"width:406.74px;height:24.43px;aspect-ratio:406.74/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Branch B.</strong></p>","<p>Its 6 filters produce shape 10 × 10 × 6.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.90px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d6970788f463cb74.svg\"><img class=\"math display-math\" src=\"assets/equations/97eb7526b53ae379.svg\" alt=\"P_B=(3\\times3\\times8+1)\\times6=73\\times6=438\" width=\"431.33\" height=\"24.43\" style=\"width:431.33px;height:24.43px;aspect-ratio:431.33/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: Branch C.</strong></p>","<p>Pooling preserves 10 × 10 × 8 here because stride is 1 and padding is same. Its parameter count is zero. The following 2-filter projection creates 10 × 10 × 2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.45px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bdab800ad8bc0347.svg\"><img class=\"math display-math\" src=\"assets/equations/61f74ab4b2624099.svg\" alt=\"P_C=0+(1\\times1\\times8+1)\\times2=18\" width=\"362.11\" height=\"24.43\" style=\"width:362.11px;height:24.43px;aspect-ratio:362.11/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: Join the shapes and add the parameters.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/567c2c4512c2cb27.svg\" alt=\"C_{\\mathrm{combined}}=4+6+2=12\" width=\"277.48\" height=\"21.08\" style=\"width:277.48px;height:21.08px;aspect-ratio:277.48/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.09px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f9a71aaf4ed27273.svg\"><img class=\"math display-math\" src=\"assets/equations/4f06023c81396b20.svg\" alt=\"P_{\\mathrm{total}}=36+438+18=492\" width=\"300.32\" height=\"20.54\" style=\"width:300.32px;height:20.54px;aspect-ratio:300.32/20.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> combined shape 10 × 10 × 12; 492 parameters. Branch B does not take branch A&#x27;s four channels as input: they are parallel branches.</p>"],"kind":"practice","id":"mt2-c17-s44","search":"Drill 44 Inception concatenation and parameter count **Question.** Input 10 × 10 × 8. Parallel branches: A uses 1 × 1 conv 4 filters ; B uses 3 × 3 same Conv 6 filters; C max pool 3 same, stride 1 then 1 × 1 conv 2 filters. Find combined shape and trainable parameters.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 10 × 10 × 8.\n\nBranch A: 1 × 1 convolution, 4 filters.\n\nBranch B: 3 × 3 same convolution, 6 filters.\n\nBranch C: 3 × 3 same max pool with stride 1, then 1 × 1 convolution, 2 filters.\n\n### To find\n\nFind each branch shape and parameters, then the concatenated shape and total parameters.\n\n### Formula — which one and why\n\n**Inception channel concatenation.** Parallel branches retain their separate features. Add their channel counts while keeping the common height and width. Add trainable parameters across branches.\n\nC₁,C₂,… = branch output channels. Concatenation requires matching spatial dimensions.\n\n\n\n\n\n**Yaad rakhne ka cue:** Channels jodo; height-width same rakho.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nEach parallel branch receives the same original 10 × 10 × 8 input. “Same” with stride 1 preserves height and width. Concatenation joins the channel lists without adding the feature values.\n\n\nAssume one bias per filter. Pooling has no learned parameters.\n**Step 1: Branch A.**\nIts 4 filters produce shape 10 × 10 × 4.\n\n**Step 2: Branch B.**\nIts 6 filters produce shape 10 × 10 × 6.\n\n**Step 3: Branch C.**\nPooling preserves 10 × 10 × 8 here because stride is 1 and padding is same. Its parameter count is zero. The following 2-filter projection creates 10 × 10 × 2.\n\n**Step 4: Join the shapes and add the parameters.**\n\n\n**Final answer:** combined shape 10 × 10 × 12; 492 parameters. Branch B does not take branch A's four channels as input: they are parallel branches.\n"},{"title":"Drill 45 Projection shortcut","question":["<p class=\"inline-question\"><strong>Question.</strong> A residual main path outputs 8 × 8 × 16 but input is 16 × 16 × 8. Design a 1 × 1 projection shortcut with stride 2, zero padding. Find its output and parameters.</p>"],"answer":["<h3>Given</h3>","<p>Residual input = 16 × 16 × 8; main-path output = 8 × 8 × 16.</p>","<p>Shortcut kernel = 1 × 1; stride 2; padding 0.</p>","<p>Use one bias per projection filter.</p>","<h3>To find</h3>","<p>Choose the number of filters and find projection output shape and parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>Residual addition needs identical shapes on both paths. The projection must reduce height and width from 16 to 8 and increase channels from 8 to 16.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.72px;--narrow-height:67.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8abfcf2c3c8a28be.svg\"><img class=\"math display-math\" src=\"assets/equations/b8afb47cd18fe03e.svg\" alt=\"P_{\\mathrm{projection}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"298.85\" height=\"28.80\" style=\"width:298.85px;height:28.80px;aspect-ratio:298.85/28.80\" loading=\"lazy\"></picture></div>","<h3>Step 1: choose 16 filters</h3>","<p>One filter creates one channel, so 16 filters give the required 16 output channels.</p>","<h3>Step 2: use the specified 1 × 1 kernel and stride 2</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecbcadd42ab07705.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{16+0-1}{2}\\right\\rfloor+1\" width=\"269.14\" height=\"58.62\" style=\"width:269.14px;height:58.62px;aspect-ratio:269.14/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.01px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55b23544c4917d4f.svg\"><img class=\"math display-math\" src=\"assets/equations/c73f4efe4e78e925.svg\" alt=\"N_{\\mathrm{out}}=\\lfloor7.5\\rfloor+1=7+1=8\" width=\"305.90\" height=\"24.43\" style=\"width:305.90px;height:24.43px;aspect-ratio:305.90/24.43\" loading=\"lazy\"></picture></div>","<p>The floor operation drops the fractional part; it does not round 7.5 to 8 before adding 1.</p>","<h3>Step 3: count weights and biases</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.20px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dfae1039bf042104.svg\"><img class=\"math display-math\" src=\"assets/equations/b4a1699aef64acc8.svg\" alt=\"\\text{weights}=1\\times1\\times8\\times16=128\" width=\"332.74\" height=\"21.99\" style=\"width:332.74px;height:21.99px;aspect-ratio:332.74/21.99\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:243.01px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/040d4fe2bfbf253e.svg\"><img class=\"math display-math\" src=\"assets/equations/3c90598459083061.svg\" alt=\"\\text{biases}=16,\\qquad \\text{total}=128+16=144\" width=\"422.46\" height=\"21.70\" style=\"width:422.46px;height:21.70px;aspect-ratio:422.46/21.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> projection output 8 × 8 × 16 and 144 parameters with biases. The projected shortcut now matches the main path, so elementwise addition is valid.</p>"],"kind":"practice","id":"mt2-c17-s45","search":"Drill 45 Projection shortcut **Question.** A residual main path outputs 8 × 8 × 16 but input is 16 × 16 × 8. Design a 1 × 1 projection shortcut with stride 2, zero padding. Find its output and parameters.\n\n**Full solution.**\n\n\n\n### Given\n\nResidual input = 16 × 16 × 8; main-path output = 8 × 8 × 16.\n\nShortcut kernel = 1 × 1; stride 2; padding 0.\n\nUse one bias per projection filter.\n\n### To find\n\nChoose the number of filters and find projection output shape and parameters.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nResidual addition needs identical shapes on both paths. The projection must reduce height and width from 16 to 8 and increase channels from 8 to 16.\n\n\n### Step 1: choose 16 filters\nOne filter creates one channel, so 16 filters give the required 16 output channels.\n### Step 2: use the specified 1 × 1 kernel and stride 2\n\n\nThe floor operation drops the fractional part; it does not round 7.5 to 8 before adding 1.\n### Step 3: count weights and biases\n\n\n**Final answer:** projection output 8 × 8 × 16 and 144 parameters with biases. The projected shortcut now matches the main path, so elementwise addition is valid.\n"},{"title":"Revising solved examples","blocks":["<p>Revisit a direct example and then its changed-number version. Write the given values, the formula and the substitutions on separate lines. If an answer differs, compare from the first line until the difference appears. Use the mixed questions after the individual methods make sense.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c17-s46","search":"Revising solved examples Revisit a direct example and then its changed-number version. Write the given values, the formula and the substitutions on separate lines. If an answer differs, compare from the first line until the difference appears. Use the mixed questions after the individual methods make sense.\n\n"}]},{"n":18,"title":"Two complete MT2 mock papers","sections":[{"title":"Start here","blocks":["<p>These mocks follow the teacher&#x27;s Unit 3–4 guidance and clarification relayed on 12 October. The 2-mark parts can be theory or a theory–numerical combination. For Q2–Q4, practise both stated arrangements: two numerical questions plus one theory question; or one mixed theory–numerical question, one numerical question and one theory question. Prepare the theory of both units as well as the numerical methods.</p>","<p>Each rehearsal uses the established 10-mark layout: Q1(a) and Q1(b), 2 marks each, are compulsory; answer any TWO of Q2–Q4, 3 marks each. Allow 60 minutes. Mock A uses numerical + numerical + theory in Q2–Q4, including two Unit 4 numericals. Mock B uses mixed + numerical + theory, including Unit 3 optimization. The topic assigned to each question, and the marks split inside Mock B&#x27;s mixed question, are practice choices rather than a fixed official blueprint. Unit 5 RNN and standalone Unit 2 ANN questions are not included here.</p>","<p>Every answer is immediately below its question. The worked answers deliberately show more explanation than you need to copy during the exam. In the exam, retain the method, substitutions, intermediate values and labelled final answer.</p>"],"kind":"read","id":"mt2-c18-intro"},{"title":"MT2 Mock A: full questions and answers","blocks":["<p>60-minute rehearsal; attempt 10 marks. Q1(a) and Q1(b) are compulsory. Answer any TWO of Q2–Q4. This practice arrangement contains Unit 3 theory and two Unit 4 long numericals.</p>","<h3>Q1a</h3>","<p class=\"inline-question\"><strong>Q1a compulsory (2 marks). Explain the key difference between the AdaGrad and RMSProp accumulators. Why can AdaGrad&#x27;s effective learning rate become very small during prolonged training?</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>1. AdaGrad stores a running sum</h3>","<p>Let gₜ be the current gradient and Gₜ the stored sum of squared gradients. AdaGrad updates that sum as follows:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<p>Every added square is nonnegative, so G cannot decrease. All past squared gradients remain in the sum.</p>","<h3>2. RMSProp stores a decaying average</h3>","<p>Let sₜ be the stored squared-gradient average and ρ the fraction of the previous average retained.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<p>RMSProp gradually reduces the influence of older squared gradients. Its accumulator can rise or fall, depending on the new squared gradient.</p>","<h3>3. Explain the effect on step size</h3>","<p>AdaGrad&#x27;s effective learning rate is:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f335dbb7b791f6d.svg\" alt=\"\\eta_{effective}=\\frac{\\eta}{\\sqrt{G_t}+\\epsilon}\" width=\"216.83\" height=\"52.24\" style=\"width:216.83px;height:52.24px;aspect-ratio:216.83/52.24\" loading=\"lazy\"></div>","<p>Here η is the base learning rate and ε is a small positive number that stabilizes division. When G becomes large, its square root becomes large, so dividing by it produces a smaller effective learning rate. RMSProp&#x27;s decaying average avoids this particular permanent-accumulation problem.</p>","<p><strong>Final answer:</strong> AdaGrad uses a nondecreasing sum of all squared gradients; RMSProp uses a decaying average. AdaGrad&#x27;s growing denominator can make future updates very small.</p>","<p><strong>Yaad rakho:</strong> AdaGrad sab squares jodta rehta hai; RMSProp purane squares ka asar dheere kam karta hai.</p>","<h3>Q1b</h3>","<p class=\"inline-question\"><strong>Q1b compulsory (2 marks). Explain local connectivity and parameter sharing in a CNN. How do they reduce the number of learned parameters compared with a fully connected mapping of an image?</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>1. Local connectivity</h3>","<p>Each convolutional output depends on a small spatial neighbourhood of the input, called its receptive field, rather than every pixel in the entire image. The filter spans the input channels within that neighbourhood. This limits the connections used to calculate each output.</p>","<h3>2. Parameter sharing</h3>","<p>The same filter weights and bias are reused at every spatial position where that filter is applied. A CNN therefore learns one set of parameters for that filter, rather than a separate set for each image location.</p>","<h3>3. Concrete image example</h3>","<p>An edge-detecting filter can identify a vertical boundary near the left of an image and then slide to look for a similar boundary near the right. Both locations use the same learned filter. The network does not need to learn an independent edge detector for every position.</p>","<h3>4. Comparison with a fully connected mapping</h3>","<p>A fully connected layer generally learns a separate weight for every input-to-output connection. Convolution reduces this requirement in two ways: local connectivity restricts each output&#x27;s input region, while parameter sharing reuses one filter across locations. More output positions create more activations and computation, but do not create new parameters for that shared filter.</p>","<p><strong>Final answer:</strong> local connectivity uses a limited input neighbourhood; parameter sharing reuses the filter&#x27;s learned values across spatial positions. Together they can require far fewer parameters than a fully connected image mapping.</p>","<p><strong>Yaad rakho:</strong> Filter ke numbers ek baar seekhte hain; image par baar-baar wahi use hote hain.</p>","<h3>Q2</h3>","<p class=\"inline-question\"><strong>Q2 optional (3 marks). An input of size 7 × 7 × 3 passes through a convolutional layer with two 3 × 3 filters, stride 2 and padding 1 on each side; then a 2 × 2 pooling layer with stride 2 and no padding; then flattening; then a dense layer with three output units. Find the output shape after every layer and the total trainable parameters. Include one bias per convolutional filter and per dense unit.</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>- Input: height 7, width 7, channels 3.</p>","<p>- Convolution: kernel 3 × 3, filters 2, stride 2, padding 1 per side.</p>","<p>- Pooling: window 2 × 2, stride 2, padding 0.</p>","<p>- Flattening followed by 3 dense output units.</p>","<p>- Include all specified biases. Pooling and flattening have no learned parameters.</p>","<h3>To find</h3>","<p>The convolution output, pooling output, flatten length, dense output length and total trainable parameter count.</p>","<h3>Formula — which one and why</h3>","<p>For either spatial axis, use the output-size formula. N is that axis&#x27;s input size, K the window size, S its stride and P padding per side. The floor means discard any fractional part because a full window must fit.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>Each convolution filter spans all input channels; each dense unit connects to every flattened input. Therefore:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/683bcf7c089c902f.svg\"><img class=\"math display-math\" src=\"assets/equations/e06582d1ab100452.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}},\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"543.72\" height=\"27.70\" style=\"width:543.72px;height:27.70px;aspect-ratio:543.72/27.70\" loading=\"lazy\"></picture></div>","<p>Flattening simply counts all values in the preceding feature maps:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<h3>Step 1: convolution height and width</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.13px;--narrow-height:97.97px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2592712257363b0.svg\"><img class=\"math display-math\" src=\"assets/equations/3ba361586be8312e.svg\" alt=\"N_{\\mathrm{conv}}=\\left\\lfloor\\frac{7+2(1)-3}{2}\\right\\rfloor+1=3+1=4\" width=\"429.90\" height=\"58.87\" style=\"width:429.90px;height:58.87px;aspect-ratio:429.90/58.87\" loading=\"lazy\"></picture></div>","<p>The numerator is 7 + 2 − 3 = 6. Divide by stride 2 to get 3, then add 1 to get 4 positions. The same calculation applies to height and width. Two filters create two output channels.</p>","<p><strong>Convolution output: 4 × 4 × 2.</strong></p>","<h3>Step 2: convolution parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.28px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e6c2c8a35c15f9ce.svg\"><img class=\"math display-math\" src=\"assets/equations/fa20139330cc7a23.svg\" alt=\"\\text{weights}=3\\times3\\times3\\times2=54\" width=\"308.30\" height=\"21.99\" style=\"width:308.30px;height:21.99px;aspect-ratio:308.30/21.99\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fa35646db3c8aec.svg\"><img class=\"math display-math\" src=\"assets/equations/b8f0882262171dff.svg\" alt=\"\\text{biases}=2,\\qquad P_{\\mathrm{conv}}=54+2=56\" width=\"376.11\" height=\"21.70\" style=\"width:376.11px;height:21.70px;aspect-ratio:376.11/21.70\" loading=\"lazy\"></picture></div>","<h3>Step 3: pooling shape and parameters</h3>","<p>The pooling input size is now 4, not the original 7.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.55px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75bb76e8c3f74574.svg\"><img class=\"math display-math\" src=\"assets/equations/6833d7ee27072935.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1=1+1=2\" width=\"353.25\" height=\"58.62\" style=\"width:353.25px;height:58.62px;aspect-ratio:353.25/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling operates separately on each channel, so the two channels remain two.</p>","<p><strong>Pooling output: 2 × 2 × 2. Pooling parameters: 0.</strong></p>","<h3>Step 4: flattening</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4eb23baff49f82cf.svg\" alt=\"n_{\\mathrm{flat}}=2\\times2\\times2=8\" width=\"215.91\" height=\"20.13\" style=\"width:215.91px;height:20.13px;aspect-ratio:215.91/20.13\" loading=\"lazy\"></div>","<p>There are eight values to send to the dense layer. Flattening rearranges them into a list and learns no parameters.</p>","<p><strong>Flatten output: 8 values. Flatten parameters: 0.</strong></p>","<h3>Step 5: dense output and parameters</h3>","<p>Each of the three dense units receives eight inputs and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.91px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5d064152bee760f3.svg\"><img class=\"math display-math\" src=\"assets/equations/ff79309a11966950.svg\" alt=\"\\text{weights}=8\\times3=24,\\quad\\text{biases}=3,\\quad P_{\\mathrm{dense}}=27\" width=\"518.32\" height=\"21.99\" style=\"width:518.32px;height:21.99px;aspect-ratio:518.32/21.99\" loading=\"lazy\"></picture></div>","<p><strong>Dense output: 3 values.</strong></p>","<h3>Step 6: total trainable parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8013f82d7c04ad92.svg\"><img class=\"math display-math\" src=\"assets/equations/021c0c327e9ed57d.svg\" alt=\"P_{\\mathrm{total}}=56+0+0+27=83\" width=\"305.76\" height=\"20.54\" style=\"width:305.76px;height:20.54px;aspect-ratio:305.76/20.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> 4 × 4 × 2 → 2 × 2 × 2 → 8 → 3. <strong>Total: 83 trainable parameters.</strong></p>","<p><strong>Yaad rakho:</strong> Pehle shape; phir weights. Ek layer ka output hi next layer ka input hai.</p>","<h3>Q3</h3>","<p class=\"inline-question\"><strong>Q3 optional (3 marks). Apply the printed kernel K to input I using the deep-learning cross-correlation convention, with stride 1, no padding and zero bias. Do not flip K. Apply ReLU to the resulting map, followed by 2 × 2 max pooling with stride 2 and no padding. Show every convolution entry and find the final output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9bf8a81efcf4cdbd.svg\" alt=\"I=\\begin{bmatrix}1&amp;2&amp;1\\\\0&amp;1&amp;3\\\\2&amp;1&amp;0\\end{bmatrix},\\quad K=\\begin{bmatrix}1&amp;-1\\\\0&amp;1\\end{bmatrix}\" width=\"346.30\" height=\"92.85\" style=\"width:346.30px;height:92.85px;aspect-ratio:346.30/92.85\" loading=\"lazy\"></div>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>- Input I is the printed 3 × 3 matrix; kernel K is the printed 2 × 2 matrix.</p>","<p>- Convolution stride 1, padding 0, bias 0; use K in its printed orientation.</p>","<p>- Activation: ReLU.</p>","<p>- Pooling: max, 2 × 2 window, stride 2, padding 0.</p>","<h3>To find</h3>","<p>All four convolution values, the ReLU output matrix and the final pooled output.</p>","<h3>Formula — which one and why</h3>","<p>For each input window, multiply entries at matching positions, then add all products and the bias once.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p>X is the input, S is stride, u and v select a kernel entry, and b is bias. This formula uses zero-based array indices; the written solution labels positions from 1 for readability.</p>","<p>ReLU is required because the question requests activation after convolution. It replaces a negative value by zero.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<p>Max pooling selects the largest value in its current window V.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<h3>Step 1: determine the convolution shape</h3>","<p>For each axis: (3 − 2)/1 + 1 = 2. Therefore calculate a 2 × 2 output matrix.</p>","<h3>Step 2: top-left output, position (1,1)</h3>","<p>The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/eed57e81393ab435.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\0 &amp; 1\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 1 × 1 = 1; 2 × (−1) = −2; 0 × 0 = 0; 1 × 1 = 1.</p>","<p>Add the products and bias: 1 − 2 + 0 + 1 + 0 = <strong>0</strong>.</p>","<h3>Step 3: top-right output, position (1,2)</h3>","<p>Move the window one column to the right. The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/85c116687119a006.svg\" alt=\"\\begin{bmatrix}2 &amp; 1\\\\1 &amp; 3\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 2 × 1 = 2; 1 × (−1) = −1; 1 × 0 = 0; 3 × 1 = 3.</p>","<p>Add: 2 − 1 + 0 + 3 + 0 = <strong>4</strong>.</p>","<h3>Step 4: bottom-left output, position (2,1)</h3>","<p>The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e06165b70c0dec06.svg\" alt=\"\\begin{bmatrix}0 &amp; 1\\\\2 &amp; 1\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 0 × 1 = 0; 1 × (−1) = −1; 2 × 0 = 0; 1 × 1 = 1.</p>","<p>Add: 0 − 1 + 0 + 1 + 0 = <strong>0</strong>.</p>","<h3>Step 5: bottom-right output, position (2,2)</h3>","<p>The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/9f01f837180dd993.svg\" alt=\"\\begin{bmatrix}1 &amp; 3\\\\1 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 1 × 1 = 1; 3 × (−1) = −3; 1 × 0 = 0; 0 × 1 = 0.</p>","<p>Add: 1 − 3 + 0 + 0 + 0 = <strong>−2</strong>.</p>","<p><strong>Convolution map: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f2f63d345efa8255.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; -2\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>.</strong></p>","<h3>Step 6: apply ReLU separately to every entry</h3>","<p>- max(0,0) = 0.</p>","<p>- max(0,4) = 4.</p>","<p>- max(0,0) = 0.</p>","<p>- max(0,−2) = 0.</p>","<p><strong>ReLU map: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ca987c6e03219656.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</strong></p>","<h3>Step 7: max pooling</h3>","<p>The 2 × 2 pooling window covers all four activated entries. Compare 0, 4, 0 and 0. Their maximum is <strong>4</strong>.</p>","<p><strong>Final answer:</strong> convolution <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f2f63d345efa8255.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; -2\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span> → ReLU <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ca987c6e03219656.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> → pooled output <strong><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/eaf8e658e6675411.svg\" alt=\"\\begin{bmatrix}4\\end{bmatrix}\" width=\"20.07\" height=\"19.00\" style=\"width:20.07px;height:19.00px;aspect-ratio:20.07/19.00\" loading=\"lazy\"></span></strong>, a 1 × 1 map.</p>","<p><strong>Yaad rakho:</strong> Multiply-add se convolution; negative hatao ReLU; biggest uthao max pool.</p>","<h3>Q4</h3>","<p class=\"inline-question\"><strong>Q4 optional (3 marks). What is overfitting? Explain how dropout and early stopping help improve generalization. State which dataset should select the stopping point.</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>1. Definition and identification</h3>","<p>Overfitting occurs when a model learns training-specific details or noise that do not generalize to new data. It commonly shows low training error together with substantially higher validation error. Generalization means performing well on new examples drawn from the task&#x27;s data distribution.</p>","<h3>2. Dropout</h3>","<p>During training, dropout randomly sets selected activations to zero. The active subnetwork changes across training passes, discouraging reliance on a fixed combination of hidden units. Under inverted dropout, retained activations are divided by the keep probability to preserve their expected scale. During ordinary inference, the masking is disabled and all units are used without that training-time rescaling.</p>","<p>Dropout is a regularizer; it can reduce overfitting, but excessive dropout can cause underfitting.</p>","<h3>3. Early stopping</h3>","<p>Train on the training set and monitor performance on a separate <strong>validation set</strong>. Save the model whenever validation loss improves. Stop after the chosen number of consecutive non-improving evaluations, called patience, then restore the saved best model.</p>","<p>For example, validation losses 0.8, 0.6, 0.5, 0.53 and 0.55 have their minimum at epoch 3. With patience 2, stop after epoch 5 and restore epoch 3. The stopping epoch and saved-model epoch are different.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_early_stop.svg\" aria-label=\"Enlarge diagram: Early stopping retains the model with the best validation performance, not necessarily the final trained model.\"><img src=\"assets/figures/v_early_stop.svg\" alt=\"Early stopping retains the model with the best validation performance, not necessarily the final trained model.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>Early stopping retains the model with the best validation performance, not necessarily the final trained model. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Final answer:</strong> dropout restricts dependence on particular training-time activations; early stopping limits training after validation performance stops improving. Choose the stopping point using validation data and reserve the test set for final evaluation.</p>","<p><strong>Yaad rakho:</strong> Training se seekho, validation se best model chuno, test se final result batao.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c18-s0","search":"MT2 Mock A: full questions and answers \n60-minute rehearsal; attempt 10 marks. Q1(a) and Q1(b) are compulsory. Answer any TWO of Q2–Q4. This practice arrangement contains Unit 3 theory and two Unit 4 long numericals.\n\n### Q1a\n**Q1a compulsory (2 marks). Explain the key difference between the AdaGrad and RMSProp accumulators. Why can AdaGrad's effective learning rate become very small during prolonged training?**\n\n**Answer — step by step.**\n\n### 1. AdaGrad stores a running sum\n\nLet gₜ be the current gradient and Gₜ the stored sum of squared gradients. AdaGrad updates that sum as follows:\n\n\n\nEvery added square is nonnegative, so G cannot decrease. All past squared gradients remain in the sum.\n\n### 2. RMSProp stores a decaying average\n\nLet sₜ be the stored squared-gradient average and ρ the fraction of the previous average retained.\n\n\n\nRMSProp gradually reduces the influence of older squared gradients. Its accumulator can rise or fall, depending on the new squared gradient.\n\n### 3. Explain the effect on step size\n\nAdaGrad's effective learning rate is:\n\n\n\nHere η is the base learning rate and ε is a small positive number that stabilizes division. When G becomes large, its square root becomes large, so dividing by it produces a smaller effective learning rate. RMSProp's decaying average avoids this particular permanent-accumulation problem.\n\n**Final answer:** AdaGrad uses a nondecreasing sum of all squared gradients; RMSProp uses a decaying average. AdaGrad's growing denominator can make future updates very small.\n\n**Yaad rakho:** AdaGrad sab squares jodta rehta hai; RMSProp purane squares ka asar dheere kam karta hai.\n\n### Q1b\n**Q1b compulsory (2 marks). Explain local connectivity and parameter sharing in a CNN. How do they reduce the number of learned parameters compared with a fully connected mapping of an image?**\n\n**Answer — step by step.**\n\n### 1. Local connectivity\n\nEach convolutional output depends on a small spatial neighbourhood of the input, called its receptive field, rather than every pixel in the entire image. The filter spans the input channels within that neighbourhood. This limits the connections used to calculate each output.\n\n### 2. Parameter sharing\n\nThe same filter weights and bias are reused at every spatial position where that filter is applied. A CNN therefore learns one set of parameters for that filter, rather than a separate set for each image location.\n\n### 3. Concrete image example\n\nAn edge-detecting filter can identify a vertical boundary near the left of an image and then slide to look for a similar boundary near the right. Both locations use the same learned filter. The network does not need to learn an independent edge detector for every position.\n\n### 4. Comparison with a fully connected mapping\n\nA fully connected layer generally learns a separate weight for every input-to-output connection. Convolution reduces this requirement in two ways: local connectivity restricts each output's input region, while parameter sharing reuses one filter across locations. More output positions create more activations and computation, but do not create new parameters for that shared filter.\n\n**Final answer:** local connectivity uses a limited input neighbourhood; parameter sharing reuses the filter's learned values across spatial positions. Together they can require far fewer parameters than a fully connected image mapping.\n\n**Yaad rakho:** Filter ke numbers ek baar seekhte hain; image par baar-baar wahi use hote hain.\n\n### Q2"},{"title":"MT2 Mock B: full questions and answers","blocks":["<p>60-minute rehearsal; attempt 10 marks. Q1(a) and Q1(b) are compulsory. Answer any TWO of Q2–Q4. Q2 is mixed theory + numerical, Q3 is numerical and Q4 is theory. The 1 + 2 split within Q2 is a practice allocation. The specific topics are not predictions of the actual paper.</p>","<h3>Q1a</h3>","<p class=\"inline-question\"><strong>Q1a compulsory (2 marks). Explain the purpose of scaling retained activations in inverted dropout. For activations [1,2,3,4], keep probability 0.5 and mask [1,0,1,0], calculate the activations used during this training pass. A mask value of 1 means keep and 0 means drop.</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>Theory: why scale retained values?</h3>","<p>Randomly dropping units would reduce the average activation. Inverted dropout divides every retained activation by the keep probability. Averaged over the random masks, this preserves the original activation&#x27;s expected value. A dropped activation is still zero.</p>","<h3>Given</h3>","<p>- Original activations a = [1,2,3,4].</p>","<p>- Keep probability q = 0.5, meaning a unit has a 50% chance of being kept.</p>","<p>- This pass&#x27;s supplied mask m = [1,0,1,0].</p>","<h3>To find</h3>","<p>The four post-dropout activations used in this training pass.</p>","<h3>Formula — which one and why</h3>","<p>Multiply the original activation aᵢ by its mask mᵢ, then divide by keep probability q.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<h3>Step 1: first activation</h3>","<p>Mask 1 keeps the value. Multiply 1 × 1 = 1; divide 1 by 0.5 to get <strong>2</strong>.</p>","<h3>Step 2: second activation</h3>","<p>Mask 0 drops the value. Multiply 0 × 2 = 0; divide 0 by 0.5 to get <strong>0</strong>.</p>","<h3>Step 3: third activation</h3>","<p>Mask 1 keeps the value. Multiply 1 × 3 = 3; divide 3 by 0.5 to get <strong>6</strong>.</p>","<h3>Step 4: fourth activation</h3>","<p>Mask 0 drops the value. Multiply 0 × 4 = 0; divide 0 by 0.5 to get <strong>0</strong>.</p>","<p><strong>Final answer: [2,0,6,0].</strong> This is the training-pass result. In ordinary inference with inverted dropout, disable the mask and its scaling.</p>","<p><strong>Yaad rakho:</strong> Mask lagao; bache hue values ko keep probability se divide karo.</p>","<h3>Q1b</h3>","<p class=\"inline-question\"><strong>Q1b compulsory (2 marks). Explain a ResNet shortcut. Why must the two tensors being added have matching shapes, and what can be done if their shapes differ?</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>1. Residual addition</h3>","<p>A residual block combines a learned transformation F(x) with a shortcut carrying the input x:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d30a7ff979462f45.svg\" alt=\"H(x)=F(x)+x\" width=\"182.40\" height=\"24.43\" style=\"width:182.40px;height:24.43px;aspect-ratio:182.40/24.43\" loading=\"lazy\"></div>","<p>F(x) is the output of the learned residual branch. Adding x provides a direct path for information and gradients, helping optimize deep networks. If the branch produces zero, the addition stage returns x. A post-addition activation, if specified by the architecture, is applied afterward.</p>","<h3>2. Why matching shapes are needed</h3>","<p>The addition is entry by entry. Each element in F(x) needs a corresponding element in x, so height, width and channel count must match. For example, a 14 × 14 × 32 tensor cannot be directly added to a 14 × 14 × 64 tensor in a standard residual shortcut.</p>","<h3>3. How a projection helps</h3>","<p>A learned projection, commonly a 1 × 1 convolution with an appropriate number of filters and stride, maps the shortcut to the required shape. Then add the projected shortcut and the residual branch. This is addition, not channel concatenation.</p>","<p><strong>Final answer:</strong> a shortcut adds input information to the learned residual branch. Use an identity shortcut when shapes match and a suitable projection when they do not.</p>","<p><strong>Yaad rakho:</strong> Same-size entries jodte hain; mismatch ho toh shortcut ka size pehle match karo.</p>","<h3>Q2</h3>","<p class=\"inline-question\"><strong>Q2 optional (3 marks). (a) Explain why Adam uses bias correction for its initially zero moment estimates. (1 mark) (b) Adam starts with θ₀ = 1 and m₀ = v₀ = 0. Use learning rate η = 0.1, β₁ = 0.9 and β₂ = 0.99. The supplied gradients are g₁ = 2 and g₂ = −1. Perform two bias-corrected updates. Show the raw first and second moments, corrected moments and updated parameter after each iteration. Set ε = 0 only for this nonzero-denominator hand calculation. (2 marks)</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>Part (a): why Adam corrects the moments</h3>","<p>Adam initializes both moving averages to zero. At early iterations, too little gradient history has accumulated, so the raw estimates are biased toward zero. Dividing mₜ by 1 − β₁ᵗ and vₜ by 1 − β₂ᵗ corrects this initialization bias before the parameter update. The power uses the current iteration number t. As t increases, these denominators approach 1.</p>","<h3>Part (b): numerical solution</h3>","<h3>Given</h3>","<p>- Starting parameter θ₀ = 1.</p>","<p>- Starting first moment m₀ = 0 and second moment v₀ = 0.</p>","<p>- Learning rate η = 0.1.</p>","<p>- Decay factors β₁ = 0.9 and β₂ = 0.99.</p>","<p>- Supplied gradients, in order: 2, then −1.</p>","<p>- ε = 0 for this exercise; both denominators will be nonzero.</p>","<h3>To find</h3>","<p>For iterations 1 and 2, calculate m, v, their bias-corrected values and the new parameter θ.</p>","<h3>Formula — which one and why</h3>","<p>Adam keeps two moving averages: m stores signed gradients and v stores squared gradients. Zero initialization makes these averages initially too small, so divide by the correction factors for the current iteration t.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/19f778fcb8d9f7b4.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"304.97\" height=\"53.28\" style=\"width:304.97px;height:53.28px;aspect-ratio:304.97/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>The hat marks a corrected value. Carry the <strong>raw</strong> m and v into the next moving-average recurrence, not the corrected values. Keep full calculator precision until the final answer.</p>","<h3>Solution — step by step</h3>","<h3>Step 1: iteration 1, raw first moment</h3>","<p>The current gradient is 2. Retain 90% of the old first moment and add 10% of this gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ac027abcdfcdb75.svg\" alt=\"m_1=0.9(0)+0.1(2)=0.2\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<h3>Step 2: iteration 1, raw second moment</h3>","<p>Square the gradient first: 2² = 4. Retain 99% of the old second moment and add 1% of that square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.98px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4af117593c0c60f1.svg\"><img class=\"math display-math\" src=\"assets/equations/9e506bfe9fd357f5.svg\" alt=\"v_1=0.99(0)+0.01(2)^2=0.04\" width=\"321.01\" height=\"27.70\" style=\"width:321.01px;height:27.70px;aspect-ratio:321.01/27.70\" loading=\"lazy\"></picture></div>","<h3>Step 3: iteration 1, bias correction</h3>","<p>Use t = 1. The correction denominators are 1 − 0.9 = 0.1 and 1 − 0.99 = 0.01.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8975b50fed0845b.svg\" alt=\"\\widehat m_1=\\frac{0.2}{1-0.9^{1}}=2\" width=\"204.24\" height=\"54.93\" style=\"width:204.24px;height:54.93px;aspect-ratio:204.24/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecdf53b308191b04.svg\" alt=\"\\widehat v_1=\\frac{0.04}{1-0.99^{1}}=4\" width=\"206.85\" height=\"55.20\" style=\"width:206.85px;height:55.20px;aspect-ratio:206.85/55.20\" loading=\"lazy\"></div>","<h3>Step 4: iteration 1, parameter update</h3>","<p>The square root of the corrected second moment is √4 = 2. The step is 0.1 × 2 ÷ 2 = 0.1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1122171b0bd236e.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{4}}=0.9\" width=\"263.68\" height=\"60.60\" style=\"width:263.68px;height:60.60px;aspect-ratio:263.68/60.60\" loading=\"lazy\"></div>","<h3>Step 5: iteration 2, raw first moment</h3>","<p>Use supplied gradient −1, previous raw m = 0.2 and previous raw v = 0.04.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/85e3c1c423ab1151.svg\"><img class=\"math display-math\" src=\"assets/equations/69b54ca313d8829c.svg\" alt=\"m_2=0.9(0.2)+0.1(-1)=0.08\" width=\"333.54\" height=\"24.43\" style=\"width:333.54px;height:24.43px;aspect-ratio:333.54/24.43\" loading=\"lazy\"></picture></div>","<p>The two contributions are 0.18 and −0.1; their sum is 0.08.</p>","<h3>Step 6: iteration 2, raw second moment</h3>","<p>The square of −1 is +1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:234.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fa8fd0cf3a03d97.svg\"><img class=\"math display-math\" src=\"assets/equations/76708a6ba327fc21.svg\" alt=\"v_2=0.99(0.04)+0.01(-1)^2=0.0496\" width=\"395.68\" height=\"27.70\" style=\"width:395.68px;height:27.70px;aspect-ratio:395.68/27.70\" loading=\"lazy\"></picture></div>","<p>The two contributions are 0.0396 and 0.01; their sum is 0.0496.</p>","<h3>Step 7: iteration 2, bias correction</h3>","<p>Use t = 2. The correction denominators are 1 − 0.9² = 0.19 and 1 − 0.99² = 0.0199.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ad611d8dfc7121b6.svg\"><img class=\"math display-math\" src=\"assets/equations/b68cf26945a449a6.svg\" alt=\"\\widehat m_2=\\frac{0.08}{1-0.9^{2}}=0.421052632\" width=\"320.99\" height=\"54.93\" style=\"width:320.99px;height:54.93px;aspect-ratio:320.99/54.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.05px;--narrow-height:94.29px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/77a755525cf83c35.svg\"><img class=\"math display-math\" src=\"assets/equations/7d078eb9618846c0.svg\" alt=\"\\widehat v_2=\\frac{0.0496}{1-0.99^{2}}=2.492462312\" width=\"323.60\" height=\"55.20\" style=\"width:323.60px;height:55.20px;aspect-ratio:323.60/55.20\" loading=\"lazy\"></picture></div>","<h3>Step 8: iteration 2, parameter update</h3>","<p>Start from the updated parameter 0.9. Take the square root of the corrected second moment, divide the corrected first moment by it, multiply by 0.1 and subtract.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.70px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a3614192f516725e.svg\"><img class=\"math display-math\" src=\"assets/equations/bd194d13466767bb.svg\" alt=\"\\theta_2=0.9-\\frac{0.1\\times(0.421052632)}{\\sqrt{2.492462312}}=0.873330057\" width=\"497.18\" height=\"60.60\" style=\"width:497.18px;height:60.60px;aspect-ratio:497.18/60.60\" loading=\"lazy\"></picture></div>","<p>The displayed decimals are rounded; evaluate using the unrounded fractions when possible.</p>","<p><strong>Final answer:</strong> θ₁ = <strong>0.9</strong> and θ₂ ≈ <strong>0.873330057</strong>. The second supplied gradient is negative, but the first-moment estimate is still positive because it retains part of the previous positive gradient.</p>","<p><strong>Yaad rakho:</strong> Do raw memories banao → current t se hats nikalo → update; next round mein raw memories le jao.</p>","<h3>Q3</h3>","<p class=\"inline-question\"><strong>Q3 optional (3 marks). A 16 × 16 × 64 feature map is processed by 32 filters of size 3 × 3 using stride 1 and same padding. Compare the direct convolution&#x27;s MAC count with a bottleneck that first applies eight 1 × 1 filters, then the same 32-filter 3 × 3 convolution. Both stages keep spatial size 16 × 16. Find both costs, the absolute saving and percentage saving. Count one multiply–accumulate as one MAC and omit bias additions.</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>- Input map: 16 × 16 with 64 channels.</p>","<p>- Direct layer: 32 filters, each 3 × 3, receiving 64 channels.</p>","<p>- Bottleneck stage 1: eight 1 × 1 filters, receiving 64 channels.</p>","<p>- Bottleneck stage 2: 32 filters, each 3 × 3, now receiving only 8 channels.</p>","<p>- Every layer has output height and width 16; ignore bias additions.</p>","<h3>To find</h3>","<p>Direct MACs, both bottleneck-stage MACs, their total, absolute saving and saving percentage.</p>","<h3>Formula — which one and why</h3>","<p>Each output entry uses K²Cᵢₙ weight–input pairs. There are HₒᵤₜWₒᵤₜCₒᵤₜ output entries. Multiply these counts:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<p>The bottleneck has two layers, so calculate each layer&#x27;s work and add them. Saving is direct work minus reduced work, expressed as a fraction of direct work.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<h3>Solution — step by step</h3>","<h3>Step 1: direct convolution</h3>","<p>Each output entry uses 3 × 3 × 64 = <strong>576</strong> weight–input pairs.</p>","<p>There are 16 × 16 × 32 = <strong>8,192</strong> output entries.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.21px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/673cd31676ab87d1.svg\"><img class=\"math display-math\" src=\"assets/equations/660ea75dfc92d56c.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=8192\\times576=4{,}718{,}592\" width=\"392.94\" height=\"22.24\" style=\"width:392.94px;height:22.24px;aspect-ratio:392.94/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 2: 1 × 1 bottleneck reduction</h3>","<p>Each reduction output uses 1 × 1 × 64 = <strong>64</strong> weight–input pairs.</p>","<p>There are 16 × 16 × 8 = <strong>2,048</strong> reduction outputs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bcc137de649f71d.svg\"><img class=\"math display-math\" src=\"assets/equations/07ded70ae81c3cd5.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=16\\times16\\times8\\times1\\times1\\times64=131{,}072\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<p>The new map is <strong>16 × 16 × 8</strong>. This changes the next layer&#x27;s input channels to 8.</p>","<h3>Step 3: following 3 × 3 convolution</h3>","<p>Each output now uses 3 × 3 × 8 = <strong>72</strong> weight–input pairs, instead of 576.</p>","<p>The number of outputs remains 16 × 16 × 32 = <strong>8,192</strong>.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.07px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/da27ae2a69680cb6.svg\"><img class=\"math display-math\" src=\"assets/equations/798ae9e57f70e0ad.svg\" alt=\"\\mathrm{MACs}_{3\\times3}=16\\times16\\times32\\times3\\times3\\times8=589{,}824\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 4: total bottleneck cost</h3>","<p>Include both stages; do not compare the direct layer against only the second stage.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/741f21ae6e5bfc83.svg\"><img class=\"math display-math\" src=\"assets/equations/ec8abadaa9257a67.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=131{,}072+589{,}824=720{,}896\" width=\"483.59\" height=\"22.24\" style=\"width:483.59px;height:22.24px;aspect-ratio:483.59/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 5: absolute saving</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/005360b3f69dc10a.svg\"><img class=\"math display-math\" src=\"assets/equations/03fa81b05dc71237.svg\" alt=\"\\mathrm{saving}=4{,}718{,}592-720{,}896=3{,}997{,}696\" width=\"440.68\" height=\"21.58\" style=\"width:440.68px;height:21.58px;aspect-ratio:440.68/21.58\" loading=\"lazy\"></picture></div>","<h3>Step 6: percentage saving</h3>","<p>Divide the saving by the original direct cost, then multiply by 100.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.96px;--narrow-height:132.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2a96913f36caca06.svg\"><img class=\"math display-math\" src=\"assets/equations/46344c94632c2247.svg\" alt=\"\\mathrm{saving\\ percent}=\\frac{3{,}997{,}696}{4{,}718{,}592}\\times100=84.722222\\%\" width=\"518.68\" height=\"54.54\" style=\"width:518.68px;height:54.54px;aspect-ratio:518.68/54.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> direct <strong>4,718,592 MACs</strong>; bottleneck <strong>720,896 MACs</strong>; saving <strong>3,997,696 MACs</strong>, approximately <strong>84.72%</strong>. Both routes end in a 16 × 16 × 32 output, though they are different learned transformations.</p>","<p><strong>Yaad rakho:</strong> 1 × 1 se channels kam; expensive 3 × 3 ka kaam kam. Dono stages ka cost jodna hai.</p>","<h3>Q4</h3>","<p class=\"inline-question\"><strong>Q4 optional (3 marks). Explain transfer learning for image classification with limited labelled data. Distinguish feature extraction from fine-tuning and describe a suitable training procedure.</strong></p>","<p><strong>Answer — step by step.</strong></p>","<h3>1. Definition</h3>","<p>Transfer learning reuses knowledge learned on a source task to help solve a target task. For image classification, a pretrained CNN can provide visual features that a new classifier uses for the target classes. This can reduce the amount of target data and training needed, provided the source features are useful for the target task.</p>","<h3>2. Feature extraction and fine-tuning</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>Which parameters learn?</th><th>Main effect</th></tr></thead><tbody><tr><td>Feature extraction</td><td>Keep pretrained backbone weights fixed; train a new classification head</td><td>Learn to classify using fixed pretrained features</td></tr><tr><td>Fine-tuning</td><td>Update selected pretrained layers as well as the new head</td><td>Adapt representations to the target task</td></tr></tbody></table></div>","<p>Freezing a layer stops its parameter updates; it does not remove its stored weights. Fine-tuning typically exposes more trainable parameters and therefore needs particular care with small datasets.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Feature extraction freezes the pretrained backbone; fine-tuning permits selected pretrained layers to update.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Feature extraction freezes the pretrained backbone; fine-tuning permits selected pretrained layers to update.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Feature extraction freezes the pretrained backbone; fine-tuning permits selected pretrained layers to update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>3. Training procedure</h3>","<p>1. Create separate training, validation and test splits for the target problem.</p>","<p>2. Choose a suitable pretrained CNN and apply its required input size and preprocessing.</p>","<p>3. Replace the original classifier with a new head matching the target classes.</p>","<p>4. Freeze the backbone and train the new head on the training set.</p>","<p>5. If validation results justify it, unfreeze selected later layers and continue with an appropriately smaller learning rate.</p>","<p>6. Select the best checkpoint using validation performance; evaluate the final model on the held-out test set.</p>","<h3>4. Concrete example</h3>","<p>For a small dataset containing cats and dogs, reuse a pretrained image backbone and replace its original classifier with a binary-classification head. First learn the new head with the backbone frozen. Later, selected high-level layers may be fine-tuned if this improves validation performance.</p>","<p><strong>Final answer:</strong> feature extraction learns a new classifier over fixed features; fine-tuning also adapts selected pretrained features. The correct choice depends on target data quantity, similarity to the source data and validation results.</p>","<p><strong>Yaad rakho:</strong> Freeze mein purane features fixed; fine-tune mein selected purane features bhi seekhte hain.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c18-s1","search":"MT2 Mock B: full questions and answers \n60-minute rehearsal; attempt 10 marks. Q1(a) and Q1(b) are compulsory. Answer any TWO of Q2–Q4. Q2 is mixed theory + numerical, Q3 is numerical and Q4 is theory. The 1 + 2 split within Q2 is a practice allocation. The specific topics are not predictions of the actual paper.\n\n### Q1a\n**Q1a compulsory (2 marks). Explain the purpose of scaling retained activations in inverted dropout. For activations [1,2,3,4], keep probability 0.5 and mask [1,0,1,0], calculate the activations used during this training pass. A mask value of 1 means keep and 0 means drop.**\n\n**Answer — step by step.**\n\n### Theory: why scale retained values?\n\nRandomly dropping units would reduce the average activation. Inverted dropout divides every retained activation by the keep probability. Averaged over the random masks, this preserves the original activation's expected value. A dropped activation is still zero.\n\n### Given\n\n- Original activations a = [1,2,3,4].\n- Keep probability q = 0.5, meaning a unit has a 50% chance of being kept.\n- This pass's supplied mask m = [1,0,1,0].\n\n### To find\n\nThe four post-dropout activations used in this training pass.\n\n### Formula — which one and why\n\nMultiply the original activation aᵢ by its mask mᵢ, then divide by keep probability q.\n\n\n\n### Solution — step by step\n\n### Step 1: first activation\n\nMask 1 keeps the value. Multiply 1 × 1 = 1; divide 1 by 0.5 to get **2**.\n\n### Step 2: second activation\n\nMask 0 drops the value. Multiply 0 × 2 = 0; divide 0 by 0.5 to get **0**.\n\n### Step 3: third activation\n\nMask 1 keeps the value. Multiply 1 × 3 = 3; divide 3 by 0.5 to get **6**.\n\n### Step 4: fourth activation\n\nMask 0 drops the value. Multiply 0 × 4 = 0; divide 0 by 0.5 to get **0**.\n\n**Final answer: [2,0,6,0].** This is the training-pass result. In ordinary inference with inverted dropout, disable the mask and its scaling.\n\n**Yaad rakho:** Mask lagao; bache hue values ko keep probability se divide karo.\n\n### Q1b\n**Q1b compulsory (2 marks). Explain a ResNet shortcut. Why must the two tensors being added have matching shapes, and what can be done if their shapes differ?**\n\n**Answer — step by step.**\n\n### 1. Residual addition\n\nA residual block combines a learned transformation F(x) with a shortcut carrying the input x:\n\n\n\nF(x) is the output of the learned residual branch. Adding x provides a direct path for information and gradients, helping optimize deep networks. If the branch produces zero, the addition stage returns x. A post-addition activation, if specified by the architecture, is applied afterward.\n\n### 2. Why matching shapes are needed\n\nThe addition is entry by entry. Each element in F(x) needs a corresponding element in x, so height, width and channel count must match. For example, a 14 × 14 × 32 tensor cannot be directly added to a 14 × 14 × 64 tensor in a standard residual shortcut.\n\n### 3. How a projection helps\n\nA learned projection, commonly a 1 × 1 convolution with an appropriate number of filters and stride, maps the shortcut to the required shape. Then add the projected shortcut and the residual branch. This is addition, not channel concatenation.\n\n**Final answer:** a shortcut adds input information to the learned residual branch. Use an identity shortcut when shapes match and a suitable projection when they do not.\n\n**Yaad rakho:** Same-size entries jodte hain; mismatch ho toh shortcut ka size pehle match karo.\n\n### Q2\n**Q2 optional (3 marks). (a) Explain why Adam uses bias correction "}]},{"n":19,"title":"Formula reference and exam revision","sections":[{"title":"The one page method map","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Question clue</th><th>First action</th><th>Core formula or check</th></tr></thead><tbody><tr><td>Neuron output</td><td>Multiply each input by its matching weight</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"133.08\" height=\"40.71\" style=\"width:133.08px;height:40.71px;aspect-ratio:133.08/40.71\" loading=\"lazy\"></span>, then activate</td></tr><tr><td>Network prediction</td><td>Finish one whole layer before the next</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5c938cf38724d627.svg\" alt=\"h=f(Wx+b)\" width=\"123.70\" height=\"19.00\" style=\"width:123.70px;height:19.00px;aspect-ratio:123.70/19.00\" loading=\"lazy\"></span></td></tr><tr><td>Backpropagation</td><td>State loss then prediction-minus-target</td><td>delta times sending activation</td></tr><tr><td>Optimizer update</td><td>Identify current gradient and stored state</td><td>old parameter minus update</td></tr><tr><td>CNN dimensions</td><td>Write N K S P and channels</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span></td></tr><tr><td>CNN parameters</td><td>Count one filter then all filters</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cfa2f04f36764d25.svg\" alt=\"(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"134.66\" height=\"21.55\" style=\"width:134.66px;height:21.55px;aspect-ratio:134.66/21.55\" loading=\"lazy\"></span></td></tr><tr><td>Pooling</td><td>Draw every valid window</td><td>Maximum, or mean of the window</td></tr><tr><td>Dense parameters</td><td>Count connections and receiving biases</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/641d99b5a929f5f6.svg\" alt=\"(N_{\\mathrm{in}}+1)N_{\\mathrm{out}}\" width=\"111.82\" height=\"19.00\" style=\"width:111.82px;height:19.00px;aspect-ratio:111.82/19.00\" loading=\"lazy\"></span></td></tr></tbody></table></div>"],"question":[],"answer":[],"kind":"read","id":"mt2-c19-s0","search":"The one page method map | Question clue | First action | Core formula or check |\n| Neuron output | Multiply each input by its matching weight | \\(z=\\sum_iw_ix_i+b\\), then activate |\n| Network prediction | Finish one whole layer before the next | \\(h=f(Wx+b)\\) |\n| Backpropagation | State loss then prediction-minus-target | delta times sending activation |\n| Optimizer update | Identify current gradient and stored state | old parameter minus update |\n| CNN dimensions | Write N K S P and channels | \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\) |\n| CNN parameters | Count one filter then all filters | \\((K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\\) |\n| Pooling | Draw every valid window | Maximum, or mean of the window |\n| Dense parameters | Count connections and receiving biases | \\((N_{\\mathrm{in}}+1)N_{\\mathrm{out}}\\) |"},{"title":"All formulas: meanings, use and substitution","blocks":["<p>These are the formulas used by this course. Each entry names its symbols and the type of calculation it serves. Numerical practice in the teaching chapters shows the longer working. Follow any different convention explicitly stated in the examination.</p>","<h3>Formula 1: Mean, variance and standard deviation</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.24px;--narrow-height:181.05px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7bccad9589b45084.svg\"><img class=\"math display-math\" src=\"assets/equations/ba649f65f75f4057.svg\" alt=\"\\mu=\\frac{1}{n}\\sum_i x_i,\\quad v=\\frac{1}{n}\\sum_i(x_i-\\mu)^2,\\quad s=\\sqrt{v}\" width=\"490.91\" height=\"61.92\" style=\"width:490.91px;height:61.92px;aspect-ratio:490.91/61.92\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> n is the count; mu is the mean; v is the population variance; s is the standard deviation.</p>","<p><strong>Use:</strong> Use when calculating a population mean/variance or standardization. Sample-variance estimates may use n−1 when explicitly requested.</p>","<p><strong>Substitution example:</strong> For [2,4]: mean = 3; deviations = −1,1; squares = 1,1; variance = 1; standard deviation = 1.</p>","<h3>Formula 2: Standardization</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a0a4f4a38fa7007.svg\" alt=\"x_{scaled}=\\frac{x-\\mu_{train}}{s_{train}}\" width=\"206.36\" height=\"51.38\" style=\"width:206.36px;height:51.38px;aspect-ratio:206.36/51.38\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> Use the mean and standard deviation estimated from training data.</p>","<p><strong>Use:</strong> Use to express a value relative to the training distribution. The standard deviation must be nonzero.</p>","<p><strong>Substitution example:</strong> For x = 7, mean = 5, standard deviation = 2: (7−5)/2 = 1.</p>","<h3>Formula 3: Power, constant and sum derivatives</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.46px;--narrow-height:154.76px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dffe83aa3b00d40c.svg\"><img class=\"math display-math\" src=\"assets/equations/0d7c48cb1d9b9e1f.svg\" alt=\"\\frac{d}{dx}(cx^n)=cnx^{n-1},\\quad\\frac{d}{dx}c=0,\\quad (f+g)\\prime=f\\prime+g\\prime\" width=\"544.76\" height=\"50.50\" style=\"width:544.76px;height:50.50px;aspect-ratio:544.76/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> c is a constant, x is the changing variable and n is the power.</p>","<p><strong>Use:</strong> Use to differentiate the loss supplied in a gradient-descent question.</p>","<p><strong>Substitution example:</strong> For 0.7x³: derivative = 0.7 × 3 × x² = 2.1x².</p>","<h3>Formula 4: Chain rule</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/434e48fc84f871b4.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}\" width=\"154.58\" height=\"50.50\" style=\"width:154.58px;height:50.50px;aspect-ratio:154.58/50.50\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> z is the intermediate value linking w to L.</p>","<p><strong>Use:</strong> Multiply derivatives along a path; add contributions from distinct paths that meet.</p>","<p><strong>Substitution example:</strong> For z = 3w+1 and L = z² at w = 1: z = 4; derivative = (2×4)×3 = 24.</p>","<h3>Formula 5: Dot product and a neuron</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.90px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e4620ff07e410bce.svg\"><img class=\"math display-math\" src=\"assets/equations/8316d459b29940dc.svg\" alt=\"z=\\sum_i w_i x_i+b,\\qquad a=f(z)\" width=\"320.16\" height=\"52.35\" style=\"width:320.16px;height:52.35px;aspect-ratio:320.16/52.35\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> x is the input; w is its matching weight; b is one bias; z is the weighted sum; a is the activated output.</p>","<p><strong>Use:</strong> Multiply each matching pair, add the products, add bias once, then activate.</p>","<p><strong>Substitution example:</strong> x = [2,1], w = [0.5,−0.2], b = 0.1: z = 1−0.2+0.1 = 0.9.</p>","<h3>Formula 6: Matrix multiplication</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47f627ca6464a106.svg\" alt=\"(AB)_{ij}=\\sum_k A_{ik}B_{kj}\" width=\"214.94\" height=\"52.91\" style=\"width:214.94px;height:52.91px;aspect-ratio:214.94/52.91\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> i selects a row of A; j selects a column of B; k runs along the matching entries.</p>","<p><strong>Use:</strong> Use row-times-column sums. A with shape m×n and B with n×p produces m×p.</p>","<p><strong>Substitution example:</strong> Row [1,2] times column [3,4] gives 1×3+2×4 = 11.</p>","<h3>Formula 7: Layer forward pass</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:72.98px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2845b5af7a9f9056.svg\"><img class=\"math display-math\" src=\"assets/equations/4698521353358290.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)},\\qquad a^{(l)}=f(z^{(l)})\" width=\"419.03\" height=\"29.16\" style=\"width:419.03px;height:29.16px;aspect-ratio:419.03/29.16\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> l labels the layer; the previous layer activations become inputs to the next layer.</p>","<p><strong>Use:</strong> For receiving-neuron rows, compute each row dot product and add that receiving neuron’s bias. Finish the whole layer before moving on.</p>","<h3>Formula 8: Sigmoid and its derivative</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.94px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e03a4bc95b918203.svg\"><img class=\"math display-math\" src=\"assets/equations/11660565b2daac98.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\quad \\sigma\\prime(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"427.89\" height=\"51.56\" style=\"width:427.89px;height:51.56px;aspect-ratio:427.89/51.56\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> e is approximately 2.71828; sigma is the output.</p>","<p><strong>Use:</strong> Use for a sigmoid forward pass and for its local backpropagation derivative.</p>","<p><strong>Substitution example:</strong> At z = 0: output = 1/(1+1) = 0.5; derivative = 0.5×0.5 = 0.25.</p>","<h3>Formula 9: Tanh and its derivative</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.66px;--narrow-height:99.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e538ee72147c838.svg\"><img class=\"math display-math\" src=\"assets/equations/210ffd0354b9c9a9.svg\" alt=\"\\tanh(z)=\\frac{e^{2z}-1}{e^{2z}+1},\\quad \\tanh\\prime(z)=1-\\tanh^2(z)\" width=\"484.74\" height=\"56.48\" style=\"width:484.74px;height:56.48px;aspect-ratio:484.74/56.48\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> Tanh gives an output between −1 and 1.</p>","<p><strong>Use:</strong> Use for a stated tanh activation, commonly an RNN hidden state or recurrent candidate.</p>","<p><strong>Substitution example:</strong> At z = 0: numerator = 0, denominator = 2; output = 0; derivative = 1.</p>","<h3>Formula 10: ReLU and its derivative</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3bc788a99b96d468.svg\" alt=\"f(z)=\\max(0,z),\\quad f\\prime(z)=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z&lt;0\\end{cases}\" width=\"404.88\" height=\"58.62\" style=\"width:404.88px;height:58.62px;aspect-ratio:404.88/58.62\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> max means choose the larger value.</p>","<p><strong>Use:</strong> Use for ReLU. At zero the derivative is mathematically undefined; use the convention stated by the question or implementation.</p>","<p><strong>Substitution example:</strong> For −2, output = 0 and derivative = 0. For 3, output = 3 and derivative = 1.</p>","<h3>Formula 11: Leaky ReLU</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3faffb967fafdf3.svg\" alt=\"f(z)=\\begin{cases}z&amp;z\\geq0\\\\az&amp;z&lt;0\\end{cases}\" width=\"199.61\" height=\"58.62\" style=\"width:199.61px;height:58.62px;aspect-ratio:199.61/58.62\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> a is the small negative-side slope, commonly 0.01 unless specified.</p>","<p><strong>Use:</strong> For negative z multiply by a; the output remains negative.</p>","<p><strong>Substitution example:</strong> For z = −2 and a = 0.01: output = −0.02; derivative on this side is 0.01.</p>","<h3>Formula 12: Stable softmax</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.27px;--narrow-height:118.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c492ec558e0b1e23.svg\"><img class=\"math display-math\" src=\"assets/equations/4f5f1a315cf3ec0f.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_j z_j\" width=\"324.43\" height=\"63.31\" style=\"width:324.43px;height:63.31px;aspect-ratio:324.43/63.31\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> z values are class scores; p values are probabilities.</p>","<p><strong>Use:</strong> Subtract the same maximum from every score, exponentiate, add, divide each by that total.</p>","<p><strong>Substitution example:</strong> For [0,0]: exponentials = [1,1]; total = 2; probabilities = [0.5,0.5].</p>","<h3>Formula 13: Squared and absolute losses</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a288e1ba23bc9347.svg\" alt=\"\\mathrm{SSE}=\\sum_i(o_i-y_i)^2\" width=\"211.02\" height=\"52.35\" style=\"width:211.02px;height:52.35px;aspect-ratio:211.02/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1bdd5bbb9ca64f61.svg\" alt=\"L_{\\mathrm{half}}=\\frac{\\mathrm{SSE}}2\" width=\"135.29\" height=\"50.50\" style=\"width:135.29px;height:50.50px;aspect-ratio:135.29/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bdee7885d635e78c.svg\" alt=\"L_{\\mathrm{MSE}}=\\frac{\\mathrm{SSE}}n\" width=\"143.04\" height=\"50.77\" style=\"width:143.04px;height:50.77px;aspect-ratio:143.04/50.77\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42ae3654ddbdf33e.svg\" alt=\"L_{\\mathrm{MAE}}=\\frac1n\\sum_i|o_i-y_i|\" width=\"243.92\" height=\"61.92\" style=\"width:243.92px;height:61.92px;aspect-ratio:243.92/61.92\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> o is prediction; y is target; n is the number of averaged terms.</p>","<p><strong>Use:</strong> Read whether the question uses a half sum, a mean, or an unhalved sum. The scaling changes gradients.</p>","<p><strong>Substitution example:</strong> For errors [−1,2]: half sum = (1+4)/2 = 2.5; MSE = 2.5; MAE = (1+2)/2 = 1.5. The first two coincide only because n = 2.</p>","<h3>Formula 14: Binary cross entropy</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> y is 0 or 1; p is the predicted probability for class 1; ln is the natural logarithm.</p>","<p><strong>Use:</strong> Use for a sigmoid binary prediction. If y = 1 use −ln(p); if y = 0 use −ln(1−p).</p>","<p><strong>Substitution example:</strong> For y = 1 and p = 0.8: loss = 0.223144.</p>","<h3>Formula 15: Categorical cross entropy</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.61px;--narrow-height:117.24px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4be60e1a1e5d9ec8.svg\"><img class=\"math display-math\" src=\"assets/equations/d607248d18cc3f42.svg\" alt=\"H(p,q)=-\\sum_i p_i\\ln q_i,\\qquad\\log_2q=\\frac{\\ln q}{\\ln2}\" width=\"434.75\" height=\"62.61\" style=\"width:434.75px;height:62.61px;aspect-ratio:434.75/62.61\" loading=\"lazy\"></picture></div>","<p>For a soft target distribution, retain every nonzero target-weighted term. Natural logs give nats; base-2 logs give bits.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.42px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea93bf47748eb958.svg\"><img class=\"math display-math\" src=\"assets/equations/abecd65b7d7b5753.svg\" alt=\"L=-\\sum_i y_i\\ln p_i=-\\ln p_{true}\" width=\"306.83\" height=\"52.35\" style=\"width:306.83px;height:52.35px;aspect-ratio:306.83/52.35\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The final equality assumes one-hot labels, with exactly one y equal to 1.</p>","<p><strong>Use:</strong> Use for mutually exclusive multiclass labels. Select the probability of the true class.</p>","<p><strong>Substitution example:</strong> True class 2 and probabilities [0.1,0.8,0.1]: loss = −ln(0.8) = 0.223144.</p>","<h3>Formula 16: Output delta for half squared loss</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc1948e719d0e70b.svg\" alt=\"\\delta^{out}=(o-y)f\\prime(z)\" width=\"193.19\" height=\"27.01\" style=\"width:193.19px;height:27.01px;aspect-ratio:193.19/27.01\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> Delta is the loss derivative with respect to the preactivation z.</p>","<p><strong>Use:</strong> Use with half squared loss. For unhalved one-output MSE multiply by 2; for an MSE averaged over m outputs multiply the half-sum delta by 2/m.</p>","<p><strong>Substitution example:</strong> Sigmoid output 0.5 and target 1: delta = (−0.5)×0.25 = −0.125.</p>","<h3>Formula 17: Sigmoid plus BCE; softmax plus CCE</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/154ed49b87099426.svg\" alt=\"\\delta^{out}=p-y\" width=\"124.09\" height=\"25.92\" style=\"width:124.09px;height:25.92px;aspect-ratio:124.09/25.92\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> p and y can be vectors for softmax.</p>","<p><strong>Use:</strong> This is the combined derivative with respect to the logits. Do not multiply by the activation derivative again.</p>","<p><strong>Substitution example:</strong> Binary p = 0.8, y = 1: delta = −0.2.</p>","<h3>Formula 18: Hidden delta, weight gradient and bias gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.54px;--narrow-height:198.12px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f960780a672401ea.svg\"><img class=\"math display-math\" src=\"assets/equations/4cb07890e7ce7a95.svg\" alt=\"\\delta_j^h=f\\prime(z_j^h)\\sum_k w_{kj}^{out}\\delta_k^{out},\\quad\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i,\\quad\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"540.82\" height=\"63.69\" style=\"width:540.82px;height:63.69px;aspect-ratio:540.82/63.69\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> a_i is the activation sending a signal along the weight; delta_j belongs to the receiving neuron.</p>","<p><strong>Use:</strong> Use OLD downstream weights throughout one backward pass. Add all outgoing-path contributions.</p>","<p><strong>Substitution example:</strong> If receiving delta = −0.2 and sending activation = 3: weight gradient = −0.6; bias gradient = −0.2.</p>","<h3>Formula 19: Gradient descent</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d35498ffd4122e2.svg\" alt=\"\\theta_{new}=\\theta-\\eta g,\\qquad g=\\frac{\\partial J}{\\partial\\theta}\" width=\"286.02\" height=\"51.29\" style=\"width:286.02px;height:51.29px;aspect-ratio:286.02/51.29\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> theta is the parameter; eta is learning rate; g is the current gradient.</p>","<p><strong>Use:</strong> Recalculate g at the current parameter unless the question supplies gradients directly.</p>","<p><strong>Substitution example:</strong> theta = 1, eta = 0.1, g = −2 gives 1−0.1(−2) = 1.2.</p>","<h3>Formula 20: Batch and mini-batch gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.65px;--narrow-height:146.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/01bdd22eb4365aa9.svg\"><img class=\"math display-math\" src=\"assets/equations/60db920018eb907a.svg\" alt=\"g_{batch}=\\frac1B\\sum_{i=1}^{B}g_i,\\quad U_{epoch}=\\left\\lceil\\frac NB\\right\\rceil\" width=\"368.95\" height=\"72.79\" style=\"width:368.95px;height:72.79px;aspect-ratio:368.95/72.79\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> B is batch size; N is sample count; U is updates per epoch when the final incomplete batch is retained.</p>","<p><strong>Use:</strong> SGD uses B = 1. Full batch uses B = N. Average only when the stated objective is a mean.</p>","<p><strong>Substitution example:</strong> N = 105, B = 20: six updates, with five samples in the last batch.</p>","<h3>Formula 21: Momentum: signed velocity</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/d6d609593a44d53f.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\qquad\\theta_t=\\theta_{t-1}+v_t\" width=\"374.50\" height=\"22.51\" style=\"width:374.50px;height:22.51px;aspect-ratio:374.50/22.51\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> v stores signed movement; beta retains part of old movement.</p>","<p><strong>Use:</strong> Use this convention consistently. Other textbooks may define an unsigned gradient accumulator and subtract it instead.</p>","<p><strong>Substitution example:</strong> beta = 0.8, old v = −0.2, eta = 0.1, g = 1.8 gives v = −0.34.</p>","<h3>Formula 22: Nesterov: look-ahead gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.80px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29d3ddbf9730bc3a.svg\"><img class=\"math display-math\" src=\"assets/equations/ba02f58e5e55b487.svg\" alt=\"\\theta_{look}=\\theta+\\beta v,\\quad v_{new}=\\beta v-\\eta g(\\theta_{look}),\\quad\\theta_{new}=\\theta+v_{new}\" width=\"597.46\" height=\"24.43\" style=\"width:597.46px;height:24.43px;aspect-ratio:597.46/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The look-ahead point is temporary; the update is added to the original theta.</p>","<p><strong>Use:</strong> Evaluate the gradient at the look-ahead point, not at the old theta.</p>","<p><strong>Substitution example:</strong> theta = 1.8, beta = 0.8 and v = −0.2 gives look-ahead = 1.64.</p>","<h3>Formula 23: AdaGrad</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> G is accumulated squared gradient; epsilon prevents division by zero.</p>","<p><strong>Use:</strong> Accumulate every squared gradient, separately for each parameter. Use the epsilon placement stated by the problem.</p>","<p><strong>Substitution example:</strong> Old G = 4 and g = −3 gives G = 13.</p>","<h3>Formula 24: RMSProp</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.46px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/459c86785f7d6c4f.svg\"><img class=\"math display-math\" src=\"assets/equations/914e44e2b8e8e8f9.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"483.06\" height=\"52.24\" style=\"width:483.06px;height:52.24px;aspect-ratio:483.06/52.24\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> rho is the decay; s is a decaying mean of squared gradients.</p>","<p><strong>Use:</strong> Calculate the new square memory first, then update the parameter.</p>","<p><strong>Substitution example:</strong> rho = 0.9, old s = 4, g = −3 gives s = 3.6+0.9 = 4.5.</p>","<h3>Formula 25: Adam: both memories</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> m remembers signed gradients; v remembers squared gradients.</p>","<p><strong>Use:</strong> Start with the initial states specified. Common defaults are beta1 = 0.9 and beta2 = 0.999.</p>","<h3>Formula 26: Adam: correction and update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.71px;--narrow-height:202.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92678247acd594b0.svg\"><img class=\"math display-math\" src=\"assets/equations/c443fc0367c152b1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\widehat v_t=\\frac{v_t}{1-\\beta_2^t},\\quad\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"571.98\" height=\"66.85\" style=\"width:571.98px;height:66.85px;aspect-ratio:571.98/66.85\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> t counts updates starting at 1, not 0.</p>","<p><strong>Use:</strong> Correct both zero-initialized memories before the update; do not multiply by the gradient a second time.</p>","<p><strong>Substitution example:</strong> At t = 1, m = 0.2 and beta1 = 0.9: corrected m = 0.2/0.1 = 2.</p>","<h3>Formula 27: L1 penalty and update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:283.85px;--narrow-height:133.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f35555b2b4b6691c.svg\"><img class=\"math display-math\" src=\"assets/equations/fd296afd4f88edb6.svg\" alt=\"J=L+\\lambda\\sum_j|w_j|,\\quad w_{new}=w-\\eta\\left[g_{data}+\\lambda\\operatorname{sign}(w)\\right]\" width=\"561.92\" height=\"55.67\" style=\"width:561.92px;height:55.67px;aspect-ratio:561.92/55.67\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> lambda is regularization strength; sign(w) is +1 for positive w and −1 for negative w.</p>","<p><strong>Use:</strong> At zero, L1 has a subgradient rather than a unique derivative; use the specified convention. Include only parameters named in the penalty.</p>","<p><strong>Substitution example:</strong> w = −2, lambda = 0.1, data gradient = 0 gives penalty gradient = −0.1.</p>","<h3>Formula 28: L2 penalty and update with a half</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.90px;--narrow-height:144.13px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a21ef40f9211941d.svg\"><img class=\"math display-math\" src=\"assets/equations/e0797baa70350e25.svg\" alt=\"J=L+\\frac\\lambda2\\sum_jw_j^2,\\quad w_{new}=w-\\eta(g_{data}+\\lambda w)\" width=\"496.66\" height=\"65.94\" style=\"width:496.66px;height:65.94px;aspect-ratio:496.66/65.94\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The half cancels the 2 produced by differentiating a square.</p>","<p><strong>Use:</strong> If the objective uses lambda times the sum of squares WITHOUT a half, use 2 lambda w instead.</p>","<p><strong>Substitution example:</strong> w = 2, lambda = 0.1, data gradient = 0.3 gives total gradient = 0.5.</p>","<h3>Formula 29: Inverted dropout</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:168.83px;--narrow-height:130.45px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4fe7ae66a3ded01.svg\"><img class=\"math display-math\" src=\"assets/equations/455d85a70cf8258a.svg\" alt=\"q=1-p,\\quad a_{train}=\\frac{m\\odot a}{q},\\quad a_{test}=a\" width=\"419.93\" height=\"52.26\" style=\"width:419.93px;height:52.26px;aspect-ratio:419.93/52.26\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> p is drop probability; q is keep probability; mask m contains zeros and ones; the circled dot means elementwise multiplication.</p>","<p><strong>Use:</strong> During training, zero dropped entries and divide kept entries by q. Disable dropout at inference.</p>","<p><strong>Substitution example:</strong> a = 3, q = 0.5, mask = 1 gives 3/0.5 = 6.</p>","<h3>Formula 30: Convolution output dimensions</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.70px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f467d926f905df6d.svg\"><img class=\"math display-math\" src=\"assets/equations/b7c680fad37aede4.svg\" alt=\"N_{out}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"293.79\" height=\"58.62\" style=\"width:293.79px;height:58.62px;aspect-ratio:293.79/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> N is input height or width; P is padding on each side; K is kernel size; S is stride; floor rounds down.</p>","<p><strong>Use:</strong> Apply separately to height and width. Output channels equal the number of filters. This formula assumes dilation 1.</p>","<p><strong>Substitution example:</strong> N = 7, P = 1, K = 3, S = 2 gives floor(6/2)+1 = 4.</p>","<h3>Formula 31: Convolution value</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:380.25px;--narrow-height:130.78px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5afb61a6d5f3879.svg\"><img class=\"math display-math\" src=\"assets/equations/0fcf0c4134fa9fe3.svg\" alt=\"Y_{ij,o}=\\sum_c\\sum_u\\sum_v K_{uvco}X_{iS+u-P,jS+v-P,c}+b_o\" width=\"473.49\" height=\"51.51\" style=\"width:473.49px;height:51.51px;aspect-ratio:473.49/51.51\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> c runs over input channels; u,v run over kernel positions; o selects one filter.</p>","<p><strong>Use:</strong> This is the usual deep-learning cross-correlation operation. Use zeros outside the padded image. Multiply matching cells, add all channels, then add the filter bias once.</p>","<h3>Formula 32: Max, min and average pooling</h3>","<p>Min pooling keeps the smallest entry in each window. For a four-entry window:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/619bb1c028de4233.svg\" alt=\"y_{\\min}=\\min(x_1,x_2,x_3,x_4)\" width=\"266.30\" height=\"24.43\" style=\"width:266.30px;height:24.43px;aspect-ratio:266.30/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.47px;--narrow-height:124.64px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/edf81d51873a0dfc.svg\"><img class=\"math display-math\" src=\"assets/equations/5d156947c613cf69.svg\" alt=\"y_{max}=\\max_{(i,j)\\in W}x_{ij},\\quad y_{avg}=\\frac1{|W|}\\sum_{(i,j)\\in W}x_{ij}\" width=\"430.66\" height=\"67.59\" style=\"width:430.66px;height:67.59px;aspect-ratio:430.66/67.59\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> W is one pooling window; its size is the number of included cells.</p>","<p><strong>Use:</strong> Move the window by the stated stride; process channels separately. For padding, follow the stated average-pooling denominator convention.</p>","<p><strong>Substitution example:</strong> For [1,4,2,3]: maximum = 4; average = 10/4 = 2.5.</p>","<h3>Formula 33: Convolution parameter count</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.37px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8a253f24fdf99d8e.svg\"><img class=\"math display-math\" src=\"assets/equations/bd7e05cdd2c763eb.svg\" alt=\"P_{conv}=(K_hK_wC_{in}+1)C_{out}\" width=\"293.70\" height=\"24.43\" style=\"width:293.70px;height:24.43px;aspect-ratio:293.70/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> Kernel height and width times input channels gives weights per filter; +1 is one bias; Cout is filter count.</p>","<p><strong>Use:</strong> Use for a fully connected, ungrouped convolution with bias. Output height and width do not multiply the parameter count.</p>","<p><strong>Substitution example:</strong> 3×3 kernel, 3 input channels, 2 filters: (27+1)×2 = 56.</p>","<h3>Formula 34: Flatten and dense parameter count</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.08px;--narrow-height:64.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/56dad01ac3222ddd.svg\"><img class=\"math display-math\" src=\"assets/equations/33a05d43681713eb.svg\" alt=\"N_{flat}=HWC,\\qquad P_{dense}=(N_{in}+1)N_{out}\" width=\"448.95\" height=\"25.53\" style=\"width:448.95px;height:25.53px;aspect-ratio:448.95/25.53\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> H,W,C are activation dimensions; Nin and Nout are dense-layer input and output counts.</p>","<p><strong>Use:</strong> Flatten has no trainable parameters. Dense biases belong to receiving neurons.</p>","<p><strong>Substitution example:</strong> 2×2×2 flattens to 8; dense 3 then has (8+1)×3 = 27 parameters.</p>","<h3>Formula 35: Convolution multiply-accumulate count</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:276.71px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d20bfcc57cb122e.svg\"><img class=\"math display-math\" src=\"assets/equations/86ffc171b254aab9.svg\" alt=\"MAC=H_{out}W_{out}K_hK_wC_{in}C_{out}\" width=\"339.28\" height=\"21.35\" style=\"width:339.28px;height:21.35px;aspect-ratio:339.28/21.35\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> Each output value uses kernel area times input-channel count multiplications.</p>","<p><strong>Use:</strong> Used for Inception bottleneck comparisons. This counts one multiply-accumulate as one MAC and ignores bias additions. Some FLOP conventions count multiply and add separately.</p>","<h3>Formula 36: Concatenation and residual addition</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.23px;--narrow-height:92.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/588297b667afd636.svg\"><img class=\"math display-math\" src=\"assets/equations/8b8cdd9b96177407.svg\" alt=\"C_{concat}=\\sum_b C_b,\\qquad y_{res}=F(x)+x\" width=\"392.84\" height=\"52.91\" style=\"width:392.84px;height:52.91px;aspect-ratio:392.84/52.91\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> b labels branches with matching spatial dimensions.</p>","<p><strong>Use:</strong> Inception concatenates channels; residual addition requires matching full shapes. Use a projection when needed.</p>","<p><strong>Substitution example:</strong> Channels 16+32+8+8 give 64. Adding two 14×14×64 tensors keeps 14×14×64.</p>","<h3>Formula 37: Vanilla RNN</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2d32a1185192d80.svg\"><img class=\"math display-math\" src=\"assets/equations/77145310b191a975.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad o_t=W_{hy}h_t+b_y\" width=\"566.32\" height=\"25.53\" style=\"width:566.32px;height:25.53px;aspect-ratio:566.32/25.53\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> x_t is current input; h_previous is previous state; the same matrices are reused at every time step.</p>","<p><strong>Use:</strong> Calculate the two matrix-vector products, add bias, then tanh. Apply the stated output activation to o_t when required.</p>","<h3>Formula 46: Batch normalization and learned scale/shift</h3>","<p>Use during training to normalize intermediate activations before a learned scale and shift. m is the number of values; μ_B and σ²_B are the batch mean and population variance; γ and β are learned. Epsilon is inside the square root. Ordinary inference uses stored running statistics. The linked full lesson calculates every stage for [2,4].</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a91b1c9216cbd799.svg\" alt=\"\\mu_B=\\frac{1}{m}\\sum_{i=1}^{m}x_i\" width=\"160.06\" height=\"68.62\" style=\"width:160.06px;height:68.62px;aspect-ratio:160.06/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcfc8cc5fd3adc8.svg\" alt=\"\\sigma_B^2=\\frac{1}{m}\\sum_{i=1}^{m}(x_i-\\mu_B)^2\" width=\"244.63\" height=\"68.62\" style=\"width:244.63px;height:68.62px;aspect-ratio:244.63/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13126b94bcd9d415.svg\" alt=\"\\hat{x}_i=\\frac{x_i-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\" width=\"159.11\" height=\"75.23\" style=\"width:159.11px;height:75.23px;aspect-ratio:159.11/75.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7fd3e426f48f08b9.svg\" alt=\"y_i=\\gamma\\hat{x}_i+\\beta\" width=\"131.48\" height=\"25.07\" style=\"width:131.48px;height:25.07px;aspect-ratio:131.48/25.07\" loading=\"lazy\"></div>","<h3>Formula 47: Global average pooling</h3>","<p>Take a separate average for each full spatial feature map. H and W count rows and columns; c selects one of C channels; a is an activation value. Output has C values. The linked lesson computes two channel averages and the following dense-layer parameters.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/002749b4b374cf54.svg\" alt=\"g_c=\\frac{1}{HW}\\sum_{i=1}^{H}\\sum_{j=1}^{W}a_{i,j,c}\" width=\"239.71\" height=\"74.90\" style=\"width:239.71px;height:74.90px;aspect-ratio:239.71/74.90\" loading=\"lazy\"></div>","<h3>Formula 48: Top-k error percentage</h3>","<p>N is the total number of evaluated examples. C_k counts those whose true class is among the k highest-scoring predictions. Count failures, divide by total, then convert to percent. The worked lesson contrasts top-1 and top-5 using the same 100 images.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fb17785121a672d.svg\" alt=\"E_k=\\frac{N-C_k}{N}\\times100\\%\" width=\"239.34\" height=\"50.50\" style=\"width:239.34px;height:50.50px;aspect-ratio:239.34/50.50\" loading=\"lazy\"></div>"],"question":[],"answer":[],"kind":"read","id":"mt2-c19-s1","search":"All formulas: meanings, use and substitution These are the formulas used by this guide. Each entry names its symbols and the type of calculation it serves. Numerical practice in the teaching chapters shows the longer working. Follow any different convention explicitly stated in the examination.\n\n### Formula 1: Mean, variance and standard deviation\n\n**Symbols:** n is the count; mu is the mean; v is the population variance; s is the standard deviation.\n**Use:** Use when calculating a population mean/variance or standardization. Sample-variance estimates may use n−1 when explicitly requested.\n**Substitution example:** For [2,4]: mean = 3; deviations = −1,1; squares = 1,1; variance = 1; standard deviation = 1.\n\n### Formula 2: Standardization\n\n**Symbols:** Use the mean and standard deviation estimated from training data.\n**Use:** Use to express a value relative to the training distribution. The standard deviation must be nonzero.\n**Substitution example:** For x = 7, mean = 5, standard deviation = 2: (7−5)/2 = 1.\n\n### Formula 3: Power, constant and sum derivatives\n\n**Symbols:** c is a constant, x is the changing variable and n is the power.\n**Use:** Use to differentiate the loss supplied in a gradient-descent question.\n**Substitution example:** For 0.7x³: derivative = 0.7 × 3 × x² = 2.1x².\n\n### Formula 4: Chain rule\n\n**Symbols:** z is the intermediate value linking w to L.\n**Use:** Multiply derivatives along a path; add contributions from distinct paths that meet.\n**Substitution example:** For z = 3w+1 and L = z² at w = 1: z = 4; derivative = (2×4)×3 = 24.\n\n### Formula 5: Dot product and a neuron\n\n**Symbols:** x is the input; w is its matching weight; b is one bias; z is the weighted sum; a is the activated output.\n**Use:** Multiply each matching pair, add the products, add bias once, then activate.\n**Substitution example:** x = [2,1], w = [0.5,−0.2], b = 0.1: z = 1−0.2+0.1 = 0.9.\n\n### Formula 6: Matrix multiplication\n\n**Symbols:** i selects a row of A; j selects a column of B; k runs along the matching entries.\n**Use:** Use row-times-column sums. A with shape m×n and B with n×p produces m×p.\n**Substitution example:** Row [1,2] times column [3,4] gives 1×3+2×4 = 11.\n\n### Formula 7: Layer forward pass\n\n**Symbols:** l labels the layer; the previous layer activations become inputs to the next layer.\n**Use:** For receiving-neuron rows, compute each row dot product and add that receiving neuron’s bias. Finish the whole layer before moving on.\n\n### Formula 8: Sigmoid and its derivative\n\n**Symbols:** e is approximately 2.71828; sigma is the output.\n**Use:** Use for a sigmoid forward pass and for its local backpropagation derivative.\n**Substitution example:** At z = 0: output = 1/(1+1) = 0.5; derivative = 0.5×0.5 = 0.25.\n\n### Formula 9: Tanh and its derivative\n\n**Symbols:** Tanh gives an output between −1 and 1.\n**Use:** Use for a stated tanh activation, commonly an RNN hidden state or recurrent candidate.\n**Substitution example:** At z = 0: numerator = 0, denominator = 2; output = 0; derivative = 1.\n\n### Formula 10: ReLU and its derivative\n\n**Symbols:** max means choose the larger value.\n**Use:** Use for ReLU. At zero the derivative is mathematically undefined; use the convention stated by the question or implementation.\n**Substitution example:** For −2, output = 0 and derivative = 0. For 3, output = 3 and derivative = 1.\n\n### Formula 11: Leaky ReLU\n\n**Symbols:** a is the small negative-side slope, commonly 0.01 unless specified.\n**Use:** For negati"},{"title":"Calculator sequence without model guesswork","blocks":["<p>The reported model name is “Casio FX ES 990”; the exact model is not confirmed. Use your calculator’s actual function labels. On common ES/ES Plus models, exp(x) is usually the shifted ln key, while the EXP/ × 10ˣ key enters scientific notation and is NOT the same as exp(x). Check the exact key labeling on your device.</p>","<p>For sigmoid at 2.2, type 1÷(1+exp(−2.2)). Keep the negative sign inside the exponential. Expected 0.900249511. For a negative gradient update, type old−rate × (negative gradient); use parentheses around the negative value. For cross-entropy, use −ln(probability), not log 10. For tanh, use the hyperbolic function or its exponential fraction if that function is difficult to find.</p>","<p>Retain 6–9 digits in intermediate results or use stored values; round final answers to 4–6 decimal places unless the paper says otherwise. Work line by line on paper even if the calculator can evaluate the whole expression. Check exp(0) = 1, ln(1) = 0, sigmoid(0) = 0.5, tanh(0) = 0 before relying on the chosen key sequence.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c19-s2","search":"Calculator sequence without model guesswork The reported model name is “Casio FX ES 990”; the exact model is not confirmed. Use your calculator’s actual function labels. On common ES/ES Plus models, exp(x) is usually the shifted ln key, while the EXP/ × 10ˣ key enters scientific notation and is NOT the same as exp(x). Check the exact key labeling on your device.\nFor sigmoid at 2.2, type 1÷(1+exp(−2.2)). Keep the negative sign inside the exponential. Expected 0.900249511. For a negative gradient update, type old−rate × (negative gradient); use parentheses around the negative value. For cross-entropy, use −ln(probability), not log 10. For tanh, use the hyperbolic function or its exponential fraction if that function is difficult to find.\nRetain 6–9 digits in intermediate results or use stored values; round final answers to 4–6 decimal places unless the paper says otherwise. Work line by line on paper even if the calculator can evaluate the whole expression. Check exp(0) = 1, ln(1) = 0, sigmoid(0) = 0.5, tanh(0) = 0 before relying on the chosen key sequence."},{"title":"What to write if the exam page feels blank","blocks":["<p>Pause briefly, put both feet down and take one slow breath. Then write only the GIVEN values and what is ASKED. Classify the question using the method map. Write its general formula before inserting numbers. One correct first line is a smaller task than “solve the whole question”.</p>","<p>For CNN, draw the shape chain. For back prop, draw arrows and label the loss. For an optimizer, draw columns for step, gradient, state, new parameter. If you remain stuck after a short attempt, leave visible working space and move to a question you can start. Return after collecting those marks.</p>","<p>The goal is to reduce the next action to something concrete and familiar. Practice it during mocks so it is available under time pressure.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c19-s3","search":"What to write if the exam page feels blank Pause briefly, put both feet down and take one slow breath. Then write only the GIVEN values and what is ASKED. Classify the question using the method map. Write its general formula before inserting numbers. One correct first line is a smaller task than “solve the whole question”.\nFor CNN, draw the shape chain. For back prop, draw arrows and label the loss. For an optimizer, draw columns for step, gradient, state, new parameter. If you remain stuck after a short attempt, leave visible working space and move to a question you can start. Return after collecting those marks.\nThe goal is to reduce the next action to something concrete and familiar. Practice it during mocks so it is available under time pressure."},{"title":"Answer lengths and partial credit habits","blocks":["<p>For 2 marks, give a precise definition plus the key distinction/example. For 5 marks, give the definition, a labeled diagram or formula, working/principle and a relevant implication. For 10 marks, answer every subpart: architecture or setup, main equations, stepwise explanation, required numerical working, and limitations or justification where asked. Do not pad a numerical with unrelated theory.</p>","<p>Always label assumptions when inputs, loss, threshold or matrix orientation are missing. Box the requested final result, include shapes or units, and retain working. An unsupported final number makes it harder to award method credit. Never say an optimizer guarantees global convergence or an architecture always outperforms another unless a specific theorem and its conditions actually apply.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c19-s4","search":"Answer lengths and partial credit habits For 2 marks, give a precise definition plus the key distinction/example. For 5 marks, give the definition, a labeled diagram or formula, working/principle and a relevant implication. For 10 marks, answer every subpart: architecture or setup, main equations, stepwise explanation, required numerical working, and limitations or justification where asked. Do not pad a numerical with unrelated theory.\nAlways label assumptions when inputs, loss, threshold or matrix orientation are missing. Box the requested final result, include shapes or units, and retain working. An unsupported final number makes it harder to award method credit. Never say an optimizer guarantees global convergence or an architecture always outperforms another unless a specific theorem and its conditions actually apply."},{"title":"Methods to revise before the examination","blocks":["<h3>Last-day revision: read in this order</h3>","<p>This is a revision digest after studying the lessons. Full solutions remain beside each topic and under Solved Questions. If a step here is unclear, return to that worked example; the final day is for recovering the method, not memorizing unexplained final numbers.</p>","<h3>1. Learning and the neuron</h3>","<p>Machine learning estimates a model from data. Deep learning uses multiple trainable layers to learn successive representations. Inputs describe a sample; targets are the required answers; predictions are the model&#x27;s answers. Weights and biases are learned parameters. Learning rate, batch size and architecture are chosen hyperparameters.</p>","<p>Training changes parameters using training examples. Validation selects settings/stopping time. Testing evaluates the final choice on held-out data. Overfitting means strong training performance with weak generalization; underfitting means the model has not captured enough of the relationship.</p>","<p>For one neuron, multiply each input by its own weight, add all products, add the bias once and apply the activation. A layer repeats this for several receiving neurons. Each weight-matrix row belongs to one receiving neuron. Transpose swaps rows and columns; it does not change signs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.90px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1489ef71177ccc4a.svg\"><img class=\"math display-math\" src=\"assets/equations/2beefda557917f96.svg\" alt=\"z=\\sum_iw_ix_i+b,\\qquad a=f(z)\" width=\"320.16\" height=\"52.35\" style=\"width:320.16px;height:52.35px;aspect-ratio:320.16/52.35\" loading=\"lazy\"></picture></div>","<p><strong>Memory cue:</strong> multiply → sum → bias → activate. In a full network, finish one complete layer before the next.</p>","<h3>2. Activation and loss choices</h3>","<p>Sigmoid maps to (0,1) and is used for binary-class probabilities. Tanh maps to (−1,1), centred on zero. Both can saturate, producing small derivatives. ReLU retains positive values and returns zero on the negative side; its negative-side gradient is zero. Leaky ReLU retains a specified small negative-side slope. Softmax normalizes a complete list of logits into mutually exclusive class probabilities.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.94px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc390cc0a677c2cc.svg\"><img class=\"math display-math\" src=\"assets/equations/afe493539b707a8a.svg\" alt=\"\\sigma(z)=\\frac1{1+e^{-z}},\\qquad\\sigma\\prime(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"452.31\" height=\"51.56\" style=\"width:452.31px;height:51.56px;aspect-ratio:452.31/51.56\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc7dbcac123b9229.svg\" alt=\"\\tanh\\prime(z)=1-\\tanh^2(z)\" width=\"254.66\" height=\"27.91\" style=\"width:254.66px;height:27.91px;aspect-ratio:254.66/27.91\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.27px;--narrow-height:118.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd0c8ddf71d7e5e7.svg\"><img class=\"math display-math\" src=\"assets/equations/b901ae0600ed0d36.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_jz_j\" width=\"324.43\" height=\"63.31\" style=\"width:324.43px;height:63.31px;aspect-ratio:324.43/63.31\" loading=\"lazy\"></picture></div>","<p>For squared errors, SSE sums squares, half SSE divides that sum by 2, and MSE divides it by the number of scalar predictions. Their derivatives differ. For one-hot categorical cross-entropy, only the correct-class probability contributes. For binary cross-entropy, p means probability of class 1, not automatically the true class.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/38b125f3e664a9e5.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i(\\hat y_i-y_i)^2\" width=\"242.52\" height=\"61.92\" style=\"width:242.52px;height:61.92px;aspect-ratio:242.52/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52c8252c5d3ef107.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i(\\hat y_i-y_i)^2\" width=\"249.46\" height=\"61.92\" style=\"width:249.46px;height:61.92px;aspect-ratio:249.46/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/519958f461b019f9.svg\" alt=\"L_{\\mathrm{BCE}}=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"373.89\" height=\"24.43\" style=\"width:373.89px;height:24.43px;aspect-ratio:373.89/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/266c4f8c9aa94e08.svg\" alt=\"L_{\\mathrm{CCE}}=-\\ln p_{\\mathrm{correct}}\" width=\"201.74\" height=\"21.70\" style=\"width:201.74px;height:21.70px;aspect-ratio:201.74/21.70\" loading=\"lazy\"></div>","<p><strong>Memory cue:</strong> loss ka denominator dekho before differentiating. Sigmoid output is not its derivative.</p>","<h3>3. Backpropagation: the repeatable method</h3>","<p>Write the given loss and activation first. Compute all forward sums/activations with the original parameters. Differentiate loss with respect to each output, multiply by the output activation derivative, and call the result the output delta.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0f696548e5b34122.svg\" alt=\"\\delta_o=\\frac{\\partial L}{\\partial o}f_o\\prime(z_o)\" width=\"164.94\" height=\"51.29\" style=\"width:164.94px;height:51.29px;aspect-ratio:164.94/51.29\" loading=\"lazy\"></div>","<p>For a hidden neuron, add the outgoing weighted deltas first and then multiply by the hidden activation derivative. Each connection gradient is receiving delta × sending activation. The bias gradient is the receiving delta. Use old weights for all gradients before making the simultaneous update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:143.05px;--narrow-height:130.54px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c82c3235c49eee6f.svg\"><img class=\"math display-math\" src=\"assets/equations/5e2e128efb837fa9.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i,\\qquad\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"292.78\" height=\"57.94\" style=\"width:292.78px;height:57.94px;aspect-ratio:292.78/57.94\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a5c419cc72b98572.svg\" alt=\"\\theta_{\\mathrm{new}}=\\theta-\\eta\\frac{\\partial L}{\\partial\\theta}\" width=\"170.52\" height=\"51.29\" style=\"width:170.52px;height:51.29px;aspect-ratio:170.52/51.29\" loading=\"lazy\"></div>","<p><strong>Memory cue:</strong> path mein multiply; paths milne par add; update sab gradients ke baad. For sigmoid+BCE or softmax+CCE, the logit delta simplifies to prediction−target for the stated single-example sum convention.</p>","<h3>4. Optimizers: identify the stored state</h3>","<p>Full-batch GD uses the entire dataset for one update; SGD uses one sample; mini-batch uses a subset. An epoch is one pass through the data. With a final incomplete batch included, updates per epoch are ceiling(N/B).</p>","<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>State and calculation order</th><th>Detail that changes the answer</th></tr></thead><tbody><tr><td>GD</td><td>Current gradient → subtract ηg</td><td>Recompute at the new parameter unless gradients are explicitly supplied</td></tr><tr><td>Momentum</td><td>Retain βv → subtract ηg → add new velocity to parameter</td><td>Signed velocity and gradient-average conventions must not be mixed</td></tr><tr><td>Nesterov</td><td>Compute lookahead θ+βv → gradient there → new velocity → update actual θ</td><td>Do not add new velocity to the lookahead point</td></tr><tr><td>AdaGrad</td><td>Add g² to all-past sum G → divide gradient by √G+ε</td><td>G never decreases</td></tr><tr><td>RMSProp</td><td>Decay old squared state → add recent g² → normalize</td><td>Use the specified decay factor</td></tr><tr><td>Adam</td><td>Update signed mean m and squared mean v → correct both → normalize</td><td>Carry raw states forward; correction powers use iteration t</td></tr></tbody></table></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/d6d609593a44d53f.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\qquad\\theta_t=\\theta_{t-1}+v_t\" width=\"374.50\" height=\"22.51\" style=\"width:374.50px;height:22.51px;aspect-ratio:374.50/22.51\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/a5e0dae9a0fb7261.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad\\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"329.41\" height=\"53.28\" style=\"width:329.41px;height:53.28px;aspect-ratio:329.41/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>Here v means signed velocity in momentum and squared-gradient state in Adam; the method defines the symbol. <strong>Memory cue:</strong> AdaGrad sab squares; RMSProp recent squares; Adam direction + squares + correction.</p>","<h3>5. Regularization and generalization</h3>","<p>L1 adds λΣ|w| and a nonzero-weight derivative λsign(w), encouraging sparsity. L2 with the half convention adds (λ/2)Σw² and derivative λw. Without that half, the derivative is 2λw. Regularization gradients add to data gradients before updating the weight.</p>","<p>Inverted dropout uses keep probability q: retain a sampled activation with scale 1/q, or replace it by zero. Inference uses the full activation without that training-time rescaling. Drop probability p gives q = 1−p. Early stopping tracks validation performance and restores the best checkpoint under the stated patience rule.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:121.40px;--narrow-height:87.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e936750aa2b4998.svg\"><img class=\"math display-math\" src=\"assets/equations/3e23910228005a23.svg\" alt=\"a&#x27;_i=\\frac{m_i a_i}{q},\\qquad m_i\\in\\{0,1\\}\" width=\"293.39\" height=\"48.82\" style=\"width:293.39px;height:48.82px;aspect-ratio:293.39/48.82\" loading=\"lazy\"></picture></div>","<p><strong>Memory cue:</strong> dropout probability aur keep probability alag; L2 mein half hai ya nahi, pehle dekho.</p>","<h3>6. CNN calculation sequence</h3>","<p>Use the deep-learning cross-correlation convention unless the question explicitly requires kernel flipping. At each output position, multiply matching input-window and kernel entries, sum over spatial entries and all input channels, and add that filter&#x27;s bias once. A new filter creates a new output channel.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4064c7b5aff30cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bf6a8c697b8e11ab.svg\" alt=\"n_{\\mathrm{flat}}=HWC,\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"425.84\" height=\"24.43\" style=\"width:425.84px;height:24.43px;aspect-ratio:425.84/24.43\" loading=\"lazy\"></picture></div>","<p>Apply the shape formula separately to height and width. Pooling changes spatial dimensions but preserves channels; ordinary pooling and flattening have zero learned parameters. Maximum pooling chooses the largest window value; average pooling adds its values and divides by the number of entries. A filter&#x27;s spatial reuse changes computation, not its parameter count.</p>","<p>For a complete architecture, make one row per layer: input shape → operation → output shape → weights → biases → total. Flatten uses the size after the final convolution/pool. <strong>Memory cue:</strong> shape count aur parameter count ko kabhi mix mat karo.</p>","<h3>7. CNN theory and architectures</h3>","<p>CNNs use local connectivity and weight sharing, reducing parameters compared with unrestricted dense image mappings. Convolution learns features; activations introduce nonlinearity; pooling summarizes local responses; dense or global-pooling/output stages make the final task prediction.</p>","<p>AlexNet: stacked convolutions with ReLU, pooling and dense classification; dropout in dense layers and data augmentation help control overfitting. Inception: parallel spatial scales, 1 × 1 reductions and channel concatenation. ResNet: learns a residual F(x) and adds a shortcut x; use projection when shapes differ. Concatenation adds channels; residual addition requires equal shapes and retains their count.</p>","<p>Transfer learning reuses a pretrained feature extractor, replaces the task head, trains the head and optionally fine-tunes selected pretrained layers at a suitable smaller learning rate. Explain classification, detection and segmentation as different outputs, with an appropriate concrete application.</p>","<h3>8. Match the announced Unit 3–4 mix</h3>","<p>Revise all theory from optimization, regularization, CNN operations and CNN architectures. For 2 marks, answer exactly the requested definition, distinction or small calculation. For 3 marks, show the complete requested numerical method or explain the mechanism clearly. The paper may combine both.</p>","<p>Prepare Unit 3 numericals and especially the two Unit 4 numerical opportunities highlighted by the faculty. Their exact question numbers are not specified. RNN, LSTM and GRU remain in the TEE material; they are not part of this focused MT2 revision.</p>","<h3>The final answer-writing routine</h3>","<p>For every numerical: full question → Given → To find → governing formula and why → separate numbered steps → final answer. Carry extra calculator precision; round at the end. Label each layer, iteration and connection so the examiner can follow the calculation.</p>","<p>For a definition question, state the technical meaning and the requested distinction/example. For a longer mechanism question, include a labelled diagram or equations, explain their sequence, then give the relevant benefits, limitations or comparison. Marks printed beside a historical question are its actual marks; individual steps here are not assigned invented official marks.</p>","<p>For this 60-minute MT2, a workable allocation is 5 minutes to read and select, 15 minutes for Q1(a,b), 15 minutes for each selected 3-mark question and 10 minutes to review. Adjust if one calculation needs more working. If stuck, write the givens and governing formula first, complete the solvable parts, then return to the unfinished calculation.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c19-s5","search":"Methods to revise before the examination \n### Last-day revision: read in this order\nThis is a revision digest after studying the lessons. Full solutions remain beside each topic and under Solved Questions. If a step here is unclear, return to that worked example; the final day is for recovering the method, not memorizing unexplained final numbers.\n\n### 1. Learning and the neuron\nMachine learning estimates a model from data. Deep learning uses multiple trainable layers to learn successive representations. Inputs describe a sample; targets are the required answers; predictions are the model's answers. Weights and biases are learned parameters. Learning rate, batch size and architecture are chosen hyperparameters.\n\nTraining changes parameters using training examples. Validation selects settings/stopping time. Testing evaluates the final choice on held-out data. Overfitting means strong training performance with weak generalization; underfitting means the model has not captured enough of the relationship.\n\nFor one neuron, multiply each input by its own weight, add all products, add the bias once and apply the activation. A layer repeats this for several receiving neurons. Each weight-matrix row belongs to one receiving neuron. Transpose swaps rows and columns; it does not change signs.\n\n**Memory cue:** multiply → sum → bias → activate. In a full network, finish one complete layer before the next.\n\n### 2. Activation and loss choices\nSigmoid maps to (0,1) and is used for binary-class probabilities. Tanh maps to (−1,1), centred on zero. Both can saturate, producing small derivatives. ReLU retains positive values and returns zero on the negative side; its negative-side gradient is zero. Leaky ReLU retains a specified small negative-side slope. Softmax normalizes a complete list of logits into mutually exclusive class probabilities.\n\n\n\nFor squared errors, SSE sums squares, half SSE divides that sum by 2, and MSE divides it by the number of scalar predictions. Their derivatives differ. For one-hot categorical cross-entropy, only the correct-class probability contributes. For binary cross-entropy, p means probability of class 1, not automatically the true class.\n\n\n\n\n**Memory cue:** loss ka denominator dekho before differentiating. Sigmoid output is not its derivative.\n\n### 3. Backpropagation: the repeatable method\nWrite the given loss and activation first. Compute all forward sums/activations with the original parameters. Differentiate loss with respect to each output, multiply by the output activation derivative, and call the result the output delta.\n\nFor a hidden neuron, add the outgoing weighted deltas first and then multiply by the hidden activation derivative. Each connection gradient is receiving delta × sending activation. The bias gradient is the receiving delta. Use old weights for all gradients before making the simultaneous update.\n\n\n\n**Memory cue:** path mein multiply; paths milne par add; update sab gradients ke baad. For sigmoid+BCE or softmax+CCE, the logit delta simplifies to prediction−target for the stated single-example sum convention.\n\n### 4. Optimizers: identify the stored state\nFull-batch GD uses the entire dataset for one update; SGD uses one sample; mini-batch uses a subset. An epoch is one pass through the data. With a final incomplete batch included, updates per epoch are ceiling(N/B).\n\n| Method | State and calculation order | Detail that changes the answer |\n| GD | Current gradient → subtract ηg | Recompute at the new pa"}]},{"n":20,"title":"Course vocabulary in plain words","sections":[{"title":"Learning and the numbers we adjust","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Term</th><th>Meaning</th><th>Tiny example</th></tr></thead><tbody><tr><td>Input / feature</td><td>A number given to the model</td><td>Image pixel intensity</td></tr><tr><td>Sample</td><td>One example processed by the model</td><td>One labeled image</td></tr><tr><td>Dataset</td><td>A collection of examples</td><td>1,000 training images</td></tr><tr><td>Target / label</td><td>Correct answer supplied for training</td><td>Class 2 is correct</td></tr><tr><td>Prediction</td><td>Model&#x27;s current answer</td><td>Class probabilities</td></tr><tr><td>Weight</td><td>Learned multiplier on a connection</td><td>0.4 multiplying an input</td></tr><tr><td>Bias</td><td>Learned value added to a weighted sum</td><td>z = wx + b</td></tr><tr><td>Parameter</td><td>A value learned during training</td><td>Weight or bias</td></tr><tr><td>Hyperparameter</td><td>A setting chosen for training</td><td>Learning rate or batch size</td></tr><tr><td>Activation</td><td>Transformation of a neuron&#x27;s raw score</td><td>ReLU or sigmoid</td></tr><tr><td>Loss</td><td>Numerical measure of prediction error</td><td>Mean squared error</td></tr><tr><td>Gradient</td><td>Local rate of loss change for parameters</td><td>Positive g means locally uphill</td></tr><tr><td>Optimizer</td><td>Rule using gradients to update parameters</td><td>Momentum or Adam</td></tr><tr><td>Epoch</td><td>One pass through the training dataset</td><td>All 100 samples processed</td></tr><tr><td>Iteration</td><td>One parameter update in these exercises</td><td>One mini-batch update</td></tr><tr><td>Inference</td><td>Applying the trained model</td><td>Predicting a new image&#x27;s class</td></tr></tbody></table></div>"],"question":[],"answer":[],"kind":"read","id":"mt2-c20-s0","search":"Learning and the numbers we adjust | Term | Meaning | Tiny example |\n| Input / feature | A number given to the model | Image pixel intensity |\n| Sample | One example processed by the model | One labeled image |\n| Dataset | A collection of examples | 1,000 training images |\n| Target / label | Correct answer supplied for training | Class 2 is correct |\n| Prediction | Model's current answer | Class probabilities |\n| Weight | Learned multiplier on a connection | 0.4 multiplying an input |\n| Bias | Learned value added to a weighted sum | z = wx + b |\n| Parameter | A value learned during training | Weight or bias |\n| Hyperparameter | A setting chosen for training | Learning rate or batch size |\n| Activation | Transformation of a neuron's raw score | ReLU or sigmoid |\n| Loss | Numerical measure of prediction error | Mean squared error |\n| Gradient | Local rate of loss change for parameters | Positive g means locally uphill |\n| Optimizer | Rule using gradients to update parameters | Momentum or Adam |\n| Epoch | One pass through the training dataset | All 100 samples processed |\n| Iteration | One parameter update in these exercises | One mini-batch update |\n| Inference | Applying the trained model | Predicting a new image's class |"},{"title":"Images and sequences","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Term</th><th>Meaning</th><th>What to keep separate</th></tr></thead><tbody><tr><td>Tensor</td><td>Array of numbers with one or more axes</td><td>Its shape and its values</td></tr><tr><td>Channel</td><td>One feature map within an image-like tensor</td><td>Channels versus spatial size</td></tr><tr><td>Kernel / filter</td><td>Learned weights sliding over a map</td><td>Kernel size versus filter count</td></tr><tr><td>Stride</td><td>Step between adjacent window positions</td><td>Stride versus kernel width</td></tr><tr><td>Padding</td><td>Extra border cells around an input</td><td>Per-side P versus total 2P</td></tr><tr><td>Feature map</td><td>Responses from a filter across positions</td><td>Activations versus parameters</td></tr><tr><td>Pooling</td><td>Window-based reduction of feature maps</td><td>Maximum versus average</td></tr><tr><td>Flatten</td><td>Rearrange H × W × C entries as a vector</td><td>Rearrangement has no parameters</td></tr><tr><td>Logit</td><td>Raw score before an output activation</td><td>Score versus probability</td></tr><tr><td>Hidden state</td><td>Recurrent features carried through time</td><td>Previous state versus current input</td></tr><tr><td>Shared weights</td><td>One learned rule reused at many positions/times</td><td>Reuse versus extra parameters</td></tr></tbody></table></div>"],"question":[],"answer":[],"kind":"read","id":"mt2-c20-s1","search":"Images and sequences | Term | Meaning | What to keep separate |\n| Tensor | Array of numbers with one or more axes | Its shape and its values |\n| Channel | One feature map within an image-like tensor | Channels versus spatial size |\n| Kernel / filter | Learned weights sliding over a map | Kernel size versus filter count |\n| Stride | Step between adjacent window positions | Stride versus kernel width |\n| Padding | Extra border cells around an input | Per-side P versus total 2P |\n| Feature map | Responses from a filter across positions | Activations versus parameters |\n| Pooling | Window-based reduction of feature maps | Maximum versus average |\n| Flatten | Rearrange H × W × C entries as a vector | Rearrangement has no parameters |\n| Logit | Raw score before an output activation | Score versus probability |\n| Hidden state | Recurrent features carried through time | Previous state versus current input |\n| Shared weights | One learned rule reused at many positions/times | Reuse versus extra parameters |"},{"title":"Reading a question precisely","blocks":["<p>“Calculate” asks for arithmetic and a result. Write the formula and substitutions before the final number.</p>","<p>“Explain” asks how and why a method works. Give its definition, describe the steps, and connect each step to its purpose.</p>","<p>“Compare” asks for matched differences. Discuss the same attributes for both methods, such as stored state, update rule, benefit and limitation.</p>","<p>“Draw” asks for a labeled structure. Label inputs, layers or time steps, arrows, activations and the output. A diagram and explanation should describe the same computation.</p>","<p>“Design” asks for a justified arrangement. State the task, input and output, chosen layers, activation/loss pair and training procedure. State any assumption needed because the question leaves a value unspecified.</p>"],"question":[],"answer":[],"kind":"read","id":"mt2-c20-s2","search":"Reading a question precisely “Calculate” asks for arithmetic and a result. Write the formula and substitutions before the final number.\n“Explain” asks how and why a method works. Give its definition, describe the steps, and connect each step to its purpose.\n“Compare” asks for matched differences. Discuss the same attributes for both methods, such as stored state, update rule, benefit and limitation.\n“Draw” asks for a labeled structure. Label inputs, layers or time steps, arrows, activations and the output. A diagram and explanation should describe the same computation.\n“Design” asks for a justified arrangement. State the task, input and output, chosen layers, activation/loss pair and training procedure. State any assumption needed because the question leaves a value unspecified."}]}],"tee":[{"n":1,"title":"TEE preparation and examination plan","sections":[{"title":"Coverage and examination structure","blocks":["<p>The TEE route covers all five units of course 702AI0C036: introduction and neural-network foundations, optimization and regularization, CNNs and their architectures, and recurrent models including BPTT, LSTM and GRU. Machine-learning prerequisites are explained within the course. Basic algebra and calculus are assumed, with a concise revision chapter available when required.</p>","<p>The supplied course policy specifies a three-hour, 100-mark TEE: Q1 is compulsory, followed by any four of Q2–Q7; each main question carries 20 marks. TEE marks are scaled to 50. Read the instructions printed on the actual examination paper.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c1-s0","search":"Coverage and examination structure The TEE route covers all five units of course 702AI0C036: introduction and neural-network foundations, optimization and regularization, CNNs and their architectures, and recurrent models including BPTT, LSTM and GRU. Machine-learning prerequisites are explained within the course. Basic algebra and calculus are assumed, with a concise revision chapter available when required.\n\nThe supplied course policy specifies a three-hour, 100-mark TEE: Q1 is compulsory, followed by any four of Q2–Q7; each main question carries 20 marks. TEE marks are scaled to 50. Read the instructions printed on the actual examination paper.\n"},{"title":"Recommended reading order","blocks":["<p>1. <strong>Neural-network foundations:</strong> learning tasks, data partitions, neuron models, perceptrons, activations, losses and backpropagation.</p>","<p>2. <strong>Optimization:</strong> gradient descent variants, momentum, Nesterov, AdaGrad, RMSProp and Adam, including their states and update conventions.</p>","<p>3. <strong>Regularization and generalization:</strong> overfitting, L1/L2 objectives, dropout, early stopping and remedies selected from training behavior.</p>","<p>4. <strong>CNNs:</strong> convolution and pooling operations, output dimensions, trainable parameter counts and complete network calculations.</p>","<p>5. <strong>CNN architectures:</strong> AlexNet, Inception, ResNet, bottlenecks and transfer learning.</p>","<p>6. <strong>Recurrent models:</strong> state equations, BPTT, vanishing/exploding gradients, LSTM and GRU.</p>","<p>7. <strong>Examination preparation:</strong> use the formula reference, complete solved questions and full TEE paper rehearsal.</p>","<p>Use the Mathematics revision chapter for notation, matrix operations, differentiation, probability and logarithms. It is a reference rather than the compulsory starting point.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c1-s1","search":"Recommended reading order 1. **Neural-network foundations:** learning tasks, data partitions, neuron models, perceptrons, activations, losses and backpropagation.\n2. **Optimization:** gradient descent variants, momentum, Nesterov, AdaGrad, RMSProp and Adam, including their states and update conventions.\n3. **Regularization and generalization:** overfitting, L1/L2 objectives, dropout, early stopping and remedies selected from training behavior.\n4. **CNNs:** convolution and pooling operations, output dimensions, trainable parameter counts and complete network calculations.\n5. **CNN architectures:** AlexNet, Inception, ResNet, bottlenecks and transfer learning.\n6. **Recurrent models:** state equations, BPTT, vanishing/exploding gradients, LSTM and GRU.\n7. **Examination preparation:** use the formula reference, complete solved questions and full TEE paper rehearsal.\n\nUse the Mathematics revision chapter for notation, matrix operations, differentiation, probability and logarithms. It is a reference rather than the compulsory starting point.\n"},{"title":"Theory answers and numerical solutions","blocks":["<p>For theory, write a precise definition, equations or a labelled architecture, the working mechanism, and the relevant properties or limitations. For comparison questions, compare the same aspects on both sides. A table should support the explanation rather than replace it with disconnected keywords.</p>","<p>For numericals, state the given values and conventions, show the governing formula, calculate each intermediate state, and identify the final result. Keep unrounded intermediate values when using the calculator. In backpropagation, calculate all gradients using the same forward-pass parameters before updating them.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c1-s2","search":"Theory answers and numerical solutions For theory, write a precise definition, equations or a labelled architecture, the working mechanism, and the relevant properties or limitations. For comparison questions, compare the same aspects on both sides. A table should support the explanation rather than replace it with disconnected keywords.\n\nFor numericals, state the given values and conventions, show the governing formula, calculate each intermediate state, and identify the final result. Keep unrounded intermediate values when using the calculator. In backpropagation, calculate all gradients using the same forward-pass parameters before updating them.\n"},{"title":"Practice resources","blocks":["<p>The reading flow places worked numericals and relevant examination questions beside their concepts. Solved Questions also provides separate lists of practice numericals, past examination questions and theory answers. Every question has its answer directly below it.</p>","<p>The supplied historical papers are filtered against the current syllabus. The TEE mock uses the December 2025 paper as a three-hour rehearsal with full solutions. This is historical practice; it is not a prediction of the forthcoming paper.</p>","<h3>How the supplied papers ask questions</h3>","<p>The course policy allocates <strong>10 marks to Class Test 2</strong>. The shared confirmed pattern is Q1(a,b), 2 marks each compulsory, followed by any two of Q2–Q4, 3 marks each, in one hour. The faculty message relayed on 12 October identifies <strong>Unit 3 and Unit 4 theory and numericals</strong>, highlighting two Unit 4 numerical questions. It describes alternative theory/numerical combinations without fixing their exact question numbers. Use the MT2 route for that focused preparation; the TEE route covers all five units.</p>","<p>TEE has <strong>100 marks in three hours</strong>. Q1 is compulsory, then answer any four of Q2–Q7. Each main question carries 20 marks. The supplied 2023–2026 end papers use four 5-mark parts in Q1 and two 10-mark parts in later main questions. The older 2022/January 2023 papers use five 4-mark parts in Q1. This is an observed historical change, not a prediction of the next paper&#x27;s subparts.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Asked question family</th><th>Examples in the supplied papers</th><th>What the answer must contain</th></tr></thead><tbody><tr><td>Neuron / activation calculation</td><td>MT1A Q2–Q3 (3 marks each); R26 Q6b (10 marks, mixed calculation and explanation)</td><td>Matching products, bias once, activation, requested derivative/probabilities</td></tr><tr><td>Forward pass and backpropagation</td><td>MT1A Q4 (3); F25 Q2a, R26 Q2a, R24 Q2a (10 each)</td><td>Network data and loss convention, forward values, chain-rule factors, requested gradients and updates</td></tr><tr><td>Perceptron training</td><td>F25 Q3a, R26 Q3a, R24 Q4a (10 each)</td><td>Threshold and target convention, every sample in order, update only as required, final weights</td></tr><tr><td>Optimizer and update-count questions</td><td>F25 Q4a and R26 Q4a (10 each)</td><td>Differentiate when needed, initialize state, show each iteration; recompute or use supplied gradients correctly</td></tr><tr><td>Regularization / overfitting</td><td>R26 Q1c (5); R24 Q3b and R23 Q7b (10 each)</td><td>Definition, mechanism, equations where relevant, training/inference distinction, suitable remedy</td></tr><tr><td>CNN map / shape / parameter calculations</td><td>F25 Q6a, R26 Q6a, R24 Q4b (10 each)</td><td>Every map entry if requested, each layer shape, filter weights and biases, pooling zero parameters, dense count</td></tr><tr><td>Architectures and comparison</td><td>F25 Q2b, F23 Q5a, R23 Q4a (10 each)</td><td>Labelled structure, working mechanism, reason for design, advantages and limitations</td></tr><tr><td>Recurrent state / LSTM / GRU</td><td>R26 Q5a, F25 Q5a, R24 Q6a (10 each)</td><td>State/gate definitions, correct activation, carried state, requested calculations and comparison</td></tr></tbody></table></div>","<p>These are examples of question types, not an official marking rubric or an assurance that topics repeat. The TEE route retains 108 mapped question parts across the two MT1 sets and six end-semester papers. Two historical parts are restricted to their current-syllabus content. A supplied model answer does not override an explicit loss, dimension or convention in the question.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c1-s3","search":"Practice resources The reading flow places worked numericals and relevant examination questions beside their concepts. Solved Questions also provides separate lists of practice numericals, past examination questions and theory answers. Every question has its answer directly below it.\n\nThe supplied historical papers are filtered against the current syllabus. The TEE mock uses the December 2025 paper as a three-hour rehearsal with full solutions. This is historical practice; it is not a prediction of the forthcoming paper.\n\n\n### How the supplied papers ask questions\nThe course policy allocates **10 marks to Class Test 2**. The shared confirmed pattern is Q1(a,b), 2 marks each compulsory, followed by any two of Q2–Q4, 3 marks each, in one hour. The faculty message relayed on 12 October identifies **Unit 3 and Unit 4 theory and numericals**, highlighting two Unit 4 numerical questions. It describes alternative theory/numerical combinations without fixing their exact question numbers. Use the MT2 route for that focused preparation; the TEE route covers all five units.\n\nTEE has **100 marks in three hours**. Q1 is compulsory, then answer any four of Q2–Q7. Each main question carries 20 marks. The supplied 2023–2026 end papers use four 5-mark parts in Q1 and two 10-mark parts in later main questions. The older 2022/January 2023 papers use five 4-mark parts in Q1. This is an observed historical change, not a prediction of the next paper's subparts.\n\n| Asked question family | Examples in the supplied papers | What the answer must contain |\n| Neuron / activation calculation | MT1A Q2–Q3 (3 marks each); R26 Q6b (10 marks, mixed calculation and explanation) | Matching products, bias once, activation, requested derivative/probabilities |\n| Forward pass and backpropagation | MT1A Q4 (3); F25 Q2a, R26 Q2a, R24 Q2a (10 each) | Network data and loss convention, forward values, chain-rule factors, requested gradients and updates |\n| Perceptron training | F25 Q3a, R26 Q3a, R24 Q4a (10 each) | Threshold and target convention, every sample in order, update only as required, final weights |\n| Optimizer and update-count questions | F25 Q4a and R26 Q4a (10 each) | Differentiate when needed, initialize state, show each iteration; recompute or use supplied gradients correctly |\n| Regularization / overfitting | R26 Q1c (5); R24 Q3b and R23 Q7b (10 each) | Definition, mechanism, equations where relevant, training/inference distinction, suitable remedy |\n| CNN map / shape / parameter calculations | F25 Q6a, R26 Q6a, R24 Q4b (10 each) | Every map entry if requested, each layer shape, filter weights and biases, pooling zero parameters, dense count |\n| Architectures and comparison | F25 Q2b, F23 Q5a, R23 Q4a (10 each) | Labelled structure, working mechanism, reason for design, advantages and limitations |\n| Recurrent state / LSTM / GRU | R26 Q5a, F25 Q5a, R24 Q6a (10 each) | State/gate definitions, correct activation, carried state, requested calculations and comparison |\n\nThese are examples of question types, not an official marking rubric or an assurance that topics repeat. The TEE route retains 108 mapped question parts across the two MT1 sets and six end-semester papers. Two historical parts are restricted to their current-syllabus content. A supplied model answer does not override an explicit loss, dimension or convention in the question.\n\n"},{"id":"tee-pyq-analysis","title":"All recovered TEE papers: unit, topic and marks map","kind":"read","blocks":["<h3>How to use this question map</h3><p>Start with the newest final and re-exam, then use older papers to practise variations. The table links each original lettered part to its complete worked answer. <strong>Repeated questions are history, not a prediction.</strong> A syllabus topic stays required even when no recovered paper asks it.</p><p><strong>Marks:</strong> 100 marks are attempted: compulsory Q1 (20), then any four other 20-mark questions. Most recovered papers offer140 marks; NLP December2023 offers120 because the complete original ends at Q6. A mixed question retains one mark allocation; its units are not counted as separate questions. Blank individual allocations remain unknown.</p><h3>2026-02-10 · re-exam · R26</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · ML versus DL task choices</td><td>case</td><td><a href=\"/#tee/question/tee-c12-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 2 · Activation functions</td><td>theory</td><td><a href=\"/#tee/question/tee-c12-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 3 · L1/L2 and specified-rate dropout</td><td>mixed</td><td><a href=\"/#tee/question/tee-c12-s2\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 5 · RNN sentiment classification</td><td>case</td><td><a href=\"/#tee/question/tee-c12-s3\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · Two-output sigmoid backpropagation</td><td>numerical</td><td><a href=\"/#tee/question/tee-c12-s4\">Read question + answer</a> · Loss omitted in original; answer states assumed half summed squared loss.</td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 4 · AlexNet, Inception and architecture recommendation</td><td>case</td><td><a href=\"/#tee/question/tee-c12-s5\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2 · Bipolar perceptron epoch</td><td>numerical</td><td><a href=\"/#tee/question/tee-c12-s6\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 4 · Five effects of CNN filter count</td><td>theory</td><td><a href=\"/#tee/question/tee-c12-s7\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 3 · Batch/SGD, learning rate and cubic-objective updates</td><td>mixed</td><td><a href=\"/#tee/question/tee-c12-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 5 · LSTM and GRU; legacy bidirectional-RNN subpart</td><td>theory</td><td><a href=\"/#tee/question/tee-c12-s9\">Read question + answer</a> · Current-syllabus extract; original part also contains Bidirectional-RNN advantages (iv)</td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 5 · RNN hidden-state matrix calculation</td><td>numerical</td><td><a href=\"/#tee/question/tee-c12-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 3 · RMSProp mechanism and SGD comparison</td><td>theory</td><td><a href=\"/#tee/question/tee-c12-s11\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 4 · CNN sizes and counts with binary-output ambiguity</td><td>numerical</td><td><a href=\"/#tee/question/tee-c12-s12\">Read question + answer</a> · Binary head unspecified: one sigmoid or two softmax units give different parameter totals; both are stated.</td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 2 · Sigmoid value/derivative and softmax</td><td>numerical</td><td><a href=\"/#tee/question/tee-c12-s13\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 2 · Feedforward roles and sigmoid forward pass</td><td>mixed</td><td><a href=\"/#tee/question/tee-c12-s14\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 4 · Transfer learning and its application</td><td>case</td><td><a href=\"/#tee/question/tee-c12-s15\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 1 parts, 5 known marks; Unit 2: 5 parts, 45 known marks; Unit 3: 3 parts, 25 known marks; Unit 5: 3 parts, 25 known marks; Unit 4: 4 parts, 40 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><p><strong>Current-syllabus qualification:</strong> Q4b: mixed current and legacy tasks; the retained-only marks cannot be determined from the printed allocation. The original whole-part marks remain visible so the paper is faithfully represented.</p><h3>2025-12-03 · final · F25</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · ML versus DL and three task choices</td><td>case</td><td><a href=\"/#tee/question/tee-c11-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 2 · Loss choice and categorical cross-entropy</td><td>mixed</td><td><a href=\"/#tee/question/tee-c11-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 3 · L1 sparsity, overfitting and dropout</td><td>case</td><td><a href=\"/#tee/question/tee-c11-s2\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 5 · RNN context and variable-length translation</td><td>case</td><td><a href=\"/#tee/question/tee-c11-s3\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · Sigmoid network: forward pass and backpropagation</td><td>numerical</td><td><a href=\"/#tee/question/tee-c11-s4\">Read question + answer</a> · Original omits inputs and loss. Answer explicitly assumes x=[1,1] and half squared loss; the result is conditional on those assumptions.</td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 4 · ResNet; Inception versus AlexNet</td><td>theory</td><td><a href=\"/#tee/question/tee-c11-s5\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2 · Biological neuron and perceptron epoch</td><td>mixed</td><td><a href=\"/#tee/question/tee-c11-s6\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 4 · Transfer learning for face attendance</td><td>case</td><td><a href=\"/#tee/question/tee-c11-s7\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 3 · Batch counts, momentum iterations and hyperparameters</td><td>mixed</td><td><a href=\"/#tee/question/tee-c11-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 5 · Vanishing gradients and LSTM forget contribution</td><td>mixed</td><td><a href=\"/#tee/question/tee-c11-s9\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 5 · LSTM gates, cell state and hidden state</td><td>mixed</td><td><a href=\"/#tee/question/tee-c11-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 3 · AdaGrad mechanism and comparison with SGD</td><td>theory</td><td><a href=\"/#tee/question/tee-c11-s11\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 4 · CNN sizes and parameters; stride-2 convolution</td><td>numerical</td><td><a href=\"/#tee/question/tee-c11-s12\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 2 · Activation functions and their roles</td><td>theory</td><td><a href=\"/#tee/question/tee-c11-s13\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 2 · Feedforward network roles and ReLU forward pass</td><td>mixed</td><td><a href=\"/#tee/question/tee-c11-s14\">Read question + answer</a> · Receiving-neuron rows give 0.55; the supplied key uses a transposed convention (0.61). Both interpretations are explained.</td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 4 · CNN feature hierarchy and applications</td><td>theory</td><td><a href=\"/#tee/question/tee-c11-s15\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 1 parts, 5 known marks; Unit 2: 5 parts, 45 known marks; Unit 3: 3 parts, 25 known marks; Unit 5: 3 parts, 25 known marks; Unit 4: 4 parts, 40 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2025-02-22 · re-exam · R25</h3><p>140 marks offered; 100 attempted. Combined-year archive filename contains one six-page exam, not two independent papers.</p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1, 4, 5 · ML versus DL and architecture choice</td><td>case</td><td><a href=\"/#tee/question/tee-c21-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 3 · Training and validation errors</td><td>case</td><td><a href=\"/#tee/question/tee-c21-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 4 · CNN hierarchy and stride-two convolution</td><td>mixed</td><td><a href=\"/#tee/question/tee-c21-s2\">Read question + answer</a> · Padding is not specified; valid/no-padding is declared. CNN cross-correlation convention is used without kernel reversal.</td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 5 · BPTT and recurrent strengths</td><td>theory</td><td><a href=\"/#tee/question/tee-c21-s3\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · Activation, ReLU and numeric outputs</td><td>mixed</td><td><a href=\"/#tee/question/tee-c21-s4\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 5 · Vanishing/exploding gradients and GRU</td><td>theory</td><td><a href=\"/#tee/question/tee-c21-s5\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2, 3 · 4–3–2 forward pass and dropout</td><td>numerical</td><td><a href=\"/#tee/question/tee-c21-s6\">Read question + answer</a> · Activation/loss/dropout scaling missing from original; result is conditional on explicit standard classroom assumptions.</td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 4 · Four CNN design explanations</td><td>theory</td><td><a href=\"/#tee/question/tee-c21-s7\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 4 · 64×64 CNN shape and parameter table</td><td>numerical</td><td><a href=\"/#tee/question/tee-c21-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 2 · Bipolar AND perceptron</td><td>numerical</td><td><a href=\"/#tee/question/tee-c21-s9\">Read question + answer</a> · Initialization, order and threshold convention explicitly supplied as assumptions; multiple equivalent separating weights exist.</td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 4 · ResNet shortcut and Inception1×1</td><td>theory</td><td><a href=\"/#tee/question/tee-c21-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 5 · ReLU RNN state with declared orientation</td><td>numerical</td><td><a href=\"/#tee/question/tee-c21-s11\">Read question + answer</a> · Square matrices and printed horizontal vectors leave orientation ambiguous; both possible readings are explained, main answer follows row-vector form.</td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 2 · 3–2–1 forward pass and update w7,w8</td><td>numerical</td><td><a href=\"/#tee/question/tee-c21-s12\">Read question + answer</a> · Original does not specify loss scaling; half-SSE is declared and alternatives distinguished.</td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 3 · AdaGrad stagnation versus RMSProp</td><td>case</td><td><a href=\"/#tee/question/tee-c21-s13\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 5 · Long-text sentiment architecture</td><td>case</td><td><a href=\"/#tee/question/tee-c21-s14\">Read question + answer</a></td></tr><tr><td><strong>Q7b [5]</strong></td><td>Unit 4 · Transfer learning</td><td>theory</td><td><a href=\"/#tee/question/tee-c21-s15\">Read question + answer</a></td></tr><tr><td><strong>Q7c [5]</strong></td><td>Unit 2, 3 · Learning rate and two losses</td><td>theory</td><td><a href=\"/#tee/question/tee-c21-s16\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1, 4, 5: 1 parts, 5 known marks; Unit 3: 2 parts, 15 known marks; Unit 4: 5 parts, 40 known marks; Unit 5: 4 parts, 35 known marks; Unit 2: 3 parts, 30 known marks; Unit 2, 3: 2 parts, 15 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2024-02-13 · re-exam · R24</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · Drivers of deep learning adoption</td><td>theory</td><td><a href=\"/#tee/question/tee-c14-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 2 · 10-5-5-5-4 dense network parameter count</td><td>numerical</td><td><a href=\"/#tee/question/tee-c14-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 3 · Overfitting diagnosis and remedies</td><td>case</td><td><a href=\"/#tee/question/tee-c14-s2\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 4 · Max and average pooling</td><td>numerical</td><td><a href=\"/#tee/question/tee-c14-s3\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · Four-hidden-neuron sigmoid MSE and update</td><td>numerical</td><td><a href=\"/#tee/question/tee-c14-s4\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 3 · Momentum/Nesterov; high momentum; excluded convex rates</td><td>theory</td><td><a href=\"/#tee/question/tee-c14-s5\">Read question + answer</a> · Current-syllabus extract; original part also contains Asymptotic convergence-rate comparison on convex problems (part of i)</td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2 · Activation comparisons and softmax</td><td>mixed</td><td><a href=\"/#tee/question/tee-c14-s6\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 3 · Regularization importance and techniques</td><td>theory</td><td><a href=\"/#tee/question/tee-c14-s7\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 2 · Perceptron training for two epochs</td><td>numerical</td><td><a href=\"/#tee/question/tee-c14-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 4 · CNN sizes, weights and biases</td><td>numerical</td><td><a href=\"/#tee/question/tee-c14-s9\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 4 · Replacing architecture to improve gradient flow</td><td>case</td><td><a href=\"/#tee/question/tee-c14-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 1, 5 · X-ray DL justification; RNN pros and cons</td><td>case</td><td><a href=\"/#tee/question/tee-c14-s11\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 5 · GRU update and reset gates</td><td>theory</td><td><a href=\"/#tee/question/tee-c14-s12\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 4 · Pretrained vegetable classifier</td><td>case</td><td><a href=\"/#tee/question/tee-c14-s13\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 5 · LSTM architecture</td><td>theory</td><td><a href=\"/#tee/question/tee-c14-s14\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 5 · RNN input/output sequence architectures</td><td>theory</td><td><a href=\"/#tee/question/tee-c14-s15\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 1 parts, 5 known marks; Unit 2: 4 parts, 35 known marks; Unit 3: 3 parts, 25 known marks; Unit 4: 4 parts, 35 known marks; Unit 1, 5: 1 parts, 10 known marks; Unit 5: 3 parts, 30 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><p><strong>Current-syllabus qualification:</strong> Q2b: mixed current and legacy tasks; the retained-only marks cannot be determined from the printed allocation. The original whole-part marks remain visible so the paper is faithfully represented.</p><h3>2023-12-02 · final · F23</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [5]</strong></td><td>Unit 1 · Deep learning features and limitations</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [5]</strong></td><td>Unit 2, 3 · ANN hyperparameters and significance</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [5]</strong></td><td>Unit 5 · Unrolled RNN and BPTT</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s2\">Read question + answer</a></td></tr><tr><td><strong>Q1d [5]</strong></td><td>Unit 4 · Convolution map</td><td>numerical</td><td><a href=\"/#tee/question/tee-c13-s3\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2 · Binary-input step-activation network</td><td>numerical</td><td><a href=\"/#tee/question/tee-c13-s4\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 2, 1 · Activation necessity; ML/DL facial-recognition choice</td><td>mixed</td><td><a href=\"/#tee/question/tee-c13-s5\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2 · Sigmoid output-weight backpropagation</td><td>numerical</td><td><a href=\"/#tee/question/tee-c13-s6\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 3 · Adam advantages versus SGD</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s7\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 4 · AlexNet-style layer dimensions and parameters</td><td>numerical</td><td><a href=\"/#tee/question/tee-c13-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 5 · LSTM autocomplete architecture and token probabilities</td><td>case</td><td><a href=\"/#tee/question/tee-c13-s9\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 4 · Inception branches and 1x1 convolution</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 2 · Linear separability; XOR and XNOR construction</td><td>mixed</td><td><a href=\"/#tee/question/tee-c13-s11\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 5 · LSTM gates; source mixes reset/update terminology</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s12\">Read question + answer</a> · Printed LSTM diagram uses update-gate wording and asks reset equations. Answer separates LSTM and GRU rather than inventing an LSTM reset gate.</td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 4 · ResNet gradient flow and block outputs</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s13\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 5 · Paragraph sentiment model</td><td>case</td><td><a href=\"/#tee/question/tee-c13-s14\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 3 · Bias-variance tradeoff and intervention table</td><td>theory</td><td><a href=\"/#tee/question/tee-c13-s15\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 1: 1 parts, 5 known marks; Unit 2, 3: 1 parts, 5 known marks; Unit 5: 4 parts, 35 known marks; Unit 4: 4 parts, 35 known marks; Unit 2: 3 parts, 30 known marks; Unit 2, 1: 1 parts, 10 known marks; Unit 3: 2 parts, 20 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2023-01-28 · re-exam · R23</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [4]</strong></td><td>Unit 5 · Music-generation RNN architecture</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [4]</strong></td><td>Unit 4 · Stride-2 average pooling and purpose</td><td>numerical</td><td><a href=\"/#tee/question/tee-c16-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [4]</strong></td><td>Unit 1 · DL advantages and limitations</td><td>theory</td><td><a href=\"/#tee/question/tee-c16-s2\">Read question + answer</a></td></tr><tr><td><strong>Q1d [4]</strong></td><td>Unit 3 · Mini-batch size and parallelism</td><td>theory</td><td><a href=\"/#tee/question/tee-c16-s3\">Read question + answer</a></td></tr><tr><td><strong>Q1e [4]</strong></td><td>Unit 2 · AND perceptron design</td><td>numerical</td><td><a href=\"/#tee/question/tee-c16-s4\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 2, 3, 4 · CNN parameters, hyperparameters and Adam</td><td>theory</td><td><a href=\"/#tee/question/tee-c16-s5\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 2, 3 · ReLU, rating regression and overfitting</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s6\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 5 · RNN language model and per-token probabilities</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s7\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 2 · ReLU/sigmoid forward pass and four output-weight updates</td><td>numerical</td><td><a href=\"/#tee/question/tee-c16-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 4 · Small-data face-attendance transfer learning</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s9\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 4 · AlexNet parameter count</td><td>numerical</td><td><a href=\"/#tee/question/tee-c16-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 5 · Vanishing-gradient RNN remedies</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s11\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 2 · Fraud classifier design and parameter count</td><td>mixed</td><td><a href=\"/#tee/question/tee-c16-s12\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 3 · Three optimization-failure scenarios</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s13\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 4 · Convolution cost and unspecified bottleneck width</td><td>numerical</td><td><a href=\"/#tee/question/tee-c16-s14\">Read question + answer</a> · The 1x1 reduction width is not specified. Answer gives a symbolic count and an explicitly assumed numerical example.</td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 5 · LSTM sentence memory and gates</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s15\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 3 · Overfitting diagnosis and remedies</td><td>case</td><td><a href=\"/#tee/question/tee-c16-s16\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 5: 4 parts, 34 known marks; Unit 4: 4 parts, 34 known marks; Unit 1: 1 parts, 4 known marks; Unit 3: 3 parts, 24 known marks; Unit 2: 3 parts, 24 known marks; Unit 2, 3, 4: 1 parts, 10 known marks; Unit 2, 3: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>2022-11-19 · final · F22</h3><p>140 marks offered; 100 attempted. </p><table><thead><tr><th>Question [marks]</th><th>Current unit and topic</th><th>Question form</th><th>Answer / scope</th></tr></thead><tbody><tr><td><strong>Q1a [4]</strong></td><td>Unit 4 · Stride-2 convolution and detected feature</td><td>numerical</td><td><a href=\"/#tee/question/tee-c15-s0\">Read question + answer</a></td></tr><tr><td><strong>Q1b [4]</strong></td><td>Unit 2 · Signed gradient-descent update</td><td>numerical</td><td><a href=\"/#tee/question/tee-c15-s1\">Read question + answer</a></td></tr><tr><td><strong>Q1c [4]</strong></td><td>Unit 1 · ML and DL comparison</td><td>theory</td><td><a href=\"/#tee/question/tee-c15-s2\">Read question + answer</a></td></tr><tr><td><strong>Q1d [4]</strong></td><td>Unit 2 · Sigmoid versus tanh</td><td>theory</td><td><a href=\"/#tee/question/tee-c15-s3\">Read question + answer</a></td></tr><tr><td><strong>Q1e [4]</strong></td><td>Unit 5 · Image-captioning RNN architecture</td><td>case</td><td><a href=\"/#tee/question/tee-c15-s4\">Read question + answer</a></td></tr><tr><td><strong>Q2a [10]</strong></td><td>Unit 5 · GRU advantages and subject memory in a sentence</td><td>case</td><td><a href=\"/#tee/question/tee-c15-s5\">Read question + answer</a></td></tr><tr><td><strong>Q2b [10]</strong></td><td>Unit 2 · Two-sample sigmoid forward pass and mean-MSE backprop</td><td>numerical</td><td><a href=\"/#tee/question/tee-c15-s6\">Read question + answer</a></td></tr><tr><td><strong>Q3a [10]</strong></td><td>Unit 2, 3 · Bias/variance, four-class activation/loss and diagnosis</td><td>case</td><td><a href=\"/#tee/question/tee-c15-s7\">Read question + answer</a></td></tr><tr><td><strong>Q3b [10]</strong></td><td>Unit 4 · LeNet-style parameter count</td><td>numerical</td><td><a href=\"/#tee/question/tee-c15-s8\">Read question + answer</a></td></tr><tr><td><strong>Q4a [10]</strong></td><td>Unit 4 · Inception bottleneck computation count</td><td>numerical</td><td><a href=\"/#tee/question/tee-c15-s9\">Read question + answer</a></td></tr><tr><td><strong>Q4b [10]</strong></td><td>Unit 2, 3 · 6-5-5-4 network; AdaGrad parameters and hyperparameters</td><td>theory</td><td><a href=\"/#tee/question/tee-c15-s10\">Read question + answer</a></td></tr><tr><td><strong>Q5a [10]</strong></td><td>Unit 5 · RNN model and BPTT updates</td><td>theory</td><td><a href=\"/#tee/question/tee-c15-s11\">Read question + answer</a></td></tr><tr><td><strong>Q5b [10]</strong></td><td>Unit 3 · Optimization challenges and momentum</td><td>theory</td><td><a href=\"/#tee/question/tee-c15-s12\">Read question + answer</a></td></tr><tr><td><strong>Q6a [10]</strong></td><td>Unit 4 · CNN vanishing-gradient remedies</td><td>case</td><td><a href=\"/#tee/question/tee-c15-s13\">Read question + answer</a></td></tr><tr><td><strong>Q6b [10]</strong></td><td>Unit 2, 3 · Clothing classifier design and six diagnostic tasks</td><td>case</td><td><a href=\"/#tee/question/tee-c15-s14\">Read question + answer</a></td></tr><tr><td><strong>Q7a [10]</strong></td><td>Unit 5 · LSTM long-sequence language model</td><td>case</td><td><a href=\"/#tee/question/tee-c15-s15\">Read question + answer</a></td></tr><tr><td><strong>Q7b [10]</strong></td><td>Unit 2 · Perceptron non-linear separability and solution</td><td>theory</td><td><a href=\"/#tee/question/tee-c15-s16\">Read question + answer</a></td></tr></tbody></table><p><strong>Original offered marks by mapped topic, grouped without double counting:</strong> Unit 4: 4 parts, 34 known marks; Unit 2: 4 parts, 28 known marks; Unit 1: 1 parts, 4 known marks; Unit 5: 4 parts, 34 known marks; Unit 2, 3: 3 parts, 30 known marks; Unit 3: 1 parts, 10 known marks. Joint-unit buckets remain joint; no invented split is assigned. These original-paper totals include any legacy tasks explicitly marked above; they are not a current-syllabus marks blueprint.</p><h3>Priority without skipping the syllabus</h3><p>The latest papers show the form and depth of questions, while the official current syllabus sets the learning scope. Authored drills, explanatory numbers and optional extensions are not counted as past questions. Source assumptions and ambiguous data are stated in their answers.</p>"],"question":[],"answer":[]}]},{"n":2,"title":"Mathematics revision","sections":[{"title":"Before maths: what are we trying to learn?","blocks":["<h3>Machine ko ek number do.</h3>","<p>Imagine a tiny machine that estimates a bill. You tell it how many notebooks you bought. This information going INTO the machine is called the INPUT. Abhi bas naam samjho: input = andar diya hua number.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/notebooks_input.png\" aria-label=\"Enlarge diagram: Start at the three notebooks on the left. Their count is the input; the machine turns that quantity into a bill estimate.\"><img src=\"assets/figures/notebooks_input.png\" alt=\"Start at the three notebooks on the left. Their count is the input; the machine turns that quantity into a bill estimate.\" width=\"1672\" height=\"941\" loading=\"lazy\"></button><figcaption>Start at the three notebooks on the left. Their count is the input; the machine turns that quantity into a bill estimate. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Input = 3 notebooks</p>","<h3>Machine se ek answer niklega.</h3>","<p>Suppose the machine says the bill is 30 rupees. This answer coming OUT is called the OUTPUT. Input aur output alag jobs hain: 3 was the quantity; 30 is the predicted bill.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_output.svg\" aria-label=\"Enlarge diagram: Input and output name two different jobs: quantity enters and the estimated bill leaves.\"><img src=\"assets/figures/v_output.svg\" alt=\"Input and output name two different jobs: quantity enters and the estimated bill leaves.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Input and output name two different jobs: quantity enters and the estimated bill leaves. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Input: 3 notebooks → Output: 30 rupees</p>","<h3>Multiply kyun karte hain?</h3>","<p>If each notebook costs 10 rupees, three notebooks cost 10 + 10 + 10 = 30. Multiplication is just the shorter calculation: 3 × 10. In this simple model the multiplying number is called a WEIGHT.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_multiply.svg\" aria-label=\"Enlarge diagram: Point to each Rs 10 notebook contribution, then add the three equal amounts.\"><img src=\"assets/figures/v_multiply.svg\" alt=\"Point to each Rs 10 notebook contribution, then add the three equal amounts.\" width=\"1080\" height=\"490\" loading=\"lazy\"></button><figcaption>Point to each Rs 10 notebook contribution, then add the three equal amounts. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> 3 × 10 = 30</p>","<h3>Weight badla, answer badla.</h3>","<p>Keep the input 3. Change only the weight from 10 to 8. The output becomes 3 × 8 = 24. A weight controls how strongly an input affects the answer. Neural-network weights can also be negative or fractions.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_weight.svg\" aria-label=\"Enlarge diagram: Only the multiplier changes. Compare both outputs while keeping the three notebooks fixed.\"><img src=\"assets/figures/v_weight.svg\" alt=\"Only the multiplier changes. Compare both outputs while keeping the three notebooks fixed.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Only the multiplier changes. Compare both outputs while keeping the three notebooks fixed. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Old: 3 × 10 = 30. New: 3 × 8 = 24.</p>","<h3>Correct answer ko target kehte hain.</h3>","<p>The real bill is 30, but the machine predicted 24. The correct answer supplied for a training example is its TARGET. Our prediction is 6 too small because 30 − 24 = 6.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_target.svg\" aria-label=\"Enlarge diagram: The prediction is the machine’s result. The target is the real bill used to judge that result.\"><img src=\"assets/figures/v_target.svg\" alt=\"The prediction is the machine’s result. The target is the real bill used to judge that result.\" width=\"1080\" height=\"480\" loading=\"lazy\"></button><figcaption>The prediction is the machine’s result. The target is the real bill used to judge that result. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Target = 30. Prediction = 24. Difference = 6.</p>","<h3>Learning ka matlab weight improve karna.</h3>","<p>For this tiny example, changing the weight from 8 to 10 changes the prediction from 24 to the correct 30. Learning means using examples to adjust weights and reduce prediction error. Later, gradient descent will calculate HOW to adjust them.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_learning.svg\" aria-label=\"Enlarge diagram: The weight changes from 8 to 10. The same input now produces a prediction closer to the fixed target.\"><img src=\"assets/figures/v_learning.svg\" alt=\"The weight changes from 8 to 10. The same input now produces a prediction closer to the fixed target.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The weight changes from 8 to 10. The same input now produces a prediction closer to the fixed target. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> 3 × 8 = 24 → adjust weight → 3 × 10 = 30</p>","<h3>Bias ek extra add hone wala number hai.</h3>","<p>Now suppose there is a fixed packing fee of 2 rupees. First calculate the notebook cost: 3 × 10 = 30. Then add 2. That extra adjustable number is called a BIAS. In a neural network, it lets the result shift independently of the input.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bias.svg\" aria-label=\"Enlarge diagram: The packing fee is added after the notebook cost. It is not multiplied by the notebook quantity.\"><img src=\"assets/figures/v_bias.svg\" alt=\"The packing fee is added after the notebook cost. It is not multiplied by the notebook quantity.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The packing fee is added after the notebook cost. It is not multiplied by the notebook quantity. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> 3 × 10 + 2 = 30 + 2 = 32</p>","<h3>Letters numbers ke naam hain.</h3>","<p>Instead of writing input, weight and bias every time, books use short names. x means input; w means weight; b means bias. So x × w + b says exactly the calculation you already did. A letter is a named box holding a number.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_symbols.svg\" aria-label=\"Enlarge diagram: Read each letter as a named box holding a number, then follow the same arithmetic.\"><img src=\"assets/figures/v_symbols.svg\" alt=\"Read each letter as a named box holding a number, then follow the same arithmetic.\" width=\"1080\" height=\"500\" loading=\"lazy\"></button><figcaption>Read each letter as a named box holding a number, then follow the same arithmetic. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> x = 3, w = 10, b = 2 → x × w + b = 32</p>","<h3>Deep learning mein aage kya hoga?</h3>","<p>A neural network connects many small calculating units called neurons. They multiply inputs by weights, add a bias and apply an activation rule. Several layers can learn more complex relationships. First we will learn the small calculation; phir layers jodenge.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_layers.svg\" aria-label=\"Enlarge diagram: Each circle is a small calculation. Outputs from one layer become the next layer’s inputs.\"><img src=\"assets/figures/v_layers.svg\" alt=\"Each circle is a small calculation. Outputs from one layer become the next layer’s inputs.\" width=\"1080\" height=\"650\" loading=\"lazy\"></button><figcaption>Each circle is a small calculation. Outputs from one layer become the next layer’s inputs. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Calculation:</strong> Input → calculations in layers → prediction</p>","<p class=\"inline-question\"><strong>Question.</strong> A toy model has input 4, weight 5 and bias 2. Find its output using input × weight + bias.</p>","<h3>Given</h3>","<p>A toy model has input 4, weight 5 and bias 2.</p>","<h3>To find</h3>","<p>Find the preactivation and the requested neuron output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> multiply input by weight: 4 × 5 = 20.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> add the bias: 20 + 2 = 22. Final output = 22. The bias is added once, after multiplication.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s0","search":"Before maths: what are we trying to learn? \n### Machine ko ek number do.\nImagine a tiny machine that estimates a bill. You tell it how many notebooks you bought. This information going INTO the machine is called the INPUT. Abhi bas naam samjho: input = andar diya hua number.\n\n\n\n**Calculation:** Input = 3 notebooks\n\n### Machine se ek answer niklega.\nSuppose the machine says the bill is 30 rupees. This answer coming OUT is called the OUTPUT. Input aur output alag jobs hain: 3 was the quantity; 30 is the predicted bill.\n\n\n\n**Calculation:** Input: 3 notebooks → Output: 30 rupees\n\n### Multiply kyun karte hain?\nIf each notebook costs 10 rupees, three notebooks cost 10 + 10 + 10 = 30. Multiplication is just the shorter calculation: 3 × 10. In this simple model the multiplying number is called a WEIGHT.\n\n\n\n**Calculation:** 3 × 10 = 30\n\n### Weight badla, answer badla.\nKeep the input 3. Change only the weight from 10 to 8. The output becomes 3 × 8 = 24. A weight controls how strongly an input affects the answer. Neural-network weights can also be negative or fractions.\n\n\n\n**Calculation:** Old: 3 × 10 = 30. New: 3 × 8 = 24.\n\n### Correct answer ko target kehte hain.\nThe real bill is 30, but the machine predicted 24. The correct answer supplied for a training example is its TARGET. Our prediction is 6 too small because 30 − 24 = 6.\n\n\n\n**Calculation:** Target = 30. Prediction = 24. Difference = 6.\n\n### Learning ka matlab weight improve karna.\nFor this tiny example, changing the weight from 8 to 10 changes the prediction from 24 to the correct 30. Learning means using examples to adjust weights and reduce prediction error. Later, gradient descent will calculate HOW to adjust them.\n\n\n\n**Calculation:** 3 × 8 = 24 → adjust weight → 3 × 10 = 30\n\n### Bias ek extra add hone wala number hai.\nNow suppose there is a fixed packing fee of 2 rupees. First calculate the notebook cost: 3 × 10 = 30. Then add 2. That extra adjustable number is called a BIAS. In a neural network, it lets the result shift independently of the input.\n\n\n\n**Calculation:** 3 × 10 + 2 = 30 + 2 = 32\n\n### Letters numbers ke naam hain.\nInstead of writing input, weight and bias every time, books use short names. x means input; w means weight; b means bias. So x × w + b says exactly the calculation you already did. A letter is a named box holding a number.\n\n\n\n**Calculation:** x = 3, w = 10, b = 2 → x × w + b = 32\n\n### Deep learning mein aage kya hoga?\nA neural network connects many small calculating units called neurons. They multiply inputs by weights, add a bias and apply an activation rule. Several layers can learn more complex relationships. First we will learn the small calculation; phir layers jodenge.\n\n\n\n**Calculation:** Input → calculations in layers → prediction\n\n**Question.** A toy model has input 4, weight 5 and bias 2. Find its output using input × weight + bias.\n\n\n\n### Given\n\nA toy model has input 4, weight 5 and bias 2.\n\n### To find\n\nFind the preactivation and the requested neuron output.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** multiply input by weight: 4 × 5 = 20.\n\n*"},{"title":"Negative numbers are direction","blocks":["<h3>1. The minus sign can describe a number</h3>","<p>Zero is the reference point. Positive numbers such as 1, 2 and 3 lie to its right on a number line. Negative numbers such as −1, −2 and −3 lie to its left. The number −3 is three units below zero; it is not an instruction to subtract until another number is supplied.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_negative.svg\" aria-label=\"Enlarge diagram: Read left as smaller and right as larger. Follow one signed movement at a time.\"><img src=\"assets/figures/v_negative.svg\" alt=\"Read left as smaller and right as larger. Follow one signed movement at a time.\" width=\"1080\" height=\"470\" loading=\"lazy\"></button><figcaption>Read left as smaller and right as larger. Follow one signed movement at a time. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>In 5 − 2, the minus sign is an operation: subtract 2 from 5. In 5 + (−2), the sign inside the brackets belongs to the number negative 2. Both expressions finish at 3. Brackets keep the signed number together.</p>","<h3>2. Adding a negative moves left</h3>","<p>Start at 5. Adding positive 2 moves two places right, to 7. Adding negative 2 moves two places left, to 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d25cc2f4afc0b12d.svg\" alt=\"\\begin{aligned}5+2&amp;=7\\\\5+(-2)&amp;=3\\end{aligned}\" width=\"137.13\" height=\"56.20\" style=\"width:137.13px;height:56.20px;aspect-ratio:137.13/56.20\" loading=\"lazy\"></div>","<p>If both numbers are negative, keep moving left. Start at −3 and add −2: the answer is −5.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6f43c9051ebbeef.svg\" alt=\"(-3)+(-2)=-5\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<h3>3. Subtracting reverses that movement</h3>","<p>Subtracting positive 2 moves left. Subtracting negative 2 reverses a leftward movement, so it moves right. A money example is removing a debt of 2: your balance increases by 2.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5db46d4affd9d09b.svg\" alt=\"5-(-2)=5+2=7\" width=\"224.01\" height=\"24.43\" style=\"width:224.01px;height:24.43px;aspect-ratio:224.01/24.43\" loading=\"lazy\"></div>","<p>The shortcut “two negatives make a positive” is not a rule for every calculation. Negative 3 plus negative 2 is still −5. First identify the operation: addition, subtraction, multiplication or division.</p>","<h3>4. Multiplication has its own sign rule</h3>","<p>For multiplication and division, equal signs give a positive result and different signs give a negative result. Calculate the ordinary size, then attach the correct sign.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Signs being multiplied</th><th>Complete calculation</th><th>Result sign</th></tr></thead><tbody><tr><td>Positive × positive</td><td>3 × 2 = 6</td><td>Positive</td></tr><tr><td>Negative × positive</td><td>(−3) × 2 = −6</td><td>Negative</td></tr><tr><td>Positive × negative</td><td>3 × (−2) = −6</td><td>Negative</td></tr><tr><td>Negative × negative</td><td>(−3) × (−2) = 6</td><td>Positive</td></tr></tbody></table></div>","<p>Division uses the same sign pattern: (−6) ÷ 2 = −3 and (−6) ÷ (−2) = 3. The divisor must be nonzero.</p>","<h3>5. Fully worked arithmetic</h3>","<p class=\"inline-question\"><strong>Question.</strong> Calculate −3 + 2, −3 − 2 and −3 − (−2).</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Expressions: −3+2; −3−2; −3−(−2).</p>","<h3>To find</h3>","<p>Evaluate the three signed-number expressions.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the first expression.</strong> start at −3 and move two places right. The answer is −1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e35736ce1cfc9727.svg\" alt=\"-3+2=-1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the second expression.</strong> start at −3 and move two places left. The answer is −5.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/53bef08286131079.svg\" alt=\"-3-2=-5\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: evaluate the third expression.</strong> replace subtract-negative-2 with add-positive-2. The answer is −1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2cc0c9e475076c06.svg\" alt=\"\\begin{aligned}-3-(-2)&amp;=-3+2\\\\&amp;=-1\\end{aligned}\" width=\"217.23\" height=\"56.20\" style=\"width:217.23px;height:56.20px;aspect-ratio:217.23/56.20\" loading=\"lazy\"></div>","<p>Later, a weight update subtracts a correction that can itself be negative. The third expression explains exactly why that update can increase a weight.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s1","search":"Negative numbers are direction ### 1. The minus sign can describe a number\nZero is the reference point. Positive numbers such as 1, 2 and 3 lie to its right on a number line. Negative numbers such as −1, −2 and −3 lie to its left. The number −3 is three units below zero; it is not an instruction to subtract until another number is supplied.\n\nIn 5 − 2, the minus sign is an operation: subtract 2 from 5. In 5 + (−2), the sign inside the brackets belongs to the number negative 2. Both expressions finish at 3. Brackets keep the signed number together.\n### 2. Adding a negative moves left\nStart at 5. Adding positive 2 moves two places right, to 7. Adding negative 2 moves two places left, to 3.\n\nIf both numbers are negative, keep moving left. Start at −3 and add −2: the answer is −5.\n\n### 3. Subtracting reverses that movement\nSubtracting positive 2 moves left. Subtracting negative 2 reverses a leftward movement, so it moves right. A money example is removing a debt of 2: your balance increases by 2.\n\nThe shortcut “two negatives make a positive” is not a rule for every calculation. Negative 3 plus negative 2 is still −5. First identify the operation: addition, subtraction, multiplication or division.\n### 4. Multiplication has its own sign rule\nFor multiplication and division, equal signs give a positive result and different signs give a negative result. Calculate the ordinary size, then attach the correct sign.\n| Signs being multiplied | Complete calculation | Result sign |\n| Positive × positive | 3 × 2 = 6 | Positive |\n| Negative × positive | (−3) × 2 = −6 | Negative |\n| Positive × negative | 3 × (−2) = −6 | Negative |\n| Negative × negative | (−3) × (−2) = 6 | Positive |\nDivision uses the same sign pattern: (−6) ÷ 2 = −3 and (−6) ÷ (−2) = 3. The divisor must be nonzero.\n### 5. Fully worked arithmetic\n**Question.** Calculate −3 + 2, −3 − 2 and −3 − (−2).\n**Answer — step by step.**\n\n\n\n### Given\n\nExpressions: −3+2; −3−2; −3−(−2).\n\n### To find\n\nEvaluate the three signed-number expressions.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n**Step 1: evaluate the first expression.** start at −3 and move two places right. The answer is −1.\n\n**Step 2: evaluate the second expression.** start at −3 and move two places left. The answer is −5.\n\n**Step 3: evaluate the third expression.** replace subtract-negative-2 with add-positive-2. The answer is −1.\n\nLater, a weight update subtracts a correction that can itself be negative. The third expression explains exactly why that update can increase a weight.\n"},{"title":"Fractions decimals and percentages","blocks":["<h3>1. A fraction tells us to divide</h3>","<p>The upper number is the <strong>numerator</strong>. The lower number is the <strong>denominator</strong>. In one-quarter, split one whole into four equal parts and take one part. The fraction bar means division.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13b13c0346dc6e67.svg\" alt=\"\\frac14=1\\div4=0.25\" width=\"185.89\" height=\"49.55\" style=\"width:185.89px;height:49.55px;aspect-ratio:185.89/49.55\" loading=\"lazy\"></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_fractions.svg\" aria-label=\"Enlarge diagram: One shaded part out of four is the same amount as 0.25 or 25 percent.\"><img src=\"assets/figures/v_fractions.svg\" alt=\"One shaded part out of four is the same amount as 0.25 or 25 percent.\" width=\"1080\" height=\"450\" loading=\"lazy\"></button><figcaption>One shaded part out of four is the same amount as 0.25 or 25 percent. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A decimal and a fraction can name the same amount. One-half is 0.5, one-tenth is 0.1, and one-hundredth is 0.01. The denominator cannot be zero: division by zero is undefined.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61c8b62ceed00f18.svg\" alt=\"\\begin{aligned}\\frac12&amp;=0.5\\\\\\frac1{10}&amp;=0.1\\\\\\frac1{100}&amp;=0.01\\end{aligned}\" width=\"123.43\" height=\"164.40\" style=\"width:123.43px;height:164.40px;aspect-ratio:123.43/164.40\" loading=\"lazy\"></div>","<h3>2. Why small decimals become smaller when multiplied</h3>","<p>Multiplying by 0.1 means taking one-tenth. Multiplying by 0.2 means taking two-tenths. For 0.2 × 0.3, express both numbers as fractions. Multiply the numerators and multiply the denominators.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ac4c9d847d5a49fc.svg\" alt=\"\\begin{aligned}0.2\\times0.3&amp;=\\frac2{10}\\times\\frac3{10}\\\\&amp;=\\frac6{100}\\\\&amp;=0.06\\end{aligned}\" width=\"225.15\" height=\"139.28\" style=\"width:225.15px;height:139.28px;aspect-ratio:225.15/139.28\" loading=\"lazy\"></div>","<p>This also explains a calculation used later: 0.1 × (−0.6) is one-tenth of negative 0.6, which is −0.06. The negative sign is kept because the factors have different signs.</p>","<h3>3. Dividing by one-half asks how many halves fit</h3>","<p>Two halves fit inside 1. Four halves fit inside 2. Therefore dividing 2 by one-half gives 4, even though division by a number greater than 1 would make 2 smaller.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e8f8b190ccce77f7.svg\" alt=\"\\begin{aligned}2\\div0.5&amp;=2\\div\\frac12\\\\&amp;=2\\times2\\\\&amp;=4\\end{aligned}\" width=\"170.95\" height=\"113.09\" style=\"width:170.95px;height:113.09px;aspect-ratio:170.95/113.09\" loading=\"lazy\"></div>","<p>The <strong>reciprocal</strong> flips a nonzero fraction: the reciprocal of 1/2 is 2/1. Dividing by a fraction means multiplying by its reciprocal. For decimals, multiplying both the numerator and denominator by the same nonzero number preserves their ratio.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e15debe515ad70bf.svg\" alt=\"\\begin{aligned}\\frac{0.8}{0.5}&amp;=\\frac{0.8\\times10}{0.5\\times10}\\\\&amp;=\\frac85\\\\&amp;=1.6\\end{aligned}\" width=\"170.85\" height=\"139.28\" style=\"width:170.85px;height:139.28px;aspect-ratio:170.85/139.28\" loading=\"lazy\"></div>","<h3>4. Percent means out of one hundred</h3>","<p>To turn a percentage into a decimal, divide by 100. To turn a decimal into a percentage, multiply by 100.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c062ee6009f1f875.svg\" alt=\"\\begin{aligned}20\\%&amp;=\\frac{20}{100}=0.2\\\\50\\%&amp;=\\frac{50}{100}=0.5\\end{aligned}\" width=\"188.59\" height=\"107.51\" style=\"width:188.59px;height:107.51px;aspect-ratio:188.59/107.51\" loading=\"lazy\"></div>","<p>If 20% is removed, 80% remains. As decimals: 1 − 0.2 = 0.8. The number 1 represents the whole amount, or 100%. This same arithmetic will be used for dropout later.</p>","<h3>5. A mean is a fair-share amount</h3>","<p>For 2, 4 and 9, first add all three numbers: 2 + 4 + 9 = 15. Divide by the number of values, which is 3. The mean is 5. Do not divide by 9 just because it is the largest value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d51e471133d25a2.svg\" alt=\"\\text{mean}=\\frac{\\text{sum}}{\\text{count}}\" width=\"160.09\" height=\"44.50\" style=\"width:160.09px;height:44.50px;aspect-ratio:160.09/44.50\" loading=\"lazy\"></div>","<p>Here the sum is 15 and the count is 3. Apply those two quantities to the formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/503bca869d213251.svg\" alt=\"\\begin{aligned}\\text{mean}&amp;=\\frac{2+4+9}{3}\\\\&amp;=\\frac{15}{3}\\\\&amp;=5\\end{aligned}\" width=\"196.73\" height=\"139.55\" style=\"width:196.73px;height:139.55px;aspect-ratio:196.73/139.55\" loading=\"lazy\"></div>","<p>A <strong>weighted mean</strong> gives different shares of importance to the values. With shares 0.9 and 0.1, the first value receives 90% of the importance and the second receives 10%. The shares add to 1.</p>","<p class=\"inline-question\"><strong>Question.</strong> Find the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Find the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.</p>","<h3>To find</h3>","<p>Find the weighted mean.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum.</strong> Multiply each value by its own coefficient and then add. For a weighted mean, divide by the sum of the weights unless that sum is already 1.</p>","<p>xᵢ = value i; aᵢ = its weight. Each input keeps its own matching coefficient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/305c0c88eaed50a3.svg\" alt=\"\\bar x_w=\\frac{\\sum_i a_ix_i}{\\sum_i a_i}\" width=\"152.45\" height=\"61.24\" style=\"width:152.45px;height:61.24px;aspect-ratio:152.45/61.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har number apne weight ke saath multiply; phir sab add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> multiply the first value by its weight: 0.9 × 10 = 9.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> multiply the second value by its weight: 0.1 × 20 = 2.</p>","<p class=\"worked-step\"><strong>Step 3:</strong> add the contributions: 9 + 2 = 11. The weighted mean is <strong>11</strong>. It is closer to 10 because 10 received most of the importance.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eef093497c3c04cc.svg\" alt=\"\\begin{aligned}0.9(10)+0.1(20)&amp;=9+2\\\\&amp;=11\\end{aligned}\" width=\"266.10\" height=\"56.20\" style=\"width:266.10px;height:56.20px;aspect-ratio:266.10/56.20\" loading=\"lazy\"></div>","<p>If importance weights do not sum to 1, divide their weighted sum by the sum of the weights to obtain the weighted mean. A neuron&#x27;s general weighted sum does not require weights to sum to 1 and is not automatically a mean.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s2","search":"Fractions decimals and percentages ### 1. A fraction tells us to divide\nThe upper number is the **numerator**. The lower number is the **denominator**. In one-quarter, split one whole into four equal parts and take one part. The fraction bar means division.\n\n\nA decimal and a fraction can name the same amount. One-half is 0.5, one-tenth is 0.1, and one-hundredth is 0.01. The denominator cannot be zero: division by zero is undefined.\n\n### 2. Why small decimals become smaller when multiplied\nMultiplying by 0.1 means taking one-tenth. Multiplying by 0.2 means taking two-tenths. For 0.2 × 0.3, express both numbers as fractions. Multiply the numerators and multiply the denominators.\n\nThis also explains a calculation used later: 0.1 × (−0.6) is one-tenth of negative 0.6, which is −0.06. The negative sign is kept because the factors have different signs.\n### 3. Dividing by one-half asks how many halves fit\nTwo halves fit inside 1. Four halves fit inside 2. Therefore dividing 2 by one-half gives 4, even though division by a number greater than 1 would make 2 smaller.\n\nThe **reciprocal** flips a nonzero fraction: the reciprocal of 1/2 is 2/1. Dividing by a fraction means multiplying by its reciprocal. For decimals, multiplying both the numerator and denominator by the same nonzero number preserves their ratio.\n\n### 4. Percent means out of one hundred\nTo turn a percentage into a decimal, divide by 100. To turn a decimal into a percentage, multiply by 100.\n\nIf 20% is removed, 80% remains. As decimals: 1 − 0.2 = 0.8. The number 1 represents the whole amount, or 100%. This same arithmetic will be used for dropout later.\n### 5. A mean is a fair-share amount\nFor 2, 4 and 9, first add all three numbers: 2 + 4 + 9 = 15. Divide by the number of values, which is 3. The mean is 5. Do not divide by 9 just because it is the largest value.\n\nHere the sum is 15 and the count is 3. Apply those two quantities to the formula.\n\nA **weighted mean** gives different shares of importance to the values. With shares 0.9 and 0.1, the first value receives 90% of the importance and the second receives 10%. The shares add to 1.\n**Question.** Find the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.\n**Answer — step by step.**\n\n\n\n### Given\n\nFind the weighted mean of 10 and 20 using weights 0.9 and 0.1 respectively.\n\n### To find\n\nFind the weighted mean.\n\n### Formula — which one and why\n\n**Weighted sum.** Multiply each value by its own coefficient and then add. For a weighted mean, divide by the sum of the weights unless that sum is already 1.\n\nxᵢ = value i; aᵢ = its weight. Each input keeps its own matching coefficient.\n\n\n\n**Yaad rakhne ka cue:** Har number apne weight ke saath multiply; phir sab add.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** multiply the first value by its weight: 0.9 × 10 = 9.\n**Step 2:** multiply the second value by its weight: 0.1 × 20 = 2.\n**Step 3:** add the contributions: 9 + 2 = 11. The weighted mean is **11**. It is closer to 10 because 10 received most of the importance.\n\nIf importance weights do not sum to 1, divide their weighted sum by the sum of the weights to obtain the weighted mean. A neuron's general weighted sum does not require weights to sum to 1 and is not automatically a mean.\n"},{"title":"Brackets before everything else","blocks":["<h3>1. Brackets tell us what must stay together</h3>","<p>An expression is a written calculation. Brackets group part of that calculation. In 1 ÷ (1 + 3), the whole quantity 1 + 3 is the divisor, so calculate it before dividing.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_brackets.svg\" aria-label=\"Enlarge diagram: Follow the bracketed calculation from left to right. The bottom line shows why removing brackets changes the answer.\"><img src=\"assets/figures/v_brackets.svg\" alt=\"Follow the bracketed calculation from left to right. The bottom line shows why removing brackets changes the answer.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow the bracketed calculation from left to right. The bottom line shows why removing brackets changes the answer. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/425b33a05c6633ee.svg\" alt=\"\\frac1{1+3}=\\frac14=0.25\" width=\"196.64\" height=\"51.56\" style=\"width:196.64px;height:51.56px;aspect-ratio:196.64/51.56\" loading=\"lazy\"></div>","<p>Removing the brackets changes the calculation. In 1 ÷ 1 + 3, division comes before addition: 1 ÷ 1 = 1, then 1 + 3 = 4.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1dbb10cc9ab1aacc.svg\" alt=\"1\\div1+3=1+3=4\" width=\"228.09\" height=\"18.54\" style=\"width:228.09px;height:18.54px;aspect-ratio:228.09/18.54\" loading=\"lazy\"></div>","<h3>2. Use this order for the expressions in this course</h3>","<p>First calculate inside brackets. Then evaluate powers and roots. Then do multiplication and division, reading left to right. Finally do addition and subtraction, again reading left to right. Multiplication does not have priority over division; they share a level.</p>","<p>For 8 ÷ 2 × 3, calculate 8 ÷ 2 = 4 and then 4 × 3 = 12. Do not change it into 8 ÷ (2 × 3).</p>","<h3>3. A full example with brackets and a power</h3>","<p class=\"inline-question\"><strong>Question.</strong> Evaluate (2 + 3)² ÷ 5.</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Evaluate (2 + 3)² ÷ 5.</p>","<h3>To find</h3>","<p>Evaluate each expression and state its value.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> finish the brackets: 2 + 3 = 5. The expression becomes 5² ÷ 5.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> square the bracket result: 5² = 25. The expression becomes 25 ÷ 5.</p>","<p class=\"worked-step\"><strong>Step 3:</strong> divide: 25 ÷ 5 = <strong>5</strong>.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/113124579583cb24.svg\" alt=\"\\begin{aligned}\\frac{(2+3)^2}{5}&amp;=\\frac{5^2}{5}\\\\&amp;=\\frac{25}{5}\\\\&amp;=5\\end{aligned}\" width=\"162.51\" height=\"144.21\" style=\"width:162.51px;height:144.21px;aspect-ratio:162.51/144.21\" loading=\"lazy\"></div>","<h3>4. A full example without grouping the addition</h3>","<p class=\"inline-question\"><strong>Question.</strong> Evaluate 2 + 3² × 4.</p>","<p><strong>Answer — step by step.</strong></p>","<h3>Given</h3>","<p>Evaluate 2 + 3² × 4.</p>","<h3>To find</h3>","<p>Evaluate each expression and state its value.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1:</strong> calculate the power: 3² = 9. Keep the other numbers where they are: 2 + 9 × 4.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> multiply: 9 × 4 = 36. The expression becomes 2 + 36.</p>","<p class=\"worked-step\"><strong>Step 3:</strong> add: 2 + 36 = <strong>38</strong>.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef5577a23a205b11.svg\" alt=\"\\begin{aligned}2+3^2\\times4&amp;=2+9\\times4\\\\&amp;=2+36\\\\&amp;=38\\end{aligned}\" width=\"236.03\" height=\"91.24\" style=\"width:236.03px;height:91.24px;aspect-ratio:236.03/91.24\" loading=\"lazy\"></div>","<h3>5. A fraction bar groups the whole denominator</h3>","<p>In a printed fraction, everything below the bar belongs to the denominator. When entering that fraction in a single calculator line, put brackets around the complete denominator. A printed fraction with 1 above and 1 + 3 below must be entered as 1 ÷ (1 + 3).</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s3","search":"Brackets before everything else ### 1. Brackets tell us what must stay together\nAn expression is a written calculation. Brackets group part of that calculation. In 1 ÷ (1 + 3), the whole quantity 1 + 3 is the divisor, so calculate it before dividing.\n\n\nRemoving the brackets changes the calculation. In 1 ÷ 1 + 3, division comes before addition: 1 ÷ 1 = 1, then 1 + 3 = 4.\n\n### 2. Use this order for the expressions in this course\nFirst calculate inside brackets. Then evaluate powers and roots. Then do multiplication and division, reading left to right. Finally do addition and subtraction, again reading left to right. Multiplication does not have priority over division; they share a level.\nFor 8 ÷ 2 × 3, calculate 8 ÷ 2 = 4 and then 4 × 3 = 12. Do not change it into 8 ÷ (2 × 3).\n### 3. A full example with brackets and a power\n**Question.** Evaluate (2 + 3)² ÷ 5.\n**Answer — step by step.**\n\n\n\n### Given\n\nEvaluate (2 + 3)² ÷ 5.\n\n### To find\n\nEvaluate each expression and state its value.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** finish the brackets: 2 + 3 = 5. The expression becomes 5² ÷ 5.\n**Step 2:** square the bracket result: 5² = 25. The expression becomes 25 ÷ 5.\n**Step 3:** divide: 25 ÷ 5 = **5**.\n\n### 4. A full example without grouping the addition\n**Question.** Evaluate 2 + 3² × 4.\n**Answer — step by step.**\n\n\n\n### Given\n\nEvaluate 2 + 3² × 4.\n\n### To find\n\nEvaluate each expression and state its value.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n**Step 1:** calculate the power: 3² = 9. Keep the other numbers where they are: 2 + 9 × 4.\n**Step 2:** multiply: 9 × 4 = 36. The expression becomes 2 + 36.\n**Step 3:** add: 2 + 36 = **38**.\n\n### 5. A fraction bar groups the whole denominator\nIn a printed fraction, everything below the bar belongs to the denominator. When entering that fraction in a single calculator line, put brackets around the complete denominator. A printed fraction with 1 above and 1 + 3 below must be entered as 1 ÷ (1 + 3).\n"},{"title":"Powers roots and very small numbers","blocks":["<h3>1. A power counts repeated multiplication</h3>","<p>In 2³, 2 is the <strong>base</strong> and 3 is the <strong>exponent</strong>. For a positive whole-number exponent, multiply that many copies of the base. It does not mean 2 × 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11e21b993b310c0e.svg\" alt=\"2^3=2\\times2\\times2=8\" width=\"196.66\" height=\"23.59\" style=\"width:196.66px;height:23.59px;aspect-ratio:196.66/23.59\" loading=\"lazy\"></div>","<p>The exponent 2 is called a <strong>square</strong>: 3² = 3 × 3 = 9. Three rows of three cells make nine cells.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_powers.svg\" aria-label=\"Enlarge diagram: Count the three rows of three cells. Squaring builds nine; the square root returns three.\"><img src=\"assets/figures/v_powers.svg\" alt=\"Count the three rows of three cells. Squaring builds nine; the square root returns three.\" width=\"1080\" height=\"520\" loading=\"lazy\"></button><figcaption>Count the three rows of three cells. Squaring builds nine; the square root returns three. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>2. A negative number must stay inside its brackets</h3>","<p>Squaring negative 2 means multiplying negative 2 by negative 2. The equal signs of the factors give a positive result.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/756026084f28a30c.svg\" alt=\"(-2)^2=(-2)(-2)=4\" width=\"238.77\" height=\"27.70\" style=\"width:238.77px;height:27.70px;aspect-ratio:238.77/27.70\" loading=\"lazy\"></div>","<p>Without brackets, −2² means first calculate 2², then apply the minus sign: −(4) = −4. Enter brackets when the entire negative number is the base.</p>","<p>For decimals, use the same rule. Negative 0.3 squared is positive 0.09 because 3/10 multiplied by 3/10 is 9/100.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24f2cf37fb12267b.svg\" alt=\"\\begin{aligned}(-0.3)^2&amp;=(-0.3)(-0.3)\\\\&amp;=0.09\\end{aligned}\" width=\"250.99\" height=\"59.48\" style=\"width:250.99px;height:59.48px;aspect-ratio:250.99/59.48\" loading=\"lazy\"></div>","<h3>3. A square root asks which nonnegative number was squared</h3>","<p>Because 3 × 3 = 9, the principal square root of 9 is 3. Although (−3)² also equals 9, the symbol √9 by itself means the nonnegative root, 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2838a7934ce26d9d.svg\" alt=\"\\begin{aligned}\\sqrt9&amp;=3\\\\\\sqrt{0.09}&amp;=0.3\\end{aligned}\" width=\"128.10\" height=\"68.28\" style=\"width:128.10px;height:68.28px;aspect-ratio:128.10/68.28\" loading=\"lazy\"></div>","<p>The <strong>absolute value</strong> of a number is its distance from zero: |−4| = 4 and |4| = 4. Squaring and taking a square root returns this nonnegative size.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bed469d925782c9b.svg\" alt=\"\\sqrt{(-4)^2}=\\sqrt{16}=4\" width=\"208.49\" height=\"45.45\" style=\"width:208.49px;height:45.45px;aspect-ratio:208.49/45.45\" loading=\"lazy\"></div>","<h3>4. Zero and negative exponents follow a pattern</h3>","<p>Start with powers of 10. Each time the exponent decreases by 1, divide the previous value by 10: 1000 → 100 → 10 → 1 → 0.1 → 0.01. This explains both the zero power and the negative powers.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Power</th><th>Calculation</th><th>Value</th></tr></thead><tbody><tr><td>10³</td><td>10 × 10 × 10</td><td>1000</td></tr><tr><td>10²</td><td>1000 ÷ 10</td><td>100</td></tr><tr><td>10¹</td><td>100 ÷ 10</td><td>10</td></tr><tr><td>10⁰</td><td>10 ÷ 10</td><td>1</td></tr><tr><td>10⁻¹</td><td>1 ÷ 10</td><td>0.1</td></tr><tr><td>10⁻²</td><td>0.1 ÷ 10</td><td>0.01</td></tr><tr><td>10⁻³</td><td>0.01 ÷ 10</td><td>0.001</td></tr></tbody></table></div>","<p>For a nonzero base, power zero is 1. A negative exponent means the reciprocal of the corresponding positive power. It does not mean a negative answer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f45c43d6b073f1bb.svg\" alt=\"\\begin{aligned}10^{-3}&amp;=\\frac1{10^3}\\\\&amp;=\\frac1{1000}\\\\&amp;=0.001\\end{aligned}\" width=\"140.75\" height=\"142.64\" style=\"width:140.75px;height:142.64px;aspect-ratio:140.75/142.64\" loading=\"lazy\"></div>","<h3>5. Tiny scientific notation is still an ordinary number</h3>","<p>The notation 1 × 10⁻⁸ equals 0.00000001. Calculators may display it as 1E−8. In optimizer formulas, ε, pronounced “epsilon”, often names a small positive constant added to a denominator. Read its supplied value before calculating.</p>","<p class=\"inline-question\"><strong>Question.</strong> Calculate 1 − 0.9².</p>","<h3>Given</h3>","<p>Expression: 1−0.9².</p>","<h3>To find</h3>","<p>Evaluate the power first, then the subtraction.</p>","<h3>Formula — which one and why</h3>","<p><strong>A square before subtraction.</strong> The exponent applies to 0.9. Squaring is repeated multiplication; perform it before subtracting the result from 1.</p>","<p>q denotes the number being squared. Parentheses would be required to square the whole difference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/12754a3d0dc07c58.svg\" alt=\"q^2=q\\times q\" width=\"108.08\" height=\"26.34\" style=\"width:108.08px;height:26.34px;aspect-ratio:108.08/26.34\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5166132378f964d6.svg\" alt=\"1-q^2=1-(q\\times q)\" width=\"211.26\" height=\"27.70\" style=\"width:211.26px;height:27.70px;aspect-ratio:211.26/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Jis number pe power hai, sirf uska square; subtraction baad mein.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: square only the 0.9.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3338c806844083ae.svg\" alt=\"0.9^2=0.9(0.9)=0.81\" width=\"231.97\" height=\"27.70\" style=\"width:231.97px;height:27.70px;aspect-ratio:231.97/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: subtract the result from 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/41335385ba7e04c7.svg\" alt=\"1-0.81=0.19\" width=\"161.56\" height=\"18.27\" style=\"width:161.56px;height:18.27px;aspect-ratio:161.56/18.27\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 0.19. The square acts on 0.9, not on the entire difference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/df575ab27bdf9309.svg\" alt=\"\\begin{aligned}1-0.9^2&amp;=1-0.81\\\\&amp;=0.19\\end{aligned}\" width=\"202.10\" height=\"59.48\" style=\"width:202.10px;height:59.48px;aspect-ratio:202.10/59.48\" loading=\"lazy\"></div>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s4","search":"Powers roots and very small numbers ### 1. A power counts repeated multiplication\nIn 2³, 2 is the **base** and 3 is the **exponent**. For a positive whole-number exponent, multiply that many copies of the base. It does not mean 2 × 3.\n\nThe exponent 2 is called a **square**: 3² = 3 × 3 = 9. Three rows of three cells make nine cells.\n\n### 2. A negative number must stay inside its brackets\nSquaring negative 2 means multiplying negative 2 by negative 2. The equal signs of the factors give a positive result.\n\nWithout brackets, −2² means first calculate 2², then apply the minus sign: −(4) = −4. Enter brackets when the entire negative number is the base.\nFor decimals, use the same rule. Negative 0.3 squared is positive 0.09 because 3/10 multiplied by 3/10 is 9/100.\n\n### 3. A square root asks which nonnegative number was squared\nBecause 3 × 3 = 9, the principal square root of 9 is 3. Although (−3)² also equals 9, the symbol √9 by itself means the nonnegative root, 3.\n\nThe **absolute value** of a number is its distance from zero: |−4| = 4 and |4| = 4. Squaring and taking a square root returns this nonnegative size.\n\n### 4. Zero and negative exponents follow a pattern\nStart with powers of 10. Each time the exponent decreases by 1, divide the previous value by 10: 1000 → 100 → 10 → 1 → 0.1 → 0.01. This explains both the zero power and the negative powers.\n| Power | Calculation | Value |\n| 10³ | 10 × 10 × 10 | 1000 |\n| 10² | 1000 ÷ 10 | 100 |\n| 10¹ | 100 ÷ 10 | 10 |\n| 10⁰ | 10 ÷ 10 | 1 |\n| 10⁻¹ | 1 ÷ 10 | 0.1 |\n| 10⁻² | 0.1 ÷ 10 | 0.01 |\n| 10⁻³ | 0.01 ÷ 10 | 0.001 |\nFor a nonzero base, power zero is 1. A negative exponent means the reciprocal of the corresponding positive power. It does not mean a negative answer.\n\n### 5. Tiny scientific notation is still an ordinary number\nThe notation 1 × 10⁻⁸ equals 0.00000001. Calculators may display it as 1E−8. In optimizer formulas, ε, pronounced “epsilon”, often names a small positive constant added to a denominator. Read its supplied value before calculating.\n**Question.** Calculate 1 − 0.9².\n\n\n\n### Given\n\nExpression: 1−0.9².\n\n### To find\n\nEvaluate the power first, then the subtraction.\n\n### Formula — which one and why\n\n**A square before subtraction.** The exponent applies to 0.9. Squaring is repeated multiplication; perform it before subtracting the result from 1.\n\nq denotes the number being squared. Parentheses would be required to square the whole difference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Jis number pe power hai, sirf uska square; subtraction baad mein.\n\n### Solution — step by step\n\n\n\n\n**Step 1: square only the 0.9.**\n\n\n\n\n\n\n\n**Step 2: subtract the result from 1.**\n\n\n\n\n\n\n\n**Final answer:** 0.19. The square acts on 0.9, not on the entire difference.\n\n"},{"title":"Variables functions and symbols","blocks":["<p>These notes assume familiarity with algebra and basic calculus. The revision here covers the notation used in neural-network equations and the conventions that affect numerical answers.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Notation</th><th>Technical meaning</th></tr></thead><tbody><tr><td>x, y, ŷ</td><td>Input feature vector, target, model prediction</td></tr><tr><td>W, b, θ</td><td>Weight matrix, bias vector, complete trainable parameter vector</td></tr><tr><td>z, a</td><td>Preactivation (affine input) and activation (layer output)</td></tr><tr><td>L, J</td><td>Per-example loss and aggregate training objective</td></tr><tr><td>∂L/∂w</td><td>Partial derivative with respect to one parameter</td></tr><tr><td>∇θJ</td><td>Gradient: vector of partial derivatives with respect to θ</td></tr><tr><td>η, λ, ε</td><td>Learning rate, regularization coefficient, numerical stabilizer</td></tr><tr><td>Wᵀ, u⊙v</td><td>Transpose and elementwise multiplication</td></tr><tr><td>θₜ, W⁽ˡ⁾</td><td>Update index t and layer index l; neither denotes a power</td></tr></tbody></table></div>","<h3>Conventions used in numerical solutions</h3>","<p>Vectors are columns unless a question specifies otherwise. A weight matrix has one row per receiving neuron and one column per incoming feature. Write matrix dimensions before multiplying. A bias is added once per receiving neuron or output feature map.</p>","<p>Keep at least six significant digits during intermediate calculations and round the final result as requested. The loss reduction matters: a sum, mean and half-sum produce different gradient factors. The location of ε also matters: a denominator √s + ε differs from √(s + ε).</p>","<p>The sign of a gradient belongs to the derivative, not to the loss value. For example, w = 0.4, η = 0.1 and gradient −2 give the update below.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.42px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aab9aaca5264ba06.svg\"><img class=\"math display-math\" src=\"assets/equations/d677f9f3ff8120b5.svg\" alt=\"w_{\\mathrm{new}}=0.4-0.1(-2)=0.6\" width=\"288.23\" height=\"24.43\" style=\"width:288.23px;height:24.43px;aspect-ratio:288.23/24.43\" loading=\"lazy\"></picture></div>","<p>In later calculations, state the optimizer convention, initial state and iteration number before substituting values. This prevents mixing momentum velocity with Adam&#x27;s second-moment accumulator.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s5","search":"Variables functions and symbols These notes assume familiarity with algebra and basic calculus. The revision here covers the notation used in neural-network equations and the conventions that affect numerical answers.\n\n| Notation | Technical meaning |\n| x, y, ŷ | Input feature vector, target, model prediction |\n| W, b, θ | Weight matrix, bias vector, complete trainable parameter vector |\n| z, a | Preactivation (affine input) and activation (layer output) |\n| L, J | Per-example loss and aggregate training objective |\n| ∂L/∂w | Partial derivative with respect to one parameter |\n| ∇θJ | Gradient: vector of partial derivatives with respect to θ |\n| η, λ, ε | Learning rate, regularization coefficient, numerical stabilizer |\n| Wᵀ, u⊙v | Transpose and elementwise multiplication |\n| θₜ, W⁽ˡ⁾ | Update index t and layer index l; neither denotes a power |\n\n### Conventions used in numerical solutions\nVectors are columns unless a question specifies otherwise. A weight matrix has one row per receiving neuron and one column per incoming feature. Write matrix dimensions before multiplying. A bias is added once per receiving neuron or output feature map.\n\nKeep at least six significant digits during intermediate calculations and round the final result as requested. The loss reduction matters: a sum, mean and half-sum produce different gradient factors. The location of ε also matters: a denominator √s + ε differs from √(s + ε).\n\nThe sign of a gradient belongs to the derivative, not to the loss value. For example, w = 0.4, η = 0.1 and gradient −2 give the update below.\n\nIn later calculations, state the optimizer convention, initial state and iteration number before substituting values. This prevents mixing momentum velocity with Adam's second-moment accumulator.\n"},{"title":"Exponentials and natural logarithms","blocks":["<p class=\"definition\"><strong>Definitions.</strong> The exponential function exp(x) = eˣ uses Euler&#x27;s constant e. The natural logarithm ln is its inverse on positive real values. These functions occur in sigmoid, tanh, softmax and cross-entropy.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8726504f24b7b8cc.svg\" alt=\"e^{-x}=\\frac1{e^x},\\qquad\\ln(e^x)=x\" width=\"272.35\" height=\"49.82\" style=\"width:272.35px;height:49.82px;aspect-ratio:272.35/49.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.83px;--narrow-height:106.38px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0f89b5131dee6b2d.svg\"><img class=\"math display-math\" src=\"assets/equations/1cb05479c1668460.svg\" alt=\"e^{\\ln x}=x\\ (x&gt;0),\\qquad\\ln(ab)=\\ln a+\\ln b\\ (a,b&gt;0)\" width=\"532.54\" height=\"28.19\" style=\"width:532.54px;height:28.19px;aspect-ratio:532.54/28.19\" loading=\"lazy\"></picture></div>","<p>For positive constants and valid domains, exponent and log rules simplify expressions before a calculator is needed. For example, e^(−ln 2) = 1/2. Use natural ln for the loss formulas, not the calculator&#x27;s base-10 log.</p>","<h3>Derivatives used in neural networks</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.79px;--narrow-height:120.14px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b8f3afdc22e0eaaf.svg\"><img class=\"math display-math\" src=\"assets/equations/3d8e93cb87192a72.svg\" alt=\"\\frac{d}{dz}e^{-z}=-e^{-z},\\qquad\\frac{d}{dp}[-\\ln p]=-\\frac1p\" width=\"399.72\" height=\"54.97\" style=\"width:399.72px;height:54.97px;aspect-ratio:399.72/54.97\" loading=\"lazy\"></picture></div>","<p>The minus sign in the first expression comes from differentiating the inner function −z. Applying the chain rule correctly here gives the sigmoid derivative derived in the activation section.</p>","<h3>Brief integration and trigonometry reminder</h3>","<p>Integration reverses differentiation up to an additive constant. The basic relevant identities are:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.87px;--narrow-height:97.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/19176aa5b80f6365.svg\"><img class=\"math display-math\" src=\"assets/equations/5b516266e8ee3cea.svg\" alt=\"\\int x^n\\,dx=\\frac{x^{n+1}}{n+1}+C\\quad(n\\ne-1)\" width=\"354.72\" height=\"57.93\" style=\"width:354.72px;height:57.93px;aspect-ratio:354.72/57.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.53px;--narrow-height:123.25px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b17aa54fb4500d95.svg\"><img class=\"math display-math\" src=\"assets/equations/a4a9ce610fff6be4.svg\" alt=\"\\int\\frac1x\\,dx=\\ln|x|+C,\\qquad\\int e^x\\,dx=e^x+C\" width=\"460.92\" height=\"54.29\" style=\"width:460.92px;height:54.29px;aspect-ratio:460.92/54.29\" loading=\"lazy\"></picture></div>","<p>For angles in radians, d(sin x)/dx = cos x and d(cos x)/dx = −sin x. The identity sin²x + cos²x = 1 concerns ordinary trigonometric functions. Hyperbolic tanh is a different function; using tan instead of tanh gives an incorrect recurrent-network answer.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.81px;--narrow-height:119.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/419a6fb08fcd40a6.svg\"><img class=\"math display-math\" src=\"assets/equations/268c7169f8f53160.svg\" alt=\"\\tanh z=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad\\frac{d}{dz}\\tanh z=1-\\tanh^2z\" width=\"502.42\" height=\"54.23\" style=\"width:502.42px;height:54.23px;aspect-ratio:502.42/54.23\" loading=\"lazy\"></picture></div>","<p>The supplied MT2 calculation families mainly require derivatives, matrix products, logarithms and elementary statistics. Extended integration or trigonometric exercises are not needed for those families.</p>","<h3>Calculator values for activation calculations</h3>","<p>At z = 2, sigmoid = 1/(1 + e⁻²) ≈ 0.880797. At z = 1, tanh ≈ 0.761594. Keep unrounded values when a later gradient uses these activations.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s6","search":"Exponentials and natural logarithms **Definitions.** The exponential function exp(x) = eˣ uses Euler's constant e. The natural logarithm ln is its inverse on positive real values. These functions occur in sigmoid, tanh, softmax and cross-entropy.\n\n\nFor positive constants and valid domains, exponent and log rules simplify expressions before a calculator is needed. For example, e^(−ln 2) = 1/2. Use natural ln for the loss formulas, not the calculator's base-10 log.\n\n### Derivatives used in neural networks\n\nThe minus sign in the first expression comes from differentiating the inner function −z. Applying the chain rule correctly here gives the sigmoid derivative derived in the activation section.\n\n### Brief integration and trigonometry reminder\nIntegration reverses differentiation up to an additive constant. The basic relevant identities are:\n\n\nFor angles in radians, d(sin x)/dx = cos x and d(cos x)/dx = −sin x. The identity sin²x + cos²x = 1 concerns ordinary trigonometric functions. Hyperbolic tanh is a different function; using tan instead of tanh gives an incorrect recurrent-network answer.\n\nThe supplied MT2 calculation families mainly require derivatives, matrix products, logarithms and elementary statistics. Extended integration or trigonometric exercises are not needed for those families.\n\n### Calculator values for activation calculations\nAt z = 2, sigmoid = 1/(1 + e⁻²) ≈ 0.880797. At z = 1, tanh ≈ 0.761594. Keep unrounded values when a later gradient uses these activations.\n"},{"title":"Calculator routine","blocks":["<p>You reported a Casio ES-series calculator. The exact model string is not confirmed. The functions below are mathematical entries; use the keys labelled on your model. On fx-991 ES/fx-991 ES PLUS models, eˣ is normally the SHIFT function of ln. Do not confuse eˣ with the × 10ˣ scientific-notation key. Use the function labels on your own calculator for these entries.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_calculator.svg\" aria-label=\"Enlarge diagram: Calculate the exponential, build the full denominator, then take its reciprocal.\"><img src=\"assets/figures/v_calculator.svg\" alt=\"Calculate the exponential, build the full denominator, then take its reciprocal.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Calculate the exponential, build the full denominator, then take its reciprocal. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>1. Use ordinary computation mode. Enter complete brackets around a denominator or negative exponent.</p>","<p>2. For sigmoid at z = 2, enter 1 ÷ (1 + e^(−2)). Result: 0.880797078. Keep the full calculator value; write about six decimals during intermediate work.</p>","<p>3. For tanh at z = 1, use the hyperbolic tanh function if available. A universal alternative is (e² − 1) ÷ (e² + 1), giving 0.761594156. Ordinary tan is a different function; do not use it.</p>","<p>4. For cross-entropy with true probability 0.8, enter −ln(0.8), giving 0.223143551.</p>","<p>5. For softmax [2.3, 4.5, 3.2], subtract 4.5 first, then calculate e⁻²·², 1, e⁻¹·³. Add them, then divide each exponential by the same total.</p>","<p>6. If a result displays as a fraction, use your model’s fraction/decimal conversion key, often S⇔D. Do not reset the calculator unnecessarily.</p>","<p><strong>Five-minute warm-up: </strong> compute sigmoid(0) = 0.5; sigmoid(−2) ≈ 0.119203; tanh(0) = 0; −ln(0.5) ≈ 0.693147; √0.25 = 0.5. A different result signals an entry mistake, not a reason to memorize a wrong value.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s7","search":"Calculator routine You reported a Casio ES-series calculator. The exact model string is not confirmed. The functions below are mathematical entries; use the keys labelled on your model. On fx-991 ES/fx-991 ES PLUS models, eˣ is normally the SHIFT function of ln. Do not confuse eˣ with the × 10ˣ scientific-notation key. Use the function labels on your own calculator for these entries.\n\n\n\n1. Use ordinary computation mode. Enter complete brackets around a denominator or negative exponent.\n2. For sigmoid at z = 2, enter 1 ÷ (1 + e^(−2)). Result: 0.880797078. Keep the full calculator value; write about six decimals during intermediate work.\n3. For tanh at z = 1, use the hyperbolic tanh function if available. A universal alternative is (e² − 1) ÷ (e² + 1), giving 0.761594156. Ordinary tan is a different function; do not use it.\n4. For cross-entropy with true probability 0.8, enter −ln(0.8), giving 0.223143551.\n5. For softmax [2.3, 4.5, 3.2], subtract 4.5 first, then calculate e⁻²·², 1, e⁻¹·³. Add them, then divide each exponential by the same total.\n6. If a result displays as a fraction, use your model’s fraction/decimal conversion key, often S⇔D. Do not reset the calculator unnecessarily.\n**Five-minute warm-up: ** compute sigmoid(0) = 0.5; sigmoid(−2) ≈ 0.119203; tanh(0) = 0; −ln(0.5) ≈ 0.693147; √0.25 = 0.5. A different result signals an entry mistake, not a reason to memorize a wrong value."},{"title":"A complete arithmetic calculation","blocks":["<p>Evaluate 0.4 − 0.1 × (−2). The multiplication has priority over the subtraction.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_arithmetic.svg\" aria-label=\"Enlarge diagram: The negative product stays in brackets until the final subtraction is simplified.\"><img src=\"assets/figures/v_arithmetic.svg\" alt=\"The negative product stays in brackets until the final subtraction is simplified.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The negative product stays in brackets until the final subtraction is simplified. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1:</strong> multiply 0.1 by −2, giving −0.2.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> substitute that entire result, including its sign: 0.4 − (−0.2).</p>","<p class=\"worked-step\"><strong>Step 3:</strong> subtracting a negative means adding its positive value: 0.4 + 0.2 = 0.6.</p>","<p>The answer is <strong>0.6</strong>. This calculation will later appear inside a weight update; the arithmetic is exactly the same.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s8","search":"A complete arithmetic calculation Evaluate 0.4 − 0.1 × (−2). The multiplication has priority over the subtraction.\n\n\n\n**Step 1:** multiply 0.1 by −2, giving −0.2.\n**Step 2:** substitute that entire result, including its sign: 0.4 − (−0.2).\n**Step 3:** subtracting a negative means adding its positive value: 0.4 + 0.2 = 0.6.\nThe answer is **0.6**. This calculation will later appear inside a weight update; the arithmetic is exactly the same.\n"},{"title":"Loss: how one wrong prediction becomes a number","blocks":["<p class=\"definition\"><strong>Definition.</strong> A residual is the signed prediction error. Squared-error objectives aggregate squared residuals; their scaling convention changes both the reported loss and its derivative.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.10px;--narrow-height:275.76px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ae0cc9bf3a93ca00.svg\"><img class=\"math display-math\" src=\"assets/equations/9e6b354fa6fa3c49.svg\" alt=\"e_i=\\hat y_i-y_i,\\qquad \\mathrm{SSE}=\\sum_{i=1}^{n}e_i^2,\\qquad L_{\\mathrm{half}}=\\frac12\\sum_{i=1}^{n}e_i^2,\\qquad \\mathrm{MSE}=\\frac1n\\sum_{i=1}^{n}e_i^2\" width=\"784.05\" height=\"68.62\" style=\"width:784.05px;height:68.62px;aspect-ratio:784.05/68.62\" loading=\"lazy\"></picture></div>","<p>For this definition of n, each i indexes one included scalar prediction. In a multi-output batch, state whether the mean is over examples, output coordinates, or both. Half SSE and MSE happen to agree when n = 2; they are not generally the same objective.</p>","<h3>Derivatives and their scaling</h3>","<p>When differentiating with respect to prediction j, all other prediction terms are constant. The derivative of the j-th square is twice its residual:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:155.75px;--narrow-height:209.30px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3476c309d4e1d90b.svg\"><img class=\"math display-math\" src=\"assets/equations/972f5a96b91fe930.svg\" alt=\"\\frac{\\partial\\mathrm{SSE}}{\\partial\\hat y_j}=2e_j,\\qquad \\frac{\\partial L_{\\mathrm{half}}}{\\partial\\hat y_j}=e_j,\\qquad \\frac{\\partial\\mathrm{MSE}}{\\partial\\hat y_j}=\\frac{2}{n}e_j\" width=\"534.78\" height=\"59.99\" style=\"width:534.78px;height:59.99px;aspect-ratio:534.78/59.99\" loading=\"lazy\"></picture></div>","<p>The factor 1/2 cancels the derivative&#x27;s factor 2. The factor 1/n instead produces 2/n. A weight derivative must also multiply by the derivative of the prediction with respect to that weight.</p>","<p class=\"inline-question\"><strong>Question. Predictions are [0.2, 0.7, 0.4] and targets are [0, 1, 1]. Find SSE, half SSE and MSE, then their gradients with respect to the prediction vector.</strong></p>","<h3>Given</h3>","<p>Predictions = [0.2,0.7,0.4].</p>","<p>Targets = [0,1,1]; n = 3 scalar predictions.</p>","<h3>To find</h3>","<p>Find SSE, half SSE and MSE, then all three prediction-gradient lists.</p>","<h3>Formula — which one and why</h3>","<p><strong>Squared-error objectives.</strong> Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.</p>","<p>ŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle error square; phir question ke hisaab se sum, half ya mean.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the three signed prediction errors.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:300.06px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/23245cd97ea478bc.svg\"><img class=\"math display-math\" src=\"assets/equations/27a2e2729d22f591.svg\" alt=\"e=[0.2-0,\\ 0.7-1,\\ 0.4-1]=[0.2,-0.3,-0.6]\" width=\"511.05\" height=\"24.43\" style=\"width:511.05px;height:24.43px;aspect-ratio:511.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: square every error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fddc4677249bcbb.svg\" alt=\"e\\odot e=[0.04,0.09,0.36]\" width=\"250.87\" height=\"24.43\" style=\"width:250.87px;height:24.43px;aspect-ratio:250.87/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the three squared errors.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4890329b3b657194.svg\"><img class=\"math display-math\" src=\"assets/equations/36128683498bbba3.svg\" alt=\"\\mathrm{SSE}=0.04+0.09+0.36=0.49\" width=\"342.50\" height=\"19.23\" style=\"width:342.50px;height:19.23px;aspect-ratio:342.50/19.23\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: apply the requested loss divisors.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.96px;--narrow-height:153.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/98422634bd86c12f.svg\"><img class=\"math display-math\" src=\"assets/equations/0add52f0daedefdc.svg\" alt=\"L_{\\mathrm{half}}=\\frac{0.49}{2}=0.245,\\qquad \\mathrm{MSE}=\\frac{0.49}{3}\\approx0.163333333\" width=\"583.87\" height=\"50.36\" style=\"width:583.87px;height:50.36px;aspect-ratio:583.87/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: multiply every error by 2 for the SSE gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fec22e50bd202c79.svg\" alt=\"\\nabla_{\\hat y}\\mathrm{SSE}=[0.4,-0.6,-1.2]\" width=\"274.27\" height=\"27.23\" style=\"width:274.27px;height:27.23px;aspect-ratio:274.27/27.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: use each error itself for the half-SSE gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dfa71d7fa81c823c.svg\" alt=\"\\nabla_{\\hat y}L_{\\mathrm{half}}=[0.2,-0.3,-0.6]\" width=\"278.60\" height=\"27.23\" style=\"width:278.60px;height:27.23px;aspect-ratio:278.60/27.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: multiply every error by 2/3 for the MSE gradient.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:297.33px;--narrow-height:131.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a584bba4763cda9f.svg\"><img class=\"math display-math\" src=\"assets/equations/661d59f4a5205fa6.svg\" alt=\"\\nabla_{\\hat y}\\mathrm{MSE}=\\frac23[0.2,-0.3,-0.6]=[0.133333333,-0.2,-0.4]\" width=\"603.39\" height=\"50.09\" style=\"width:603.39px;height:50.09px;aspect-ratio:603.39/50.09\" loading=\"lazy\"></picture></div>","<p>The residual signs survive in the gradients even though the losses are nonnegative. Multiplying a loss by a positive constant leaves its unregularized minimizers unchanged, but scales its gradients and therefore its updates at a fixed learning rate.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c2-s9","search":"Loss: how one wrong prediction becomes a number \n**Definition.** A residual is the signed prediction error. Squared-error objectives aggregate squared residuals; their scaling convention changes both the reported loss and its derivative.\n\nFor this definition of n, each i indexes one included scalar prediction. In a multi-output batch, state whether the mean is over examples, output coordinates, or both. Half SSE and MSE happen to agree when n = 2; they are not generally the same objective.\n\n### Derivatives and their scaling\nWhen differentiating with respect to prediction j, all other prediction terms are constant. The derivative of the j-th square is twice its residual:\n\nThe factor 1/2 cancels the derivative's factor 2. The factor 1/n instead produces 2/n. A weight derivative must also multiply by the derivative of the prediction with respect to that weight.\n\n**Question. Predictions are [0.2, 0.7, 0.4] and targets are [0, 1, 1]. Find SSE, half SSE and MSE, then their gradients with respect to the prediction vector.**\n\n\n\n### Given\n\nPredictions = [0.2,0.7,0.4].\n\nTargets = [0,1,1]; n = 3 scalar predictions.\n\n### To find\n\nFind SSE, half SSE and MSE, then all three prediction-gradient lists.\n\n### Formula — which one and why\n\n**Squared-error objectives.** Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.\n\nŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle error square; phir question ke hisaab se sum, half ya mean.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: calculate the three signed prediction errors.**\n\n\n**Step 2: square every error.**\n\n\n**Step 3: add the three squared errors.**\n\n\n**Step 4: apply the requested loss divisors.**\n\n\n**Step 5: multiply every error by 2 for the SSE gradient.**\n\n\n**Step 6: use each error itself for the half-SSE gradient.**\n\n\n**Step 7: multiply every error by 2/3 for the MSE gradient.**\n\n\nThe residual signs survive in the gradients even though the losses are nonnegative. Multiplying a loss by a positive constant leaves its unregularized minimizers unchanged, but scales its gradients and therefore its updates at a fixed learning rate.\n\n"}]},{"n":3,"title":"The maths behind a network","sections":[{"title":"A vector is a list and a matrix is a table","blocks":["<p>The input [2, 3] is a vector containing two features. A matrix is a rectangle of numbers. “2 by 3” means two rows and three columns. A column vector with two entries has shape 2 by 1. Always write rows before columns.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_matrix.svg\" aria-label=\"Enlarge diagram: Count rows downward and columns across. The shape describes the arrangement of entries.\"><img src=\"assets/figures/v_matrix.svg\" alt=\"Count rows downward and columns across. The shape describes the arrangement of entries.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>Count rows downward and columns across. The shape describes the arrangement of entries. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>In this course, unless a question’s diagram explicitly uses another convention, <strong>each row of a weight matrix belongs to one receiving neuron</strong>. Thus W has shape number of output neurons by number of input features, and the input is a column vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5226c7a9750fc29a.svg\" alt=\"W=\\begin{bmatrix}0.11&amp;0.21\\\\0.12&amp;0.08\\end{bmatrix},\\quad x=\\begin{bmatrix}2\\\\3\\end{bmatrix},\\quad Wx=\\begin{bmatrix}0.11(2)+0.21(3)\\\\0.12(2)+0.08(3)\\end{bmatrix}=\\begin{bmatrix}0.85\\\\0.48\\end{bmatrix}\" width=\"729.52\" height=\"58.64\" style=\"width:729.52px;height:58.64px;aspect-ratio:729.52/58.64\" loading=\"lazy\"></div>","<p><strong>Do it slowly: </strong> row 1 says 0.11 × 2 = 0.22 and 0.21 × 3 = 0.63, so its answer is 0.85. Row 2 says 0.12 × 2 = 0.24 and 0.08 × 3 = 0.24, so its answer is 0.48. Matrix multiplication is several weighted sums written together.</p>","<p><strong>Shape check: </strong> (2 by 2) × (2 by 1) gives (2 by 1). The inside numbers must match; the outside numbers are the answer shape. This check catches many transposed-weight errors before arithmetic begins.</p>","<p>Transpose swaps rows and columns. Elementwise multiplication does not do row-by-column sums: [2, 3] ⊙ [4, 5] = [8, 15]. Dot product does add: [2, 3] · [4, 5] = 8 + 15 = 23. LSTM gates use elementwise multiplication, not a dot product.</p>","<p><strong>Practice.</strong> Multiply W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/af9cca7044f770c7.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\3 &amp; 4\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> by x = [2, 1] as a column. Answer: first row 1 × 2 + 2 × 1 = 4; second row 3 × 2 + 4 × 1 = 10. With b = [1, −1], Wx + b = [5, 9].</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s0","search":"A vector is a list and a matrix is a table The input [2, 3] is a vector containing two features. A matrix is a rectangle of numbers. “2 by 3” means two rows and three columns. A column vector with two entries has shape 2 by 1. Always write rows before columns.\n\n\n\nIn this book, unless a question’s diagram explicitly uses another convention, **each row of a weight matrix belongs to one receiving neuron**. Thus W has shape number of output neurons by number of input features, and the input is a column vector.\n\n**Do it slowly: ** row 1 says 0.11 × 2 = 0.22 and 0.21 × 3 = 0.63, so its answer is 0.85. Row 2 says 0.12 × 2 = 0.24 and 0.08 × 3 = 0.24, so its answer is 0.48. Matrix multiplication is several weighted sums written together.\n**Shape check: ** (2 by 2) × (2 by 1) gives (2 by 1). The inside numbers must match; the outside numbers are the answer shape. This check catches many transposed-weight errors before arithmetic begins.\nTranspose swaps rows and columns. Elementwise multiplication does not do row-by-column sums: [2, 3] ⊙ [4, 5] = [8, 15]. Dot product does add: [2, 3] · [4, 5] = 8 + 15 = 23. LSTM gates use elementwise multiplication, not a dot product.\n**Practice.** Multiply W =  by x = [2, 1] as a column. Answer: first row 1 × 2 + 2 × 1 = 4; second row 3 × 2 + 4 × 1 = 10. With b = [1, −1], Wx + b = [5, 9]."},{"title":"Matrix multiplication: every row has a job","blocks":["<h3>Row, column, vector and matrix — read these first</h3>","<p>A <strong>row</strong> runs horizontally, from left to right. A <strong>column</strong> runs vertically, from top to bottom. A <strong>matrix</strong> is a rectangular arrangement of numbers in rows and columns. Its size is written rows × columns. A 2 × 3 matrix therefore has two rows and three columns, not six rows.</p>","<p>A <strong>vector</strong> is an ordered list of numbers. Written horizontally it is a row vector, such as [2, 1, 3]. Written vertically it is a column vector. Neural-network equations in these notes usually use column vectors.</p>","<h3>Transpose: rows become columns</h3>","<p>The superscript T means <strong>transpose</strong>, not a power. To obtain Aᵀ, copy row 1 of A as column 1, row 2 as column 2, and so on. Do not reverse the order within a row, change a sign or multiply anything. An m × n matrix becomes n × m.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p>The two indices are positions: i identifies a row and j a column. The rule says “swap the row and column addresses”. For example, the value at row 1, column 3 moves to row 3, column 1.</p>","<p><strong>Yaad rakhne ka cue:</strong> transpose = row ko column bana; number aur sign ko haath mat laga.</p>","<h3>Transpose example 1</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f5189f9c2294a43.svg\" alt=\"A=\\begin{bmatrix}2&amp;1&amp;3\\end{bmatrix}\" width=\"150.01\" height=\"24.43\" style=\"width:150.01px;height:24.43px;aspect-ratio:150.01/24.43\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 1 row(s) and 3 column(s), so its size is 1 × 3.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [2, 1, 3] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dafe6e5e80b48abd.svg\" alt=\"A^T=\\begin{bmatrix}2\\\\1\\\\3\\end{bmatrix}\" width=\"109.91\" height=\"92.85\" style=\"width:109.91px;height:92.85px;aspect-ratio:109.91/92.85\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: state its new size.</strong></p>","<p>The result has 3 row(s) and 1 column(s): 3 × 1.</p>","<p><strong>Final answer:</strong> Aᵀ has size 3 × 1. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 1 rows × 3 columns</div><table class=\"lv-matrix\" aria-label=\"A: 1 rows × 3 columns\"><caption>A: 1 rows × 3 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 3 rows × 1 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 3 rows × 1 columns\"><caption>Aᵀ: 3 rows × 1 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td></tr><tr><td class=\"lv-row-0\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Transpose example 2</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/19f2e9948f5cc39f.svg\" alt=\"A=\\begin{bmatrix}1&amp;2&amp;3\\\\4&amp;5&amp;6\\end{bmatrix}\" width=\"162.24\" height=\"58.64\" style=\"width:162.24px;height:58.64px;aspect-ratio:162.24/58.64\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 2 row(s) and 3 column(s), so its size is 2 × 3.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [1, 2, 3] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: move original row 2 into new column 2.</strong></p>","<p>Copy [4, 5, 6] down column 2, in the same order.</p>","<p class=\"worked-step\"><strong>Step 4: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78bde861f7b64a93.svg\" alt=\"A^T=\\begin{bmatrix}1&amp;4\\\\2&amp;5\\\\3&amp;6\\end{bmatrix}\" width=\"146.57\" height=\"92.85\" style=\"width:146.57px;height:92.85px;aspect-ratio:146.57/92.85\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: state its new size.</strong></p>","<p>The result has 3 row(s) and 2 column(s): 3 × 2.</p>","<p><strong>Final answer:</strong> Aᵀ has size 3 × 2. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 2 rows × 3 columns</div><table class=\"lv-matrix\" aria-label=\"A: 2 rows × 3 columns\"><caption>A: 2 rows × 3 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 3\">3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 5\">5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 3 rows × 2 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 3 rows × 2 columns\"><caption>Aᵀ: 3 rows × 2 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 4\">4</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 5\">5</td></tr><tr><td class=\"lv-row-0\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-1\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 6\">6</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Transpose example 3</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ffb51554b200bfc3.svg\" alt=\"A=\\begin{bmatrix}1&amp;-2\\\\0&amp;3\\end{bmatrix}\" width=\"144.59\" height=\"58.64\" style=\"width:144.59px;height:58.64px;aspect-ratio:144.59/58.64\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 2 row(s) and 2 column(s), so its size is 2 × 2.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [1, -2] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: move original row 2 into new column 2.</strong></p>","<p>Copy [0, 3] down column 2, in the same order.</p>","<p class=\"worked-step\"><strong>Step 4: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3f6121853d314156.svg\" alt=\"A^T=\\begin{bmatrix}1&amp;0\\\\-2&amp;3\\end{bmatrix}\" width=\"158.78\" height=\"58.64\" style=\"width:158.78px;height:58.64px;aspect-ratio:158.78/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: state its new size.</strong></p>","<p>The result has 2 row(s) and 2 column(s): 2 × 2.</p>","<p><strong>Final answer:</strong> Aᵀ has size 2 × 2. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 2 rows × 2 columns</div><table class=\"lv-matrix\" aria-label=\"A: 2 rows × 2 columns\"><caption>A: 2 rows × 2 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 2 rows × 2 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 2 rows × 2 columns\"><caption>Aᵀ: 2 rows × 2 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −2\">−2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Transpose example 4</h3>","<p class=\"inline-question\"><strong>Question. Find the transpose of the following matrix A and state the size of both matrices.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b21656f3402af964.svg\" alt=\"A=\\begin{bmatrix}-1\\\\4\\\\2\\end{bmatrix}\" width=\"114.73\" height=\"92.85\" style=\"width:114.73px;height:92.85px;aspect-ratio:114.73/92.85\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>Aᵀ and both matrix sizes.</p>","<h3>Formula — which one and why</h3>","<p>A transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.</p>","<p>A is the original matrix; Aᵀ is its transpose; i and j are row/column positions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07cc0861475dad67.svg\" alt=\"[A^T]_{ij}=A_{ji}\" width=\"127.22\" height=\"28.98\" style=\"width:127.22px;height:28.98px;aspect-ratio:127.22/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Row seedha column mein; double transpose se original wapas.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the original size.</strong></p>","<p>A has 3 row(s) and 1 column(s), so its size is 3 × 1.</p>","<p class=\"worked-step\"><strong>Step 2: move original row 1 into new column 1.</strong></p>","<p>Copy [-1] down column 1, in the same order.</p>","<p class=\"worked-step\"><strong>Step 3: move original row 2 into new column 2.</strong></p>","<p>Copy [4] down column 2, in the same order.</p>","<p class=\"worked-step\"><strong>Step 4: move original row 3 into new column 3.</strong></p>","<p>Copy [2] down column 3, in the same order.</p>","<p class=\"worked-step\"><strong>Step 5: write the transposed matrix.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5b69eb45dcd67397.svg\" alt=\"A^T=\\begin{bmatrix}-1&amp;4&amp;2\\end{bmatrix}\" width=\"183.22\" height=\"27.90\" style=\"width:183.22px;height:27.90px;aspect-ratio:183.22/27.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: state its new size.</strong></p>","<p>The result has 1 row(s) and 3 column(s): 1 × 3.</p>","<p><strong>Final answer:</strong> Aᵀ has size 1 × 3. Transposing it again gives the original A.</p>","<figure class=\"learning-visual lv-transpose\" data-visual=\"transpose\"><figcaption class=\"lv-title\">Transpose: follow the same numbers from a row into a column</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">A: 3 rows × 1 columns</div><table class=\"lv-matrix\" aria-label=\"A: 3 rows × 1 columns\"><caption>A: 3 rows × 1 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Read each colored row left to right.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Aᵀ: 1 rows × 3 columns</div><table class=\"lv-matrix\" aria-label=\"Aᵀ: 1 rows × 3 columns\"><caption>Aᵀ: 1 rows × 3 columns</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: −1\">−1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 4\">4</td><td class=\"lv-row-2\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each original row is now the matching colored column.</p></div></div><p class=\"lv-caption\">The entry at row i, column j moves to row j, column i. Its value and sign do not change.</p></figure>","<h3>Dot product: multiply matching entries, then add</h3>","<p>A <strong>dot product</strong> turns two equally long lists into one number. Match first with first, second with second, and so on. It is the weighted sum inside a neuron. If both lists are columns, wᵀ turns the weight column into a row so row × column is allowed.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:213.73px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/97799e8f51bd1031.svg\"><img class=\"math display-math\" src=\"assets/equations/ccb1c24c2967c1fa.svg\" alt=\"w^Tx=w_1x_1+w_2x_2+w_3x_3\" width=\"296.41\" height=\"25.83\" style=\"width:296.41px;height:25.83px;aspect-ratio:296.41/25.83\" loading=\"lazy\"></picture></div>","<p>This formula is the three-input case. With two inputs there are only two products; with d inputs there are d products. A bias is an additional term, added after these products.</p>","<h3>Dot-product example 1</h3>","<p class=\"inline-question\"><strong>Question. For w = [2, 3] and x = [4, 1], calculate wᵀx.</strong></p>","<h3>Given</h3>","<p>Weights w = [2, 3].</p>","<p>Matching inputs x = [4, 1].</p>","<p>Both lists contain 2 numbers.</p>","<h3>To find</h3>","<p>One scalar value wᵀx.</p>","<h3>Formula — which one and why</h3>","<p>A dot product is a sum of matching products. There is no bias in this question.</p>","<p>Σ means add; the index i visits each matching pair.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce95abc5189aaf50.svg\" alt=\"w^Tx=\\sum_i w_ix_i\" width=\"165.06\" height=\"52.35\" style=\"width:165.06px;height:52.35px;aspect-ratio:165.06/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position multiply; sab products add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching pair 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb39ee363580ed9c.svg\" alt=\"(2)(4)=8\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply matching pair 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9934bcd789a00e7d.svg\" alt=\"(3)(1)=3\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b366d83f24fd5dd.svg\" alt=\"w^Tx=(8)+(3)=11\" width=\"227.59\" height=\"27.90\" style=\"width:227.59px;height:27.90px;aspect-ratio:227.59/27.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> wᵀx = 11.</p>","<h3>Dot-product example 2</h3>","<p class=\"inline-question\"><strong>Question. For w = [1, -2] and x = [2, 3], calculate wᵀx.</strong></p>","<h3>Given</h3>","<p>Weights w = [1, -2].</p>","<p>Matching inputs x = [2, 3].</p>","<p>Both lists contain 2 numbers.</p>","<h3>To find</h3>","<p>One scalar value wᵀx.</p>","<h3>Formula — which one and why</h3>","<p>A dot product is a sum of matching products. There is no bias in this question.</p>","<p>Σ means add; the index i visits each matching pair.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce95abc5189aaf50.svg\" alt=\"w^Tx=\\sum_i w_ix_i\" width=\"165.06\" height=\"52.35\" style=\"width:165.06px;height:52.35px;aspect-ratio:165.06/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position multiply; sab products add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching pair 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7259499711e389d2.svg\" alt=\"(1)(2)=2\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply matching pair 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02560299473dc26e.svg\" alt=\"(-2)(3)=-6\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/368a39aeec6c928d.svg\" alt=\"w^Tx=(2)+(-6)=-4\" width=\"253.39\" height=\"27.90\" style=\"width:253.39px;height:27.90px;aspect-ratio:253.39/27.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> wᵀx = -4.</p>","<h3>Dot-product example 3</h3>","<p class=\"inline-question\"><strong>Question. For w = [0.5, 1, -1] and x = [4, 2, 3], calculate wᵀx.</strong></p>","<h3>Given</h3>","<p>Weights w = [0.5, 1, -1].</p>","<p>Matching inputs x = [4, 2, 3].</p>","<p>Both lists contain 3 numbers.</p>","<h3>To find</h3>","<p>One scalar value wᵀx.</p>","<h3>Formula — which one and why</h3>","<p>A dot product is a sum of matching products. There is no bias in this question.</p>","<p>Σ means add; the index i visits each matching pair.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce95abc5189aaf50.svg\" alt=\"w^Tx=\\sum_i w_ix_i\" width=\"165.06\" height=\"52.35\" style=\"width:165.06px;height:52.35px;aspect-ratio:165.06/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position multiply; sab products add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching pair 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3430445c8f6a121.svg\" alt=\"(0.5)(4)=2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply matching pair 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7259499711e389d2.svg\" alt=\"(1)(2)=2\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply matching pair 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c5d478557eb834e1.svg\" alt=\"(-1)(3)=-3\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the products.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.68px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bf7dc79763479e35.svg\"><img class=\"math display-math\" src=\"assets/equations/b85e0c042b7b8396.svg\" alt=\"w^Tx=(2)+(2)+(-3)=1\" width=\"295.48\" height=\"27.90\" style=\"width:295.48px;height:27.90px;aspect-ratio:295.48/27.90\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> wᵀx = 1.</p>","<h3>Matrix multiplication: each row makes one output</h3>","<p>To multiply A of size m × n by B of size n × p, the inner sizes n must match. The result has size m × p. Output entry (i,j) is row i of A dotted with column j of B.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d566b516b84686ee.svg\" alt=\"C_{ij}=\\sum_{k=1}^{n}A_{ik}B_{kj}\" width=\"176.53\" height=\"69.11\" style=\"width:176.53px;height:69.11px;aspect-ratio:176.53/69.11\" loading=\"lazy\"></div>","<p>For a layer receiving two inputs and producing two neuron outputs, W is 2 × 2, x is 2 × 1 and Wx is 2 × 1. Each row of W holds all weights entering one receiving neuron. Its matching bias is added once.</p>","<p><strong>Yaad rakhne ka cue:</strong> multiplication mein andar ke sizes match; answer ka size bahar ke sizes. Har output = ek row × ek column.</p>","<p class=\"definition\"><strong>Definition.</strong> A vector is an ordered collection of scalars; a matrix represents a linear transformation between vector spaces. A neural-network layer combines a linear transformation with an additive bias, giving an affine transformation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28b5d89094e7d00d.svg\" alt=\"z=Wx+b\" width=\"123.89\" height=\"18.96\" style=\"width:123.89px;height:18.96px;aspect-ratio:123.89/18.96\" loading=\"lazy\"></div>","<p>For d input features and m receiving neurons, the dimensions are:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:119.53px;--narrow-height:113.41px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fb325b4580ff43a.svg\"><img class=\"math display-math\" src=\"assets/equations/a38b418b5411afa4.svg\" alt=\"W\\in\\mathbb R^{m\\times d},\\quad x\\in\\mathbb R^{d\\times1},\\quad b,z\\in\\mathbb R^{m\\times1}\" width=\"397.43\" height=\"26.83\" style=\"width:397.43px;height:26.83px;aspect-ratio:397.43/26.83\" loading=\"lazy\"></picture></div>","<p>The inner dimensions must match. Output component j is the dot product of row j of W with x, plus bias bⱼ. Wᵀ reverses the matrix dimensions. The Hadamard product u⊙v multiplies corresponding components and is different from a matrix product.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_matrix.svg\" aria-label=\"Enlarge diagram: Each row of the weight matrix calculates one receiving neuron&#x27;s preactivation.\"><img src=\"assets/figures/v_matrix.svg\" alt=\"Each row of the weight matrix calculates one receiving neuron&#x27;s preactivation.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>Each row of the weight matrix calculates one receiving neuron&#x27;s preactivation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Given W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/aad1d6a46cb2c7f1.svg\" alt=\"\\begin{bmatrix}1 &amp; -2\\\\0.5 &amp; 3\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>, x = [2, 1]ᵀ and b = [0.1, −0.2]ᵀ, calculate z = Wx + b.</p>","<h3>Given</h3>","<p>Weights W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/aad1d6a46cb2c7f1.svg\" alt=\"\\begin{bmatrix}1 &amp; -2\\\\0.5 &amp; 3\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>.</p>","<p>Input column x = [2,1]ᵀ; bias column b = [0.1,−0.2]ᵀ.</p>","<h3>To find</h3>","<p>Find both components of z = Wx+b.</p>","<h3>Formula — which one and why</h3>","<p><strong>Row–column multiplication.</strong> Each receiving neuron uses one weight row. Multiply that row by the input column, add the products, then add that neuron’s bias.</p>","<p>Wⱼᵢ = weight from input i to receiver j; xᵢ = input i; bⱼ = bias of receiver j; zⱼ = its preactivation. A superscript T means transpose: exchange rows and columns.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc40cdac8ad4c81c.svg\" alt=\"z_j=\\sum_i W_{ji}x_i+b_j\" width=\"202.09\" height=\"52.35\" style=\"width:202.09px;height:52.35px;aspect-ratio:202.09/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek row × poora input column = ek receiving neuron ka answer.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: verify compatible dimensions.</strong></p>","<p>W has 2 rows and 2 columns; x has 2 rows and 1 column. The inner dimensions match, and the result has 2 rows and 1 column.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the first receiving row products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07ce1f7a3ced3979.svg\" alt=\"1(2)=2\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28ad4ad477ec80b7.svg\" alt=\"(-2)(1)=-2\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: sum row 1 and add its bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6eacd9d3a609cc.svg\" alt=\"z_1=2+(-2)+0.1=0.1\" width=\"271.85\" height=\"24.43\" style=\"width:271.85px;height:24.43px;aspect-ratio:271.85/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: calculate the second receiving row products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4b945ff5abf26e2.svg\" alt=\"0.5(2)=1\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/464c4958d256b6c8.svg\" alt=\"3(1)=3\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: sum row 2 and add its bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b340e43d0e100bc4.svg\" alt=\"z_2=1+3-0.2=3.8\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.39px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/133f56723bb2a1d8.svg\"><img class=\"math display-math\" src=\"assets/equations/2f3707d9acaff1b9.svg\" alt=\"z_1=1(2)+(-2)(1)+0.1=0.1\" width=\"334.30\" height=\"24.43\" style=\"width:334.30px;height:24.43px;aspect-ratio:334.30/24.43\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-matrix-row\" data-visual=\"matrix-row\"><figcaption class=\"lv-title\">Row 1 produces output component z1</figcaption><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select weight row 1</div><table class=\"lv-matrix\" aria-label=\"1. Select weight row 1\"><caption>1. Select weight row 1</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Use the entire input column</div><table class=\"lv-matrix\" aria-label=\"2. Use the entire input column\"><caption>2. Use the entire input column</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td></tr><tr><td class=\"lv-row-0\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Match and multiply</div><table class=\"lv-matrix\" aria-label=\"3. Match and multiply\"><caption>3. Match and multiply</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr></tbody></table><p class=\"lv-matrix-note\">First × first; second × second.</p></div></div><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sum the products</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias for this row</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">z1</span><strong class=\"lv-value\">0.1</strong></div></div><p class=\"lv-caption\">One receiving neuron corresponds to one row of W and one bias. The other weight row is not used for this component.</p></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.48px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dbd8ceb08ae05e33.svg\"><img class=\"math display-math\" src=\"assets/equations/73b17a005abd5aba.svg\" alt=\"z_2=0.5(2)+3(1)-0.2=3.8\" width=\"315.30\" height=\"24.43\" style=\"width:315.30px;height:24.43px;aspect-ratio:315.30/24.43\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-matrix-row\" data-visual=\"matrix-row\"><figcaption class=\"lv-title\">Row 2 produces output component z2</figcaption><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select weight row 2</div><table class=\"lv-matrix\" aria-label=\"1. Select weight row 2\"><caption>1. Select weight row 2</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Use the entire input column</div><table class=\"lv-matrix\" aria-label=\"2. Use the entire input column\"><caption>2. Use the entire input column</caption><tbody><tr><td class=\"lv-row-1\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Match and multiply</div><table class=\"lv-matrix\" aria-label=\"3. Match and multiply\"><caption>3. Match and multiply</caption><tbody><tr><td class=\"lv-row-1\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">First × first; second × second.</p></div></div><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sum the products</span><strong class=\"lv-value\">4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias for this row</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">z2</span><strong class=\"lv-value\">3.8</strong></div></div><p class=\"lv-caption\">One receiving neuron corresponds to one row of W and one bias. The other weight row is not used for this component.</p></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0bcbcaa175e8ffb8.svg\" alt=\"z=\\begin{bmatrix}0.1\\\\3.8\\end{bmatrix}\" width=\"100.98\" height=\"58.64\" style=\"width:100.98px;height:58.64px;aspect-ratio:100.98/58.64\" loading=\"lazy\"></div>","<p>An activation is applied afterward if the question asks for the layer output. In backpropagation, the input gradient uses Wᵀ because it maps derivatives from m outputs back to d inputs. For a single example, an outer product δxᵀ produces a weight-gradient matrix with exactly the same dimensions as W.</p>","<h3>Two output columns</h3>","<p class=\"inline-question\"><strong>Question. Multiply A = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/af9cca7044f770c7.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\3 &amp; 4\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> by B = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/969e894914a74419.svg\" alt=\"\\begin{bmatrix}2 &amp; 0\\\\1 &amp; 3\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Show all four output entries.</strong></p>","<h3>Given</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f32200eba37c0ea5.svg\" alt=\"A=\\begin{bmatrix}1&amp;2\\\\3&amp;4\\end{bmatrix}\" width=\"125.58\" height=\"58.64\" style=\"width:125.58px;height:58.64px;aspect-ratio:125.58/58.64\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d45fb6a21c1dc67e.svg\" alt=\"B=\\begin{bmatrix}2&amp;0\\\\1&amp;3\\end{bmatrix}\" width=\"125.80\" height=\"58.64\" style=\"width:125.80px;height:58.64px;aspect-ratio:125.80/58.64\" loading=\"lazy\"></div>","<h3>To find</h3>","<p>The 2 × 2 matrix C = AB.</p>","<h3>Formula — which one and why</h3>","<p>Matrix multiplication pairs one row of A with one column of B for each output. It is not entry-by-entry multiplication.</p>","<p>Cᵢⱼ is the entry in output row i, column j.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46672bbce5b57e87.svg\" alt=\"C_{ij}=\\sum_k A_{ik}B_{kj}\" width=\"176.53\" height=\"52.91\" style=\"width:176.53px;height:52.91px;aspect-ratio:176.53/52.91\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Output ki position dekho: wahi row, wahi column.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: check the dimensions.</strong></p>","<p>(2 × 2)(2 × 2) is valid; output size = 2 × 2.</p>","<p class=\"worked-step\"><strong>Step 2: row 1 with column 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/646952b8a744b648.svg\"><img class=\"math display-math\" src=\"assets/equations/d47e20af5264ff61.svg\" alt=\"C_{11}=1(2)+2(1)=2+2=4\" width=\"317.81\" height=\"24.43\" style=\"width:317.81px;height:24.43px;aspect-ratio:317.81/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: row 1 with column 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2d6dd50233caecfb.svg\"><img class=\"math display-math\" src=\"assets/equations/bf3f58226647b592.svg\" alt=\"C_{12}=1(0)+2(3)=0+6=6\" width=\"317.81\" height=\"24.43\" style=\"width:317.81px;height:24.43px;aspect-ratio:317.81/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: row 2 with column 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c49b369448ab5419.svg\"><img class=\"math display-math\" src=\"assets/equations/ef4f6c3c29a39671.svg\" alt=\"C_{21}=3(2)+4(1)=6+4=10\" width=\"330.03\" height=\"24.43\" style=\"width:330.03px;height:24.43px;aspect-ratio:330.03/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: row 2 with column 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b9ab897087e15f9b.svg\"><img class=\"math display-math\" src=\"assets/equations/c42e9c75451d67af.svg\" alt=\"C_{22}=3(0)+4(3)=0+12=12\" width=\"342.24\" height=\"24.43\" style=\"width:342.24px;height:24.43px;aspect-ratio:342.24/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: assemble the output by position.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/65427879b2654199.svg\" alt=\"C=\\begin{bmatrix}4&amp;6\\\\10&amp;12\\end{bmatrix}\" width=\"150.26\" height=\"58.64\" style=\"width:150.26px;height:58.64px;aspect-ratio:150.26/58.64\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> C = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/6f769fba9b2febe4.svg\" alt=\"\\begin{bmatrix}4 &amp; 6\\\\10 &amp; 12\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>, with size 2 × 2.</p>","<h3>Two products that must not be confused</h3>","<p class=\"inline-question\"><strong>Question. Let a = [2,3]ᵀ and b = [4,5]ᵀ. Find the entry-by-entry product a ⊙ b and the outer product abᵀ.</strong></p>","<h3>Given</h3>","<p>a and b are both 2 × 1 columns: a contains 2,3 and b contains 4,5.</p>","<h3>To find</h3>","<p>The 2 × 1 entry-by-entry product and the 2 × 2 outer product.</p>","<h3>Formula — which one and why</h3>","<p>⊙ multiplies corresponding positions; the outer product combines every value of a with every value of b. Backpropagation uses both operations for different reasons.</p>","<p>⊙ is called the Hadamard or elementwise product. bᵀ is a 1 × 2 row.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/696e2da1033ab6fa.svg\" alt=\"(a\\odot b)_i=a_i b_i\" width=\"152.25\" height=\"24.43\" style=\"width:152.25px;height:24.43px;aspect-ratio:152.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11b839db8ece52c1.svg\" alt=\"(ab^T)_{ij}=a_i b_j\" width=\"144.85\" height=\"28.98\" style=\"width:144.85px;height:28.98px;aspect-ratio:144.85/28.98\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> ⊙ mein same jagah; outer product mein har pair.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply matching entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c69bdb17e45bd1d3.svg\" alt=\"a\\odot b=\\begin{bmatrix}8\\\\15\\end{bmatrix}\" width=\"136.10\" height=\"58.64\" style=\"width:136.10px;height:58.64px;aspect-ratio:136.10/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: transpose b.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a491055be3cc3700.svg\" alt=\"b^T=\\begin{bmatrix}4&amp;5\\end{bmatrix}\" width=\"119.72\" height=\"27.90\" style=\"width:119.72px;height:27.90px;aspect-ratio:119.72/27.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: form row 1 of the outer product.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3e7e9d7e4e1bc080.svg\" alt=\"2(4)=8,\\qquad2(5)=10\" width=\"248.44\" height=\"24.43\" style=\"width:248.44px;height:24.43px;aspect-ratio:248.44/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: form row 2 of the outer product.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/399713a01b02cfa8.svg\" alt=\"3(4)=12,\\qquad3(5)=15\" width=\"260.66\" height=\"24.43\" style=\"width:260.66px;height:24.43px;aspect-ratio:260.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: write both rows.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b24f1f7b777962.svg\" alt=\"ab^T=\\begin{bmatrix}8&amp;10\\\\12&amp;15\\end{bmatrix}\" width=\"169.29\" height=\"58.64\" style=\"width:169.29px;height:58.64px;aspect-ratio:169.29/58.64\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Entry-by-entry result = [8,15]ᵀ. Outer product = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/db73fdbe57c2c901.svg\" alt=\"\\begin{bmatrix}8 &amp; 10\\\\12 &amp; 15\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s1","search":"Matrix multiplication: every row has a job ### Row, column, vector and matrix — read these first\nA **row** runs horizontally, from left to right. A **column** runs vertically, from top to bottom. A **matrix** is a rectangular arrangement of numbers in rows and columns. Its size is written rows × columns. A 2 × 3 matrix therefore has two rows and three columns, not six rows.\n\nA **vector** is an ordered list of numbers. Written horizontally it is a row vector, such as [2, 1, 3]. Written vertically it is a column vector. Neural-network equations in these notes usually use column vectors.\n\n### Transpose: rows become columns\nThe superscript T means **transpose**, not a power. To obtain Aᵀ, copy row 1 of A as column 1, row 2 as column 2, and so on. Do not reverse the order within a row, change a sign or multiply anything. An m × n matrix becomes n × m.\n\nThe two indices are positions: i identifies a row and j a column. The rule says “swap the row and column addresses”. For example, the value at row 1, column 3 moves to row 3, column 1.\n\n**Yaad rakhne ka cue:** transpose = row ko column bana; number aur sign ko haath mat laga.\n\n\n### Transpose example 1\n\n**Question. Find the transpose of the following matrix A and state the size of both matrices.**\n\n\n\n### Given\n\n\n\n\n\n\n\n### To find\n\nAᵀ and both matrix sizes.\n\n### Formula — which one and why\n\nA transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.\n\nA is the original matrix; Aᵀ is its transpose; i and j are row/column positions.\n\n\n\n**Yaad rakhne ka cue:** Row seedha column mein; double transpose se original wapas.\n\n### Solution — step by step\n\n\n\n**Step 1: write the original size.**\n\nA has 1 row(s) and 3 column(s), so its size is 1 × 3.\n\n**Step 2: move original row 1 into new column 1.**\n\nCopy [2, 1, 3] down column 1, in the same order.\n\n**Step 3: write the transposed matrix.**\n\n\n\n\n\n\n\n**Step 4: state its new size.**\n\nThe result has 3 row(s) and 1 column(s): 3 × 1.\n\n**Final answer:** Aᵀ has size 3 × 1. Transposing it again gives the original A.\n\n}]]\n\n\n\n### Transpose example 2\n\n**Question. Find the transpose of the following matrix A and state the size of both matrices.**\n\n\n\n### Given\n\n\n\n\n\n\n\n### To find\n\nAᵀ and both matrix sizes.\n\n### Formula — which one and why\n\nA transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.\n\nA is the original matrix; Aᵀ is its transpose; i and j are row/column positions.\n\n\n\n**Yaad rakhne ka cue:** Row seedha column mein; double transpose se original wapas.\n\n### Solution — step by step\n\n\n\n**Step 1: write the original size.**\n\nA has 2 row(s) and 3 column(s), so its size is 2 × 3.\n\n**Step 2: move original row 1 into new column 1.**\n\nCopy [1, 2, 3] down column 1, in the same order.\n\n**Step 3: move original row 2 into new column 2.**\n\nCopy [4, 5, 6] down column 2, in the same order.\n\n**Step 4: write the transposed matrix.**\n\n\n\n\n\n\n\n**Step 5: state its new size.**\n\nThe result has 3 row(s) and 2 column(s): 3 × 2.\n\n**Final answer:** Aᵀ has size 3 × 2. Transposing it again gives the original A.\n\n}]]\n\n\n\n### Transpose example 3\n\n**Question. Find the transpose of the following matrix A and state the size of both matrices.**\n\n\n\n### Given\n\n\n\n\n\n\n\n### To find\n\nAᵀ and both matrix sizes.\n\n### Formula — which one and why\n\nA transpose exchanges the row and column positions of every entry. It involves rearrangement, not multiplication.\n\nA is the original matrix; Aᵀ is its transpose;"},{"title":"A graph and a slope","blocks":["<p>A graph shows how one value changes with another. Put the weight w on the horizontal axis and the loss L on the vertical axis. A slope is change in height divided by change in horizontal position. If L rises by 6 when w rises by 2, the average slope is 3.</p>","<p>A derivative is the slope for an extremely small change at one location. A positive derivative says increasing the weight initially increases loss. A negative derivative says increasing the weight initially decreases loss. Gradient descent moves against that local slope. <strong>Gradient batata hai loss kis taraf badhega; hum ulte taraf chhota step lete hain.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aab6f621e9833b07.svg\" alt=\"L(w)=w^2,\\qquad \\frac{dL}{dw}=2w\" width=\"276.87\" height=\"50.50\" style=\"width:276.87px;height:50.50px;aspect-ratio:276.87/50.50\" loading=\"lazy\"></div>","<p>At w = 3, slope = 6. With learning rate 0.1, the update is 3 − 0.1 × 6 = 2.4. Loss falls from 9 to 5.76. At w = −3, slope = −6, so the update is −3 − 0.1 × (−6) = −2.4. Both moves approach zero.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gradient.svg\" aria-label=\"Enlarge diagram: A slope tells you the local direction of increasing loss\"><img src=\"assets/figures/gradient.svg\" alt=\"A slope tells you the local direction of increasing loss\" width=\"960\" height=\"390\" loading=\"lazy\"></button><figcaption>A slope tells you the local direction of increasing loss <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s2","search":"A graph and a slope A graph shows how one value changes with another. Put the weight w on the horizontal axis and the loss L on the vertical axis. A slope is change in height divided by change in horizontal position. If L rises by 6 when w rises by 2, the average slope is 3.\nA derivative is the slope for an extremely small change at one location. A positive derivative says increasing the weight initially increases loss. A negative derivative says increasing the weight initially decreases loss. Gradient descent moves against that local slope. **Gradient batata hai loss kis taraf badhega; hum ulte taraf chhota step lete hain.**\n\nAt w = 3, slope = 6. With learning rate 0.1, the update is 3 − 0.1 × 6 = 2.4. Loss falls from 9 to 5.76. At w = −3, slope = −6, so the update is −3 − 0.1 × (−6) = −2.4. Both moves approach zero.\n"},{"title":"Derivatives without a calculus course","blocks":["<p class=\"definition\"><strong>Definition.</strong> A derivative measures the local rate of change of a function. A partial derivative varies one argument while holding the others fixed. The gradient of a scalar-valued function collects its partial derivatives into a vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef6399f58ca20acf.svg\" alt=\"\\nabla_\\theta J=\\begin{bmatrix}\\partial J/\\partial\\theta_1\\\\\\vdots\\\\\\partial J/\\partial\\theta_d\\end{bmatrix}\" width=\"188.95\" height=\"106.29\" style=\"width:188.95px;height:106.29px;aspect-ratio:188.95/106.29\" loading=\"lazy\"></div>","<p>The rules needed for the supplied neural-network numericals are:</p>","<div class=\"table-scroll\"><table><thead><tr><th>Function or operation</th><th>Derivative</th></tr></thead><tbody><tr><td>Constant c</td><td>0</td></tr><tr><td>xⁿ</td><td>nxⁿ⁻¹</td></tr><tr><td>c f(x)</td><td>c f′(x)</td></tr><tr><td>f(x) + g(x)</td><td>f′(x) + g′(x)</td></tr><tr><td>f(x)g(x)</td><td>f′(x)g(x) + f(x)g′(x)</td></tr><tr><td>eˣ</td><td>eˣ</td></tr><tr><td>ln x, x &gt; 0</td><td>1/x</td></tr><tr><td>f(g(x))</td><td>f′(g(x))g′(x)</td></tr></tbody></table></div>","<h3>A parameter derivative is not an input derivative</h3>","<p>For z = wx + b, the variable named in the denominator determines which derivative is required.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:95.43px;--narrow-height:183.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8e90f73571d42f2e.svg\"><img class=\"math display-math\" src=\"assets/equations/b7574a6d14a06a47.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x,\\qquad\\frac{\\partial z}{\\partial x}=w,\\qquad\\frac{\\partial z}{\\partial b}=1\" width=\"377.48\" height=\"51.29\" style=\"width:377.48px;height:51.29px;aspect-ratio:377.48/51.29\" loading=\"lazy\"></picture></div>","<p>At x = 2, w = 3 and b = 1, z = 7, but the three derivatives are 2, 3 and 1 respectively. A function value and its derivative are distinct quantities.</p>","<h3>Gradient direction</h3>","<p>For a small parameter displacement Δθ, first-order Taylor expansion gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:186.14px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9060e5490f15d100.svg\"><img class=\"math display-math\" src=\"assets/equations/2f6a587716d3d081.svg\" alt=\"J(\\theta+\\Delta\\theta)\\approx J(\\theta)+\\nabla J(\\theta)^T\\Delta\\theta\" width=\"328.31\" height=\"27.90\" style=\"width:328.31px;height:27.90px;aspect-ratio:328.31/27.90\" loading=\"lazy\"></picture></div>","<p>The gradient points in the direction of greatest local increase under the Euclidean norm. Choosing Δθ opposite to the gradient gives a local descent direction. This is the mathematical basis of gradient descent; a finite step can still overshoot if the learning rate is too large.</p>","<h3>Differentiate before substituting: 3w^2+5</h3>","<p class=\"inline-question\"><strong>Question. Let J(w) = 3w^2+5. At w = 2, find J and dJ/dw.</strong></p>","<h3>Given</h3>","<p>J(w) = 3w^2+5; w = 2.</p>","<h3>To find</h3>","<p>The function value and its derivative value.</p>","<h3>Formula — which one and why</h3>","<p>The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.</p>","<p>c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/706ea9b2290fe843.svg\" alt=\"\\frac{d(cw^n+k)}{dw}=cnw^{n-1}\" width=\"235.33\" height=\"52.70\" style=\"width:235.33px;height:52.70px;aspect-ratio:235.33/52.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Power neeche multiply; exponent ek kam; constant ka zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the function itself.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b64892fad56f04e4.svg\" alt=\"J(2)=3(2)^2+5=17\" width=\"232.49\" height=\"27.70\" style=\"width:232.49px;height:27.70px;aspect-ratio:232.49/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate symbolically.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f98b439990365e5d.svg\" alt=\"J\\prime(w)=3(2)w^{2-1}+0\" width=\"227.05\" height=\"27.70\" style=\"width:227.05px;height:27.70px;aspect-ratio:227.05/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: put the given w into the derivative.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d4fbd4bd0e97e8fb.svg\" alt=\"J\\prime(2)=3(2)(2)^{1}=12\" width=\"228.36\" height=\"27.70\" style=\"width:228.36px;height:27.70px;aspect-ratio:228.36/27.70\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> J = 17; derivative = 12.</p>","<h3>Differentiate before substituting: 0.7w^3+0</h3>","<p class=\"inline-question\"><strong>Question. Let J(w) = 0.7w^3+0. At w = 1, find J and dJ/dw.</strong></p>","<h3>Given</h3>","<p>J(w) = 0.7w^3+0; w = 1.</p>","<h3>To find</h3>","<p>The function value and its derivative value.</p>","<h3>Formula — which one and why</h3>","<p>The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.</p>","<p>c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/706ea9b2290fe843.svg\" alt=\"\\frac{d(cw^n+k)}{dw}=cnw^{n-1}\" width=\"235.33\" height=\"52.70\" style=\"width:235.33px;height:52.70px;aspect-ratio:235.33/52.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Power neeche multiply; exponent ek kam; constant ka zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the function itself.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5c598d8efe6ecd14.svg\" alt=\"J(1)=0.7(1)^3+0=0.7\" width=\"258.30\" height=\"27.69\" style=\"width:258.30px;height:27.69px;aspect-ratio:258.30/27.69\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate symbolically.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f7d282bf1129194.svg\" alt=\"J\\prime(w)=0.7(3)w^{3-1}+0\" width=\"246.06\" height=\"27.70\" style=\"width:246.06px;height:27.70px;aspect-ratio:246.06/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: put the given w into the derivative.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/38040daaa10cb32e.svg\" alt=\"J\\prime(1)=0.7(3)(1)^{2}=2.1\" width=\"254.16\" height=\"27.70\" style=\"width:254.16px;height:27.70px;aspect-ratio:254.16/27.70\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> J = 0.7; derivative = 2.1.</p>","<h3>Differentiate before substituting: 2w^1+4</h3>","<p class=\"inline-question\"><strong>Question. Let J(w) = 2w^1+4. At w = -1, find J and dJ/dw.</strong></p>","<h3>Given</h3>","<p>J(w) = 2w^1+4; w = -1.</p>","<h3>To find</h3>","<p>The function value and its derivative value.</p>","<h3>Formula — which one and why</h3>","<p>The power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.</p>","<p>c is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/706ea9b2290fe843.svg\" alt=\"\\frac{d(cw^n+k)}{dw}=cnw^{n-1}\" width=\"235.33\" height=\"52.70\" style=\"width:235.33px;height:52.70px;aspect-ratio:235.33/52.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Power neeche multiply; exponent ek kam; constant ka zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the function itself.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/625a082643eb2a43.svg\" alt=\"J(-1)=2(-1)^1+4=2\" width=\"258.30\" height=\"27.70\" style=\"width:258.30px;height:27.70px;aspect-ratio:258.30/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate symbolically.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/091a2e97f7d74170.svg\" alt=\"J\\prime(w)=2(1)w^{1-1}+0\" width=\"227.05\" height=\"27.70\" style=\"width:227.05px;height:27.70px;aspect-ratio:227.05/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: put the given w into the derivative.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d63d0415964167b7.svg\" alt=\"J\\prime(-1)=2(1)(-1)^{0}=2\" width=\"254.16\" height=\"27.70\" style=\"width:254.16px;height:27.70px;aspect-ratio:254.16/27.70\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> J = 2; derivative = 2.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s3","search":"Derivatives without a calculus course **Definition.** A derivative measures the local rate of change of a function. A partial derivative varies one argument while holding the others fixed. The gradient of a scalar-valued function collects its partial derivatives into a vector.\n\nThe rules needed for the supplied neural-network numericals are:\n\n| Function or operation | Derivative |\n| Constant c | 0 |\n| xⁿ | nxⁿ⁻¹ |\n| c f(x) | c f′(x) |\n| f(x) + g(x) | f′(x) + g′(x) |\n| f(x)g(x) | f′(x)g(x) + f(x)g′(x) |\n| eˣ | eˣ |\n| ln x, x > 0 | 1/x |\n| f(g(x)) | f′(g(x))g′(x) |\n\n### A parameter derivative is not an input derivative\nFor z = wx + b, the variable named in the denominator determines which derivative is required.\n\nAt x = 2, w = 3 and b = 1, z = 7, but the three derivatives are 2, 3 and 1 respectively. A function value and its derivative are distinct quantities.\n\n### Gradient direction\nFor a small parameter displacement Δθ, first-order Taylor expansion gives:\n\nThe gradient points in the direction of greatest local increase under the Euclidean norm. Choosing Δθ opposite to the gradient gives a local descent direction. This is the mathematical basis of gradient descent; a finite step can still overshoot if the learning rate is too large.\n\n\n\n### Differentiate before substituting: 3w^2+5\n\n**Question. Let J(w) = 3w^2+5. At w = 2, find J and dJ/dw.**\n\n\n\n### Given\n\nJ(w) = 3w^2+5; w = 2.\n\n### To find\n\nThe function value and its derivative value.\n\n### Formula — which one and why\n\nThe power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.\n\nc is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.\n\n\n\n**Yaad rakhne ka cue:** Power neeche multiply; exponent ek kam; constant ka zero.\n\n### Solution — step by step\n\n\n\n**Step 1: evaluate the function itself.**\n\n\n\n\n\n\n\n**Step 2: differentiate symbolically.**\n\n\n\n\n\n\n\n**Step 3: put the given w into the derivative.**\n\n\n\n\n\n\n\n**Final answer:** J = 17; derivative = 12.\n\n\n\n### Differentiate before substituting: 0.7w^3+0\n\n**Question. Let J(w) = 0.7w^3+0. At w = 1, find J and dJ/dw.**\n\n\n\n### Given\n\nJ(w) = 0.7w^3+0; w = 1.\n\n### To find\n\nThe function value and its derivative value.\n\n### Formula — which one and why\n\nThe power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.\n\nc is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.\n\n\n\n**Yaad rakhne ka cue:** Power neeche multiply; exponent ek kam; constant ka zero.\n\n### Solution — step by step\n\n\n\n**Step 1: evaluate the function itself.**\n\n\n\n\n\n\n\n**Step 2: differentiate symbolically.**\n\n\n\n\n\n\n\n**Step 3: put the given w into the derivative.**\n\n\n\n\n\n\n\n**Final answer:** J = 0.7; derivative = 2.1.\n\n\n\n### Differentiate before substituting: 2w^1+4\n\n**Question. Let J(w) = 2w^1+4. At w = -1, find J and dJ/dw.**\n\n\n\n### Given\n\nJ(w) = 2w^1+4; w = -1.\n\n### To find\n\nThe function value and its derivative value.\n\n### Formula — which one and why\n\nThe power rule brings the exponent down as a multiplier and reduces its power by one. An added constant has derivative zero.\n\nc is the coefficient; n is the power; k is an added constant. J and dJ/dw are different quantities.\n\n\n\n**Yaad rakhne ka cue:** Power neeche multiply; exponent ek kam; constant ka zero.\n\n### Solution — step by step\n\n\n\n**Step 1: evaluate the function itself.**\n\n\n\n\n\n\n\n**Step 2: differentiate symbolically.**\n\n\n\n\n\n\n\n**S"},{"title":"Derivatives: from an ordinary change to a local slope","blocks":["<h3>1. Function value and change are different numbers</h3>","<p>Let L(w) = w². At w = 3, loss is 9. If we increase w to 4, loss becomes 16. The loss change is 16 − 9 = 7 and the weight change is 4 − 3 = 1. Their ratio is 7. This is an average slope over a whole interval.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_slope_limit.svg\" aria-label=\"Enlarge diagram: Start at weight 3 each time. As the increase becomes smaller, the slope estimate approaches 6.\"><img src=\"assets/figures/v_slope_limit.svg\" alt=\"Start at weight 3 each time. As the increase becomes smaller, the slope estimate approaches 6.\" width=\"1080\" height=\"630\" loading=\"lazy\"></button><figcaption>Start at weight 3 each time. As the increase becomes smaller, the slope estimate approaches 6. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:301.28px;--narrow-height:94.37px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ddbf51217582c207.svg\"><img class=\"math display-math\" src=\"assets/equations/e5eede05db6e20c3.svg\" alt=\"\\text{average slope}=\\frac{\\text{new loss}-\\text{old loss}}{\\text{new weight}-\\text{old weight}}\" width=\"441.29\" height=\"55.27\" style=\"width:441.29px;height:55.27px;aspect-ratio:441.29/55.27\" loading=\"lazy\"></picture></div>","<h3>2. Shrink the interval</h3>","<p>For the same starting weight 3, use an increase of 0.1. The new weight is 3.1 and its square is 9.61. The slope estimate is (9.61 − 9)/0.1 = 6.1. With an increase of 0.01, it is (9.0601 − 9)/0.01 = 6.01. Smaller intervals approach 6.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Increase in w</th><th>New w</th><th>New loss w²</th><th>Change in loss</th><th>Change ratio</th></tr></thead><tbody><tr><td>1</td><td>4</td><td>16</td><td>7</td><td>7</td></tr><tr><td>0.1</td><td>3.1</td><td>9.61</td><td>0.61</td><td>6.1</td></tr><tr><td>0.01</td><td>3.01</td><td>9.0601</td><td>0.0601</td><td>6.01</td></tr></tbody></table></div>","<p>The derivative is the limiting local slope as that interval approaches zero. We do not substitute a literal zero into a division by the interval.</p>","<h3>3. Why the square has derivative 2w</h3>","<p>Call a small nonzero change Δw, read “delta w”. Expanding the new square gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.82px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4e8dd2d8556610b9.svg\"><img class=\"math display-math\" src=\"assets/equations/4203633eb5975d8b.svg\" alt=\"(w+\\Delta w)^2=w^2+2w\\Delta w+(\\Delta w)^2\" width=\"370.46\" height=\"27.70\" style=\"width:370.46px;height:27.70px;aspect-ratio:370.46/27.70\" loading=\"lazy\"></picture></div>","<p>Subtract the old square w² and divide by the change Δw:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.97px;--narrow-height:93.85px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1e547bc2dd023797.svg\"><img class=\"math display-math\" src=\"assets/equations/b33822670f9d55b8.svg\" alt=\"\\frac{(w+\\Delta w)^2-w^2}{\\Delta w}=2w+\\Delta w\" width=\"313.69\" height=\"54.76\" style=\"width:313.69px;height:54.76px;aspect-ratio:313.69/54.76\" loading=\"lazy\"></picture></div>","<p>As Δw approaches zero, this approaches 2w. That is the origin of the rule d(w²)/dw = 2w. At w = 3 it gives 6, matching the table&#x27;s trend.</p>","<h3>4. Reading derivative notation</h3>","<p>In dL/dw, the top names the quantity whose response we study, and the bottom names what we vary. Read it as “the derivative of L with respect to w”. The notation is not asking you to divide the current loss 9 by the current weight 3; that would give 3 and answer a different question.</p>","<p>For a function of several variables, ∂L/∂w is a partial derivative: change w while holding the other independent variables fixed. The gradient groups those partial derivatives for all parameters.</p>","<h3>5. Why subtract the gradient?</h3>","<p>If the derivative is positive, increasing w locally increases loss, so we try a small decrease. If it is negative, increasing w locally decreases loss, so we try a small increase. The subtraction in gradient descent automatically handles both signs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p>This is local information. A very large step can cross a minimum and make loss worse. The learning rate η keeps control of the step; the derivative does not promise that any step size is safe.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s4","search":"Derivatives: from an ordinary change to a local slope ### 1. Function value and change are different numbers\nLet L(w) = w². At w = 3, loss is 9. If we increase w to 4, loss becomes 16. The loss change is 16 − 9 = 7 and the weight change is 4 − 3 = 1. Their ratio is 7. This is an average slope over a whole interval.\n\n\n\n\n### 2. Shrink the interval\nFor the same starting weight 3, use an increase of 0.1. The new weight is 3.1 and its square is 9.61. The slope estimate is (9.61 − 9)/0.1 = 6.1. With an increase of 0.01, it is (9.0601 − 9)/0.01 = 6.01. Smaller intervals approach 6.\n| Increase in w | New w | New loss w² | Change in loss | Change ratio |\n| 1 | 4 | 16 | 7 | 7 |\n| 0.1 | 3.1 | 9.61 | 0.61 | 6.1 |\n| 0.01 | 3.01 | 9.0601 | 0.0601 | 6.01 |\nThe derivative is the limiting local slope as that interval approaches zero. We do not substitute a literal zero into a division by the interval.\n\n### 3. Why the square has derivative 2w\nCall a small nonzero change Δw, read “delta w”. Expanding the new square gives:\n\nSubtract the old square w² and divide by the change Δw:\n\nAs Δw approaches zero, this approaches 2w. That is the origin of the rule d(w²)/dw = 2w. At w = 3 it gives 6, matching the table's trend.\n\n### 4. Reading derivative notation\nIn dL/dw, the top names the quantity whose response we study, and the bottom names what we vary. Read it as “the derivative of L with respect to w”. The notation is not asking you to divide the current loss 9 by the current weight 3; that would give 3 and answer a different question.\nFor a function of several variables, ∂L/∂w is a partial derivative: change w while holding the other independent variables fixed. The gradient groups those partial derivatives for all parameters.\n\n### 5. Why subtract the gradient?\nIf the derivative is positive, increasing w locally increases loss, so we try a small decrease. If it is negative, increasing w locally decreases loss, so we try a small increase. The subtraction in gradient descent automatically handles both signs.\n\nThis is local information. A very large step can cross a minimum and make loss worse. The learning rate η keeps control of the step; the derivative does not promise that any step size is safe.\n"},{"title":"Partial derivatives hold other things still","blocks":["<p>For z = wx + b, the derivative with respect to w is x, because x is held fixed. The derivative with respect to b is 1. The derivative with respect to x is w. This is the entire local maths of a neuron’s weighted sum.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_partial.svg\" aria-label=\"Enlarge diagram: Choose one changing parameter. Everything else is held fixed while you find its effect.\"><img src=\"assets/figures/v_partial.svg\" alt=\"Choose one changing parameter. Everything else is held fixed while you find its effect.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Choose one changing parameter. Everything else is held fixed while you find its effect. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:95.43px;--narrow-height:183.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6437deea893fce68.svg\"><img class=\"math display-math\" src=\"assets/equations/d1922f2b91d23e75.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x,\\qquad \\frac{\\partial z}{\\partial b}=1,\\qquad \\frac{\\partial z}{\\partial x}=w\" width=\"377.48\" height=\"51.29\" style=\"width:377.48px;height:51.29px;aspect-ratio:377.48/51.29\" loading=\"lazy\"></picture></div>","<p class=\"inline-question\"><strong>Question: </strong> z = 3w + b, w = 2, b = 1. Find z, ∂z/∂w and ∂z/∂b.</p>","<h3>Given</h3>","<p>z = 3w+b; w = 2; b = 1.</p>","<h3>To find</h3>","<p>Find z, ∂z/∂w and ∂z/∂b.</p>","<h3>Formula — which one and why</h3>","<p><strong>Partial derivatives.</strong> Differentiate only with respect to the named variable; all other independent inputs and parameters remain fixed.</p>","<p>∂z/∂w reads “rate of change of z when w changes”. For z = wx+b, x is the coefficient of w, while b has coefficient 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c448c09e6087f1d5.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x\" width=\"88.64\" height=\"51.29\" style=\"width:88.64px;height:51.29px;aspect-ratio:88.64/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d2edf1641e728713.svg\" alt=\"\\frac{\\partial z}{\\partial b}=1\" width=\"80.74\" height=\"51.29\" style=\"width:80.74px;height:51.29px;aspect-ratio:80.74/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Neeche jis letter ka naam hai, sirf usko change samjho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the function value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c86ffb173c8d136d.svg\" alt=\"z=3(2)+1=6+1=7\" width=\"261.17\" height=\"24.43\" style=\"width:261.17px;height:24.43px;aspect-ratio:261.17/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate with respect to w while b is fixed.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3ab15e4d1d60b4eb.svg\" alt=\"\\frac{\\partial z}{\\partial w}=3+0=3\" width=\"173.76\" height=\"51.29\" style=\"width:173.76px;height:51.29px;aspect-ratio:173.76/51.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: differentiate with respect to b while w is fixed.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/edaff0abc794c10d.svg\" alt=\"\\frac{\\partial z}{\\partial b}=0+1=1\" width=\"167.64\" height=\"51.29\" style=\"width:167.64px;height:51.29px;aspect-ratio:167.64/51.29\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 7; weight derivative = 3; bias derivative = 1. A function value and its rate of change are different quantities.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s5","search":"Partial derivatives hold other things still For z = wx + b, the derivative with respect to w is x, because x is held fixed. The derivative with respect to b is 1. The derivative with respect to x is w. This is the entire local maths of a neuron’s weighted sum.\n\n\n\n\n**Question: ** z = 3w + b, w = 2, b = 1. Find z, ∂z/∂w and ∂z/∂b.\n\n\n\n### Given\n\nz = 3w+b; w = 2; b = 1.\n\n### To find\n\nFind z, ∂z/∂w and ∂z/∂b.\n\n### Formula — which one and why\n\n**Partial derivatives.** Differentiate only with respect to the named variable; all other independent inputs and parameters remain fixed.\n\n∂z/∂w reads “rate of change of z when w changes”. For z = wx+b, x is the coefficient of w, while b has coefficient 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Neeche jis letter ka naam hai, sirf usko change samjho.\n\n### Solution — step by step\n\n\n\n\n**Step 1: calculate the function value.**\n\n\n\n\n\n\n\n**Step 2: differentiate with respect to w while b is fixed.**\n\n\n\n\n\n\n\n**Step 3: differentiate with respect to b while w is fixed.**\n\n\n\n\n\n\n\n**Final answer:** z = 7; weight derivative = 3; bias derivative = 1. A function value and its rate of change are different quantities."},{"title":"The chain rule is multiplying linked effects","blocks":["<p class=\"definition\"><strong>Definition.</strong> The chain rule finds a rate of change when one quantity depends on another through intermediate calculations. Multiply the local rates along one path. If several paths connect the same starting quantity to the final answer, add their complete contributions.</p>","<h3>First understand why the rates multiply</h3>","<p>Suppose w controls u and u controls v. If each one-unit change in w makes u change by 3 units, and each one-unit change in u makes v change by 2 units, the combined rate is 3 × 2 = 6. Adding 3+2 would describe neither dependency.</p>","<p>The notation du/dw reads “the rate at which u changes when w changes”. A partial derivative ∂L/∂w means the same kind of rate while other independent parameters are held fixed. It is not ordinary division of the values L and w.</p>","<p><strong>Yaad rakhne ka cue:</strong> ek raaste par slopes multiply; alag raaston ke full answers add.</p>","<h3>Chain-rule example 1: two linear links</h3>","<p class=\"inline-question\"><strong>Question. Let u = 3w+1 and v = 2u. At w = 1, find u, v and dv/dw.</strong></p>","<h3>Given</h3>","<p>w = 1; u = 3w+1; v = 2u.</p>","<h3>To find</h3>","<p>The two function values and the rate dv/dw.</p>","<h3>Formula — which one and why</h3>","<p>v depends on w through u. Both links must be included, so multiply the two local derivatives.</p>","<p>du/dw is the slope of 3w+1. dv/du is the slope of 2u.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17086b5a41fb1edf.svg\" alt=\"\\frac{dv}{dw}=\\frac{dv}{du}\\frac{du}{dw}\" width=\"151.92\" height=\"50.50\" style=\"width:151.92px;height:50.50px;aspect-ratio:151.92/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Andar ka slope × bahar ka slope.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the intermediate value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b14c00d5dab41947.svg\" alt=\"u=3(1)+1=4\" width=\"176.89\" height=\"24.43\" style=\"width:176.89px;height:24.43px;aspect-ratio:176.89/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the final value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/396fa5f1dfbfd157.svg\" alt=\"v=2(4)=8\" width=\"132.68\" height=\"24.43\" style=\"width:132.68px;height:24.43px;aspect-ratio:132.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: differentiate the first link.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1379a65c2b33abc7.svg\" alt=\"\\frac{du}{dw}=3\" width=\"85.75\" height=\"50.50\" style=\"width:85.75px;height:50.50px;aspect-ratio:85.75/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: differentiate the second link.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0af363fd8a85c3ab.svg\" alt=\"\\frac{dv}{du}=2\" width=\"82.23\" height=\"50.50\" style=\"width:82.23px;height:50.50px;aspect-ratio:82.23/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: multiply along the path.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/746afadc90e4f6c9.svg\" alt=\"\\frac{dv}{dw}=2(3)=6\" width=\"161.78\" height=\"50.50\" style=\"width:161.78px;height:50.50px;aspect-ratio:161.78/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> u = 4, v = 8 and dv/dw = 6. The function value 8 and its rate 6 are different.</p>","<h3>2. One output: calculate both parameter gradients</h3>","<p class=\"inline-question\"><strong>Question.</strong> A linear neuron has z = wx + b and half squared loss L = ½(z − y)². Given x = 2, y = 4, w = 1 and b = 0, obtain both parameter gradients and perform one gradient-descent update with η = 0.1.</p>","<h3>Given</h3>","<p>Input x = 2; target y = 4.</p>","<p>Old weight w = 1; old bias b = 0.</p>","<p>Linear prediction z = wx+b; loss L = ½(z−y)².</p>","<p>Learning rate η = 0.1; update both parameters once.</p>","<h3>To find</h3>","<p>Find the loss gradient for w and for b, then w_new and b_new. Finally evaluate the changed prediction and loss.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule for a linear neuron.</strong> The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.</p>","<p>z = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/00f49c1127dda70e.svg\" alt=\"z=wx+b\" width=\"115.77\" height=\"18.96\" style=\"width:115.77px;height:18.96px;aspect-ratio:115.77/18.96\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f50d7e1cde6462d5.svg\" alt=\"L=\\frac12(z-y)^2\" width=\"155.08\" height=\"49.55\" style=\"width:155.08px;height:49.55px;aspect-ratio:155.08/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/955c63d58ce8cb9b.svg\" alt=\"g_w=\\frac{\\partial L}{\\partial w}=(z-y)x\" width=\"219.49\" height=\"51.29\" style=\"width:219.49px;height:51.29px;aspect-ratio:219.49/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a5a6192e644e19b.svg\" alt=\"g_b=\\frac{\\partial L}{\\partial b}=z-y\" width=\"180.69\" height=\"51.29\" style=\"width:180.69px;height:51.29px;aspect-ratio:180.69/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33df8d5a70c57c14.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_w\" width=\"167.42\" height=\"19.53\" style=\"width:167.42px;height:19.53px;aspect-ratio:167.42/19.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c2843cb0410cd77b.svg\" alt=\"b_{\\mathrm{new}}=b-\\eta g_b\" width=\"148.44\" height=\"22.24\" style=\"width:148.44px;height:22.24px;aspect-ratio:148.44/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek path mein multiply; alag paths mil rahe hon toh add.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/chain_linear_revision.svg\" aria-label=\"Enlarge diagram: The forward values are z = 2, error = −2 and loss = 2. The backward loss derivative is −2; multiply it by x = 2 for the weight gradient and by 1 for the bias gradient.\"><img src=\"assets/figures/chain_linear_revision.svg\" alt=\"The forward values are z = 2, error = −2 and loss = 2. The backward loss derivative is −2; multiply it by x = 2 for the weight gradient and by 1 for the bias gradient.\" width=\"720\" height=\"635\" loading=\"lazy\"></button><figcaption>The forward values are z = 2, error = −2 and loss = 2. The backward loss derivative is −2; multiply it by x = 2 for the weight gradient and by 1 for the bias gradient. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 — evaluate the original model.</strong> Use the given parameters before applying any update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73aa46b2ed8f2b55.svg\" alt=\"z=wx+b=1(2)+0=2\" width=\"278.68\" height=\"24.43\" style=\"width:278.68px;height:24.43px;aspect-ratio:278.68/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef2733b3de84bfed.svg\" alt=\"e=z-y=2-4=-2\" width=\"247.87\" height=\"21.55\" style=\"width:247.87px;height:21.55px;aspect-ratio:247.87/21.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7adb597b6b18fec3.svg\" alt=\"L=\\frac12e^2=\\frac12(-2)^2=2\" width=\"255.51\" height=\"49.55\" style=\"width:255.51px;height:49.55px;aspect-ratio:255.51/49.55\" loading=\"lazy\"></div>","<figure class=\"learning-visual lv-linear-forward\" data-visual=\"linear-forward\"><figcaption class=\"lv-title\">Forward pass: three distinct quantities</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Prediction z</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">1 × 2 + 0</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Error e</span><strong class=\"lv-value\">−2</strong><span class=\"lv-detail\">Prediction 2 − target 4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Half squared loss</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">½ × (−2)²</span></div></div></figure>","<p>The prediction is 2, the signed error is −2 and the loss is 2. These are three different quantities, even when some numerical values happen to coincide.</p>","<p class=\"worked-step\"><strong>Step 2 — differentiate the loss, keeping the target constant.</strong> First differentiate the square, then the error inside it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba371707e98b2bc9.svg\" alt=\"\\frac{\\partial L}{\\partial e}=\\frac12(2e)=e\" width=\"183.36\" height=\"51.29\" style=\"width:183.36px;height:51.29px;aspect-ratio:183.36/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66db443def7ab596.svg\" alt=\"\\frac{\\partial e}{\\partial z}=\\frac{\\partial(z-y)}{\\partial z}=1\" width=\"210.15\" height=\"52.97\" style=\"width:210.15px;height:52.97px;aspect-ratio:210.15/52.97\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e9802e836c671214.svg\" alt=\"\\delta_z=\\frac{\\partial L}{\\partial z}=e(1)=-2\" width=\"233.72\" height=\"51.29\" style=\"width:233.72px;height:51.29px;aspect-ratio:233.72/51.29\" loading=\"lazy\"></div>","<p>The symbol δ (delta) is a convenient name for the derivative with respect to a neuron&#x27;s preactivation. Delta is not automatically the weight gradient; the weight gradient also depends on the input to that connection.</p>","<p class=\"worked-step\"><strong>Step 3 — differentiate the neuron&#x27;s affine expression.</strong> When differentiating with respect to w, x is a constant coefficient. When differentiating with respect to b, the coefficient of b is 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6badd88b171bea97.svg\" alt=\"\\frac{\\partial z}{\\partial w}=x=2\" width=\"133.43\" height=\"51.29\" style=\"width:133.43px;height:51.29px;aspect-ratio:133.43/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d2edf1641e728713.svg\" alt=\"\\frac{\\partial z}{\\partial b}=1\" width=\"80.74\" height=\"51.29\" style=\"width:80.74px;height:51.29px;aspect-ratio:80.74/51.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4 — multiply along each parameter&#x27;s path.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.29px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b51cdfbc8d705d9a.svg\"><img class=\"math display-math\" src=\"assets/equations/b65d42a6fa860d4a.svg\" alt=\"g_w=\\frac{\\partial L}{\\partial w}=\\delta_z\\frac{\\partial z}{\\partial w}=(-2)(2)=-4\" width=\"374.14\" height=\"51.29\" style=\"width:374.14px;height:51.29px;aspect-ratio:374.14/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:184.33px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a2c0a4ed56c043f.svg\"><img class=\"math display-math\" src=\"assets/equations/f357d7ca8a5a76dc.svg\" alt=\"g_b=\\frac{\\partial L}{\\partial b}=\\delta_z\\frac{\\partial z}{\\partial b}=(-2)(1)=-2\" width=\"362.20\" height=\"51.29\" style=\"width:362.20px;height:51.29px;aspect-ratio:362.20/51.29\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-linear-backward\" data-visual=\"linear-backward\"><figcaption class=\"lv-title\">Backward pass: a separate derivative for each parameter</figcaption><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Shared loss derivative δz</span><strong class=\"lv-value\">−2</strong><span class=\"lv-detail\">Both parameter paths start here.</span></div><div class=\"lv-branch-pair\"><div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weight path: multiply by x = 2</span><strong class=\"lv-value\">−4</strong><span class=\"lv-detail\">∂L/∂w = (−2) × 2</span></div></div><div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias path: multiply by 1</span><strong class=\"lv-value\">−2</strong><span class=\"lv-detail\">∂L/∂b = (−2) × 1</span></div></div></div></figure>","<p>Both derivatives use the original forward-pass values. The weight and bias are different parameters, so keep their gradients separate.</p>","<p class=\"worked-step\"><strong>Step 5 — update both parameters simultaneously.</strong> Gradient descent subtracts the learning rate times the corresponding gradient.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8330219a13690888.svg\"><img class=\"math display-math\" src=\"assets/equations/cb9c6fe7ef91a2db.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_w=1-0.1(-4)=1.4\" width=\"387.37\" height=\"24.43\" style=\"width:387.37px;height:24.43px;aspect-ratio:387.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.24px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d5507ad8ee01624d.svg\"><img class=\"math display-math\" src=\"assets/equations/8186eb873e399f7a.svg\" alt=\"b_{\\mathrm{new}}=b-\\eta g_b=0-0.1(-2)=0.2\" width=\"368.39\" height=\"24.43\" style=\"width:368.39px;height:24.43px;aspect-ratio:368.39/24.43\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-linear-update\" data-visual=\"linear-update\"><figcaption class=\"lv-title\">One simultaneous parameter update</figcaption><div class=\"lv-branch-pair\"><div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weight</span><strong class=\"lv-value\">1 → 1.4</strong><span class=\"lv-detail\">Subtract 0.1 × (−4)</span></div></div><div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias</span><strong class=\"lv-value\">0 → 0.2</strong><span class=\"lv-detail\">Subtract 0.1 × (−2)</span></div></div></div><p class=\"lv-caption\">Both updates use gradients from the same original forward pass. Re-evaluate the model afterward.</p></figure>","<p>Subtracting a negative gradient increases the parameter. Do not recompute the bias gradient using the already changed weight; that would be a different update procedure.</p>","<p class=\"worked-step\"><strong>Step 6 — perform a new forward pass to evaluate the update.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f27e43a3756292cb.svg\" alt=\"z_{\\mathrm{new}}=1.4(2)+0.2=3\" width=\"244.08\" height=\"24.43\" style=\"width:244.08px;height:24.43px;aspect-ratio:244.08/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1762c7935645936f.svg\" alt=\"L_{\\mathrm{new}}=\\frac12(3-4)^2=0.5\" width=\"251.77\" height=\"49.55\" style=\"width:251.77px;height:49.55px;aspect-ratio:251.77/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> weight gradient −4, bias gradient −2; updated weight 1.4 and bias 0.2; new prediction 3 and loss 0.5. If a different question fixes the bias at zero, update only the weight; its new prediction would be 2.8, not 3.</p>","<h3>3. Two outputs: why backward contributions are added</h3>","<p>A shared intermediate value can influence more than one output. The derivative with respect to that shared value must include every output path. Adding paths happens before passing the accumulated derivative further backward.</p>","<p class=\"inline-question\"><strong>Question.</strong> A shared linear hidden value is h = wx + b. Two linear outputs are o₁ = 2h and o₂ = −h; their targets are y₁ = 1 and y₂ = 0. The total loss is L = ½(o₁ − y₁)² + ½(o₂ − y₂)². At x = 2, w = 0.5 and b = 0.1, calculate the loss and the gradients with respect to h, w and b. Treat the output multipliers 2 and −1 as fixed.</p>","<h3>Given</h3>","<p>h = wx+b; outputs o₁ = 2h and o₂ = −h.</p>","<p>x = 2; w = 0.5; b = 0.1; targets = [1,0].</p>","<p>Loss = half the sum of the two squared output errors.</p>","<p>Output multipliers 2 and −1 stay fixed.</p>","<h3>To find</h3>","<p>Find total loss and its derivatives with respect to h, w and b.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule with more than one path.</strong> The shared hidden value affects each output. Multiply derivatives within each path, then add the complete path contributions before continuing to w and b.</p>","<p>oⱼ = output j; yⱼ = its target; h = shared hidden value; ∂oⱼ/∂h is the multiplier on that output path.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e472e733a927b24.svg\" alt=\"\\frac{\\partial L}{\\partial h}=\\sum_j(o_j-y_j)\\frac{\\partial o_j}{\\partial h}\" width=\"245.67\" height=\"68.36\" style=\"width:245.67px;height:68.36px;aspect-ratio:245.67/68.36\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/19ebe8d0b832533d.svg\" alt=\"\\frac{\\partial L}{\\partial w}=\\frac{\\partial L}{\\partial h}x\" width=\"129.86\" height=\"51.29\" style=\"width:129.86px;height:51.29px;aspect-ratio:129.86/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44f3dd28940be744.svg\" alt=\"\\frac{\\partial L}{\\partial b}=\\frac{\\partial L}{\\partial h}\" width=\"115.03\" height=\"51.29\" style=\"width:115.03px;height:51.29px;aspect-ratio:115.03/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har raaste ka effect pehle multiply, junction par sab add.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/chain_branch_revision.svg\" aria-label=\"Enlarge diagram: The shared hidden value affects both losses. The first path contributes 2.4 and the second contributes 1.1, giving a combined derivative of 3.5 before continuing to the weight and bias.\"><img src=\"assets/figures/chain_branch_revision.svg\" alt=\"The shared hidden value affects both losses. The first path contributes 2.4 and the second contributes 1.1, giving a combined derivative of 3.5 before continuing to the weight and bias.\" width=\"720\" height=\"705\" loading=\"lazy\"></button><figcaption>The shared hidden value affects both losses. The first path contributes 2.4 and the second contributes 1.1, giving a combined derivative of 3.5 before continuing to the weight and bias. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 — forward values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c54d1626a0bf10fc.svg\" alt=\"h=0.5(2)+0.1=1.1\" width=\"234.03\" height=\"24.43\" style=\"width:234.03px;height:24.43px;aspect-ratio:234.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.17px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/efc23fa7e963abec.svg\"><img class=\"math display-math\" src=\"assets/equations/a05e20f353481e0c.svg\" alt=\"o_1=2(1.1)=2.2,\\qquad o_2=-(1.1)=-1.1\" width=\"448.28\" height=\"24.43\" style=\"width:448.28px;height:24.43px;aspect-ratio:448.28/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9cca9af1e961da75.svg\" alt=\"L_1=\\frac12(2.2-1)^2=0.72\" width=\"261.88\" height=\"49.55\" style=\"width:261.88px;height:49.55px;aspect-ratio:261.88/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.87px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31043c1e17e75c9f.svg\"><img class=\"math display-math\" src=\"assets/equations/6fa32649e91893bc.svg\" alt=\"L_2=\\frac12(-1.1-0)^2=0.605\" width=\"293.11\" height=\"49.55\" style=\"width:293.11px;height:49.55px;aspect-ratio:293.11/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.74px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/115053bc42452eb3.svg\"><img class=\"math display-math\" src=\"assets/equations/6adf6f563023ced5.svg\" alt=\"L=L_1+L_2=0.72+0.605=1.325\" width=\"383.52\" height=\"20.36\" style=\"width:383.52px;height:20.36px;aspect-ratio:383.52/20.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 — output derivatives.</strong> Each half squared loss differentiates to prediction minus target. The other loss does not depend on this output.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.53px;--narrow-height:93.51px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0cee4ce79f255618.svg\"><img class=\"math display-math\" src=\"assets/equations/cf26e13f912b7730.svg\" alt=\"\\frac{\\partial L}{\\partial o_1}=o_1-y_1=2.2-1=1.2\" width=\"324.42\" height=\"54.41\" style=\"width:324.42px;height:54.41px;aspect-ratio:324.42/54.41\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.54px;--narrow-height:93.51px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1551245d19941245.svg\"><img class=\"math display-math\" src=\"assets/equations/c2e5f710a0148c3f.svg\" alt=\"\\frac{\\partial L}{\\partial o_2}=o_2-y_2=-1.1-0=-1.1\" width=\"362.44\" height=\"54.41\" style=\"width:362.44px;height:54.41px;aspect-ratio:362.44/54.41\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3 — calculate the contribution of each complete path.</strong> The derivative of 2h with respect to h is 2; the derivative of −h is −1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b03138eedef68e56.svg\" alt=\"\\frac{\\partial L_1}{\\partial h}=(1.2)(2)=2.4\" width=\"229.75\" height=\"51.29\" style=\"width:229.75px;height:51.29px;aspect-ratio:229.75/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74549258b69e068b.svg\" alt=\"\\frac{\\partial L_2}{\\partial h}=(-1.1)(-1)=1.1\" width=\"267.76\" height=\"51.29\" style=\"width:267.76px;height:51.29px;aspect-ratio:267.76/51.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4 — add the two contributions at the shared hidden value.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4fb627a77ae8284.svg\" alt=\"\\frac{\\partial L}{\\partial h}=\\frac{\\partial L_1}{\\partial h}+\\frac{\\partial L_2}{\\partial h}\" width=\"207.45\" height=\"51.29\" style=\"width:207.45px;height:51.29px;aspect-ratio:207.45/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61ff2149ac92a571.svg\" alt=\"\\frac{\\partial L}{\\partial h}=2.4+1.1=3.5\" width=\"229.94\" height=\"51.29\" style=\"width:229.94px;height:51.29px;aspect-ratio:229.94/51.29\" loading=\"lazy\"></div>","<p>Adding the raw output errors, 1.2 + (−1.1), would omit the output multipliers. Each error must first be multiplied by the local derivative on its own path.</p>","<p class=\"worked-step\"><strong>Step 5 — continue to the hidden weight and bias.</strong> Since h = wx + b, its derivatives with respect to w and b are x and 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/54071389e64f7570.svg\" alt=\"\\frac{\\partial L}{\\partial w}=\\frac{\\partial L}{\\partial h}x=3.5(2)=7\" width=\"269.70\" height=\"51.29\" style=\"width:269.70px;height:51.29px;aspect-ratio:269.70/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/327ca2cf6e5be3c3.svg\" alt=\"\\frac{\\partial L}{\\partial b}=\\frac{\\partial L}{\\partial h}(1)=3.5\" width=\"210.06\" height=\"51.29\" style=\"width:210.06px;height:51.29px;aspect-ratio:210.06/51.29\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> L = 1.325, ∂L/∂h = 3.5, ∂L/∂w = 7 and ∂L/∂b = 3.5. If the hidden value instead includes a nonlinear activation, multiply the accumulated downstream derivative by that activation&#x27;s derivative before multiplying by x. This is the hidden-delta calculation in multilayer backpropagation.</p>","<h3>Chain-rule example 4: a square after a linear link</h3>","<p class=\"inline-question\"><strong>Question. Let z = 3w+1 and L = z². At w = 1, find z, L and dL/dw.</strong></p>","<h3>Given</h3>","<p>w = 1; z = 3w+1; L = z².</p>","<h3>To find</h3>","<p>z, L and the derivative of L with respect to w.</p>","<h3>Formula — which one and why</h3>","<p>The square acts on z, not directly on w. Differentiate the square first and include the change of z with w.</p>","<p>dL/dz = slope of the outer square; dz/dw = slope of the inner linear expression.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/434e48fc84f871b4.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}\" width=\"154.58\" height=\"50.50\" style=\"width:154.58px;height:50.50px;aspect-ratio:154.58/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33825b3d129b23da.svg\" alt=\"\\frac{d(z^2)}{dz}=2z\" width=\"120.66\" height=\"54.76\" style=\"width:120.66px;height:54.76px;aspect-ratio:120.66/54.76\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square ka 2z; andar ka 3; dono multiply.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the inner expression.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8a300d26d67e84f4.svg\" alt=\"z=3(1)+1=4\" width=\"174.28\" height=\"24.43\" style=\"width:174.28px;height:24.43px;aspect-ratio:174.28/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the loss expression.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e7a8c4341fdaf1f8.svg\" alt=\"L=4^2=16\" width=\"129.12\" height=\"23.60\" style=\"width:129.12px;height:23.60px;aspect-ratio:129.12/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: differentiate the square and use z = 4.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3a7684d15448f2e4.svg\" alt=\"\\frac{dL}{dz}=2z=2(4)=8\" width=\"217.09\" height=\"50.50\" style=\"width:217.09px;height:50.50px;aspect-ratio:217.09/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: differentiate the inner expression.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbe8fc0fd6788a9a.svg\" alt=\"\\frac{dz}{dw}=3\" width=\"85.75\" height=\"50.50\" style=\"width:85.75px;height:50.50px;aspect-ratio:85.75/50.50\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: multiply, because the changes occur in sequence.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90d0d059a0fe1d53.svg\" alt=\"\\frac{dL}{dw}=8(3)=24\" width=\"174.00\" height=\"50.50\" style=\"width:174.00px;height:50.50px;aspect-ratio:174.00/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 4, L = 16 and dL/dw = 24. The combined operation is multiplication, not 8+3.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s6","search":"The chain rule is multiplying linked effects **Definition.** The chain rule finds a rate of change when one quantity depends on another through intermediate calculations. Multiply the local rates along one path. If several paths connect the same starting quantity to the final answer, add their complete contributions.\n\n### First understand why the rates multiply\nSuppose w controls u and u controls v. If each one-unit change in w makes u change by 3 units, and each one-unit change in u makes v change by 2 units, the combined rate is 3 × 2 = 6. Adding 3+2 would describe neither dependency.\n\nThe notation du/dw reads “the rate at which u changes when w changes”. A partial derivative ∂L/∂w means the same kind of rate while other independent parameters are held fixed. It is not ordinary division of the values L and w.\n\n**Yaad rakhne ka cue:** ek raaste par slopes multiply; alag raaston ke full answers add.\n\n\n### Chain-rule example 1: two linear links\n\n**Question. Let u = 3w+1 and v = 2u. At w = 1, find u, v and dv/dw.**\n\n\n\n### Given\n\nw = 1; u = 3w+1; v = 2u.\n\n### To find\n\nThe two function values and the rate dv/dw.\n\n### Formula — which one and why\n\nv depends on w through u. Both links must be included, so multiply the two local derivatives.\n\ndu/dw is the slope of 3w+1. dv/du is the slope of 2u.\n\n\n\n**Yaad rakhne ka cue:** Andar ka slope × bahar ka slope.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the intermediate value.**\n\n\n\n\n\n\n\n**Step 2: calculate the final value.**\n\n\n\n\n\n\n\n**Step 3: differentiate the first link.**\n\n\n\n\n\n\n\n**Step 4: differentiate the second link.**\n\n\n\n\n\n\n\n**Step 5: multiply along the path.**\n\n\n\n\n\n\n\n**Final answer:** u = 4, v = 8 and dv/dw = 6. The function value 8 and its rate 6 are different.\n\n### 2. One output: calculate both parameter gradients\n**Question.** A linear neuron has z = wx + b and half squared loss L = ½(z − y)². Given x = 2, y = 4, w = 1 and b = 0, obtain both parameter gradients and perform one gradient-descent update with η = 0.1.\n\n\n\n### Given\n\nInput x = 2; target y = 4.\n\nOld weight w = 1; old bias b = 0.\n\nLinear prediction z = wx+b; loss L = ½(z−y)².\n\nLearning rate η = 0.1; update both parameters once.\n\n### To find\n\nFind the loss gradient for w and for b, then w_new and b_new. Finally evaluate the changed prediction and loss.\n\n### Formula — which one and why\n\n**Chain rule for a linear neuron.** The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.\n\nz = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.\n\n\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek path mein multiply; alag paths mil rahe hon toh add.\n\n### Solution — step by step\n\n\n\n\n\n\n\n**Step 1 — evaluate the original model.** Use the given parameters before applying any update.\n\n\n\nThe prediction is 2, the signed error is −2 and the loss is 2. These are three different quantities, even when some numerical values happen to coincide.\n\n**Step 2 — differentiate the loss, keeping the target constant.** First differentiate the square, then the error inside it.\n\n\n\nThe symbol δ (delta) is a convenient name for the derivative with respect to a neuron's preactivation. Delta is not automatically the weight gradient; the weight gradient also depends on the input to that connection.\n\n**Step 3 — differentiate the neuron's "},{"title":"The derivative of prediction error","blocks":["<p>For the half squared loss, use prediction minus target. Let target be y and prediction be ŷ.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_loss_gradient.svg\" aria-label=\"Enlarge diagram: The half and the averaging factor belong to the loss definition, so they also affect its derivative.\"><img src=\"assets/figures/v_loss_gradient.svg\" alt=\"The half and the averaging factor belong to the loss definition, so they also affect its derivative.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The half and the averaging factor belong to the loss definition, so they also affect its derivative. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.48px;--narrow-height:122.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3bd0a5a4ecdf16a4.svg\"><img class=\"math display-math\" src=\"assets/equations/689f9f8b396b9fab.svg\" alt=\"L=\\frac12(\\hat y-y)^2,\\qquad \\frac{\\partial L}{\\partial \\hat y}=\\hat y-y\" width=\"343.04\" height=\"57.81\" style=\"width:343.04px;height:57.81px;aspect-ratio:343.04/57.81\" loading=\"lazy\"></picture></div>","<p>The 2 from differentiating a square cancels the half. Writing the loss as ½(y − ŷ)² gives the same derivative: the derivative of the inside y − ŷ adds a minus sign. This is why “target minus prediction” without the extra minus gives the wrong gradient.</p>","<p>If the question uses plain squared error, its derivative is 2(ŷ − y). If it averages errors over n values, also divide by n. Read the stated loss before using a memorized gradient.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s7","search":"The derivative of prediction error For the half squared loss, use prediction minus target. Let target be y and prediction be ŷ.\n\n\n\n\nThe 2 from differentiating a square cancels the half. Writing the loss as ½(y − ŷ)² gives the same derivative: the derivative of the inside y − ŷ adds a minus sign. This is why “target minus prediction” without the extra minus gives the wrong gradient.\nIf the question uses plain squared error, its derivative is 2(ŷ − y). If it averages errors over n values, also divide by n. Read the stated loss before using a memorized gradient."},{"title":"Loss scaling: derive the gradient instead of guessing a factor","blocks":["<h3>1. One error, three possible objectives</h3>","<p>Let a be a prediction and y a fixed target. The error is a − y. The derivative of that error with respect to a is 1 because y stays fixed. Apply the chain rule to its square:</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_loss_gradient.svg\" aria-label=\"Enlarge diagram: Read the two conventions separately. A derivative for one convention must not be copied into the other unchanged.\"><img src=\"assets/figures/v_loss_gradient.svg\" alt=\"Read the two conventions separately. A derivative for one convention must not be copied into the other unchanged.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Read the two conventions separately. A derivative for one convention must not be copied into the other unchanged. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5f66834fe766593d.svg\" alt=\"\\frac{\\partial (a-y)^2}{\\partial a}=2(a-y)\\times1\" width=\"269.70\" height=\"55.03\" style=\"width:269.70px;height:55.03px;aspect-ratio:269.70/55.03\" loading=\"lazy\"></div>","<p>Multiplying the objective by a constant multiplies its derivative by the same constant. This gives the common loss conventions below.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Stated loss over n outputs</th><th>Derivative with respect to one prediction aⱼ</th></tr></thead><tbody><tr><td>SSE: sum of all squared errors</td><td>2(aⱼ − yⱼ)</td></tr><tr><td>Half SSE: half of that sum</td><td>aⱼ − yⱼ</td></tr><tr><td>MSE: that sum divided by n</td><td>2(aⱼ − yⱼ)/n</td></tr><tr><td>Half MSE: that sum divided by 2n</td><td>(aⱼ − yⱼ)/n</td></tr></tbody></table></div>","<h3>2. Why only the matching output appears</h3>","<p>Suppose three predictions are separate output variables a₁, a₂ and a₃. When differentiating the loss with respect to a₂, the a₁ and a₃ terms are constant with respect to that output variable, so their direct derivatives are zero. The remaining term is the error of output 2, with the correct scaling factor.</p>","<p>Later, a shared hidden weight may influence all three predictions. Backpropagation then combines those separate output contributions through the chain rule. “Differentiate with respect to one output” and “differentiate with respect to a shared weight” are different stages.</p>","<h3>3. The activation contributes another factor</h3>","<p>If a = sigmoid(z), the derivative of a with respect to its input is a(1 − a). For half SSE, the output delta is therefore:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d269ffed64d3f80c.svg\" alt=\"\\delta=\\frac{\\partial L}{\\partial z}=(a-y)a(1-a)\" width=\"277.97\" height=\"51.29\" style=\"width:277.97px;height:51.29px;aspect-ratio:277.97/51.29\" loading=\"lazy\"></div>","<p>For a linear output, the activation derivative is 1. For positive ReLU input it is also 1; for negative ReLU input it is 0. Always use the derivative of the activation actually given in the question.</p>","<h3>4. A numerical comparison</h3>","<p>For a = 0.7 and y = 1, the signed error is −0.3. For half SSE with sigmoid, the activation derivative is 0.7 × 0.3 = 0.21. The output delta is −0.3 × 0.21 = −0.063. With plain SSE it doubles to −0.126. With MSE over three outputs it is −0.126/3 = −0.042.</p>","<p>The forward prediction 0.7 did not change. The loss convention changed the gradient scale. This is why the first line of a backpropagation answer should state the loss being used.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s8","search":"Loss scaling: derive the gradient instead of guessing a factor ### 1. One error, three possible objectives\nLet a be a prediction and y a fixed target. The error is a − y. The derivative of that error with respect to a is 1 because y stays fixed. Apply the chain rule to its square:\n\n\n\n\nMultiplying the objective by a constant multiplies its derivative by the same constant. This gives the common loss conventions below.\n\n| Stated loss over n outputs | Derivative with respect to one prediction aⱼ |\n| SSE: sum of all squared errors | 2(aⱼ − yⱼ) |\n| Half SSE: half of that sum | aⱼ − yⱼ |\n| MSE: that sum divided by n | 2(aⱼ − yⱼ)/n |\n| Half MSE: that sum divided by 2n | (aⱼ − yⱼ)/n |\n\n### 2. Why only the matching output appears\nSuppose three predictions are separate output variables a₁, a₂ and a₃. When differentiating the loss with respect to a₂, the a₁ and a₃ terms are constant with respect to that output variable, so their direct derivatives are zero. The remaining term is the error of output 2, with the correct scaling factor.\nLater, a shared hidden weight may influence all three predictions. Backpropagation then combines those separate output contributions through the chain rule. “Differentiate with respect to one output” and “differentiate with respect to a shared weight” are different stages.\n\n### 3. The activation contributes another factor\nIf a = sigmoid(z), the derivative of a with respect to its input is a(1 − a). For half SSE, the output delta is therefore:\n\nFor a linear output, the activation derivative is 1. For positive ReLU input it is also 1; for negative ReLU input it is 0. Always use the derivative of the activation actually given in the question.\n\n### 4. A numerical comparison\nFor a = 0.7 and y = 1, the signed error is −0.3. For half SSE with sigmoid, the activation derivative is 0.7 × 0.3 = 0.21. The output delta is −0.3 × 0.21 = −0.063. With plain SSE it doubles to −0.126. With MSE over three outputs it is −0.126/3 = −0.042.\nThe forward prediction 0.7 did not change. The loss convention changed the gradient scale. This is why the first line of a backpropagation answer should state the loss being used.\n"},{"title":"Probability mean and variance in plain language","blocks":["<p class=\"definition\"><strong>Definitions.</strong> A probability assigns a value between 0 and 1 to an event. A discrete probability distribution assigns probabilities to mutually exclusive outcomes whose probabilities sum to 1. Expectation is a probability-weighted average. Variance measures expected squared deviation from the mean.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.88px;--narrow-height:119.35px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6a90dd79f192150.svg\"><img class=\"math display-math\" src=\"assets/equations/f1386430c4600e23.svg\" alt=\"\\sum_i p_i=1,\\qquad\\mathbb E[X]=\\sum_i p_i x_i\" width=\"329.05\" height=\"52.35\" style=\"width:329.05px;height:52.35px;aspect-ratio:329.05/52.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.51px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2228ef692c83a513.svg\"><img class=\"math display-math\" src=\"assets/equations/6fbba36f3ebff68d.svg\" alt=\"\\operatorname{Var}(X)=\\mathbb E[(X-\\mu)^2]=\\mathbb E[X^2]-\\mu^2\" width=\"387.99\" height=\"27.70\" style=\"width:387.99px;height:27.70px;aspect-ratio:387.99/27.70\" loading=\"lazy\"></picture></div>","<h3>Conditional probability and classification</h3>","<p>P(A|B) is the probability of A conditional on B, defined when P(B) &gt; 0. Bayes&#x27; rule relates it to the reverse conditional probability.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.33px;--narrow-height:132.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f464138921aade18.svg\"><img class=\"math display-math\" src=\"assets/equations/ca109f70fdd2c998.svg\" alt=\"P(A\\mid B)=\\frac{P(A\\cap B)}{P(B)}=\\frac{P(B\\mid A)P(A)}{P(B)}\" width=\"432.94\" height=\"59.13\" style=\"width:432.94px;height:59.13px;aspect-ratio:432.94/59.13\" loading=\"lazy\"></picture></div>","<p>For classification, the network estimates P(class | input). A softmax output is normalized across mutually exclusive classes. Independent sigmoid outputs are used for multiple labels that can be present together.</p>","<h3>Empirical mean, variance and standardization</h3>","<p>For N observed values, use the stated variance convention. These notes use division by N for the population-style variance in the numerical; an unbiased sample-variance estimate uses N − 1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.26px;--narrow-height:138.50px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/554920a13a606ed9.svg\"><img class=\"math display-math\" src=\"assets/equations/e7193fbf5e735f5d.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i,\\qquad\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"430.15\" height=\"61.92\" style=\"width:430.15px;height:61.92px;aspect-ratio:430.15/61.92\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:141.06px;--narrow-height:96.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f7fcc7ba3415fbf.svg\"><img class=\"math display-math\" src=\"assets/equations/6d0a9fe98061d681.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2},\\qquad x_{\\mathrm{std}}=\\frac{x-\\mu}{\\sigma}\" width=\"296.87\" height=\"47.79\" style=\"width:296.87px;height:47.79px;aspect-ratio:296.87/47.79\" loading=\"lazy\"></picture></div>","<p>For values [3, 3, 7, 7], μ = 5, squared deviations are [4, 4, 4, 4], σ² = 16/4 = 4 and σ = 2. Thus a value 7 standardizes to (7 − 5)/2 = 1: one standard deviation above the mean. For preprocessing, fit μ and σ on training data and reuse them for validation/test data; σ must be nonzero.</p>","<h3>Likelihood and cross-entropy</h3>","<p>If the correct class has predicted probability p, its negative-log loss is −ln p. For p = 0.8, this is approximately 0.223144. For p = 0.1, it is approximately 2.302585. Increasing correct-class probability lowers this loss. Over independent examples, maximizing the product of correct-class probabilities is equivalent to minimizing the sum of negative log probabilities.</p>","<h3>Population mean and spread: [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. For the population [1, 2, 3], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [1, 2, 3]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23a1d761557fba99.svg\" alt=\"1+2+3=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cde1ff63a64aa7ce.svg\" alt=\"(1-2)=-1\" width=\"137.13\" height=\"24.43\" style=\"width:137.13px;height:24.43px;aspect-ratio:137.13/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46782fbf983b8482.svg\" alt=\"(-1)^2=1\" width=\"105.71\" height=\"27.70\" style=\"width:105.71px;height:27.70px;aspect-ratio:105.71/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebe985168f035d36.svg\" alt=\"(3-2)=1\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4b8daac35aec1bc.svg\" alt=\"(1)^2=1\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e913fcfda4146fb6.svg\"><img class=\"math display-math\" src=\"assets/equations/33fa105b83cd3564.svg\" alt=\"\\sigma^2=\\frac{1+0+1}{3}\\approx0.666666667\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c7d94a64e886a59.svg\"><img class=\"math display-math\" src=\"assets/equations/28845fc5f4238747.svg\" alt=\"\\sigma=\\sqrt{0.666666667}\\approx0.816496581\" width=\"357.89\" height=\"26.49\" style=\"width:357.89px;height:26.49px;aspect-ratio:357.89/26.49\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.666666667; σ ≈ 0.816496581.</p>","<h3>Population mean and spread: [2, 2, 2]</h3>","<p class=\"inline-question\"><strong>Question. For the population [2, 2, 2], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [2, 2, 2]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fc38a48a0a6427f.svg\" alt=\"2+2+2=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b0fc9edc8362e2a5.svg\"><img class=\"math display-math\" src=\"assets/equations/f4e20a1682fadce3.svg\" alt=\"\\sigma^2=\\frac{0+0+0}{3}\\approx0.000000000\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.57px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9ee45ab162936835.svg\"><img class=\"math display-math\" src=\"assets/equations/c43ce89c0112ae99.svg\" alt=\"\\sigma=\\sqrt{0.000000000}\\approx0.000000000\" width=\"357.89\" height=\"26.37\" style=\"width:357.89px;height:26.37px;aspect-ratio:357.89/26.37\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.000000000; σ ≈ 0.000000000. Standardization is undefined with this zero standard deviation.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s9","search":"Probability mean and variance in plain language **Definitions.** A probability assigns a value between 0 and 1 to an event. A discrete probability distribution assigns probabilities to mutually exclusive outcomes whose probabilities sum to 1. Expectation is a probability-weighted average. Variance measures expected squared deviation from the mean.\n\n\n\n### Conditional probability and classification\nP(A|B) is the probability of A conditional on B, defined when P(B) > 0. Bayes' rule relates it to the reverse conditional probability.\n\nFor classification, the network estimates P(class | input). A softmax output is normalized across mutually exclusive classes. Independent sigmoid outputs are used for multiple labels that can be present together.\n\n### Empirical mean, variance and standardization\nFor N observed values, use the stated variance convention. These notes use division by N for the population-style variance in the numerical; an unbiased sample-variance estimate uses N − 1.\n\n\nFor values [3, 3, 7, 7], μ = 5, squared deviations are [4, 4, 4, 4], σ² = 16/4 = 4 and σ = 2. Thus a value 7 standardizes to (7 − 5)/2 = 1: one standard deviation above the mean. For preprocessing, fit μ and σ on training data and reuse them for validation/test data; σ must be nonzero.\n\n### Likelihood and cross-entropy\nIf the correct class has predicted probability p, its negative-log loss is −ln p. For p = 0.8, this is approximately 0.223144. For p = 0.1, it is approximately 2.302585. Increasing correct-class probability lowers this loss. Over independent examples, maximizing the product of correct-class probabilities is equivalent to minimizing the sum of negative log probabilities.\n\n### Population mean and spread: [1, 2, 3]\n\n**Question. For the population [1, 2, 3], find mean, population variance and standard deviation.**\n\n\n\n### Given\n\nValues = [1, 2, 3]; N = 3. Use population division by N.\n\n### To find\n\nMean μ, variance σ² and standard deviation σ.\n\n### Formula — which one and why\n\nThe question specifies a population, so use N rather than the N−1 sample-variance divisor.\n\nμ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean, distance, square, mean again, then root.\n\n### Solution — step by step\n\n\n\n**Step 1: add all values.**\n\n\n\n\n\n\n\n**Step 2: divide by the number of values.**\n\n\n\n\n\n\n\n**Step 3: find and square deviation 1.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 4: find and square deviation 2.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 5: find and square deviation 3.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 6: average the squared deviations.**\n\n\n\n\n\n\n\n**Step 7: take the nonnegative square root.**\n\n\n\n\n\n\n\n**Final answer:** μ = 2; σ² ≈ 0.666666667; σ ≈ 0.816496581.\n\n\n\n\n\n### Population mean and spread: [2, 2, 2]\n\n**Question. For the population [2, 2, 2], find mean, population variance and standard deviation.**\n\n\n\n### Given\n\nValues = [2, 2, 2]; N = 3. Use population division by N.\n\n### To find\n\nMean μ, variance σ² and standard deviation σ.\n\n### Formula — which one and why\n\nThe question specifies a population, so use N rather than the N−1 sample-variance divisor.\n\nμ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean, distance, square, mean again, then root.\n\n### Solution — step by step\n\n\n\n**Step 1: add all values.**\n\n\n\n\n\n\n\n**Step 2: divide by the number of values.**\n\n\n\n\n\n\n\n**Step 3: find and square deviation 1.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 4: find and square deviation 2.**\n\n\n"},{"title":"Mean, variance and standard deviation from ordinary arithmetic","blocks":["<p class=\"definition\"><strong>Definition.</strong> The arithmetic mean measures the centre of a numerical dataset. Variance measures the average squared deviation from that mean, and standard deviation expresses dispersion in the original units.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.05px;--narrow-height:209.10px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8b9cec002314f2de.svg\"><img class=\"math display-math\" src=\"assets/equations/9231d9bbf6a6372d.svg\" alt=\"\\mu=\\frac{1}{N}\\sum_{i=1}^{N}x_i,\\qquad \\sigma^2=\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\mu)^2,\\qquad \\sigma=\\sqrt{\\sigma^2}\" width=\"585.96\" height=\"72.79\" style=\"width:585.96px;height:72.79px;aspect-ratio:585.96/72.79\" loading=\"lazy\"></picture></div>","<p>These are population formulas, or empirical moments treating the supplied dataset as the complete reference set. An unbiased sample-variance estimate instead divides the squared-deviation sum by N−1. Use the convention specified by the question; the two denominators are not interchangeable.</p>","<p class=\"inline-question\"><strong>Question. Find the population mean, variance and standard deviation of [3, 3, 7, 7].</strong></p>","<h3>Given</h3>","<p>Observations = [3,3,7,7]; N = 4.</p>","<p>Use population variance (divide by N).</p>","<h3>To find</h3>","<p>Find the population mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p><strong>Mean and spread.</strong> The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.</p>","<p>N = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aa827d67a05a9234.svg\" alt=\"\\mu=\\frac{1}{N}\\sum_{i=1}^{N}x_i\" width=\"145.16\" height=\"72.79\" style=\"width:145.16px;height:72.79px;aspect-ratio:145.16/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a1a03dea0d7cf33e.svg\" alt=\"\\sigma^2=\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\mu)^2\" width=\"225.26\" height=\"72.79\" style=\"width:225.26px;height:72.79px;aspect-ratio:225.26/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean = sabka total ÷ count; variance = squared distances ka mean.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all four observations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b29c1c44847515f7.svg\" alt=\"3+3+7+7=20\" width=\"195.50\" height=\"18.52\" style=\"width:195.50px;height:18.52px;aspect-ratio:195.50/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the count to obtain the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eafa89b652a5378.svg\" alt=\"\\mu=\\frac{20}{4}=5\" width=\"127.31\" height=\"49.55\" style=\"width:127.31px;height:49.55px;aspect-ratio:127.31/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: subtract the mean from each observation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:263.40px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f5609e02cf210acd.svg\"><img class=\"math display-math\" src=\"assets/equations/1c77fe3ea3cb5cf4.svg\" alt=\"[3-5,3-5,7-5,7-5]=[-2,-2,2,2]\" width=\"429.05\" height=\"24.43\" style=\"width:429.05px;height:24.43px;aspect-ratio:429.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: square each deviation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:213.75px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8423c755b10f2fe0.svg\"><img class=\"math display-math\" src=\"assets/equations/54a284752c898da0.svg\" alt=\"[(-2)^2,(-2)^2,2^2,2^2]=[4,4,4,4]\" width=\"341.39\" height=\"27.70\" style=\"width:341.39px;height:27.70px;aspect-ratio:341.39/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the squared deviations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8b51d1e9b84e8106.svg\" alt=\"4+4+4+4=16\" width=\"195.50\" height=\"18.54\" style=\"width:195.50px;height:18.54px;aspect-ratio:195.50/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: divide by four for population variance.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47e0cbf4557b9859.svg\" alt=\"\\sigma^2=\\frac{16}{4}=4\" width=\"137.19\" height=\"49.55\" style=\"width:137.19px;height:49.55px;aspect-ratio:137.19/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a8d993f2bb3889d.svg\" alt=\"\\sigma=\\sqrt4=2\" width=\"124.39\" height=\"26.77\" style=\"width:124.39px;height:26.77px;aspect-ratio:124.39/26.77\" loading=\"lazy\"></div>","<p><strong>Answer:</strong> mean = 5, population variance = 4 and population standard deviation = 2. Variance has squared units; standard deviation has the same units as the observations. With the sample convention, the variance would instead be 16/3.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s10","search":"Mean, variance and standard deviation from ordinary arithmetic \n**Definition.** The arithmetic mean measures the centre of a numerical dataset. Variance measures the average squared deviation from that mean, and standard deviation expresses dispersion in the original units.\n\nThese are population formulas, or empirical moments treating the supplied dataset as the complete reference set. An unbiased sample-variance estimate instead divides the squared-deviation sum by N−1. Use the convention specified by the question; the two denominators are not interchangeable.\n\n**Question. Find the population mean, variance and standard deviation of [3, 3, 7, 7].**\n\n\n\n### Given\n\nObservations = [3,3,7,7]; N = 4.\n\nUse population variance (divide by N).\n\n### To find\n\nFind the population mean μ, variance σ² and standard deviation σ.\n\n### Formula — which one and why\n\n**Mean and spread.** The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.\n\nN = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean = sabka total ÷ count; variance = squared distances ka mean.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: add all four observations.**\n\n\n\n\n\n\n\n**Step 2: divide by the count to obtain the mean.**\n\n\n\n\n\n\n\n**Step 3: subtract the mean from each observation.**\n\n\n\n\n\n\n\n**Step 4: square each deviation.**\n\n\n\n\n\n\n\n**Step 5: add the squared deviations.**\n\n\n\n\n\n\n\n**Step 6: divide by four for population variance.**\n\n\n\n\n\n\n\n**Step 7: take the nonnegative square root.**\n\n\n\n\n\n\n\n**Answer:** mean = 5, population variance = 4 and population standard deviation = 2. Variance has squared units; standard deviation has the same units as the observations. With the sample convention, the variance would instead be 16/3.\n\n"},{"title":"Standardization: what the answer 1 actually means","blocks":["<p class=\"definition\"><strong>Definition.</strong> Standardization is an affine transformation that expresses an observation as its signed distance from a reference mean, measured in reference standard-deviation units.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.64px;--narrow-height:90.47px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/45ffeb13784592e1.svg\"><img class=\"math display-math\" src=\"assets/equations/6f3798eefa1e56a4.svg\" alt=\"z=\\frac{x-\\mu_{\\mathrm{train}}}{\\sigma_{\\mathrm{train}}},\\qquad \\sigma_{\\mathrm{train}}&gt;0\" width=\"308.90\" height=\"51.38\" style=\"width:308.90px;height:51.38px;aspect-ratio:308.90/51.38\" loading=\"lazy\"></picture></div>","<p>Subtracting the mean centres the reference data. Dividing by its standard deviation rescales its spread. The result is dimensionless. A positive z lies above the training mean, a negative z below it, and z = 0 equals it. Standardization does not make an arbitrary distribution Gaussian and does not restrict values to [0,1].</p>","<p class=\"inline-question\"><strong>Question. A feature has training values [3, 3, 7, 7]. Using population standard deviation, standardize the training values and a new observation x = 9.</strong></p>","<h3>Given</h3>","<p>Training observations = [3,3,7,7].</p>","<p>New observation = 9.</p>","<p>Estimate the population standard deviation from the training values.</p>","<h3>To find</h3>","<p>Find the training mean and standard deviation; standardize all four training values and the new observation.</p>","<h3>Formula — which one and why</h3>","<p><strong>Mean and spread.</strong> The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.</p>","<p>N = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aa827d67a05a9234.svg\" alt=\"\\mu=\\frac{1}{N}\\sum_{i=1}^{N}x_i\" width=\"145.16\" height=\"72.79\" style=\"width:145.16px;height:72.79px;aspect-ratio:145.16/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a1a03dea0d7cf33e.svg\" alt=\"\\sigma^2=\\frac{1}{N}\\sum_{i=1}^{N}(x_i-\\mu)^2\" width=\"225.26\" height=\"72.79\" style=\"width:225.26px;height:72.79px;aspect-ratio:225.26/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean = sabka total ÷ count; variance = squared distances ka mean.</p>","<p><strong>Standardization.</strong> Subtract the training mean to measure distance from the centre; divide by the training standard deviation to express that distance in standard-deviation units.</p>","<p>x = original value; μ = training mean; σ = training standard deviation, which must be nonzero; z = standardized value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle centre hatao, phir spread se divide karo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all four observations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b29c1c44847515f7.svg\" alt=\"3+3+7+7=20\" width=\"195.50\" height=\"18.52\" style=\"width:195.50px;height:18.52px;aspect-ratio:195.50/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the count to obtain the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eafa89b652a5378.svg\" alt=\"\\mu=\\frac{20}{4}=5\" width=\"127.31\" height=\"49.55\" style=\"width:127.31px;height:49.55px;aspect-ratio:127.31/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: subtract the mean from each observation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:263.40px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f5609e02cf210acd.svg\"><img class=\"math display-math\" src=\"assets/equations/1c77fe3ea3cb5cf4.svg\" alt=\"[3-5,3-5,7-5,7-5]=[-2,-2,2,2]\" width=\"429.05\" height=\"24.43\" style=\"width:429.05px;height:24.43px;aspect-ratio:429.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: square each deviation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:213.75px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8423c755b10f2fe0.svg\"><img class=\"math display-math\" src=\"assets/equations/54a284752c898da0.svg\" alt=\"[(-2)^2,(-2)^2,2^2,2^2]=[4,4,4,4]\" width=\"341.39\" height=\"27.70\" style=\"width:341.39px;height:27.70px;aspect-ratio:341.39/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the squared deviations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8b51d1e9b84e8106.svg\" alt=\"4+4+4+4=16\" width=\"195.50\" height=\"18.54\" style=\"width:195.50px;height:18.54px;aspect-ratio:195.50/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: divide by four for population variance.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47e0cbf4557b9859.svg\" alt=\"\\sigma^2=\\frac{16}{4}=4\" width=\"137.19\" height=\"49.55\" style=\"width:137.19px;height:49.55px;aspect-ratio:137.19/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a8d993f2bb3889d.svg\" alt=\"\\sigma=\\sqrt4=2\" width=\"124.39\" height=\"26.77\" style=\"width:124.39px;height:26.77px;aspect-ratio:124.39/26.77\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: standardize each original training observation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb029ad3b6f0a91a.svg\" alt=\"\\frac{3-5}{2}=-1\" width=\"128.87\" height=\"49.55\" style=\"width:128.87px;height:49.55px;aspect-ratio:128.87/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0a2851f2b573cc2.svg\" alt=\"\\frac{7-5}{2}=1\" width=\"109.86\" height=\"49.80\" style=\"width:109.86px;height:49.80px;aspect-ratio:109.86/49.80\" loading=\"lazy\"></div>","<p>The repeated observations give [-1, −1, 1, 1].</p>","<p class=\"worked-step\"><strong>Step 9: subtract the training mean from the new observation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/116784e6eda9bc25.svg\" alt=\"9-5=4\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 10: divide by the training standard deviation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a563909e15c191b2.svg\" alt=\"z_{\\mathrm{new}}=\\frac42=2\" width=\"143.50\" height=\"49.82\" style=\"width:143.50px;height:49.82px;aspect-ratio:143.50/49.82\" loading=\"lazy\"></div>","<p><strong>Answer:</strong> the new observation is two training standard deviations above the training mean. Do not recompute the mean and standard deviation using the new observation; validation and test data use the training transformation to avoid leakage. A constant feature has zero standard deviation and needs a stated handling policy.</p>","<h3>Standardization with x = 3</h3>","<p class=\"inline-question\"><strong>Question. Training mean is 5 and training standard deviation is 2. Standardize x = 3 and interpret the result.</strong></p>","<h3>Given</h3>","<p>x = 3; training mean μ = 5; training standard deviation σ = 2.</p>","<h3>To find</h3>","<p>Standardized value z and its meaning.</p>","<h3>Formula — which one and why</h3>","<p>Subtract the training centre, then measure that distance in units of the training standard deviation.</p>","<p>A negative z means below the training mean; positive means above it; zero means equal to it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Centre hatao, spread se divide; answer batata hai kitne σ door.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find distance from the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29b71ab0c556c6dc.svg\" alt=\"x-\\mu=3-5=-2\" width=\"209.28\" height=\"21.55\" style=\"width:209.28px;height:21.55px;aspect-ratio:209.28/21.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by one standard-deviation unit.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/679dccde63fa3152.svg\" alt=\"z=\\frac{-2}{2}=-1\" width=\"149.74\" height=\"49.55\" style=\"width:149.74px;height:49.55px;aspect-ratio:149.74/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: interpret sign and size.</strong></p>","<p>The value is 1 standard-deviation unit(s) below the training mean.</p>","<p><strong>Final answer:</strong> z = -1. Use the same training statistics when transforming a new test input.</p>","<h3>Standardization with x = 5</h3>","<p class=\"inline-question\"><strong>Question. Training mean is 5 and training standard deviation is 2. Standardize x = 5 and interpret the result.</strong></p>","<h3>Given</h3>","<p>x = 5; training mean μ = 5; training standard deviation σ = 2.</p>","<h3>To find</h3>","<p>Standardized value z and its meaning.</p>","<h3>Formula — which one and why</h3>","<p>Subtract the training centre, then measure that distance in units of the training standard deviation.</p>","<p>A negative z means below the training mean; positive means above it; zero means equal to it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Centre hatao, spread se divide; answer batata hai kitne σ door.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find distance from the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46cf71d500f243a5.svg\" alt=\"x-\\mu=5-5=0\" width=\"190.27\" height=\"21.55\" style=\"width:190.27px;height:21.55px;aspect-ratio:190.27/21.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by one standard-deviation unit.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8d3a4b4364ff836.svg\" alt=\"z=\\frac{0}{2}=0\" width=\"111.72\" height=\"49.55\" style=\"width:111.72px;height:49.55px;aspect-ratio:111.72/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: interpret sign and size.</strong></p>","<p>The value is 0 standard-deviation unit(s) away from the training mean.</p>","<p><strong>Final answer:</strong> z = 0. Use the same training statistics when transforming a new test input.</p>","<h3>Standardization with x = 9</h3>","<p class=\"inline-question\"><strong>Question. Training mean is 5 and training standard deviation is 2. Standardize x = 9 and interpret the result.</strong></p>","<h3>Given</h3>","<p>x = 9; training mean μ = 5; training standard deviation σ = 2.</p>","<h3>To find</h3>","<p>Standardized value z and its meaning.</p>","<h3>Formula — which one and why</h3>","<p>Subtract the training centre, then measure that distance in units of the training standard deviation.</p>","<p>A negative z means below the training mean; positive means above it; zero means equal to it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05f73c2bd4e79c0a.svg\" alt=\"z=\\frac{x-\\mu}{\\sigma}\" width=\"113.28\" height=\"47.79\" style=\"width:113.28px;height:47.79px;aspect-ratio:113.28/47.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Centre hatao, spread se divide; answer batata hai kitne σ door.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find distance from the mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/640d8d05be10b7d3.svg\" alt=\"x-\\mu=9-5=4\" width=\"190.27\" height=\"21.82\" style=\"width:190.27px;height:21.82px;aspect-ratio:190.27/21.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by one standard-deviation unit.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b913089938e80c1f.svg\" alt=\"z=\\frac{4}{2}=2\" width=\"111.72\" height=\"49.82\" style=\"width:111.72px;height:49.82px;aspect-ratio:111.72/49.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: interpret sign and size.</strong></p>","<p>The value is 2 standard-deviation unit(s) above the training mean.</p>","<p><strong>Final answer:</strong> z = 2. Use the same training statistics when transforming a new test input.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s11","search":"Standardization: what the answer 1 actually means \n**Definition.** Standardization is an affine transformation that expresses an observation as its signed distance from a reference mean, measured in reference standard-deviation units.\n\nSubtracting the mean centres the reference data. Dividing by its standard deviation rescales its spread. The result is dimensionless. A positive z lies above the training mean, a negative z below it, and z = 0 equals it. Standardization does not make an arbitrary distribution Gaussian and does not restrict values to [0,1].\n\n**Question. A feature has training values [3, 3, 7, 7]. Using population standard deviation, standardize the training values and a new observation x = 9.**\n\n\n\n### Given\n\nTraining observations = [3,3,7,7].\n\nNew observation = 9.\n\nEstimate the population standard deviation from the training values.\n\n### To find\n\nFind the training mean and standard deviation; standardize all four training values and the new observation.\n\n### Formula — which one and why\n\n**Mean and spread.** The mean is the sum divided by the number of values. Population variance averages squared distances from that mean; standard deviation is its square root.\n\nN = number of values; xᵢ = value i; μ = mean; σ² = variance; σ = standard deviation. Σ means add the indicated terms.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Mean = sabka total ÷ count; variance = squared distances ka mean.\n\n**Standardization.** Subtract the training mean to measure distance from the centre; divide by the training standard deviation to express that distance in standard-deviation units.\n\nx = original value; μ = training mean; σ = training standard deviation, which must be nonzero; z = standardized value.\n\n\n\n**Yaad rakhne ka cue:** Pehle centre hatao, phir spread se divide karo.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: add all four observations.**\n\n\n\n\n\n\n\n**Step 2: divide by the count to obtain the mean.**\n\n\n\n\n\n\n\n**Step 3: subtract the mean from each observation.**\n\n\n\n\n\n\n\n**Step 4: square each deviation.**\n\n\n\n\n\n\n\n**Step 5: add the squared deviations.**\n\n\n\n\n\n\n\n**Step 6: divide by four for population variance.**\n\n\n\n\n\n\n\n**Step 7: take the nonnegative square root.**\n\n\n\n\n\n\n\n**Step 8: standardize each original training observation.**\n\n\n\n\n\n\n\n\n\nThe repeated observations give [-1, −1, 1, 1].\n\n**Step 9: subtract the training mean from the new observation.**\n\n\n\n\n\n\n\n**Step 10: divide by the training standard deviation.**\n\n\n\n\n\n\n\n**Answer:** the new observation is two training standard deviations above the training mean. Do not recompute the mean and standard deviation using the new observation; validation and test data use the training transformation to avoid leakage. A constant feature has zero standard deviation and needs a stated handling policy.\n\n### Standardization with x = 3\n\n**Question. Training mean is 5 and training standard deviation is 2. Standardize x = 3 and interpret the result.**\n\n\n\n### Given\n\nx = 3; training mean μ = 5; training standard deviation σ = 2.\n\n### To find\n\nStandardized value z and its meaning.\n\n### Formula — which one and why\n\nSubtract the training centre, then measure that distance in units of the training standard deviation.\n\nA negative z means below the training mean; positive means above it; zero means equal to it.\n\n\n\n**Yaad rakhne ka cue:** Centre hatao, spread se divide; answer batata hai kitne σ door.\n\n### Solution — step by step\n\n\n\n**Step 1: find distance from the mean.**\n\n\n\n\n\n\n\n**Step 2: divide by one standard-deviation unit.**\n\n\n\n\n\n\n\n"},{"title":"Chain rule: the complete calculation","blocks":["<p>When one value depends on another, a change passes through both calculations. The total derivative multiplies the two local derivatives. It does not add them. Here w is the number being changed, z is an intermediate value, and L is the final value.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_chain_rule.svg\" aria-label=\"Enlarge diagram: Follow w to z to loss. The local slopes on that dependency path multiply.\"><img src=\"assets/figures/v_chain_rule.svg\" alt=\"Follow w to z to loss. The local slopes on that dependency path multiply.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow w to z to loss. The local slopes on that dependency path multiply. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Let z = 3w + 1 and L = z². We will calculate the derivative of L with respect to w at w = 1.</p>","<p class=\"worked-step\"><strong>Step 1: find the intermediate value.</strong> Replace w by 1: z = 3 × 1 + 1 = 4.</p>","<p class=\"worked-step\"><strong>Step 2: differentiate the last calculation.</strong> For L = z², the power rule gives dL/dz = 2z. At z = 4, this is 2 × 4 = 8. This measures how L responds to z.</p>","<p class=\"worked-step\"><strong>Step 3: differentiate the first calculation.</strong> For z = 3w + 1, the derivative of 3w is 3 and the derivative of the constant 1 is 0. Therefore dz/dw = 3. This measures how z responds to w.</p>","<p class=\"worked-step\"><strong>Step 4: connect the two effects.</strong> Multiply 8 by 3. The final derivative is 24.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.31px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f43476deed69b900.svg\"><img class=\"math display-math\" src=\"assets/equations/f69ed1214540da40.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}=(2z)(3)=8\\times3=24\" width=\"404.89\" height=\"50.50\" style=\"width:404.89px;height:50.50px;aspect-ratio:404.89/50.50\" loading=\"lazy\"></picture></div>","<p>The function value is L = 4² = 16. The derivative is 24. These have different meanings: 16 is the current value of L; 24 is its local rate of change per unit change in w.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c3-s12","search":"Chain rule: the complete calculation When one value depends on another, a change passes through both calculations. The total derivative multiplies the two local derivatives. It does not add them. Here w is the number being changed, z is an intermediate value, and L is the final value.\n\n\n\nLet z = 3w + 1 and L = z². We will calculate the derivative of L with respect to w at w = 1.\n**Step 1: find the intermediate value.** Replace w by 1: z = 3 × 1 + 1 = 4.\n**Step 2: differentiate the last calculation.** For L = z², the power rule gives dL/dz = 2z. At z = 4, this is 2 × 4 = 8. This measures how L responds to z.\n**Step 3: differentiate the first calculation.** For z = 3w + 1, the derivative of 3w is 3 and the derivative of the constant 1 is 0. Therefore dz/dw = 3. This measures how z responds to w.\n**Step 4: connect the two effects.** Multiply 8 by 3. The final derivative is 24.\n\nThe function value is L = 4² = 16. The derivative is 24. These have different meanings: 16 is the current value of L; 24 is its local rate of change per unit change in w.\n"}]},{"n":4,"title":"Neural-network foundations","sections":[{"title":"What does learning from data mean","blocks":["<p class=\"definition\"><strong>Definition.</strong> Machine learning develops models from data so that they can perform a task on new examples. A model is a calculation rule with adjustable numbers. Deep learning uses neural networks with multiple trainable layers; each layer transforms the previous layer&#x27;s outputs.</p>","<h3>Start with one complete training example</h3>","<p>A <strong>sample</strong> means one example in the dataset. Suppose one example says: an input number is 2 and the required answer is 4. We write the input as x = 2 and the correct answer, or <strong>target</strong>, as y = 4. These letters are labels for the two numbers.</p>","<p>An <strong>input feature</strong> is one recorded property used to make a prediction. One house might have area, number of rooms and age as three features. The three values together describe one sample. An <strong>input vector</strong> is just an ordered list of those feature values. Order matters: the first model weight must always multiply the first feature.</p>","<p>The model&#x27;s calculated answer is the <strong>prediction</strong>, written ŷ, read “y hat”. The hat helps us distinguish the calculated answer ŷ from the required answer y. A prediction is a probability only when the task and output function give it that interpretation.</p>","<h3>The simplest model: multiply, then add</h3>","<p>In the following model, x is the input, w is a weight and b is a bias. A <strong>weight</strong> multiplies the input. A <strong>bias</strong> is added once after multiplication. Both w and b are adjustable model numbers, called <strong>parameters</strong>.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p>The model first multiplies w and x; then it adds b. For several inputs it uses one matching weight per input, adds their products, and then adds the bias.</p>","<p><strong>Yaad rakhne ka cue:</strong> x diya hua input; y sahi answer; ŷ model ka answer; w aur b training mein badlenge.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: Input numbers are multiplied by weights, their contributions are added with a bias, and an activation gives the neuron output. The next lesson explains each part.\"><img src=\"assets/figures/neuron.svg\" alt=\"Input numbers are multiplied by weights, their contributions are added with a bias, and an activation gives the neuron output. The next lesson explains each part.\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>Input numbers are multiplied by weights, their contributions are added with a bias, and an activation gives the neuron output. The next lesson explains each part. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Model example 1: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 2, w = 1 and b = 0, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 2.</p>","<p>Weight w = 1; bias b = 0.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0690bd581db62ce5.svg\" alt=\"wx=(1)(2)=2\" width=\"171.31\" height=\"24.43\" style=\"width:171.31px;height:24.43px;aspect-ratio:171.31/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31e3d42796c5dd84.svg\" alt=\"\\hat y=2+(0)=2\" width=\"162.67\" height=\"25.90\" style=\"width:162.67px;height:25.90px;aspect-ratio:162.67/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 2. This is a prediction, not a loss or a learned weight.</p>","<h3>Model example 2: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 2, w = 1.5 and b = 1, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 2.</p>","<p>Weight w = 1.5; bias b = 1.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cafd271941bad15.svg\" alt=\"wx=(1.5)(2)=3\" width=\"190.32\" height=\"24.43\" style=\"width:190.32px;height:24.43px;aspect-ratio:190.32/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3a2f92dc89e2b2d2.svg\" alt=\"\\hat y=3+(1)=4\" width=\"162.67\" height=\"25.90\" style=\"width:162.67px;height:25.90px;aspect-ratio:162.67/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 4. This is a prediction, not a loss or a learned weight.</p>","<h3>Model example 3: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 3, w = 1.5 and b = 1, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 3.</p>","<p>Weight w = 1.5; bias b = 1.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b2ec1addfdbb9fd.svg\" alt=\"wx=(1.5)(3)=4.5\" width=\"209.34\" height=\"24.43\" style=\"width:209.34px;height:24.43px;aspect-ratio:209.34/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b28b202a19e96ace.svg\" alt=\"\\hat y=4.5+(1)=5.5\" width=\"200.70\" height=\"25.90\" style=\"width:200.70px;height:25.90px;aspect-ratio:200.70/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 5.5. This is a prediction, not a loss or a learned weight.</p>","<h3>Model example 4: calculate a prediction</h3>","<p class=\"inline-question\"><strong>Question. A linear model uses ŷ = wx+b. For x = 2, w = -0.5 and b = 3, calculate its prediction.</strong></p>","<h3>Given</h3>","<p>Input x = 2.</p>","<p>Weight w = -0.5; bias b = 3.</p>","<p>The output is linear: no extra activation is specified.</p>","<h3>To find</h3>","<p>The predicted value ŷ.</p>","<h3>Formula — which one and why</h3>","<p>Use the stated model. The multiplication gives the input contribution; the bias shifts the result.</p>","<p>x is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b896c82c08881db8.svg\" alt=\"\\hat y=wx+b\" width=\"116.38\" height=\"24.80\" style=\"width:116.38px;height:24.80px;aspect-ratio:116.38/24.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle input × weight, phir bias add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the input by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ee6e60703add42d.svg\" alt=\"wx=(-0.5)(2)=-1\" width=\"228.34\" height=\"24.43\" style=\"width:228.34px;height:24.43px;aspect-ratio:228.34/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2369bf69098b26c.svg\" alt=\"\\hat y=-1+(3)=2\" width=\"181.69\" height=\"25.90\" style=\"width:181.69px;height:25.90px;aspect-ratio:181.69/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> ŷ = 2. This is a prediction, not a loss or a learned weight.</p>","<h3>How the model learns</h3>","<p>An initial model can predict 2 when the target is 4. A <strong>loss function</strong> measures the discrepancy. Training calculates how changing each parameter changes the loss; that rate is a <strong>gradient</strong>. An <strong>optimizer</strong> uses the gradient to adjust the parameters. The learning rate controls the size of this adjustment. The loss, derivative and complete update are explained with full examples in the next lessons.</p>","<p>The learning rate is a <strong>hyperparameter</strong>: a setting chosen for training. A learned weight is a <strong>parameter</strong>: an adjustable number inside the model. During ordinary <strong>inference</strong>, the trained weights stay fixed and the model calculates an output for a new input.</p>","<p>For many training samples, the objective normally averages the individual losses. θ (theta) means the collection of adjustable parameters; N is the number of training examples; Lᵢ is the loss for example i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48f2afe9071bd1c9.svg\" alt=\"J(\\theta)=\\frac1N\\sum_{i=1}^{N}L_i(\\theta)\" width=\"209.50\" height=\"72.79\" style=\"width:209.50px;height:72.79px;aspect-ratio:209.50/72.79\" loading=\"lazy\"></div>","<p>Σ is an instruction to add the listed terms. For three losses it means L₁ + L₂ + L₃, followed by division by 3. Regularization may add a penalty; the regularization chapter explains that separate term.</p>","<h3>Why several layers help</h3>","<p>A <strong>layer</strong> contains several neurons that calculate outputs from the same incoming values. In an image model, earlier layers can respond to simple patterns such as edges; later layers combine earlier responses into more complex features. This hierarchy is learned from data. A deep network is not guaranteed to learn useful features merely because it has many layers; training data, architecture and optimization still matter.</p>","<p><strong>Generalization</strong> means performing well on new examples. Training data adjusts weights; validation data helps choose settings and stopping time; held-out test data evaluates the chosen model. Small training loss alone does not establish good generalization.</p>","<p><strong>Yaad rakhne ka cue:</strong> training = answer nikalo → loss nikalo → gradients nikalo → parameters update karo; inference = trained model se answer nikalo.</p>","<h3>Average training loss</h3>","<p class=\"inline-question\"><strong>Question. Three training examples have losses 2, 0.5 and 0.5. Calculate their mean training loss.</strong></p>","<h3>Given</h3>","<p>L₁ = 2; L₂ = 0.5; L₃ = 0.5; N = 3.</p>","<h3>To find</h3>","<p>The mean loss J.</p>","<h3>Formula — which one and why</h3>","<p>The question asks for the mean, so add all sample losses and divide by the number of samples.</p>","<p>Lᵢ means loss of example i. N counts examples.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3763c395ed6a5c3c.svg\" alt=\"J=\\frac{L_1+L_2+L_3}{N}\" width=\"200.46\" height=\"49.97\" style=\"width:200.46px;height:49.97px;aspect-ratio:200.46/49.97\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean = total loss ÷ examples.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add the losses.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a5dc1556ae91ba13.svg\" alt=\"2+0.5+0.5=3\" width=\"179.22\" height=\"18.27\" style=\"width:179.22px;height:18.27px;aspect-ratio:179.22/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of examples.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ddda757808debff5.svg\" alt=\"J=\\frac33=1\" width=\"115.82\" height=\"50.07\" style=\"width:115.82px;height:50.07px;aspect-ratio:115.82/50.07\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Mean training loss = 1.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s0","search":"What does learning from data mean **Definition.** Machine learning develops models from data so that they can perform a task on new examples. A model is a calculation rule with adjustable numbers. Deep learning uses neural networks with multiple trainable layers; each layer transforms the previous layer's outputs.\n\n### Start with one complete training example\nA **sample** means one example in the dataset. Suppose one example says: an input number is 2 and the required answer is 4. We write the input as x = 2 and the correct answer, or **target**, as y = 4. These letters are labels for the two numbers.\n\nAn **input feature** is one recorded property used to make a prediction. One house might have area, number of rooms and age as three features. The three values together describe one sample. An **input vector** is just an ordered list of those feature values. Order matters: the first model weight must always multiply the first feature.\n\nThe model's calculated answer is the **prediction**, written ŷ, read “y hat”. The hat helps us distinguish the calculated answer ŷ from the required answer y. A prediction is a probability only when the task and output function give it that interpretation.\n\n### The simplest model: multiply, then add\nIn the following model, x is the input, w is a weight and b is a bias. A **weight** multiplies the input. A **bias** is added once after multiplication. Both w and b are adjustable model numbers, called **parameters**.\n\nThe model first multiplies w and x; then it adds b. For several inputs it uses one matching weight per input, adds their products, and then adds the bias.\n\n**Yaad rakhne ka cue:** x diya hua input; y sahi answer; ŷ model ka answer; w aur b training mein badlenge.\n\n\n\n\n### Model example 1: calculate a prediction\n\n**Question. A linear model uses ŷ = wx+b. For x = 2, w = 1 and b = 0, calculate its prediction.**\n\n\n\n### Given\n\nInput x = 2.\n\nWeight w = 1; bias b = 0.\n\nThe output is linear: no extra activation is specified.\n\n### To find\n\nThe predicted value ŷ.\n\n### Formula — which one and why\n\nUse the stated model. The multiplication gives the input contribution; the bias shifts the result.\n\nx is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.\n\n\n\n**Yaad rakhne ka cue:** Pehle input × weight, phir bias add.\n\n### Solution — step by step\n\n\n\n**Step 1: multiply the input by its weight.**\n\n\n\n\n\n\n\n**Step 2: add the bias once.**\n\n\n\n\n\n\n\n**Final answer:** ŷ = 2. This is a prediction, not a loss or a learned weight.\n\n\n\n### Model example 2: calculate a prediction\n\n**Question. A linear model uses ŷ = wx+b. For x = 2, w = 1.5 and b = 1, calculate its prediction.**\n\n\n\n### Given\n\nInput x = 2.\n\nWeight w = 1.5; bias b = 1.\n\nThe output is linear: no extra activation is specified.\n\n### To find\n\nThe predicted value ŷ.\n\n### Formula — which one and why\n\nUse the stated model. The multiplication gives the input contribution; the bias shifts the result.\n\nx is the input; w is its multiplier; b is the added offset; ŷ is the calculated output.\n\n\n\n**Yaad rakhne ka cue:** Pehle input × weight, phir bias add.\n\n### Solution — step by step\n\n\n\n**Step 1: multiply the input by its weight.**\n\n\n\n\n\n\n\n**Step 2: add the bias once.**\n\n\n\n\n\n\n\n**Final answer:** ŷ = 4. This is a prediction, not a loss or a learned weight.\n\n\n\n### Model example 3: calculate a prediction\n\n**Question. A linear model uses ŷ = wx+b. For x = 3, w = 1.5 and b = 1, calculate its prediction.**\n\n\n\n### Given\n\nInput x = 3.\n\nWeight w = 1.5; bias b"},{"title":"Your first complete training step","blocks":["<p class=\"inline-question\"><strong>Question.</strong> A linear model is defined by <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b0668b91b6f454d0.svg\" alt=\"\\hat y=wx\" width=\"59.14\" height=\"19.29\" style=\"width:59.14px;height:19.29px;aspect-ratio:59.14/19.29\" loading=\"lazy\"></span>. For the training example x = 2, y = 4, use initial weight w₀ = 1, learning rate η = 0.1 and half squared loss. Perform two gradient-descent updates and report the prediction and loss after each update.</p>","<h3>Given</h3>","<p>Model: ŷ = wx; bias is absent and is not updated.</p>","<p>x = 2; y = 4; initial w₀ = 1; η = 0.1.</p>","<p>Loss = half squared error; perform two updates.</p>","<h3>To find</h3>","<p>Find the weight, prediction and loss after each update.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule with only a trainable weight.</strong> The weight changes the prediction and the prediction changes the half squared loss. Multiply both rates, then subtract the scaled gradient. The stated model has no bias parameter.</p>","<p>ŷ = prediction; y = target; x = input; w = weight; η = learning rate; g = loss derivative with respect to w.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b0668b91b6f454d0.svg\" alt=\"\\hat y=wx\" width=\"76.03\" height=\"24.80\" style=\"width:76.03px;height:24.80px;aspect-ratio:76.03/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/df5fc0c0a9ad8296.svg\" alt=\"L=\\frac12(\\hat y-y)^2\" width=\"155.68\" height=\"49.55\" style=\"width:155.68px;height:49.55px;aspect-ratio:155.68/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f90a893376d444b0.svg\" alt=\"g=(\\hat y-y)x\" width=\"131.04\" height=\"25.90\" style=\"width:131.04px;height:25.90px;aspect-ratio:131.04/25.90\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Prediction minus target, phir input se multiply; naya weight = purana − ηg.</p>","<h3>Solution — step by step</h3>","<h3>Model, objective and gradient</h3>","<p>The input and target remain fixed; only the weight is trainable. There is no bias parameter in this question.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.48px;--narrow-height:129.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/991254a061f484f9.svg\"><img class=\"math display-math\" src=\"assets/equations/c9459723553604be.svg\" alt=\"\\hat y=wx,\\qquad L(w)=\\frac12(wx-y)^2,\\qquad w_t=w_{t-1}-\\eta g_t\" width=\"575.31\" height=\"49.55\" style=\"width:575.31px;height:49.55px;aspect-ratio:575.31/49.55\" loading=\"lazy\"></picture></div>","<p>Apply the chain rule through the prediction:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.46px;--narrow-height:103.10px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/48779dd96502307c.svg\"><img class=\"math display-math\" src=\"assets/equations/297f87410a0b6ab4.svg\" alt=\"g_t=\\left.\\frac{\\partial L}{\\partial w}\\right|_{w_{t-1}}=\\frac{\\partial L}{\\partial\\hat y}\\frac{\\partial\\hat y}{\\partial w}=(\\hat y-y)x\" width=\"373.84\" height=\"62.54\" style=\"width:373.84px;height:62.54px;aspect-ratio:373.84/62.54\" loading=\"lazy\"></picture></div>","<p>The factor 1/2 in the objective cancels the factor 2 from differentiating the square. The remaining factor x comes from differentiating wx with respect to w.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/first_training.png\" aria-label=\"Enlarge diagram: Forward evaluation, gradient calculation and a parameter update for the same training example.\"><img src=\"assets/figures/first_training.png\" alt=\"Forward evaluation, gradient calculation and a parameter update for the same training example.\" width=\"1536\" height=\"1024\" loading=\"lazy\"></button><figcaption>Forward evaluation, gradient calculation and a parameter update for the same training example. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Iteration 1</h3>","<p class=\"worked-step\"><strong>Step 1: forward evaluation at the current parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.99px;--narrow-height:105.56px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8f7cd4947851e2db.svg\"><img class=\"math display-math\" src=\"assets/equations/396cd8262d595e6d.svg\" alt=\"\\hat y_0=w_0x=1(2)=2,\\qquad e_0=\\hat y_0-y=2-4=-2\" width=\"547.74\" height=\"25.90\" style=\"width:547.74px;height:25.90px;aspect-ratio:547.74/25.90\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6de0a03e9715872f.svg\" alt=\"L_0=\\frac12(-2)^2=2\" width=\"188.57\" height=\"49.55\" style=\"width:188.57px;height:49.55px;aspect-ratio:188.57/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: gradient at the current parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.87px;--narrow-height:64.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eca6d4b6240460b4.svg\"><img class=\"math display-math\" src=\"assets/equations/4b34bd0ab6469482.svg\" alt=\"g_1=(\\hat y_0-y)x=(-2)(2)=-4\" width=\"330.23\" height=\"25.90\" style=\"width:330.23px;height:25.90px;aspect-ratio:330.23/25.90\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: parameter update.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10fc5d59ff5f6fd3.svg\"><img class=\"math display-math\" src=\"assets/equations/32a8eeeef9367ad9.svg\" alt=\"w_1=w_0-\\eta g_1=1-0.1(-4)=1.4\" width=\"373.19\" height=\"24.43\" style=\"width:373.19px;height:24.43px;aspect-ratio:373.19/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: evaluate the updated model.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.29px;--narrow-height:129.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/80c9306a0dfccc42.svg\"><img class=\"math display-math\" src=\"assets/equations/dc92a06893eca5f4.svg\" alt=\"\\hat y_1=1.4(2)=2.8,\\qquad L_1=\\frac12(2.8-4)^2=0.72\" width=\"503.11\" height=\"49.55\" style=\"width:503.11px;height:49.55px;aspect-ratio:503.11/49.55\" loading=\"lazy\"></picture></div>","<h3>Iteration 2</h3>","<p>Use w₁ = 1.4 and recompute the gradient; reusing the previous gradient would not be gradient descent on this objective.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.96px;--narrow-height:64.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a7b033dfd881b35.svg\"><img class=\"math display-math\" src=\"assets/equations/d5601224799e33a1.svg\" alt=\"g_2=(\\hat y_1-y)x=(2.8-4)(2)=-2.4\" width=\"391.34\" height=\"25.90\" style=\"width:391.34px;height:25.90px;aspect-ratio:391.34/25.90\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.06px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ef24d99282ed8b6f.svg\"><img class=\"math display-math\" src=\"assets/equations/1a64bdc673ed180f.svg\" alt=\"w_2=w_1-\\eta g_2=1.4-0.1(-2.4)=1.64\" width=\"423.42\" height=\"24.43\" style=\"width:423.42px;height:24.43px;aspect-ratio:423.42/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.72px;--narrow-height:129.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/09afd5ffebd67c9e.svg\"><img class=\"math display-math\" src=\"assets/equations/cde5a74260a032c4.svg\" alt=\"\\hat y_2=1.64(2)=3.28,\\qquad L_2=\\frac12(3.28-4)^2=0.2592\" width=\"564.19\" height=\"49.55\" style=\"width:564.19px;height:49.55px;aspect-ratio:564.19/49.55\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Model state</th><th>Weight</th><th>Prediction</th><th>Half squared loss</th></tr></thead><tbody><tr><td>Initial</td><td>1</td><td>2</td><td>2</td></tr><tr><td>After update 1</td><td>1.4</td><td>2.8</td><td>0.72</td></tr><tr><td>After update 2</td><td>1.64</td><td>3.28</td><td>0.2592</td></tr></tbody></table></div>","<p><strong>Interpretation.</strong> Both gradients are negative, so the updates increase the weight toward the optimum w = y/x = 2. The loss decreases in these iterations. Gradient descent does not guarantee a decrease for every learning rate; step size matters.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s1","search":"Your first complete training step \n**Question.** A linear model is defined by \\(\\hat y=wx\\). For the training example x = 2, y = 4, use initial weight w₀ = 1, learning rate η = 0.1 and half squared loss. Perform two gradient-descent updates and report the prediction and loss after each update.\n\n\n\n### Given\n\nModel: ŷ = wx; bias is absent and is not updated.\n\nx = 2; y = 4; initial w₀ = 1; η = 0.1.\n\nLoss = half squared error; perform two updates.\n\n### To find\n\nFind the weight, prediction and loss after each update.\n\n### Formula — which one and why\n\n**Chain rule with only a trainable weight.** The weight changes the prediction and the prediction changes the half squared loss. Multiply both rates, then subtract the scaled gradient. The stated model has no bias parameter.\n\nŷ = prediction; y = target; x = input; w = weight; η = learning rate; g = loss derivative with respect to w.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Prediction minus target, phir input se multiply; naya weight = purana − ηg.\n\n### Solution — step by step\n\n\n\n\n\n### Model, objective and gradient\nThe input and target remain fixed; only the weight is trainable. There is no bias parameter in this question.\n\nApply the chain rule through the prediction:\n\nThe factor 1/2 in the objective cancels the factor 2 from differentiating the square. The remaining factor x comes from differentiating wx with respect to w.\n\n\n\n### Iteration 1\n**Step 1: forward evaluation at the current parameter.**\n\n\n**Step 2: gradient at the current parameter.**\n\n**Step 3: parameter update.**\n\n**Step 4: evaluate the updated model.**\n\n\n### Iteration 2\nUse w₁ = 1.4 and recompute the gradient; reusing the previous gradient would not be gradient descent on this objective.\n\n\n\n| Model state | Weight | Prediction | Half squared loss |\n| Initial | 1 | 2 | 2 |\n| After update 1 | 1.4 | 2.8 | 0.72 |\n| After update 2 | 1.64 | 3.28 | 0.2592 |\n**Interpretation.** Both gradients are negative, so the updates increase the weight toward the optimum w = y/x = 2. The loss decreases in these iterations. Gradient descent does not guarantee a decrease for every learning rate; step size matters.\n\n"},{"title":"Classification regression and learning types","blocks":["<p class=\"definition\"><strong>Definition.</strong> A learning problem is specified by its data, desired output and objective. Classification estimates a discrete label or class distribution; regression estimates numerical responses. The supervision type describes the feedback available during training.</p>","<h3>Explanation and working</h3>","<p><strong>Regression</strong> predicts a numerical quantity, such as temperature, price or a continuous rating. <strong>Classification</strong> predicts a category, such as defective/non-defective or cat/dog/bird. Binary classification has two classes. Multiclass classification chooses one of several classes. Multilabel classification can choose several labels together, such as “beach” and “sunset” for the same image.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_tasks.svg\" aria-label=\"Enlarge diagram: Look at the required answer: a numerical quantity is regression; a category is classification.\"><img src=\"assets/figures/v_tasks.svg\" alt=\"Look at the required answer: a numerical quantity is regression; a category is classification.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Look at the required answer: a numerical quantity is regression; a category is classification. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Supervised learning</strong> uses known input–target pairs. Most examination numericals in this course use it. <strong>Unsupervised learning</strong> searches for patterns without supplied target labels, for example grouping similar samples. <strong>Reinforcement learning</strong> learns actions using rewards from an environment. You only need these distinctions as vocabulary here; detailed algorithms from last semester are not prerequisites for this course.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s2","search":"Classification regression and learning types **Definition.** A learning problem is specified by its data, desired output and objective. Classification estimates a discrete label or class distribution; regression estimates numerical responses. The supervision type describes the feedback available during training.\n\n### Explanation and working\n**Regression** predicts a numerical quantity, such as temperature, price or a continuous rating. **Classification** predicts a category, such as defective/non-defective or cat/dog/bird. Binary classification has two classes. Multiclass classification chooses one of several classes. Multilabel classification can choose several labels together, such as “beach” and “sunset” for the same image.\n\n\n\n**Supervised learning** uses known input–target pairs. Most examination numericals in this course use it. **Unsupervised learning** searches for patterns without supplied target labels, for example grouping similar samples. **Reinforcement learning** learns actions using rewards from an environment. You only need these distinctions as vocabulary here; detailed algorithms from last semester are not prerequisites for this book."},{"title":"Training validation and test data","blocks":["<p class=\"definition\"><strong>Definition.</strong> Dataset partitioning separates parameter estimation, model selection and final performance assessment. This separation is essential to evaluate generalization without contaminating the evaluation with selection decisions.</p>","<h3>Explanation and working</h3>","<p>Training data changes the weights. Validation data helps choose settings such as layer size, learning rate and the stopping epoch. Test data is held back for the final estimate of performance on unseen samples. A possible split is 70% training, 15% validation, 15% testing, but the best split depends on the task and dataset size.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_splits.svg\" aria-label=\"Enlarge diagram: The three splits have different jobs. Only the training part is used to fit preprocessing and model parameters.\"><img src=\"assets/figures/v_splits.svg\" alt=\"The three splits have different jobs. Only the training part is used to fit preprocessing and model parameters.\" width=\"1080\" height=\"520\" loading=\"lazy\"></button><figcaption>The three splits have different jobs. Only the training part is used to fit preprocessing and model parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For 1,000 independent samples, this split gives 700 training, 150 validation and 150 testing. Avoid putting duplicates or near-identical views of the same subject across splits. For time series, later observations normally belong after earlier observations rather than being mixed randomly without considering time.</p>","<p><strong>Data leakage</strong> occurs when information that would not be available at prediction time enters training or model selection. Fitting a normalization rule to the whole dataset before splitting can leak information. Estimate preprocessing quantities from training data and apply the same rule to validation and test data.</p>","<p><strong>Normalization example.</strong> To map a training range 0 to 100 into 0 to 1, divide by 100. A value 40 becomes 0.4. Standardization instead subtracts the training mean and divides by the training standard deviation. Scaling can make gradients easier to optimize; it does not create labels or guarantee accuracy.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s3","search":"Training validation and test data **Definition.** Dataset partitioning separates parameter estimation, model selection and final performance assessment. This separation is essential to evaluate generalization without contaminating the evaluation with selection decisions.\n\n### Explanation and working\nTraining data changes the weights. Validation data helps choose settings such as layer size, learning rate and the stopping epoch. Test data is held back for the final estimate of performance on unseen samples. A possible split is 70% training, 15% validation, 15% testing, but the best split depends on the task and dataset size.\n\n\n\nFor 1,000 independent samples, this split gives 700 training, 150 validation and 150 testing. Avoid putting duplicates or near-identical views of the same subject across splits. For time series, later observations normally belong after earlier observations rather than being mixed randomly without considering time.\n**Data leakage** occurs when information that would not be available at prediction time enters training or model selection. Fitting a normalization rule to the whole dataset before splitting can leak information. Estimate preprocessing quantities from training data and apply the same rule to validation and test data.\n**Normalization example.** To map a training range 0 to 100 into 0 to 1, divide by 100. A value 40 becomes 0.4. Standardization instead subtracts the training mean and divides by the training standard deviation. Scaling can make gradients easier to optimize; it does not create labels or guarantee accuracy."},{"title":"Parameters and hyperparameters","blocks":["<p class=\"definition\"><strong>Definition.</strong> Model parameters are quantities estimated during training, whereas hyperparameters specify the architecture or training procedure and are selected separately. Optimizer states are algorithmic accumulators associated with the training procedure.</p>","<h3>Explanation and working</h3>","<p>Weights and biases are parameters learned during training. Learning rate, batch size, number of epochs, network architecture, dropout rate and regularization strength are hyperparameters chosen or tuned using validation performance. Adam’s moving averages are optimizer state: they are updated by the algorithm but are not extra network connection weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters.svg\" aria-label=\"Enlarge diagram: Weights change during training. Settings such as batch size and learning rate are chosen or tuned separately.\"><img src=\"assets/figures/v_parameters.svg\" alt=\"Weights change during training. Settings such as batch size and learning rate are chosen or tuned separately.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Weights change during training. Settings such as batch size and learning rate are chosen or tuned separately. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>An <strong>epoch</strong> is one complete pass through the training dataset. A <strong>batch</strong> is the group used to calculate one update. An <strong>iteration</strong> here means one update. If there are 100 samples and batch size 10, one epoch has 10 updates. One epoch does not generally mean one update.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s4","search":"Parameters and hyperparameters **Definition.** Model parameters are quantities estimated during training, whereas hyperparameters specify the architecture or training procedure and are selected separately. Optimizer states are algorithmic accumulators associated with the training procedure.\n\n### Explanation and working\nWeights and biases are parameters learned during training. Learning rate, batch size, number of epochs, network architecture, dropout rate and regularization strength are hyperparameters chosen or tuned using validation performance. Adam’s moving averages are optimizer state: they are updated by the algorithm but are not extra network connection weights.\n\n\n\nAn **epoch** is one complete pass through the training dataset. A **batch** is the group used to calculate one update. An **iteration** here means one update. If there are 100 samples and batch size 10, one epoch has 10 updates. One epoch does not generally mean one update."},{"title":"Artificial intelligence machine learning and deep learning","blocks":["<p class=\"definition\"><strong>Definition.</strong> Deep learning is a subfield of machine learning that learns representations through multiple trainable processing layers. Each layer transforms the preceding representation, allowing the complete model to learn a composition of functions from data.</p>","<h3>Position within artificial intelligence</h3>","<p>Artificial intelligence studies systems that perform tasks such as perception, reasoning and decision-making. Machine learning develops models whose parameters or behavior are estimated from data. Deep learning uses layered neural models within machine learning.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/862fde9ce2f6cd54.svg\" alt=\"\\text{Deep learning}\\subset\\text{Machine learning}\\subset\\text{Artificial intelligence}\" width=\"613.55\" height=\"22.53\" style=\"width:613.55px;height:22.53px;aspect-ratio:613.55/22.53\" loading=\"lazy\"></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_ai_ml_dl.svg\" aria-label=\"Enlarge diagram: AI is the broad field. Machine learning learns from data; deep learning learns through multiple representation layers.\"><img src=\"assets/figures/v_ai_ml_dl.svg\" alt=\"AI is the broad field. Machine learning learns from data; deep learning learns through multiple representation layers.\" width=\"1080\" height=\"590\" loading=\"lazy\"></button><figcaption>AI is the broad field. Machine learning learns from data; deep learning learns through multiple representation layers. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Motivation: why use multiple learned layers?</h3>","<p><strong>Representation learning.</strong> Hand-designing every useful image or speech feature is difficult. A deep model can learn intermediate representations together with the final prediction objective. In a CNN, early layers may respond to local edges, while later layers combine information over larger regions. These patterns depend on training and are not guaranteed to have a particular human meaning.</p>","<p><strong>Nonlinear relationships.</strong> Real tasks often depend on combinations of input variables. Composing affine transformations with nonlinear activations can represent interactions that a single linear decision boundary cannot. Depth supplies repeated transformations; increasing only the number of neurons in one layer changes width instead.</p>","<p><strong>End-to-end optimization.</strong> The final task loss supplies gradients to the preceding trainable layers. The feature extractor and prediction head can therefore be adjusted for the same task. Preprocessing and human decisions about architecture, data and evaluation still remain necessary.</p>","<h3>Factors that made deep learning practical</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Factor</th><th>How it contributes</th></tr></thead><tbody><tr><td>Larger datasets</td><td>Provide more examples of the variations a complex model must learn</td></tr><tr><td>GPUs and parallel computation</td><td>Accelerate the large matrix and convolution operations used in training</td></tr><tr><td>Improved training methods</td><td>Backpropagation, suitable activations, initialization and optimizers make fitting deep models more practical</td></tr><tr><td>Pretrained models</td><td>Reuse learned features so a new task may require less labeled data and training effort</td></tr></tbody></table></div>","<h3>Applications in different domains</h3>","<p>An application answer should identify the input, the prediction and the role of the learned representation.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Domain</th><th>Example input</th><th>Required output</th><th>Role of deep learning</th></tr></thead><tbody><tr><td>Computer vision</td><td>Photograph or video frame</td><td>Image class, object locations or pixel labels</td><td>Learn visual features with a CNN and an appropriate task head</td></tr><tr><td>Language</td><td>Review, sentence or conversation</td><td>Sentiment label, translated words or a response</td><td>Learn representations of text and its context</td></tr><tr><td>Speech</td><td>Audio sequence</td><td>Words or a speaker label</td><td>Model patterns in acoustic features over time</td></tr><tr><td>Healthcare</td><td>Medical image or patient measurements</td><td>A task-specific class or numerical estimate</td><td>Learn associations from labeled examples; assess results on suitable held-out data</td></tr><tr><td>Autonomous systems and robotics</td><td>Camera and other sensor measurements</td><td>Perception estimates used by a larger control system</td><td>Recognize objects and relevant environmental features</td></tr><tr><td>Financial services</td><td>Transaction features or a time-ordered record</td><td>Fraud score, risk estimate or forecast</td><td>Model patterns and interactions among observations</td></tr></tbody></table></div>","<h3>Advantages, limitations and comparison with traditional ML</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Aspect</th><th>Traditional machine learning often uses</th><th>Deep learning often uses</th></tr></thead><tbody><tr><td>Representation</td><td>Selected or engineered input features</td><td>Features learned jointly across layers</td></tr><tr><td>Useful architectures</td><td>Linear models, decision trees, SVMs</td><td>MLPs, CNNs, RNNs and gated recurrent models</td></tr><tr><td>Training from scratch</td><td>Can be effective with modest structured datasets</td><td>Large models often need substantial data and computation</td></tr><tr><td>Interpretation</td><td>Some models have directly inspectable rules or coefficients</td><td>Learned internal representations can be harder to interpret</td></tr></tbody></table></div>","<p>Feature learning, flexible nonlinear modeling and reuse of pretrained representations are major advantages. Limitations include computation and memory costs, overfitting with insufficient representative data, difficulty interpreting predictions, and reduced reliability when deployment data differs from training data. High training accuracy does not establish generalization.</p>","<p>These are tendencies, not absolute divisions. Traditional ML can also learn representations; deep models can process tabular data. A pretrained deep model may be useful even with a small target dataset. Select the model according to the task, available data, resources and validation results.</p>","<p class=\"inline-question\"><strong>Question. Explain the motivation for deep learning and describe applications in at least three domains.</strong></p>","<p><strong>Answer.</strong> Deep learning is motivated by the need to learn useful hierarchical representations and nonlinear relationships directly from complex data. Multiple trainable layers compose feature transformations, and the task loss can train those transformations jointly with the predictor. Larger datasets, GPU computation and improved optimization methods have made this practical. In computer vision, CNNs learn visual features for image classification and object localization. In language processing, neural sequence models use word representations and context for sentiment analysis or translation. In speech processing, neural models map acoustic patterns to words. The benefits must be balanced against data requirements, computation, overfitting and interpretability limitations.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s5","search":"Artificial intelligence machine learning and deep learning **Definition.** Deep learning is a subfield of machine learning that learns representations through multiple trainable processing layers. Each layer transforms the preceding representation, allowing the complete model to learn a composition of functions from data.\n\n### Position within artificial intelligence\nArtificial intelligence studies systems that perform tasks such as perception, reasoning and decision-making. Machine learning develops models whose parameters or behavior are estimated from data. Deep learning uses layered neural models within machine learning.\n\n\n\n### Motivation: why use multiple learned layers?\n**Representation learning.** Hand-designing every useful image or speech feature is difficult. A deep model can learn intermediate representations together with the final prediction objective. In a CNN, early layers may respond to local edges, while later layers combine information over larger regions. These patterns depend on training and are not guaranteed to have a particular human meaning.\n\n**Nonlinear relationships.** Real tasks often depend on combinations of input variables. Composing affine transformations with nonlinear activations can represent interactions that a single linear decision boundary cannot. Depth supplies repeated transformations; increasing only the number of neurons in one layer changes width instead.\n\n**End-to-end optimization.** The final task loss supplies gradients to the preceding trainable layers. The feature extractor and prediction head can therefore be adjusted for the same task. Preprocessing and human decisions about architecture, data and evaluation still remain necessary.\n\n### Factors that made deep learning practical\n| Factor | How it contributes |\n| Larger datasets | Provide more examples of the variations a complex model must learn |\n| GPUs and parallel computation | Accelerate the large matrix and convolution operations used in training |\n| Improved training methods | Backpropagation, suitable activations, initialization and optimizers make fitting deep models more practical |\n| Pretrained models | Reuse learned features so a new task may require less labeled data and training effort |\n\n### Applications in different domains\nAn application answer should identify the input, the prediction and the role of the learned representation.\n| Domain | Example input | Required output | Role of deep learning |\n| Computer vision | Photograph or video frame | Image class, object locations or pixel labels | Learn visual features with a CNN and an appropriate task head |\n| Language | Review, sentence or conversation | Sentiment label, translated words or a response | Learn representations of text and its context |\n| Speech | Audio sequence | Words or a speaker label | Model patterns in acoustic features over time |\n| Healthcare | Medical image or patient measurements | A task-specific class or numerical estimate | Learn associations from labeled examples; assess results on suitable held-out data |\n| Autonomous systems and robotics | Camera and other sensor measurements | Perception estimates used by a larger control system | Recognize objects and relevant environmental features |\n| Financial services | Transaction features or a time-ordered record | Fraud score, risk estimate or forecast | Model patterns and interactions among observations |\n\n### Advantages, limitations and comparison with traditional ML\n| Aspect | Traditional machine learni"},{"title":"What one artificial neuron does","blocks":["<p class=\"definition\"><strong>Definition.</strong> An artificial neuron is a calculation unit that multiplies each input by a matching weight, adds the products and a bias, and applies an activation function to produce its output.</p>","<h3>What goes into a neuron?</h3>","<p>An input is a number supplied to the calculation. With three inputs, x = [2,1,3] simply lists those three numbers in order. The matching weight list tells the neuron which multiplier to use for each input. A negative weight contributes a negative amount when its input is positive.</p>","<p>The <strong>bias</strong> is one extra adjustable number added to the total. The total before activation is called z or <strong>preactivation</strong>. The <strong>activation function</strong> is the final rule applied to z: for example, ReLU replaces a negative z with zero, while sigmoid turns z into a number between 0 and 1. The resulting output is called a or the <strong>activation</strong>.</p>","<p><strong>Yaad rakhne ka cue:</strong> inputs × apne weights → products ka sum → ek bias → activation → output.</p>","<h3>Mathematical model and notation</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.35px;--narrow-height:112.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8032854fc489fa3f.svg\"><img class=\"math display-math\" src=\"assets/equations/28f8b2ebee0ebbf6.svg\" alt=\"z=\\sum_{i=1}^{d}w_ix_i+b=w^Tx+b\" width=\"289.70\" height=\"72.98\" style=\"width:289.70px;height:72.98px;aspect-ratio:289.70/72.98\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<div class=\"table-scroll\"><table><thead><tr><th>Symbol</th><th>Meaning and role</th></tr></thead><tbody><tr><td>xᵢ</td><td>Input component i; the neuron receives d such components</td></tr><tr><td>wᵢ</td><td>Trainable weight multiplying that input component</td></tr><tr><td>b</td><td>Trainable bias added once to this neuron&#x27;s total</td></tr><tr><td>z</td><td>Preactivation: the result before applying the activation function</td></tr><tr><td>f</td><td>Chosen activation function, such as sigmoid or ReLU</td></tr><tr><td>a</td><td>Activation: the neuron&#x27;s output after applying f</td></tr></tbody></table></div>","<p>The dot product wᵀx is a compact notation for the sum of matching weight–input products. A positive weight and a negative weight can make opposite contributions for the same positive input. A larger weight magnitude means a larger contribution for a fixed input; it is not, by itself, a general measure of feature importance across differently scaled inputs.</p>","<h3>Why both a bias and an activation are needed</h3>","<p>The bias changes the preactivation independently of x. In a one-input affine function z = wx + b, it is the intercept. In a classifier with a decision boundary z = 0, a bias allows that boundary to be shifted instead of forcing it through the origin.</p>","<p>The activation determines how z is transformed. Sigmoid produces a value between 0 and 1; ReLU retains positive preactivations and sets negative ones to zero. Nonlinear activations let stacked layers represent nonlinear functions. The preactivation and activation are distinct quantities even when a particular ReLU calculation gives them equal values.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: Read the neuron in order: input contributions → affine sum z → activation function f → output a. Add one bias at the receiving neuron.\"><img src=\"assets/figures/neuron.svg\" alt=\"Read the neuron in order: input contributions → affine sum z → activation function f → output a. Add one bias at the receiving neuron.\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>Read the neuron in order: input contributions → affine sum z → activation function f → output a. Add one bias at the receiving neuron. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Worked numerical</h3>","<p class=\"inline-question\"><strong>Question.</strong> A neuron has x = [2, 1, 3]ᵀ, w = [0.4, −0.2, 0.5]ᵀ and b = 0.1. Calculate its preactivation and sigmoid output.</p>","<h3>Given</h3>","<p>Inputs = [2,1,3]; matching weights = [0.4,−0.2,0.5].</p>","<p>Bias = 0.1; activation = sigmoid.</p>","<h3>To find</h3>","<p>Find the preactivation z, then the sigmoid output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid output.</strong> The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.</p>","<p>z = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Minus-z ki e power, plus one, phir one divided by whole denominator.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/568d8f8a50e883d1.svg\" alt=\"x_1w_1=2(0.4)=0.8\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by weight 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2aecb1c03e00ecf3.svg\" alt=\"x_2w_2=1(-0.2)=-0.2\" width=\"249.67\" height=\"24.43\" style=\"width:249.67px;height:24.43px;aspect-ratio:249.67/24.43\" loading=\"lazy\"></div>","<p>The minus sign belongs to the weight, so the contribution stays negative.</p>","<p class=\"worked-step\"><strong>Step 3: multiply input 3 by weight 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b26c8cde278f5783.svg\" alt=\"x_3w_3=3(0.5)=1.5\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the three contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.48px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/928ca4d8a84ae46e.svg\"><img class=\"math display-math\" src=\"assets/equations/fa72e2cee0620f1c.svg\" alt=\"s=0.8+(-0.2)+1.5=0.6+1.5=2.1\" width=\"424.20\" height=\"24.43\" style=\"width:424.20px;height:24.43px;aspect-ratio:424.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc2fbdf24fc7fcdc.svg\" alt=\"z=s+b=2.1+0.1=2.2\" width=\"284.48\" height=\"18.96\" style=\"width:284.48px;height:18.96px;aspect-ratio:284.48/18.96\" loading=\"lazy\"></div>","<p>This is the preactivation. It is not yet the requested sigmoid output.</p>","<p class=\"worked-step\"><strong>Step 6: negate z for the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6ae6042702919060.svg\" alt=\"-z=-2.2\" width=\"113.19\" height=\"18.27\" style=\"width:113.19px;height:18.27px;aspect-ratio:113.19/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3e8120863f30069.svg\" alt=\"e^{-z}=e^{-2.2}\\approx0.110803158\" width=\"277.96\" height=\"23.60\" style=\"width:277.96px;height:23.60px;aspect-ratio:277.96/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:104.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/417b75e5d36172d1.svg\"><img class=\"math display-math\" src=\"assets/equations/72d833375eab0d1c.svg\" alt=\"1+e^{-z}=1+0.110803158=1.110803158\" width=\"442.16\" height=\"22.17\" style=\"width:442.16px;height:22.17px;aspect-ratio:442.16/22.17\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide one by that denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:155.40px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bc1ac01a29b10b0.svg\"><img class=\"math display-math\" src=\"assets/equations/7567a6adfafdbad0.svg\" alt=\"a=\\frac1{1+e^{-z}}=\\frac1{1.110803158}\\approx0.900249511\" width=\"467.09\" height=\"51.56\" style=\"width:467.09px;height:51.56px;aspect-ratio:467.09/51.56\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> sigmoid output ≈ 0.900249511. It lies between 0 and 1. The raw sum was 2.2, whereas the activated output is approximately 0.90025.</p>","<h3>From one neuron to a layer</h3>","<p>With m receiving neurons and d input components, W has shape m × d. Row j contains the incoming weights of neuron j. The bias vector has m entries, one for each receiving neuron:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/247718acabda6724.svg\" alt=\"z=Wx+b,\\qquad a=f(z)\" width=\"272.94\" height=\"24.43\" style=\"width:272.94px;height:24.43px;aspect-ratio:272.94/24.43\" loading=\"lazy\"></div>","<p>Sigmoid, tanh and ReLU apply independently to each component. Softmax is different: it transforms a whole vector of output logits together.</p>","<h3>Neuron example 2: ReLU output</h3>","<p class=\"inline-question\"><strong>Question. A neuron receives inputs [2], weights [3] and bias 1. Calculate its preactivation and ReLU output.</strong></p>","<h3>Given</h3>","<p>Inputs = [2].</p>","<p>Weights = [3]; bias = 1.</p>","<p>Activation = ReLU.</p>","<h3>To find</h3>","<p>z before activation and a after activation.</p>","<h3>Formula — which one and why</h3>","<p>The weighted sum combines the inputs. The output must then use the activation explicitly requested.</p>","<p>z names the sum; a names the activated result. They are not always equal.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3497cbcbfa494dd1.svg\" alt=\"z=\\sum_i w_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sum alag, activation alag; activation lagana mat bhool.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0789e90228011be2.svg\" alt=\"(2)(3)=6\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the input contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7d688f2957123f9f.svg\" alt=\"s=(6)=6\" width=\"120.07\" height=\"24.43\" style=\"width:120.07px;height:24.43px;aspect-ratio:120.07/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cd7ec47b25d8ce7.svg\" alt=\"z=6+(1)=7\" width=\"162.06\" height=\"24.43\" style=\"width:162.06px;height:24.43px;aspect-ratio:162.06/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply the stated activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a730b8a58ff43cba.svg\" alt=\"a=\\max(0,7)=7\" width=\"190.09\" height=\"24.43\" style=\"width:190.09px;height:24.43px;aspect-ratio:190.09/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 7; a = 7.</p>","<h3>Neuron example 3: ReLU output</h3>","<p class=\"inline-question\"><strong>Question. A neuron receives inputs [2, 1], weights [-1, 0.5] and bias 0.2. Calculate its preactivation and ReLU output.</strong></p>","<h3>Given</h3>","<p>Inputs = [2, 1].</p>","<p>Weights = [-1, 0.5]; bias = 0.2.</p>","<p>Activation = ReLU.</p>","<h3>To find</h3>","<p>z before activation and a after activation.</p>","<h3>Formula — which one and why</h3>","<p>The weighted sum combines the inputs. The output must then use the activation explicitly requested.</p>","<p>z names the sum; a names the activated result. They are not always equal.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3497cbcbfa494dd1.svg\" alt=\"z=\\sum_i w_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sum alag, activation alag; activation lagana mat bhool.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc29fd0da04569d8.svg\" alt=\"(2)(-1)=-2\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47470f92bf2adcc4.svg\" alt=\"(1)(0.5)=0.5\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the input contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2345e5dfa56c33e.svg\" alt=\"s=(-2)+(0.5)=-1.5\" width=\"257.21\" height=\"24.43\" style=\"width:257.21px;height:24.43px;aspect-ratio:257.21/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3c99c8f72adf2141.svg\" alt=\"z=-1.5+(0.2)=-1.3\" width=\"257.12\" height=\"24.43\" style=\"width:257.12px;height:24.43px;aspect-ratio:257.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2503c315df3664fa.svg\" alt=\"a=\\max(0,-1.3)=0\" width=\"228.12\" height=\"24.43\" style=\"width:228.12px;height:24.43px;aspect-ratio:228.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = -1.3; a = 0.</p>","<h3>Neuron example 4: sigmoid output</h3>","<p class=\"inline-question\"><strong>Question. A neuron receives inputs [1, 2], weights [0.2, -0.1] and bias 0. Calculate its preactivation and sigmoid output.</strong></p>","<h3>Given</h3>","<p>Inputs = [1, 2].</p>","<p>Weights = [0.2, -0.1]; bias = 0.</p>","<p>Activation = sigmoid.</p>","<h3>To find</h3>","<p>z before activation and a after activation.</p>","<h3>Formula — which one and why</h3>","<p>The weighted sum combines the inputs. The output must then use the activation explicitly requested.</p>","<p>z names the sum; a names the activated result. They are not always equal.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3497cbcbfa494dd1.svg\" alt=\"z=\\sum_i w_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sum alag, activation alag; activation lagana mat bhool.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5c759a37e815fafb.svg\" alt=\"(1)(0.2)=0.2\" width=\"145.27\" height=\"24.43\" style=\"width:145.27px;height:24.43px;aspect-ratio:145.27/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its own weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba87aedd127c080a.svg\" alt=\"(2)(-0.1)=-0.2\" width=\"183.30\" height=\"24.43\" style=\"width:183.30px;height:24.43px;aspect-ratio:183.30/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the input contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9a1dc06bff5e31d8.svg\" alt=\"s=(0.2)+(-0.2)=0\" width=\"238.20\" height=\"24.43\" style=\"width:238.20px;height:24.43px;aspect-ratio:238.20/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8d9f0d00314027b.svg\" alt=\"z=0+(0)=0\" width=\"162.06\" height=\"24.43\" style=\"width:162.06px;height:24.43px;aspect-ratio:162.06/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2d7874ea2511447b.svg\" alt=\"a=\\frac1{1+e^{0}}=\\frac1{1+1}=0.5\" width=\"281.86\" height=\"52.39\" style=\"width:281.86px;height:52.39px;aspect-ratio:281.86/52.39\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 0; a = 0.5.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s6","search":"What one artificial neuron does **Definition.** An artificial neuron is a calculation unit that multiplies each input by a matching weight, adds the products and a bias, and applies an activation function to produce its output.\n\n### What goes into a neuron?\nAn input is a number supplied to the calculation. With three inputs, x = [2,1,3] simply lists those three numbers in order. The matching weight list tells the neuron which multiplier to use for each input. A negative weight contributes a negative amount when its input is positive.\n\nThe **bias** is one extra adjustable number added to the total. The total before activation is called z or **preactivation**. The **activation function** is the final rule applied to z: for example, ReLU replaces a negative z with zero, while sigmoid turns z into a number between 0 and 1. The resulting output is called a or the **activation**.\n\n**Yaad rakhne ka cue:** inputs × apne weights → products ka sum → ek bias → activation → output.\n\n### Mathematical model and notation\n\n\n| Symbol | Meaning and role |\n| xᵢ | Input component i; the neuron receives d such components |\n| wᵢ | Trainable weight multiplying that input component |\n| b | Trainable bias added once to this neuron's total |\n| z | Preactivation: the result before applying the activation function |\n| f | Chosen activation function, such as sigmoid or ReLU |\n| a | Activation: the neuron's output after applying f |\n\nThe dot product wᵀx is a compact notation for the sum of matching weight–input products. A positive weight and a negative weight can make opposite contributions for the same positive input. A larger weight magnitude means a larger contribution for a fixed input; it is not, by itself, a general measure of feature importance across differently scaled inputs.\n\n### Why both a bias and an activation are needed\nThe bias changes the preactivation independently of x. In a one-input affine function z = wx + b, it is the intercept. In a classifier with a decision boundary z = 0, a bias allows that boundary to be shifted instead of forcing it through the origin.\n\nThe activation determines how z is transformed. Sigmoid produces a value between 0 and 1; ReLU retains positive preactivations and sets negative ones to zero. Nonlinear activations let stacked layers represent nonlinear functions. The preactivation and activation are distinct quantities even when a particular ReLU calculation gives them equal values.\n\n\n\n### Worked numerical\n**Question.** A neuron has x = [2, 1, 3]ᵀ, w = [0.4, −0.2, 0.5]ᵀ and b = 0.1. Calculate its preactivation and sigmoid output.\n\n\n\n### Given\n\nInputs = [2,1,3]; matching weights = [0.4,−0.2,0.5].\n\nBias = 0.1; activation = sigmoid.\n\n### To find\n\nFind the preactivation z, then the sigmoid output.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**Sigmoid output.** The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.\n\nz = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.\n\n\n\n**Yaad rakhne ka cue:** Minus-z ki e power, plus"},{"title":"Model answer: explain an artificial neuron","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain the structure and working of an artificial neuron. Describe the roles of inputs, weights, bias and activation with a numerical example.</p>"],"answer":["<p>An artificial neuron is a computational unit that applies an activation function to an affine combination of its inputs. Its trainable weights and bias determine the preactivation; its output is passed to subsequent layers.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: Follow each input through its weight, add one bias at the receiving neuron, then apply activation.\"><img src=\"assets/figures/neuron.svg\" alt=\"Follow each input through its weight, add one bias at the receiving neuron, then apply activation.\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>Follow each input through its weight, add one bias at the receiving neuron, then apply activation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Formula and symbols</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.93px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8477fc1ddc03ffc3.svg\"><img class=\"math display-math\" src=\"assets/equations/32a736852ff7774e.svg\" alt=\"z=w_1x_1+w_2x_2+\\cdots+w_nx_n+b,\\qquad a=f(z)\" width=\"513.48\" height=\"24.43\" style=\"width:513.48px;height:24.43px;aspect-ratio:513.48/24.43\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Part</th><th>Meaning</th><th>What it does</th></tr></thead><tbody><tr><td>x₁, x₂, …</td><td>Input features</td><td>Supply the information for this calculation</td></tr><tr><td>w₁, w₂, …</td><td>Weights</td><td>Control the contribution of each matching input</td></tr><tr><td>b</td><td>Bias</td><td>Shifts the weighted sum independently of the inputs</td></tr><tr><td>z</td><td>Net input</td><td>The number before activation</td></tr><tr><td>f</td><td>Activation rule</td><td>Transforms z, often nonlinearly</td></tr><tr><td>a</td><td>Activated output</td><td>The number sent onward</td></tr></tbody></table></div>","<h3>Worked ReLU neuron example</h3>","<p class=\"inline-question\"><strong>Question. An artificial neuron has x₁ = 2, x₂ = 1, w₁ = 0.5, w₂ = −0.2 and b = 0.1. Calculate its preactivation and ReLU output.</strong></p>","<h3>Given</h3>","<p>Inputs = [2,1]; weights = [0.5,−0.2]; bias = 0.1; activation = ReLU.</p>","<h3>To find</h3>","<p>Preactivation z and activated output a.</p>","<h3>Formula — which one and why</h3>","<p>Each input contributes through its own weight. Add one bias after summing the products; ReLU then keeps a positive total.</p>","<p>z means before activation; a means after activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/04168cf0cec0712f.svg\" alt=\"z=w_1x_1+w_2x_2+b\" width=\"219.78\" height=\"20.63\" style=\"width:219.78px;height:20.63px;aspect-ratio:219.78/20.63\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Product, product, sum, bias, phir activation.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply the first pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4b945ff5abf26e2.svg\" alt=\"0.5(2)=1\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply the second pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44552ee4afe034fa.svg\" alt=\"(-0.2)(1)=-0.2\" width=\"183.30\" height=\"24.43\" style=\"width:183.30px;height:24.43px;aspect-ratio:183.30/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add both contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d74c1d06c5bc866b.svg\" alt=\"1+(-0.2)=0.8\" width=\"175.14\" height=\"24.43\" style=\"width:175.14px;height:24.43px;aspect-ratio:175.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe5a369324074a4c.svg\" alt=\"z=0.8+0.1=0.9\" width=\"200.08\" height=\"18.27\" style=\"width:200.08px;height:18.27px;aspect-ratio:200.08/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply ReLU.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/abc54eeca8cf7516.svg\" alt=\"a=\\max(0,0.9)=0.9\" width=\"228.12\" height=\"24.43\" style=\"width:228.12px;height:24.43px;aspect-ratio:228.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> z = 0.9 and a = 0.9. ReLU leaves this positive preactivation unchanged.</p>","<p>The weights and bias are learned parameters. During training, their values are adjusted to reduce an objective. The activation function itself is usually chosen as part of the architecture. Adding a bias does not mean adding one bias after every input product; add the receiving neuron&#x27;s bias once.</p>"],"kind":"theory","id":"tee-c4-s7","search":"Model answer: explain an artificial neuron **Question.** Explain the structure and working of an artificial neuron. Describe the roles of inputs, weights, bias and activation with a numerical example.\n\n**Model answer.**\nAn artificial neuron is a computational unit that applies an activation function to an affine combination of its inputs. Its trainable weights and bias determine the preactivation; its output is passed to subsequent layers.\n\n\n\n\n### Formula and symbols\n\n| Part | Meaning | What it does |\n| x₁, x₂, … | Input features | Supply the information for this calculation |\n| w₁, w₂, … | Weights | Control the contribution of each matching input |\n| b | Bias | Shifts the weighted sum independently of the inputs |\n| z | Net input | The number before activation |\n| f | Activation rule | Transforms z, often nonlinearly |\n| a | Activated output | The number sent onward |\n\n\n\n### Worked ReLU neuron example\n\n**Question. An artificial neuron has x₁ = 2, x₂ = 1, w₁ = 0.5, w₂ = −0.2 and b = 0.1. Calculate its preactivation and ReLU output.**\n\n\n\n### Given\n\nInputs = [2,1]; weights = [0.5,−0.2]; bias = 0.1; activation = ReLU.\n\n### To find\n\nPreactivation z and activated output a.\n\n### Formula — which one and why\n\nEach input contributes through its own weight. Add one bias after summing the products; ReLU then keeps a positive total.\n\nz means before activation; a means after activation.\n\n\n\n\n\n**Yaad rakhne ka cue:** Product, product, sum, bias, phir activation.\n\n### Solution — step by step\n\n\n\n**Step 1: multiply the first pair.**\n\n\n\n\n\n\n\n**Step 2: multiply the second pair.**\n\n\n\n\n\n\n\n**Step 3: add both contributions.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply ReLU.**\n\n\n\n\n\n\n\n**Final answer:** z = 0.9 and a = 0.9. ReLU leaves this positive preactivation unchanged.\n\n\n\nThe weights and bias are learned parameters. During training, their values are adjusted to reduce an objective. The activation function itself is usually chosen as part of the architecture. Adding a bias does not mean adding one bias after every input product; add the receiving neuron's bias once.\n"},{"title":"Perceptrons and the threshold","blocks":["<p>A perceptron is a simple neuron used for classification with a threshold decision. If a question says output 1 for z ≥ 0 and 0 otherwise, then z = 0 gives 1. If it says output 1 for z &gt; 0 and 0 otherwise, then z = 0 gives 0. That single equality sign can change an entire training table.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_threshold.svg\" aria-label=\"Enlarge diagram: The weighted sum is a real number. The threshold turns that number into a hard decision.\"><img src=\"assets/figures/v_threshold.svg\" alt=\"The weighted sum is a real number. The threshold turns that number into a hard decision.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The weighted sum is a real number. The threshold turns that number into a hard decision. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Implement binary AND with w₁ = w₂ = 0.6, b = −0.8 and output 1 when z ≥ 0.</p>","<h3>Given</h3>","<p>w₁ = w₂ = 0.6; bias b = −0.8.</p>","<p>Binary inputs; output 1 when z ≥ 0.</p>","<h3>To find</h3>","<p>Calculate the output for 00,01,10,11 and show that the result is AND.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<h3>Input (0, 0)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e725afda84fc9ed3.svg\" alt=\"s=0+0=0\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d15ca461c07dd695.svg\" alt=\"z=0+(-0.8)=-0.8\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.8; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (0, 1)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8544b9e49d354ea3.svg\" alt=\"s=0+0.6=0.6\" width=\"181.17\" height=\"18.27\" style=\"width:181.17px;height:18.27px;aspect-ratio:181.17/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f10c0127832440d1.svg\" alt=\"z=0.6+(-0.8)=-0.2\" width=\"257.12\" height=\"24.43\" style=\"width:257.12px;height:24.43px;aspect-ratio:257.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.2; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (1, 0)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5398d7a271c52472.svg\" alt=\"s=0.6+0=0.6\" width=\"181.17\" height=\"18.27\" style=\"width:181.17px;height:18.27px;aspect-ratio:181.17/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f10c0127832440d1.svg\" alt=\"z=0.6+(-0.8)=-0.2\" width=\"257.12\" height=\"24.43\" style=\"width:257.12px;height:24.43px;aspect-ratio:257.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.2; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (1, 1)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/379a82d19e479abf.svg\" alt=\"s=0.6+0.6=1.2\" width=\"200.18\" height=\"18.27\" style=\"width:200.18px;height:18.27px;aspect-ratio:200.18/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/63a2763d058f9aec.svg\" alt=\"z=1.2+(-0.8)=0.4\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = 0.4; output = 1 because output is 1 exactly when z ≥ 0.</p>","<p><strong>Final answer:</strong> outputs are [0, 0, 0, 1] for inputs 00, 01, 10, 11: exactly AND.</p>","<h3>Summary of the four cases</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Inputs</th><th>Full net calculation</th><th>Net z</th><th>Output</th><th>AND target</th></tr></thead><tbody><tr><td>0, 0</td><td>0.6(0) + 0.6(0) − 0.8</td><td>−0.8</td><td>0</td><td>0</td></tr><tr><td>0, 1</td><td>0.6(0) + 0.6(1) − 0.8</td><td>−0.2</td><td>0</td><td>0</td></tr><tr><td>1, 0</td><td>0.6(1) + 0.6(0) − 0.8</td><td>−0.2</td><td>0</td><td>0</td></tr><tr><td>1, 1</td><td>0.6(1) + 0.6(1) − 0.8</td><td>0.4</td><td>1</td><td>1</td></tr></tbody></table></div>","<p>The neuron fires only when both inputs are 1. No weight update was requested, so this is a forward evaluation, not a training problem.</p>","<p>For binary targets, a common learning rule is w ← w + η(t − a)x and b ← b + η(t − a). For bipolar targets −1 and +1, the class notes use a different rule: on a mismatch, w ← w + η tx and b ← b + ηt; otherwise keep them. The notes give output 0 at zero threshold, +1 above it and −1 below it. Never combine the activation from one convention with an unexplained update from another.</p>","<p><strong>Training table routine: </strong> copy current weights → calculate z → apply the stated threshold → compare output with target → compute every weight change → update bias → carry new values to the next row. Reset nothing between rows or epochs unless instructed.</p>","<h3>Binary perceptron: target 1</h3>","<p class=\"inline-question\"><strong>Question. A binary perceptron has x = [1,2], weights [-0.2, 0.1], bias 0 and target 1. Use output 1 for net ≥ 0 and learning rate 0.1. Perform one update.</strong></p>","<h3>Given</h3>","<p>x = [1,2]; w = [-0.2, 0.1]; b = 0; target = 1; η = 0.1.</p>","<h3>To find</h3>","<p>Net, threshold output, correction and new weights/bias.</p>","<h3>Formula — which one and why</h3>","<p>This binary learning rule uses target minus output. Carry the same correction into every input weight and the bias.</p>","<p>t is target; o is threshold output; Δ means the amount added to the current parameter.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3870c6199f4ce08e.svg\" alt=\"\\Delta w_i=\\eta(t-o)x_i\" width=\"182.09\" height=\"24.43\" style=\"width:182.09px;height:24.43px;aspect-ratio:182.09/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/998f813758f64544.svg\" alt=\"\\Delta b=\\eta(t-o)\" width=\"145.12\" height=\"24.43\" style=\"width:145.12px;height:24.43px;aspect-ratio:145.12/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Target minus output; correct prediction ho toh correction zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the net input.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.75px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ad825aadcb48f967.svg\"><img class=\"math display-math\" src=\"assets/equations/358f13c8da68054b.svg\" alt=\"z=(-0.2)(1)+(0.1)(2)+0=0\" width=\"342.64\" height=\"24.43\" style=\"width:342.64px;height:24.43px;aspect-ratio:342.64/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: apply the threshold.</strong></p>","<p>Net = 0; output = 1 under the stated ≥ 0 rule.</p>","<p class=\"worked-step\"><strong>Step 3: calculate the correction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec562da655acc385.svg\" alt=\"t-o=1-1=0\" width=\"182.23\" height=\"18.27\" style=\"width:182.23px;height:18.27px;aspect-ratio:182.23/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: update weight 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.65px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35b1f47fa8ef32d6.svg\"><img class=\"math display-math\" src=\"assets/equations/44ce80449df859db.svg\" alt=\"w_1^{\\mathrm{new}}=-0.2+0.1(0)(1)=-0.2\" width=\"338.47\" height=\"24.43\" style=\"width:338.47px;height:24.43px;aspect-ratio:338.47/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: update weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.64px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a1cc84ebf8de3e99.svg\"><img class=\"math display-math\" src=\"assets/equations/097ad2a2a1d15af5.svg\" alt=\"w_2^{\\mathrm{new}}=0.1+0.1(0)(2)=0.1\" width=\"300.45\" height=\"24.43\" style=\"width:300.45px;height:24.43px;aspect-ratio:300.45/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: update the bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/920794cfde95f28a.svg\" alt=\"b_{\\mathrm{new}}=0+0.1(0)=0\" width=\"224.19\" height=\"24.43\" style=\"width:224.19px;height:24.43px;aspect-ratio:224.19/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> New weights = [-0.2,0.1]; new bias = 0.</p>","<h3>Binary perceptron: target 0</h3>","<p class=\"inline-question\"><strong>Question. A binary perceptron has x = [1,2], weights [0.2, 0.1], bias 0 and target 0. Use output 1 for net ≥ 0 and learning rate 0.1. Perform one update.</strong></p>","<h3>Given</h3>","<p>x = [1,2]; w = [0.2, 0.1]; b = 0; target = 0; η = 0.1.</p>","<h3>To find</h3>","<p>Net, threshold output, correction and new weights/bias.</p>","<h3>Formula — which one and why</h3>","<p>This binary learning rule uses target minus output. Carry the same correction into every input weight and the bias.</p>","<p>t is target; o is threshold output; Δ means the amount added to the current parameter.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3870c6199f4ce08e.svg\" alt=\"\\Delta w_i=\\eta(t-o)x_i\" width=\"182.09\" height=\"24.43\" style=\"width:182.09px;height:24.43px;aspect-ratio:182.09/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/998f813758f64544.svg\" alt=\"\\Delta b=\\eta(t-o)\" width=\"145.12\" height=\"24.43\" style=\"width:145.12px;height:24.43px;aspect-ratio:145.12/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Target minus output; correct prediction ho toh correction zero.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the net input.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.75px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cc07c4020befc673.svg\"><img class=\"math display-math\" src=\"assets/equations/2a3bdd44838a1ac8.svg\" alt=\"z=(0.2)(1)+(0.1)(2)+0=0.4\" width=\"342.64\" height=\"24.43\" style=\"width:342.64px;height:24.43px;aspect-ratio:342.64/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: apply the threshold.</strong></p>","<p>Net = 0.4; output = 1 under the stated ≥ 0 rule.</p>","<p class=\"worked-step\"><strong>Step 3: calculate the correction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/84c2ca9c5cec76e2.svg\" alt=\"t-o=0-1=-1\" width=\"201.24\" height=\"18.27\" style=\"width:201.24px;height:18.27px;aspect-ratio:201.24/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: update weight 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.65px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e7f1347350326319.svg\"><img class=\"math display-math\" src=\"assets/equations/2bd36e593c9db7e2.svg\" alt=\"w_1^{\\mathrm{new}}=0.2+0.1(-1)(1)=0.1\" width=\"319.46\" height=\"24.43\" style=\"width:319.46px;height:24.43px;aspect-ratio:319.46/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: update weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.65px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ced16326d7d6ffec.svg\"><img class=\"math display-math\" src=\"assets/equations/5463d220fc6276c5.svg\" alt=\"w_2^{\\mathrm{new}}=0.1+0.1(-1)(2)=-0.1\" width=\"338.47\" height=\"24.43\" style=\"width:338.47px;height:24.43px;aspect-ratio:338.47/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: update the bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d6c4895766052790.svg\" alt=\"b_{\\mathrm{new}}=0+0.1(-1)=-0.1\" width=\"281.22\" height=\"24.43\" style=\"width:281.22px;height:24.43px;aspect-ratio:281.22/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> New weights = [0.1,-0.1]; new bias = -0.1.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s8","search":"Perceptrons and the threshold A perceptron is a simple neuron used for classification with a threshold decision. If a question says output 1 for z ≥ 0 and 0 otherwise, then z = 0 gives 1. If it says output 1 for z > 0 and 0 otherwise, then z = 0 gives 0. That single equality sign can change an entire training table.\n\n\n\n**Question.** Implement binary AND with w₁ = w₂ = 0.6, b = −0.8 and output 1 when z ≥ 0.\n\n\n\n### Given\n\nw₁ = w₂ = 0.6; bias b = −0.8.\n\nBinary inputs; output 1 when z ≥ 0.\n\n### To find\n\nCalculate the output for 00,01,10,11 and show that the result is AND.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\n### Input (0, 0)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.8; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (0, 1)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.2; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (1, 0)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.2; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (1, 1)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = 0.4; output = 1 because output is 1 exactly when z ≥ 0.\n\n**Final answer:** outputs are [0, 0, 0, 1] for inputs 00, 01, 10, 11: exactly AND.\n\n### Summary of the four cases\n\n| Inputs | Full net calculation | Net z | Output | AND target |\n| 0, 0 | 0.6(0) + 0.6(0) − 0.8 | −0.8 | 0 | 0 |\n| 0, 1 | 0.6(0) + 0.6(1) − 0.8 | −0.2 | 0 | 0 |\n| 1, 0 | 0.6(1) + 0.6(0) − 0.8 | −0.2 | 0 | 0 |\n| 1, 1 | 0.6(1) + 0.6(1) − 0.8 | 0.4 | 1 | 1 |\nThe neuron fires only when both inputs are 1. No weight update was requested, so this is a forward evaluation, not a training problem.\nFor binary targets, a common learning rule is w ← w + η(t − a)x and b ← b + η(t − a). For bipolar targets −1 and +1, the class notes use a different rule: on a mismatch, w ← w + η tx and b ← b + ηt; otherwise keep them. The notes give output 0 at zero threshold, +1 above it and −1 below it. Never combine the activation from one convention with an unexplained update from another.\n**Training table routine: ** copy current weights → calculate z → apply the stated threshold → compare output with target → compute every weight change → update bias → carry new values to the next row. Reset nothing between rows or epochs unless instructed.\n\n\n\n### Binary perceptron: target 1\n\n**Question. A binary perceptron has x = [1,2], weights [-0.2, 0.1], "},{"title":"Why XOR needs more than one perceptron","blocks":["<p>XOR outputs 1 for [0,1] and [1,0], but 0 for [0,0] and [1,1]. On a graph the positive points occupy opposite corners. A single straight line cannot put both positive points on one side and both negative points on the other. A single perceptron has only one linear decision boundary.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/xor.svg\" aria-label=\"Enlarge diagram: XOR needs a combination of boundaries\"><img src=\"assets/figures/xor.svg\" alt=\"XOR needs a combination of boundaries\" width=\"960\" height=\"430\" loading=\"lazy\"></button><figcaption>XOR needs a combination of boundaries <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A two-layer construction solves it. Let h₁ = step(x₁ + x₂ − 0.5), which is OR. Let h₂ = step(x₁ + x₂ − 1.5), which is AND. With step(z) = 1 for z ≥ 0, output XOR = step(h₁ − 2h₂ − 0.5). Output XNOR = step(−h₁ + 2h₂ + 0.5).</p>","<div class=\"table-scroll\"><table><thead><tr><th>x₁ x₂</th><th>h₁ OR</th><th>h₂ AND</th><th>XOR net</th><th>XOR</th><th>XNOR</th></tr></thead><tbody><tr><td>0 0</td><td>0</td><td>0</td><td>−0.5</td><td>0</td><td>1</td></tr><tr><td>0 1</td><td>1</td><td>0</td><td>0.5</td><td>1</td><td>0</td></tr><tr><td>1 0</td><td>1</td><td>0</td><td>0.5</td><td>1</td><td>0</td></tr><tr><td>1 1</td><td>1</td><td>1</td><td>−1.5</td><td>0</td><td>1</td></tr></tbody></table></div>","<p>More layers help only if appropriate nonlinearities are used. Two purely affine layers collapse into one affine map: W₂(W₁x + b₁) + b₂ = (W₂W₁)x + W₂b₁ + b₂. Affine means linear plus a bias.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s9","search":"Why XOR needs more than one perceptron XOR outputs 1 for [0,1] and [1,0], but 0 for [0,0] and [1,1]. On a graph the positive points occupy opposite corners. A single straight line cannot put both positive points on one side and both negative points on the other. A single perceptron has only one linear decision boundary.\n\nA two-layer construction solves it. Let h₁ = step(x₁ + x₂ − 0.5), which is OR. Let h₂ = step(x₁ + x₂ − 1.5), which is AND. With step(z) = 1 for z ≥ 0, output XOR = step(h₁ − 2h₂ − 0.5). Output XNOR = step(−h₁ + 2h₂ + 0.5).\n| x₁ x₂ | h₁ OR | h₂ AND | XOR net | XOR | XNOR |\n| 0 0 | 0 | 0 | −0.5 | 0 | 1 |\n| 0 1 | 1 | 0 | 0.5 | 1 | 0 |\n| 1 0 | 1 | 0 | 0.5 | 1 | 0 |\n| 1 1 | 1 | 1 | −1.5 | 0 | 1 |\nMore layers help only if appropriate nonlinearities are used. Two purely affine layers collapse into one affine map: W₂(W₁x + b₁) + b₂ = (W₂W₁)x + W₂b₁ + b₂. Affine means linear plus a bias."},{"title":"Activation functions and how to calculate them","blocks":["<h3>What an activation function does, and why it is needed</h3>","<p>A neuron first produces the weighted sum z. The activation function f is a rule that transforms that sum into the output a = f(z). Applying an activation does not change the stored weights; it calculates a new output from the current sum.</p>","<p>If every layer only multiplies and adds, several layers still combine into a single affine transformation. A nonlinear activation lets the network represent more complicated relationships. The output activation must also suit the task: sigmoid for a binary-class probability, softmax for mutually exclusive class probabilities, and often a linear output for unrestricted regression.</p>","<p>The <strong>activation value</strong> says what the neuron outputs. The <strong>activation derivative</strong> says how quickly that output changes when z changes, which is needed during backpropagation. For sigmoid at z = 0, the value is 0.5 but the derivative is 0.25. They serve different purposes.</p>","<p><strong>Yaad rakhne ka cue:</strong> z = activation se pehle ka sum; a = uske baad ka answer; f′ = answer kitni tezi se badlega.</p>","<p class=\"definition\"><strong>Definition.</strong> An activation function maps a neuron&#x27;s preactivation to its output. Nonlinear activations allow a multilayer network to represent nonlinear functions; the output activation also encodes the prediction type. Without a nonlinear activation, a composition of affine layers remains affine.</p>","<h3>Explanation and working</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.01px;--narrow-height:92.09px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b7ede87d0558048.svg\"><img class=\"math display-math\" src=\"assets/equations/7addd035227c8e01.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\quad \\sigma&#x27;(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"427.95\" height=\"51.56\" style=\"width:427.95px;height:51.56px;aspect-ratio:427.95/51.56\" loading=\"lazy\"></picture></div>","<p>Sigmoid converts any finite real input into a value strictly between 0 and 1. At zero it is 0.5. It is useful for a binary-class probability or independent multilabel outputs. At very positive or negative inputs it saturates, so its derivative becomes small. Its derivative is at most 0.25.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_activations.svg\" aria-label=\"Enlarge diagram: Trace the output of each curve as the same raw input moves from negative to positive.\"><img src=\"assets/figures/v_activations.svg\" alt=\"Trace the output of each curve as the same raw input moves from negative to positive.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Trace the output of each curve as the same raw input moves from negative to positive. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.65px;--narrow-height:99.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/151466f4a43db268.svg\"><img class=\"math display-math\" src=\"assets/equations/610c0fbb4970deec.svg\" alt=\"\\tanh(z)=\\frac{e^{2z}-1}{e^{2z}+1},\\quad \\tanh&#x27;(z)=1-\\tanh^2(z)\" width=\"480.72\" height=\"56.48\" style=\"width:480.72px;height:56.48px;aspect-ratio:480.72/56.48\" loading=\"lazy\"></picture></div>","<p>Tanh lies between −1 and +1 and is zero-centered. It is common in recurrent hidden states and LSTM candidates. It also saturates. “Zero-centered” does not mean “no vanishing gradients”.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8ed42aad8099504b.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z),\\quad f&#x27;(z)=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z&lt;0\\end{cases}\" width=\"455.22\" height=\"58.62\" style=\"width:455.22px;height:58.62px;aspect-ratio:455.22/58.62\" loading=\"lazy\"></div>","<p>ReLU returns the input if positive and zero if negative. It is cheap to compute and has derivative 1 on its positive side. Units can become inactive on all relevant inputs, known as dying ReLU. At z = 0 the mathematical derivative is undefined; a convention such as 0 is used in implementations and this course’s exercises when needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba63451671574a0f.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\az&amp;z&lt;0\\end{cases},\\qquad a=0.01\\ \\text{unless specified}\" width=\"628.12\" height=\"58.62\" style=\"width:628.12px;height:58.62px;aspect-ratio:628.12/58.62\" loading=\"lazy\"></div>","<p>The small negative slope a lets some gradient through for negative inputs. At z = −2 and a = 0.01, output = −0.02. Do not take the absolute value. PReLU learns the negative slope; Leaky ReLU normally fixes it.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:137.99px;--narrow-height:193.56px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ad7e7d9830e70ac.svg\"><img class=\"math display-math\" src=\"assets/equations/50824a322c80361f.svg\" alt=\"p_i=\\frac{e^{z_i}}{\\sum_j e^{z_j}}=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_jz_j\" width=\"434.70\" height=\"63.31\" style=\"width:434.70px;height:63.31px;aspect-ratio:434.70/63.31\" loading=\"lazy\"></picture></div>","<p>Softmax acts on a group of class scores, called logits. All probabilities are positive and sum to 1. Subtracting the same maximum c from all logits leaves the result unchanged and avoids very large exponentials. It is suited to mutually exclusive multiclass output.</p>","<p><strong>Full softmax example.</strong> For [−1, 0, 1], exponentials are [0.367879, 1, 2.718282]. Sum = 4.086161. Divide each by that same sum: [0.090031, 0.244728, 0.665241]. Check their sum is approximately 1. Three separate sigmoids would give [0.268941, 0.5, 0.731059], which are different and do not sum to 1.</p>","<h3>Derivation of the sigmoid derivative</h3>","<p>Write sigmoid as a negative power. The outer derivative contributes −1, and differentiating the inner exponential contributes a second negative sign:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4d8f5baacfd2120.svg\" alt=\"\\sigma(z)=(1+e^{-z})^{-1}\" width=\"197.00\" height=\"27.70\" style=\"width:197.00px;height:27.70px;aspect-ratio:197.00/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.60px;--narrow-height:142.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/25b5ff83cfc93c4e.svg\"><img class=\"math display-math\" src=\"assets/equations/67121a49478eada8.svg\" alt=\"\\sigma&#x27;(z)=-(1+e^{-z})^{-2}(-e^{-z})=\\frac{e^{-z}}{(1+e^{-z})^2}\" width=\"445.69\" height=\"59.16\" style=\"width:445.69px;height:59.16px;aspect-ratio:445.69/59.16\" loading=\"lazy\"></picture></div>","<p>Separate the expression into two factors:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.04px;--narrow-height:133.86px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8342957fe889eca9.svg\"><img class=\"math display-math\" src=\"assets/equations/c3ea50ce5747d8ce.svg\" alt=\"\\sigma&#x27;(z)=\\frac{1}{1+e^{-z}}\\frac{e^{-z}}{1+e^{-z}}=\\sigma(z)[1-\\sigma(z)]\" width=\"436.05\" height=\"54.23\" style=\"width:436.05px;height:54.23px;aspect-ratio:436.05/54.23\" loading=\"lazy\"></picture></div>","<p>The second factor is 1−σ(z) because subtracting 1/(1+e⁻ᶻ) from 1 leaves e⁻ᶻ/(1+e⁻ᶻ). Once a forward pass has supplied σ(z), its derivative requires no further exponential evaluation.</p>","<h3>Derivation of the tanh derivative</h3>","<p>Use the quotient rule on the exponential definition. Here u = e²ᶻ−1 and v = e²ᶻ+1, with u′ = v′ = 2e²ᶻ.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:340.18px;--narrow-height:201.84px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1eaf1c302e07c3ae.svg\"><img class=\"math display-math\" src=\"assets/equations/730661d0a7189944.svg\" alt=\"\\frac{d}{dz}\\tanh z=\\frac{2e^{2z}(e^{2z}+1)-2e^{2z}(e^{2z}-1)}{(e^{2z}+1)^2}=\\frac{4e^{2z}}{(e^{2z}+1)^2}\" width=\"584.52\" height=\"61.42\" style=\"width:584.52px;height:61.42px;aspect-ratio:584.52/61.42\" loading=\"lazy\"></picture></div>","<p>The identity 1−tanh²(z) gives the same expression, since the numerator becomes (e²ᶻ+1)²−(e²ᶻ−1)² = 4e²ᶻ. Therefore the backward-pass factor is 1−a² when a = tanh(z).</p>","<h3>Why nonlinear activations are required</h3>","<p>For two affine layers without a nonlinear activation:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.41px;--narrow-height:104.09px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/886e2a40c2cd8e26.svg\"><img class=\"math display-math\" src=\"assets/equations/dac24947cfd3e2d0.svg\" alt=\"h=W_1x+b_1,\\qquad \\hat y=W_2h+b_2=W_2W_1x+(W_2b_1+b_2)\" width=\"617.32\" height=\"25.90\" style=\"width:617.32px;height:25.90px;aspect-ratio:617.32/25.90\" loading=\"lazy\"></picture></div>","<p>The composition is still one affine transformation. A nonlinear activation between layers changes the family of functions the network can represent. This is the mathematical reason for using nonlinear hidden activations; merely adding affine layers does not provide this expressive advantage.</p>","<h3>sigmoid example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9feed82e056cf24.svg\" alt=\"-z=-(-2)=2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b83d9532e6445b5a.svg\" alt=\"e^{2}\\approx7.389056099\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4026cb0f8944f24f.svg\"><img class=\"math display-math\" src=\"assets/equations/fb7c0cac9ced67f0.svg\" alt=\"1+7.389056099\\approx8.389056099\" width=\"332.60\" height=\"18.52\" style=\"width:332.60px;height:18.52px;aspect-ratio:332.60/18.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f4a3cb96f1098e79.svg\"><img class=\"math display-math\" src=\"assets/equations/b44984dd703daaf9.svg\" alt=\"a=\\frac1{8.389056099}\\approx0.119202922\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/154ffcd0747b53aa.svg\"><img class=\"math display-math\" src=\"assets/equations/61cf4a9551a25fd6.svg\" alt=\"f\\prime(-2)=(0.119202922)(1-0.119202922)\\approx0.104993585\" width=\"602.56\" height=\"24.43\" style=\"width:602.56px;height:24.43px;aspect-ratio:602.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.119202922. Derivative ≈ 0.104993585.</p>","<h3>sigmoid example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17055d0f6bb7d8cb.svg\" alt=\"-z=-(0)=0\" width=\"157.99\" height=\"24.43\" style=\"width:157.99px;height:24.43px;aspect-ratio:157.99/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/88f353ee1ae5e616.svg\"><img class=\"math display-math\" src=\"assets/equations/048aaa762a498d29.svg\" alt=\"1+1.000000000\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55f56d862c8a637f.svg\"><img class=\"math display-math\" src=\"assets/equations/bb9808b4290f77c2.svg\" alt=\"a=\\frac1{2.000000000}\\approx0.500000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5e112d2ee69475de.svg\"><img class=\"math display-math\" src=\"assets/equations/fe0302f0c6aecdca.svg\" alt=\"f\\prime(0)=(0.500000000)(1-0.500000000)\\approx0.250000000\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.500000000. Derivative ≈ 0.250000000.</p>","<h3>sigmoid example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbbb55e23c6ba6a0.svg\" alt=\"-z=-(2)=-2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1264450d54002695.svg\"><img class=\"math display-math\" src=\"assets/equations/21d0f7a7fd447a52.svg\" alt=\"1+0.135335283\\approx1.135335283\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f08d0c34f5e2fdf7.svg\"><img class=\"math display-math\" src=\"assets/equations/6480e62e9ef0f8a2.svg\" alt=\"a=\\frac1{1.135335283}\\approx0.880797078\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278a4098b6b446b4.svg\"><img class=\"math display-math\" src=\"assets/equations/00492ebf856c8aae.svg\" alt=\"f\\prime(2)=(0.880797078)(1-0.880797078)\\approx0.104993585\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.880797078. Derivative ≈ 0.104993585.</p>","<h3>tanh example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ab8a21d8aab882c.svg\" alt=\"2z=2(-2)=-4\" width=\"182.43\" height=\"24.43\" style=\"width:182.43px;height:24.43px;aspect-ratio:182.43/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c3b8c152fd312b9.svg\" alt=\"e^{-4}\\approx0.018315639\" width=\"197.05\" height=\"22.32\" style=\"width:197.05px;height:22.32px;aspect-ratio:197.05/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/782210c69a20fd3b.svg\"><img class=\"math display-math\" src=\"assets/equations/38bd067833181d6c.svg\" alt=\"0.018315639-1\\approx-0.981684361\" width=\"351.62\" height=\"18.54\" style=\"width:351.62px;height:18.54px;aspect-ratio:351.62/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c7713b25655beb72.svg\"><img class=\"math display-math\" src=\"assets/equations/dee5ac5546f1b2f2.svg\" alt=\"0.018315639+1\\approx1.018315639\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.24px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/300fc0089c5516db.svg\"><img class=\"math display-math\" src=\"assets/equations/809bd6f34ad5f6a6.svg\" alt=\"a=\\frac{-0.981684361}{1.018315639}\\approx-0.964027580\" width=\"384.79\" height=\"50.36\" style=\"width:384.79px;height:50.36px;aspect-ratio:384.79/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.52px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bb2d4ce554c14198.svg\"><img class=\"math display-math\" src=\"assets/equations/c4ff92106fa31931.svg\" alt=\"f\\prime(-2)=1-(-0.964027580)^2\\approx0.070650825\" width=\"484.27\" height=\"27.70\" style=\"width:484.27px;height:27.70px;aspect-ratio:484.27/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ -0.964027580. Derivative ≈ 0.070650825.</p>","<h3>tanh example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83fefb855224c584.svg\" alt=\"2z=2(0)=0\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/40327f28206586d2.svg\"><img class=\"math display-math\" src=\"assets/equations/fa618ba26a236aab.svg\" alt=\"1.000000000-1\\approx0.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5e16c3256057084.svg\"><img class=\"math display-math\" src=\"assets/equations/46b371b545cc8bc8.svg\" alt=\"1.000000000+1\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/081512ac7f7a1b51.svg\"><img class=\"math display-math\" src=\"assets/equations/da7a029e0ae3e61f.svg\" alt=\"a=\\frac{0.000000000}{2.000000000}\\approx0.000000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3899b5f76509b8c.svg\"><img class=\"math display-math\" src=\"assets/equations/b3f22ac5fb036f65.svg\" alt=\"f\\prime(0)=1-(0.000000000)^2\\approx1.000000000\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 1.000000000.</p>","<h3>tanh example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28a6e73374f6be65.svg\" alt=\"2z=2(2)=4\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dcc7f746c4400033.svg\" alt=\"e^{4}\\approx54.598150033\" width=\"195.81\" height=\"22.32\" style=\"width:195.81px;height:22.32px;aspect-ratio:195.81/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f63e045301bde055.svg\"><img class=\"math display-math\" src=\"assets/equations/a7f29872524e69fc.svg\" alt=\"54.598150033-1\\approx53.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c86d55c9549cedd.svg\"><img class=\"math display-math\" src=\"assets/equations/1a7460c08ec0eb4e.svg\" alt=\"54.598150033+1\\approx55.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.45px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a5642fac7a0997.svg\"><img class=\"math display-math\" src=\"assets/equations/9d5e297333003136.svg\" alt=\"a=\\frac{53.598150033}{55.598150033}\\approx0.964027580\" width=\"358.99\" height=\"50.09\" style=\"width:358.99px;height:50.09px;aspect-ratio:358.99/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/52d252bd261b679f.svg\"><img class=\"math display-math\" src=\"assets/equations/6f2d0c822236e436.svg\" alt=\"f\\prime(2)=1-(0.964027580)^2\\approx0.070650825\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.964027580. Derivative ≈ 0.070650825.</p>","<h3>ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbc65c947d4ed97f.svg\" alt=\"f\\prime(-2)=0\" width=\"115.19\" height=\"24.43\" style=\"width:115.19px;height:24.43px;aspect-ratio:115.19/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 0.000000000.</p>","<h3>ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>","<h3>Leaky ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24b81e63d794388e.svg\" alt=\"a=-0.2\" width=\"95.75\" height=\"18.27\" style=\"width:95.75px;height:18.27px;aspect-ratio:95.75/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaab86572902924a.svg\" alt=\"f\\prime(-2)=0.1\" width=\"134.21\" height=\"24.43\" style=\"width:134.21px;height:24.43px;aspect-ratio:134.21/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ -0.200000000. Derivative ≈ 0.100000000.</p>","<h3>Leaky ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>Leaky ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>","<h3>Softmax for [0, 0, 0]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [0, 0, 0].</strong></p>","<h3>Given</h3>","<p>Logits = [0, 0, 0]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e35e2c8f440c3bf.svg\" alt=\"z-c=\\begin{bmatrix}0&amp;0&amp;0\\end{bmatrix}\" width=\"183.50\" height=\"24.43\" style=\"width:183.50px;height:24.43px;aspect-ratio:183.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5cbcea061b92c91b.svg\"><img class=\"math display-math\" src=\"assets/equations/77bfb08512787403.svg\" alt=\"D=1.000000000+1.000000000+1.000000000\\approx3.000000000\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/abb38634253b454f.svg\"><img class=\"math display-math\" src=\"assets/equations/aac567888a814ba9.svg\" alt=\"p_1=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6f93f83cf16d42a1.svg\"><img class=\"math display-math\" src=\"assets/equations/4e80a74382faa499.svg\" alt=\"p_2=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd8dca9605ca9fba.svg\"><img class=\"math display-math\" src=\"assets/equations/932805d4a7ff7186.svg\" alt=\"p_3=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.333333333, 0.333333333, 0.333333333]; they sum to 1 within rounding.</p>","<h3>Softmax for [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [1, 2, 3].</strong></p>","<h3>Given</h3>","<p>Logits = [1, 2, 3]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/36a969786afa504d.svg\" alt=\"z-c=\\begin{bmatrix}-2&amp;-1&amp;0\\end{bmatrix}\" width=\"221.52\" height=\"24.43\" style=\"width:221.52px;height:24.43px;aspect-ratio:221.52/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8b081af8baa5f1b.svg\" alt=\"e^{-1}\\approx0.367879441\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff6afad7c399e8cd.svg\"><img class=\"math display-math\" src=\"assets/equations/3e8d536144b8581d.svg\" alt=\"D=0.135335283+0.367879441+1.000000000\\approx1.503214724\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60d7f2c1aed7f3ca.svg\"><img class=\"math display-math\" src=\"assets/equations/806ad5813b3ff8c0.svg\" alt=\"p_1=\\frac{0.135335283}{1.503214724}\\approx0.090030573\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/958d44e6661ca616.svg\"><img class=\"math display-math\" src=\"assets/equations/a839a3e6b8973897.svg\" alt=\"p_2=\\frac{0.367879441}{1.503214724}\\approx0.244728471\" width=\"356.81\" height=\"50.36\" style=\"width:356.81px;height:50.36px;aspect-ratio:356.81/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6153a5efe8276ec2.svg\"><img class=\"math display-math\" src=\"assets/equations/fdcbdba7b8490dd2.svg\" alt=\"p_3=\\frac{1.000000000}{1.503214724}\\approx0.665240956\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.090030573, 0.244728471, 0.665240956]; they sum to 1 within rounding.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s10","search":"Activation functions and how to calculate them \n### What an activation function does, and why it is needed\nA neuron first produces the weighted sum z. The activation function f is a rule that transforms that sum into the output a = f(z). Applying an activation does not change the stored weights; it calculates a new output from the current sum.\n\nIf every layer only multiplies and adds, several layers still combine into a single affine transformation. A nonlinear activation lets the network represent more complicated relationships. The output activation must also suit the task: sigmoid for a binary-class probability, softmax for mutually exclusive class probabilities, and often a linear output for unrestricted regression.\n\nThe **activation value** says what the neuron outputs. The **activation derivative** says how quickly that output changes when z changes, which is needed during backpropagation. For sigmoid at z = 0, the value is 0.5 but the derivative is 0.25. They serve different purposes.\n\n**Yaad rakhne ka cue:** z = activation se pehle ka sum; a = uske baad ka answer; f′ = answer kitni tezi se badlega.\n\n**Definition.** An activation function maps a neuron's preactivation to its output. Nonlinear activations allow a multilayer network to represent nonlinear functions; the output activation also encodes the prediction type. Without a nonlinear activation, a composition of affine layers remains affine.\n\n### Explanation and working\n\nSigmoid converts any finite real input into a value strictly between 0 and 1. At zero it is 0.5. It is useful for a binary-class probability or independent multilabel outputs. At very positive or negative inputs it saturates, so its derivative becomes small. Its derivative is at most 0.25.\n\n\n\n\nTanh lies between −1 and +1 and is zero-centered. It is common in recurrent hidden states and LSTM candidates. It also saturates. “Zero-centered” does not mean “no vanishing gradients”.\n\nReLU returns the input if positive and zero if negative. It is cheap to compute and has derivative 1 on its positive side. Units can become inactive on all relevant inputs, known as dying ReLU. At z = 0 the mathematical derivative is undefined; a convention such as 0 is used in implementations and this book’s exercises when needed.\n\nThe small negative slope a lets some gradient through for negative inputs. At z = −2 and a = 0.01, output = −0.02. Do not take the absolute value. PReLU learns the negative slope; Leaky ReLU normally fixes it.\n\nSoftmax acts on a group of class scores, called logits. All probabilities are positive and sum to 1. Subtracting the same maximum c from all logits leaves the result unchanged and avoids very large exponentials. It is suited to mutually exclusive multiclass output.\n**Full softmax example.** For [−1, 0, 1], exponentials are [0.367879, 1, 2.718282]. Sum = 4.086161. Divide each by that same sum: [0.090031, 0.244728, 0.665241]. Check their sum is approximately 1. Three separate sigmoids would give [0.268941, 0.5, 0.731059], which are different and do not sum to 1.\n\n### Derivation of the sigmoid derivative\nWrite sigmoid as a negative power. The outer derivative contributes −1, and differentiating the inner exponential contributes a second negative sign:\n\n\nSeparate the expression into two factors:\n\nThe second factor is 1−σ(z) because subtracting 1/(1+e⁻ᶻ) from 1 leaves e⁻ᶻ/(1+e⁻ᶻ). Once a forward pass has supplied σ(z), its derivative requires no further exponential evaluation.\n\n### Derivation of the tanh "},{"title":"Model answer: why a network needs nonlinear activation","question":["<p class=\"inline-question\"><strong>Question.</strong> Why are activation functions required in a multilayer neural network? Compare sigmoid, tanh and ReLU, including their limitations.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum into its output. Nonlinear activations allow successive layers to represent nonlinear relationships. If every layer is only linear or affine, composing those layers still gives one affine transformation; depth alone does not create a nonlinear decision boundary.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nonlinear.svg\" aria-label=\"Enlarge diagram: Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation.\"><img src=\"assets/figures/v_nonlinear.svg\" alt=\"Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Why two linear layers are still linear in the input</h3>","<p>For the first layer let h = 2x + 1. Let the second output be y = 3h + 4. Substitute the first rule into the second:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f54676c512498a38.svg\"><img class=\"math display-math\" src=\"assets/equations/0da4ca75660c25f8.svg\" alt=\"y=3(2x+1)+4=6x+3+4=6x+7\" width=\"429.97\" height=\"24.43\" style=\"width:429.97px;height:24.43px;aspect-ratio:429.97/24.43\" loading=\"lazy\"></picture></div>","<p>This is one straight-line rule. A nonlinear activation between the two calculations changes what the combined model can represent.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Activation</th><th>Output range</th><th>Useful property</th><th>Main limitation</th></tr></thead><tbody><tr><td>Sigmoid</td><td>Strictly between 0 and 1</td><td>Useful as a binary-class probability output</td><td>Saturates at large positive or negative inputs; gradients become small</td></tr><tr><td>Tanh</td><td>Strictly between −1 and 1</td><td>Can represent signed, zero-centered activations</td><td>Also saturates and can contribute to vanishing gradients</td></tr><tr><td>ReLU</td><td>From 0 upward</td><td>Simple; derivative is 1 for positive inputs</td><td>A unit that stays on the negative side receives zero local gradient</td></tr></tbody></table></div>","<p>Sigmoid and tanh do not return negative and positive versions of the same scale: their ranges differ. ReLU is not restricted to values below 1. For multiclass output, softmax normalizes a group of class scores so the probabilities sum to 1; it acts on the score vector rather than independently applying sigmoid to each score.</p>","<p><strong>Exam conclusion:</strong> select the activation according to the layer&#x27;s job and task. Hidden layers need useful nonlinear transformations; the output activation must match the meaning of the desired prediction.</p>"],"kind":"theory","id":"tee-c4-s11","search":"Model answer: why a network needs nonlinear activation **Question.** Why are activation functions required in a multilayer neural network? Compare sigmoid, tanh and ReLU, including their limitations.\n\n**Model answer.**\nAn activation function transforms a neuron's weighted sum into its output. Nonlinear activations allow successive layers to represent nonlinear relationships. If every layer is only linear or affine, composing those layers still gives one affine transformation; depth alone does not create a nonlinear decision boundary.\n\n\n\n\n### Why two linear layers are still linear in the input\nFor the first layer let h = 2x + 1. Let the second output be y = 3h + 4. Substitute the first rule into the second:\n\nThis is one straight-line rule. A nonlinear activation between the two calculations changes what the combined model can represent.\n\n| Activation | Output range | Useful property | Main limitation |\n| Sigmoid | Strictly between 0 and 1 | Useful as a binary-class probability output | Saturates at large positive or negative inputs; gradients become small |\n| Tanh | Strictly between −1 and 1 | Can represent signed, zero-centered activations | Also saturates and can contribute to vanishing gradients |\n| ReLU | From 0 upward | Simple; derivative is 1 for positive inputs | A unit that stays on the negative side receives zero local gradient |\n\nSigmoid and tanh do not return negative and positive versions of the same scale: their ranges differ. ReLU is not restricted to values below 1. For multiclass output, softmax normalizes a group of class scores so the probabilities sum to 1; it acts on the score vector rather than independently applying sigmoid to each score.\n\n**Exam conclusion:** select the activation according to the layer's job and task. Hidden layers need useful nonlinear transformations; the output activation must match the meaning of the desired prediction.\n"},{"title":"Choosing a loss","blocks":["<p class=\"definition\"><strong>Definition.</strong> A loss function quantifies the discrepancy between a prediction and its target. The training objective aggregates per-example losses and may add regularization. The loss must be compatible with the task and output parameterization.</p>","<h3>Explanation and working</h3>","<p>Activation produces the prediction. Loss measures how wrong that prediction is. An optimizer uses gradients to update parameters. These are three different roles.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_loss_choice.svg\" aria-label=\"Enlarge diagram: First identify what the prediction means. Then choose the loss paired with that task and output.\"><img src=\"assets/figures/v_loss_choice.svg\" alt=\"First identify what the prediction means. Then choose the loss paired with that task and output.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>First identify what the prediction means. Then choose the loss paired with that task and output. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.25px;--narrow-height:151.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46872a64dc44481e.svg\"><img class=\"math display-math\" src=\"assets/equations/52f47ec283865e9e.svg\" alt=\"\\operatorname{MSE}=\\frac1n\\sum_{i=1}^n(\\hat y_i-y_i)^2,\\qquad \\operatorname{MAE}=\\frac1n\\sum_{i=1}^n|\\hat y_i-y_i|\" width=\"551.36\" height=\"68.62\" style=\"width:551.36px;height:68.62px;aspect-ratio:551.36/68.62\" loading=\"lazy\"></picture></div>","<p class=\"inline-question\"><strong>Question.</strong> Targets are [2, 4], predictions are [1, 6]. Find MSE and MAE.</p>","<h3>Given</h3>","<p>Targets = [2,4]; predictions = [1,6]; n = 2.</p>","<h3>To find</h3>","<p>Find mean squared error and mean absolute error.</p>","<h3>Formula — which one and why</h3>","<p><strong>Squared-error objectives.</strong> Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.</p>","<p>ŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle error square; phir question ke hisaab se sum, half ya mean.</p>","<p><strong>Mean absolute error.</strong> Absolute value removes the sign of each prediction error without squaring its magnitude. Average those magnitudes.</p>","<p>n = number of predictions. |e| means the nonnegative magnitude of error e.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/da84fa0919b7d150.svg\" alt=\"\\mathrm{MAE}=\\frac1n\\sum_i|\\hat y_i-y_i|\" width=\"242.18\" height=\"61.92\" style=\"width:242.18px;height:61.92px;aspect-ratio:242.18/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MAE mein magnitude; MSE mein square.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate prediction minus target.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dba84d8eacba9175.svg\" alt=\"e_1=1-2=-1\" width=\"172.76\" height=\"19.94\" style=\"width:172.76px;height:19.94px;aspect-ratio:172.76/19.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7004e5d2962bc876.svg\" alt=\"e_2=6-4=2\" width=\"153.75\" height=\"20.21\" style=\"width:153.75px;height:20.21px;aspect-ratio:153.75/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square both errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/725d81fce4be12d0.svg\" alt=\"e_1^2=(-1)^2=1\" width=\"160.35\" height=\"27.70\" style=\"width:160.35px;height:27.70px;aspect-ratio:160.35/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4282b80c2e07509.svg\" alt=\"e_2^2=2^2=4\" width=\"122.32\" height=\"27.64\" style=\"width:122.32px;height:27.64px;aspect-ratio:122.32/27.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add squares and divide by two observations.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9258cd0363de1324.svg\" alt=\"\\mathrm{MSE}=\\frac{1+4}{2}=2.5\" width=\"214.09\" height=\"49.82\" style=\"width:214.09px;height:49.82px;aspect-ratio:214.09/49.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: take the absolute value of each original error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a8f4cb66d218e6f.svg\" alt=\"|-1|=1,\\qquad |2|=2\" width=\"230.82\" height=\"24.41\" style=\"width:230.82px;height:24.41px;aspect-ratio:230.82/24.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add absolute errors and divide by two.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2d85cc8a7db473e8.svg\" alt=\"\\mathrm{MAE}=\\frac{1+2}{2}=1.5\" width=\"218.82\" height=\"49.55\" style=\"width:218.82px;height:49.55px;aspect-ratio:218.82/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> MSE = 2.5; MAE = 1.5. Squaring gives larger errors more influence; MAE is not differentiable at zero error.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:325.53px;--narrow-height:131.10px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9ec44fbf24f3156c.svg\"><img class=\"math display-math\" src=\"assets/equations/ceba44b43aaab755.svg\" alt=\"L_{\\mathrm{BCE}}=-[y\\ln p+(1-y)\\ln(1-p)],\\qquad L_{\\mathrm{CCE}}=-\\sum_k y_k\\ln p_k\" width=\"658.88\" height=\"52.91\" style=\"width:658.88px;height:52.91px;aspect-ratio:658.88/52.91\" loading=\"lazy\"></picture></div>","<p>For binary y = 1, BCE becomes −ln(p). For y = 0, it becomes −ln(1 − p). For one-hot multiclass labels, CCE is simply minus the natural log of the predicted probability assigned to the correct class.</p>","<p class=\"inline-question\"><strong>Question.</strong> True class is Mild, encoded [0,1,0], and probabilities are [0.1,0.8,0.1]. Find CCE.</p>","<h3>Given</h3>","<p>True class = Mild; one-hot target = [0,1,0].</p>","<p>Predicted probabilities = [0.1,0.8,0.1].</p>","<h3>To find</h3>","<p>Find the categorical cross-entropy.</p>","<h3>Formula — which one and why</h3>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write one weighted log term for each class.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6cc766252350138b.svg\" alt=\"L=-[0\\ln(0.1)+1\\ln(0.8)+0\\ln(0.1)]\" width=\"402.28\" height=\"24.43\" style=\"width:402.28px;height:24.43px;aspect-ratio:402.28/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: remove terms with zero target weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17a83c5bb645a7c5.svg\" alt=\"L=-\\ln(0.8)\" width=\"142.93\" height=\"24.43\" style=\"width:142.93px;height:24.43px;aspect-ratio:142.93/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: evaluate the natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply the outer minus sign.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b71a143e9ddc291e.svg\"><img class=\"math display-math\" src=\"assets/equations/8076883238c541d3.svg\" alt=\"L\\approx-(-0.223143551)=0.223143551\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> CCE ≈ 0.223144. Only the correct-class probability contributes for this one-hot target.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Task</th><th>Typical output</th><th>Typical loss</th></tr></thead><tbody><tr><td>Unbounded numerical regression</td><td>One linear output</td><td>MSE or MAE</td></tr><tr><td>Binary classification</td><td>One sigmoid output</td><td>Binary cross-entropy</td></tr><tr><td>Exactly one of K classes</td><td>K softmax outputs</td><td>Categorical cross-entropy</td></tr><tr><td>Several independent labels</td><td>K sigmoid outputs</td><td>Binary cross-entropy per label</td></tr></tbody></table></div>","<p>A continuous rating restricted to 0–10 can use a linear output with a stated range policy, or 10 × sigmoid with an appropriate regression loss. If ratings are treated as discrete ordered categories, modelling choices differ. State the interpretation instead of selecting a loss merely from the number 10.</p>","<h3>Squared-error scaling in backpropagation</h3>","<p>For n included scalar predictions, let eᵢ = ŷᵢ−yᵢ. Three frequently used objectives are:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.10px;--narrow-height:205.50px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90823ff8e0467213.svg\"><img class=\"math display-math\" src=\"assets/equations/74a2e5af6d9c93b2.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2,\\qquad L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2,\\qquad \\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"602.56\" height=\"61.92\" style=\"width:602.56px;height:61.92px;aspect-ratio:602.56/61.92\" loading=\"lazy\"></picture></div>","<p>Differentiating with respect to one prediction produces different factors:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:154.58px;--narrow-height:202.76px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1bf294550797614e.svg\"><img class=\"math display-math\" src=\"assets/equations/9c169d2ae1cd10a3.svg\" alt=\"\\frac{\\partial\\mathrm{SSE}}{\\partial\\hat y_i}=2e_i,\\quad \\frac{\\partial L_{\\mathrm{half}}}{\\partial\\hat y_i}=e_i,\\quad \\frac{\\partial\\mathrm{MSE}}{\\partial\\hat y_i}=\\frac2n e_i\" width=\"482.44\" height=\"57.81\" style=\"width:482.44px;height:57.81px;aspect-ratio:482.44/57.81\" loading=\"lazy\"></picture></div>","<p>Use the exact objective in the question. The teacher&#x27;s two-output backpropagation example uses half SSE. Do not automatically insert the MSE factor into that example.</p>","<h3>Why cross-entropy uses the negative logarithm</h3>","<p>For a one-hot target, the likelihood of the observed class is the probability assigned to it. Maximizing that likelihood is equivalent to minimizing its negative logarithm. For independent training examples, multiplying probabilities becomes adding their logarithms. A low correct-class probability therefore produces a large loss.</p>","<h3>Sigmoid with binary cross-entropy: output delta</h3>","<p>Let p = σ(z). First differentiate the loss with respect to p, holding y constant:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.86px;--narrow-height:124.37px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc392cea6dae6dda.svg\"><img class=\"math display-math\" src=\"assets/equations/a1bc86d47cf16a06.svg\" alt=\"\\frac{\\partial L}{\\partial p}=-\\frac yp+\\frac{1-y}{1-p}=\\frac{p-y}{p(1-p)}\" width=\"339.87\" height=\"57.45\" style=\"width:339.87px;height:57.45px;aspect-ratio:339.87/57.45\" loading=\"lazy\"></picture></div>","<p>Then multiply by the sigmoid derivative:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.69px;--narrow-height:163.47px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6d9c2d8649b6476d.svg\"><img class=\"math display-math\" src=\"assets/equations/88355caa5908a259.svg\" alt=\"\\frac{\\partial L}{\\partial z}=\\frac{\\partial L}{\\partial p}\\frac{\\partial p}{\\partial z}=\\frac{p-y}{p(1-p)}p(1-p)=p-y\" width=\"453.31\" height=\"57.45\" style=\"width:453.31px;height:57.45px;aspect-ratio:453.31/57.45\" loading=\"lazy\"></picture></div>","<p>Thus the logit delta is p−y for this paired output and loss. With sigmoid and half squared error it is instead (p−y)p(1−p). Confusing these two cases changes every subsequent gradient.</p>","<h3>Softmax with categorical cross-entropy: output delta</h3>","<p>For a normalized target vector, the derivative of softmax component pᵢ with respect to logit zⱼ is pᵢ times (δᵢⱼ−pⱼ), where δᵢⱼ is 1 if i = j and 0 otherwise. Therefore:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:242.60px;--narrow-height:236.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/add665e2f73a094d.svg\"><img class=\"math display-math\" src=\"assets/equations/630851ea15af9c6b.svg\" alt=\"\\frac{\\partial L}{\\partial z_j}=-\\sum_i\\frac{y_i}{p_i}p_i(\\delta_{ij}-p_j)=-y_j+p_j\\sum_i y_i=p_j-y_j\" width=\"580.11\" height=\"63.12\" style=\"width:580.11px;height:63.12px;aspect-ratio:580.11/63.12\" loading=\"lazy\"></picture></div>","<p>This result assumes the target components sum to 1. For a mean loss over a batch, include the corresponding averaging factor as well.</p>","<h3>Three squared-error conventions: [1, 3]</h3>","<p class=\"inline-question\"><strong>Question. Predictions are [1, 3] and targets are [2, 3]. Find SSE, half SSE and MSE.</strong></p>","<h3>Given</h3>","<p>Predictions = [1, 3].</p>","<p>Targets = [2, 3].</p>","<p>Number of scalar predictions n = 2.</p>","<h3>To find</h3>","<p>SSE, half SSE and MSE separately.</p>","<h3>Formula — which one and why</h3>","<p>All three use the same squared errors but divide the sum differently. The question explicitly asks for each convention.</p>","<p>ŷᵢ is a prediction; yᵢ its target; n counts predictions, not network layers.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square sab mein; half mein 2, mean mein n se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dba84d8eacba9175.svg\" alt=\"e_1=1-2=-1\" width=\"172.76\" height=\"19.94\" style=\"width:172.76px;height:19.94px;aspect-ratio:172.76/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/725d81fce4be12d0.svg\" alt=\"e_1^2=(-1)^2=1\" width=\"160.35\" height=\"27.70\" style=\"width:160.35px;height:27.70px;aspect-ratio:160.35/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/168d50f2de11bd29.svg\" alt=\"e_2=3-3=0\" width=\"153.75\" height=\"19.94\" style=\"width:153.75px;height:19.94px;aspect-ratio:153.75/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: square error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/760944c761b54733.svg\" alt=\"e_2^2=(0)^2=0\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add squared errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d7eadaf7257dae1.svg\" alt=\"\\mathrm{SSE}=1+0=1\" width=\"175.50\" height=\"19.23\" style=\"width:175.50px;height:19.23px;aspect-ratio:175.50/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: divide by 2 for half SSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6b038fb864ecaa7.svg\" alt=\"L_{\\mathrm{half}}=\\frac{1}{2}=0.5\" width=\"167.51\" height=\"49.55\" style=\"width:167.51px;height:49.55px;aspect-ratio:167.51/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: divide by the number of predictions for MSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89fe10c4fdc1b2d9.svg\" alt=\"\\mathrm{MSE}=\\frac{1}{2}\\approx0.500000000\" width=\"269.73\" height=\"49.55\" style=\"width:269.73px;height:49.55px;aspect-ratio:269.73/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> SSE = 1; half SSE = 0.5; MSE ≈ 0.500000000.</p>","<h3>Three squared-error conventions: [2, 5, 1]</h3>","<p class=\"inline-question\"><strong>Question. Predictions are [2, 5, 1] and targets are [1, 3, 2]. Find SSE, half SSE and MSE.</strong></p>","<h3>Given</h3>","<p>Predictions = [2, 5, 1].</p>","<p>Targets = [1, 3, 2].</p>","<p>Number of scalar predictions n = 3.</p>","<h3>To find</h3>","<p>SSE, half SSE and MSE separately.</p>","<h3>Formula — which one and why</h3>","<p>All three use the same squared errors but divide the sum differently. The question explicitly asks for each convention.</p>","<p>ŷᵢ is a prediction; yᵢ its target; n counts predictions, not network layers.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square sab mein; half mein 2, mean mein n se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b0c87b502c9af9cc.svg\" alt=\"e_1=2-1=1\" width=\"153.75\" height=\"19.94\" style=\"width:153.75px;height:19.94px;aspect-ratio:153.75/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/527befb1696e696d.svg\" alt=\"e_1^2=(1)^2=1\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/776a0d96be6de464.svg\" alt=\"e_2=5-3=2\" width=\"153.75\" height=\"19.94\" style=\"width:153.75px;height:19.94px;aspect-ratio:153.75/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: square error 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c723f0acd2a3070.svg\" alt=\"e_2^2=(2)^2=4\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate error 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b685cf877781a273.svg\" alt=\"e_3=1-2=-1\" width=\"172.76\" height=\"20.31\" style=\"width:172.76px;height:20.31px;aspect-ratio:172.76/20.31\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: square error 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1212dd80c80f5b96.svg\" alt=\"e_3^2=(-1)^2=1\" width=\"160.35\" height=\"28.02\" style=\"width:160.35px;height:28.02px;aspect-ratio:160.35/28.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: add squared errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8252220326cba08a.svg\" alt=\"\\mathrm{SSE}=1+4+1=6\" width=\"217.59\" height=\"19.23\" style=\"width:217.59px;height:19.23px;aspect-ratio:217.59/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: divide by 2 for half SSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5e41d17ab2e98c3d.svg\" alt=\"L_{\\mathrm{half}}=\\frac{6}{2}=3\" width=\"148.50\" height=\"49.55\" style=\"width:148.50px;height:49.55px;aspect-ratio:148.50/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 9: divide by the number of predictions for MSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4955c778fd95a4f.svg\" alt=\"\\mathrm{MSE}=\\frac{6}{3}\\approx2.000000000\" width=\"269.73\" height=\"50.09\" style=\"width:269.73px;height:50.09px;aspect-ratio:269.73/50.09\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> SSE = 6; half SSE = 3; MSE ≈ 2.000000000.</p>","<h3>Three squared-error conventions: [4]</h3>","<p class=\"inline-question\"><strong>Question. Predictions are [4] and targets are [1]. Find SSE, half SSE and MSE.</strong></p>","<h3>Given</h3>","<p>Predictions = [4].</p>","<p>Targets = [1].</p>","<p>Number of scalar predictions n = 1.</p>","<h3>To find</h3>","<p>SSE, half SSE and MSE separately.</p>","<h3>Formula — which one and why</h3>","<p>All three use the same squared errors but divide the sum differently. The question explicitly asks for each convention.</p>","<p>ŷᵢ is a prediction; yᵢ its target; n counts predictions, not network layers.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square sab mein; half mein 2, mean mein n se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35c4c4ba3ef807a6.svg\" alt=\"e_1=4-1=3\" width=\"153.75\" height=\"20.21\" style=\"width:153.75px;height:20.21px;aspect-ratio:153.75/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: square error 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1c1774a6ed0f013e.svg\" alt=\"e_1^2=(3)^2=9\" width=\"141.33\" height=\"27.70\" style=\"width:141.33px;height:27.70px;aspect-ratio:141.33/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add squared errors.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3acb15eecc0c073c.svg\" alt=\"\\mathrm{SSE}=9=9\" width=\"133.41\" height=\"19.23\" style=\"width:133.41px;height:19.23px;aspect-ratio:133.41/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide by 2 for half SSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6c789702092108e1.svg\" alt=\"L_{\\mathrm{half}}=\\frac{9}{2}=4.5\" width=\"167.51\" height=\"49.55\" style=\"width:167.51px;height:49.55px;aspect-ratio:167.51/49.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: divide by the number of predictions for MSE.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1fcd30496290844.svg\" alt=\"\\mathrm{MSE}=\\frac{9}{1}\\approx9.000000000\" width=\"269.73\" height=\"49.55\" style=\"width:269.73px;height:49.55px;aspect-ratio:269.73/49.55\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> SSE = 9; half SSE = 4.5; MSE ≈ 9.000000000.</p>","<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fcb072c6f4519069.svg\" alt=\"p=0.8\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65af868a518fd08e.svg\"><img class=\"math display-math\" src=\"assets/equations/710d02f73efd4006.svg\" alt=\"L=-(-0.223143551)=0.223143551\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.223143551 nats.</p>","<h3>Binary cross-entropy: target 0, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 0. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 0; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/438398f064595bb7.svg\" alt=\"1-p=1-0.8=0.2\" width=\"224.09\" height=\"21.02\" style=\"width:224.09px;height:21.02px;aspect-ratio:224.09/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a82bb66e18d1bf7c.svg\" alt=\"\\ln(0.2)\\approx-1.609437912\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe3e4a4ff07bc0e0.svg\"><img class=\"math display-math\" src=\"assets/equations/8a78ffe2df23393c.svg\" alt=\"L=-(-1.609437912)=1.609437912\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 1.609437912 nats.</p>","<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.5</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.5. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.5; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c8d4b00d7d4788e.svg\" alt=\"p=0.5\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89c211e38f586f86.svg\" alt=\"\\ln(0.5)\\approx-0.693147181\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e0e8fd22135c9d7b.svg\"><img class=\"math display-math\" src=\"assets/equations/4bf6a8c1047d0f4a.svg\" alt=\"L=-(-0.693147181)=0.693147181\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.693147181 nats.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=1</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 1. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 1; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55554414edc61afc.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-1}{0.16}=-1.25\" width=\"251.78\" height=\"54.97\" style=\"width:251.78px;height:54.97px;aspect-ratio:251.78/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.60px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/352e50cd272ef421.svg\"><img class=\"math display-math\" src=\"assets/equations/b564b0f8f85410b8.svg\" alt=\"\\frac{dL}{dz}=(-1.25)(0.16)=-0.2\" width=\"299.42\" height=\"50.50\" style=\"width:299.42px;height:50.50px;aspect-ratio:299.42/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> dL/dz = -0.2. No further sigmoid derivative is needed.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=0</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 0. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 0; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcb217487ddffdd.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-0}{0.16}=5\" width=\"201.55\" height=\"54.97\" style=\"width:201.55px;height:54.97px;aspect-ratio:201.55/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86de3ab6d9deb754.svg\" alt=\"\\frac{dL}{dz}=(5)(0.16)=0.8\" width=\"230.17\" height=\"50.50\" style=\"width:230.17px;height:50.50px;aspect-ratio:230.17/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> dL/dz = 0.8. No further sigmoid derivative is needed.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s12","search":"Choosing a loss **Definition.** A loss function quantifies the discrepancy between a prediction and its target. The training objective aggregates per-example losses and may add regularization. The loss must be compatible with the task and output parameterization.\n\n### Explanation and working\nActivation produces the prediction. Loss measures how wrong that prediction is. An optimizer uses gradients to update parameters. These are three different roles.\n\n\n\n\n**Question.** Targets are [2, 4], predictions are [1, 6]. Find MSE and MAE.\n\n\n\n### Given\n\nTargets = [2,4]; predictions = [1,6]; n = 2.\n\n### To find\n\nFind mean squared error and mean absolute error.\n\n### Formula — which one and why\n\n**Squared-error objectives.** Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.\n\nŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle error square; phir question ke hisaab se sum, half ya mean.\n\n**Mean absolute error.** Absolute value removes the sign of each prediction error without squaring its magnitude. Average those magnitudes.\n\nn = number of predictions. |e| means the nonnegative magnitude of error e.\n\n\n\n**Yaad rakhne ka cue:** MAE mein magnitude; MSE mein square.\n\n### Solution — step by step\n\n\n\n\n**Step 1: calculate prediction minus target.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 2: square both errors.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 3: add squares and divide by two observations.**\n\n\n\n\n\n\n\n**Step 4: take the absolute value of each original error.**\n\n\n\n\n\n\n\n**Step 5: add absolute errors and divide by two.**\n\n\n\n\n\n\n\n**Final answer:** MSE = 2.5; MAE = 1.5. Squaring gives larger errors more influence; MAE is not differentiable at zero error.\n\nFor binary y = 1, BCE becomes −ln(p). For y = 0, it becomes −ln(1 − p). For one-hot multiclass labels, CCE is simply minus the natural log of the predicted probability assigned to the correct class.\n**Question.** True class is Mild, encoded [0,1,0], and probabilities are [0.1,0.8,0.1]. Find CCE.\n\n\n\n### Given\n\nTrue class = Mild; one-hot target = [0,1,0].\n\nPredicted probabilities = [0.1,0.8,0.1].\n\n### To find\n\nFind the categorical cross-entropy.\n\n### Formula — which one and why\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n**Step 1: write one weighted log term for each class.**\n\n\n\n\n\n\n\n**Step 2: remove terms with zero target weight.**\n\n\n\n\n\n\n\n**Step 3: evaluate the natural logarithm.**\n\n\n\n\n\n\n\n**Step 4: apply the outer minus sign.**\n\n\n\n\n\n\n\n**Final answer:** CCE ≈ 0.223144. Only the correct-class probability contributes for this one-hot target.\n| Task | Typical output | Typical loss |\n| Unbounded numerical regression | One linear output | MSE or MAE |\n| Binary classification | One sigmoid output | Binary cross-entropy |\n| Exactly one of K classes | K softmax outputs | Categorical cross-entropy |\n| Several independent labels | K sigmoid outputs | Binary cross-entropy per label |\nA continuous rating restricted to 0–10 can us"},{"title":"Forward propagation through multiple neurons","blocks":["<p class=\"definition\"><strong>Definitions.</strong> A feedforward neural network has a directed acyclic computation graph: information moves from inputs toward outputs without recurrent feedback connections. A multilayer perceptron (MLP) is a feedforward network built from fully connected layers, with one or more hidden layers and nonlinear hidden activations.</p>","<h3>Input, hidden and output layers</h3>","<p>The <strong>input layer</strong> supplies the feature vector. A <strong>hidden layer</strong> learns an intermediate representation; its outputs are computed from preceding activations, not supplied as target labels. The <strong>output layer</strong> produces the prediction in the form needed by the task.</p>","<p>In a dense connection between two layers, every receiving neuron has a weight for every preceding activation. Each receiving neuron also normally has its own bias. An ANN is the broader family containing feedforward and recurrent models. A CNN can be feedforward without being an MLP, because convolution uses local shared connections.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/network.svg\" aria-label=\"Enlarge diagram: A feedforward network calculates each hidden representation before using it to calculate the next layer.\"><img src=\"assets/figures/network.svg\" alt=\"A feedforward network calculates each hidden representation before using it to calculate the next layer.\" width=\"960\" height=\"440\" loading=\"lazy\"></button><figcaption>A feedforward network calculates each hidden representation before using it to calculate the next layer. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>General layer equations and dimensions</h3>","<p>Let a⁽⁰⁾ = x. For layer l:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/87472012ebbb4a9d.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)}\" width=\"228.73\" height=\"25.06\" style=\"width:228.73px;height:25.06px;aspect-ratio:228.73/25.06\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/da3b4bdac78b839b.svg\" alt=\"a^{(l)}=f^{(l)}(z^{(l)})\" width=\"152.47\" height=\"29.16\" style=\"width:152.47px;height:29.16px;aspect-ratio:152.47/29.16\" loading=\"lazy\"></div>","<p>If the preceding layer has n inputs and the current layer has m neurons, W has m rows and n columns. The vectors z, a and b have m components. Row j of W contains the incoming weights of neuron j.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.15px;--narrow-height:72.98px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bb1ec5bee5b7117c.svg\"><img class=\"math display-math\" src=\"assets/equations/6213a7d0a0d572f3.svg\" alt=\"W^{(l)}\\in\\mathbb R^{m\\times n},\\qquad b^{(l)},z^{(l)},a^{(l)}\\in\\mathbb R^{m\\times1}\" width=\"400.98\" height=\"27.79\" style=\"width:400.98px;height:27.79px;aspect-ratio:400.98/27.79\" loading=\"lazy\"></picture></div>","<p>For one hidden layer, these computations compose to give:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ff7d7b3e6546d64.svg\" alt=\"h=f^{(1)}(W^{(1)}x+b^{(1)})\" width=\"234.01\" height=\"29.16\" style=\"width:234.01px;height:29.16px;aspect-ratio:234.01/29.16\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb13b3127fe27394.svg\" alt=\"\\hat y=f^{(2)}(W^{(2)}h+b^{(2)})\" width=\"232.01\" height=\"29.16\" style=\"width:232.01px;height:29.16px;aspect-ratio:232.01/29.16\" loading=\"lazy\"></div>","<p>The hidden activation must be nonlinear to obtain nonlinear representational power. Stacking affine layers alone still gives one affine mapping. A single threshold perceptron cannot separate XOR; a hidden nonlinear representation can make the two classes separable for the output layer.</p>","<h3>Forward propagation versus training</h3>","<p>Forward propagation evaluates these layer equations using the current parameters. Training additionally evaluates a loss, uses backpropagation to calculate gradients, and applies an optimizer update. The architecture specifies connections; backpropagation is a differentiation algorithm used to train that architecture.</p>","<h3>Complete two-layer numerical</h3>","<p class=\"inline-question\"><strong>Question. A feedforward network receives x = [1, 0]ᵀ. Its hidden-layer weights are W¹ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/59303f63a5ad2b9b.svg\" alt=\"\\begin{bmatrix}0.2 &amp; 0.4\\\\0.3 &amp; 0.7\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span> and biases are b¹ = [0.1, 0.2]ᵀ. The output weights are W² = [0.5, 0.6] and output bias is b² = 0.1. Use ReLU in both layers and one row per receiving neuron. Calculate every preactivation and the final output.</strong></p>","<h3>Given</h3>","<p>A feedforward network receives x = [1, 0]ᵀ.</p>","<p>Its hidden-layer weights are W¹ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/59303f63a5ad2b9b.svg\" alt=\"\\begin{bmatrix}0.2 &amp; 0.4\\\\0.3 &amp; 0.7\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span> and biases are b¹ = [0.1, 0.2]ᵀ.</p>","<p>The output weights are W² = [0.5, 0.6] and output bias is b² = 0.1.</p>","<p>Use ReLU in both layers and one row per receiving neuron.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the requested activation values and slopes.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_5f379b367f.svg\" aria-label=\"Enlarge diagram: The given weights use rows for receiving neurons. There are two hidden neurons and one output neuron.\"><img src=\"assets/figures/given_5f379b367f.svg\" alt=\"The given weights use rows for receiving neurons. There are two hidden neurons and one output neuron.\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>The given weights use rows for receiving neurons. There are two hidden neurons and one output neuron. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1: identify the matrix dimensions.</strong> W¹ is 2 × 2 and x is 2 × 1, so the hidden preactivation has two entries. W² is 1 × 2, so it takes those two activations and produces one output.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the first hidden preactivation.</strong> Multiply the first row by x, then add the first hidden bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:72.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f1a7c307bfbc37e.svg\"><img class=\"math display-math\" src=\"assets/equations/2aa7feda8e9b9e38.svg\" alt=\"z^{(1)}_1=0.2(1)+0.4(0)+0.1=0.3\" width=\"347.74\" height=\"33.18\" style=\"width:347.74px;height:33.18px;aspect-ratio:347.74/33.18\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the second hidden preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:72.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee1bd9d85fa15d84.svg\"><img class=\"math display-math\" src=\"assets/equations/8b6a4f4bbfa44dae.svg\" alt=\"z^{(1)}_2=0.3(1)+0.7(0)+0.2=0.5\" width=\"347.74\" height=\"33.18\" style=\"width:347.74px;height:33.18px;aspect-ratio:347.74/33.18\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: activate the hidden layer.</strong> Both values are positive, so ReLU retains them.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0b16aa9984127202.svg\" alt=\"a^{(1)}_1=\\max(0,0.3)=0.3\" width=\"252.22\" height=\"33.18\" style=\"width:252.22px;height:33.18px;aspect-ratio:252.22/33.18\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6263aed38871ad59.svg\" alt=\"a^{(1)}_2=\\max(0,0.5)=0.5\" width=\"252.22\" height=\"33.18\" style=\"width:252.22px;height:33.18px;aspect-ratio:252.22/33.18\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/368b9c59527b8200.svg\" alt=\"a^{(1)}=\\begin{bmatrix}0.3\\\\0.5\\end{bmatrix}\" width=\"126.65\" height=\"58.64\" style=\"width:126.65px;height:58.64px;aspect-ratio:126.65/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the output preactivation.</strong> Use the activated hidden values as this layer&#x27;s inputs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.43px;--narrow-height:68.26px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f3fff5a6e4a523e4.svg\"><img class=\"math display-math\" src=\"assets/equations/3480e69d1dd395dc.svg\" alt=\"z^{(2)}=0.5(0.3)+0.6(0.5)+0.1\" width=\"321.95\" height=\"29.16\" style=\"width:321.95px;height:29.16px;aspect-ratio:321.95/29.16\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:184.81px;--narrow-height:68.26px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2fda741950753a37.svg\"><img class=\"math display-math\" src=\"assets/equations/ccbd4dc810f4e3fd.svg\" alt=\"z^{(2)}=0.15+0.30+0.10=0.55\" width=\"334.15\" height=\"25.06\" style=\"width:334.15px;height:25.06px;aspect-ratio:334.15/25.06\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the output activation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc763b55540917.svg\" alt=\"\\hat y=\\max(0,0.55)=0.55\" width=\"251.60\" height=\"25.90\" style=\"width:251.60px;height:25.90px;aspect-ratio:251.60/25.90\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> hidden preactivations and activations are [0.3, 0.5]ᵀ; output preactivation and prediction are both 0.55. They coincide here because every ReLU input is positive. No parameter has been updated during this forward pass.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s13","search":"Forward propagation through multiple neurons **Definitions.** A feedforward neural network has a directed acyclic computation graph: information moves from inputs toward outputs without recurrent feedback connections. A multilayer perceptron (MLP) is a feedforward network built from fully connected layers, with one or more hidden layers and nonlinear hidden activations.\n\n### Input, hidden and output layers\nThe **input layer** supplies the feature vector. A **hidden layer** learns an intermediate representation; its outputs are computed from preceding activations, not supplied as target labels. The **output layer** produces the prediction in the form needed by the task.\n\nIn a dense connection between two layers, every receiving neuron has a weight for every preceding activation. Each receiving neuron also normally has its own bias. An ANN is the broader family containing feedforward and recurrent models. A CNN can be feedforward without being an MLP, because convolution uses local shared connections.\n\n\n\n### General layer equations and dimensions\nLet a⁽⁰⁾ = x. For layer l:\n\n\nIf the preceding layer has n inputs and the current layer has m neurons, W has m rows and n columns. The vectors z, a and b have m components. Row j of W contains the incoming weights of neuron j.\n\nFor one hidden layer, these computations compose to give:\n\n\nThe hidden activation must be nonlinear to obtain nonlinear representational power. Stacking affine layers alone still gives one affine mapping. A single threshold perceptron cannot separate XOR; a hidden nonlinear representation can make the two classes separable for the output layer.\n\n### Forward propagation versus training\nForward propagation evaluates these layer equations using the current parameters. Training additionally evaluates a loss, uses backpropagation to calculate gradients, and applies an optimizer update. The architecture specifies connections; backpropagation is a differentiation algorithm used to train that architecture.\n\n### Complete two-layer numerical\n**Question. A feedforward network receives x = [1, 0]ᵀ. Its hidden-layer weights are W¹ =  and biases are b¹ = [0.1, 0.2]ᵀ. The output weights are W² = [0.5, 0.6] and output bias is b² = 0.1. Use ReLU in both layers and one row per receiving neuron. Calculate every preactivation and the final output.**\n\n\n\n### Given\n\nA feedforward network receives x = [1, 0]ᵀ.\n\nIts hidden-layer weights are W¹ =  and biases are b¹ = [0.1, 0.2]ᵀ.\n\nThe output weights are W² = [0.5, 0.6] and output bias is b² = 0.1.\n\nUse ReLU in both layers and one row per receiving neuron.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the requested activation values and slopes.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota"},{"title":"Backpropagation with one hidden neuron","blocks":["<p class=\"definition\"><strong>Definition.</strong> Backpropagation computes the derivatives of a scalar objective with respect to network parameters by applying the chain rule in reverse through the computational graph. An optimizer then uses these derivatives to update the parameters.</p>","<h3>Network equations and the meaning of delta</h3>","<p>Consider one input, one hidden neuron and one output neuron:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:155.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3f2141c2576fb066.svg\"><img class=\"math display-math\" src=\"assets/equations/3c0624453c85b214.svg\" alt=\"z_h=w_1x+b_1,\\qquad h=f(z_h)\" width=\"311.27\" height=\"24.43\" style=\"width:311.27px;height:24.43px;aspect-ratio:311.27/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:154.41px;--narrow-height:64.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b90638b5849c176.svg\"><img class=\"math display-math\" src=\"assets/equations/60f589c099da8571.svg\" alt=\"z_o=w_2h+b_2,\\qquad\\hat y=g(z_o)\" width=\"304.33\" height=\"25.90\" style=\"width:304.33px;height:25.90px;aspect-ratio:304.33/25.90\" loading=\"lazy\"></picture></div>","<p>For the half squared loss used in this example:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/df5fc0c0a9ad8296.svg\" alt=\"L=\\frac12(\\hat y-y)^2\" width=\"155.68\" height=\"49.55\" style=\"width:155.68px;height:49.55px;aspect-ratio:155.68/49.55\" loading=\"lazy\"></div>","<p>Define a neuron&#x27;s delta as the derivative of the loss with respect to its <strong>preactivation</strong>, not with respect to its output:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6215ea243129f507.svg\" alt=\"\\delta_o=\\frac{\\partial L}{\\partial z_o}=(\\hat y-y)g&#x27;(z_o)\" width=\"264.82\" height=\"54.60\" style=\"width:264.82px;height:54.60px;aspect-ratio:264.82/54.60\" loading=\"lazy\"></div>","<p>The output-weight derivative contains the hidden activation because zₒ = w₂h + b₂:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/338a3082f0298cb5.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=\\delta_o h,\\qquad\\frac{\\partial L}{\\partial b_2}=\\delta_o\" width=\"279.97\" height=\"54.41\" style=\"width:279.97px;height:54.41px;aspect-ratio:279.97/54.41\" loading=\"lazy\"></div>","<p>To reach the hidden neuron, continue backwards through the old output weight and the hidden activation:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6409774c2652b14e.svg\" alt=\"\\delta_h=\\delta_o w_2 f&#x27;(z_h)\" width=\"168.70\" height=\"25.88\" style=\"width:168.70px;height:25.88px;aspect-ratio:168.70/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/675e596602704d40.svg\" alt=\"\\frac{\\partial L}{\\partial w_1}=\\delta_h x,\\qquad\\frac{\\partial L}{\\partial b_1}=\\delta_h\" width=\"283.01\" height=\"54.41\" style=\"width:283.01px;height:54.41px;aspect-ratio:283.01/54.41\" loading=\"lazy\"></div>","<p>The bias derivative equals the corresponding delta because the derivative of z with respect to its additive bias is 1. All these derivatives belong to the same forward pass; an updated weight must not be used partway through this backward pass.</p>","<h3>Complete worked numerical</h3>","<p class=\"inline-question\"><strong>Question.</strong> x = 2, y = 1; w₁ = 0.5, b₁ = 0.1; w₂ = 0.8, b₂ = 0.2. Both neurons use ReLU. Use half squared loss. Find the output and all four parameter gradients, then update all four parameters using η = 0.1.</p>","<h3>Given</h3>","<p>x = 2, y = 1.</p>","<p>w₁ = 0.5, b₁ = 0.1.</p>","<p>w₂ = 0.8, b₂ = 0.2.</p>","<p>Both neurons use ReLU.</p>","<p>Use half squared loss.</p>","<p>Find the output and all four parameter gradients, then update all four parameters using η = 0.1.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_single_backprop.svg\" aria-label=\"Enlarge diagram: The forward pass evaluates hidden and output activations. The backward pass multiplies local derivatives through the same, unchanged weights.\"><img src=\"assets/figures/v_single_backprop.svg\" alt=\"The forward pass evaluates hidden and output activations. The backward pass multiplies local derivatives through the same, unchanged weights.\" width=\"1080\" height=\"690\" loading=\"lazy\"></button><figcaption>The forward pass evaluates hidden and output activations. The backward pass multiplies local derivatives through the same, unchanged weights. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1: forward propagation through the hidden neuron.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5613b3868c5f8d85.svg\" alt=\"z_h=0.5(2)+0.1=1.1\" width=\"243.29\" height=\"24.43\" style=\"width:243.29px;height:24.43px;aspect-ratio:243.29/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5206a5b2ac9abfe4.svg\" alt=\"h=\\operatorname{ReLU}(1.1)=1.1\" width=\"223.14\" height=\"24.43\" style=\"width:223.14px;height:24.43px;aspect-ratio:223.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: forward propagation through the output neuron.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a7535982ea7d2cd.svg\" alt=\"z_o=0.8(1.1)+0.2=1.08\" width=\"272.95\" height=\"24.43\" style=\"width:272.95px;height:24.43px;aspect-ratio:272.95/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8a3b4bb2871113ef.svg\" alt=\"\\hat y=\\operatorname{ReLU}(1.08)=1.08\" width=\"245.47\" height=\"25.90\" style=\"width:245.47px;height:25.90px;aspect-ratio:245.47/25.90\" loading=\"lazy\"></div>","<p>ReLU is not bounded above by 1, so this output is valid. It is not being interpreted as a probability here.</p>","<p class=\"worked-step\"><strong>Step 3: calculate the loss and output delta.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e51ef56449f25818.svg\" alt=\"L=\\frac12(1.08-1)^2=0.0032\" width=\"287.86\" height=\"49.55\" style=\"width:287.86px;height:49.55px;aspect-ratio:287.86/49.55\" loading=\"lazy\"></div>","<p>Both preactivations are positive, so both ReLU derivatives are 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ead62e2abd6d370.svg\" alt=\"\\delta_o=(1.08-1)(1)=0.08\" width=\"265.64\" height=\"24.43\" style=\"width:265.64px;height:24.43px;aspect-ratio:265.64/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: calculate the output-layer parameter gradients.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/20d536b8c74dbceb.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=0.08(1.1)=0.088\" width=\"267.26\" height=\"54.41\" style=\"width:267.26px;height:54.41px;aspect-ratio:267.26/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57f3bbde46d88ee8.svg\" alt=\"\\frac{\\partial L}{\\partial b_2}=0.08\" width=\"121.76\" height=\"54.41\" style=\"width:121.76px;height:54.41px;aspect-ratio:121.76/54.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: propagate the derivative to the hidden neuron.</strong></p>","<p>Use w₂ = 0.8, its value during the forward pass:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cf97525165cb969.svg\" alt=\"\\delta_h=0.08(0.8)(1)=0.064\" width=\"268.56\" height=\"24.43\" style=\"width:268.56px;height:24.43px;aspect-ratio:268.56/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a31fd300551ec8e1.svg\" alt=\"\\frac{\\partial L}{\\partial w_1}=0.064(2)=0.128\" width=\"260.46\" height=\"54.41\" style=\"width:260.46px;height:54.41px;aspect-ratio:260.46/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc73ac9e8421c88b.svg\" alt=\"\\frac{\\partial L}{\\partial b_1}=0.064\" width=\"133.97\" height=\"54.41\" style=\"width:133.97px;height:54.41px;aspect-ratio:133.97/54.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: update each parameter using its own gradient.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a6ad843a78157c3.svg\"><img class=\"math display-math\" src=\"assets/equations/d781e32010d9fb09.svg\" alt=\"w_{1,\\mathrm{new}}=0.5-0.1(0.128)=0.4872\" width=\"362.76\" height=\"25.35\" style=\"width:362.76px;height:25.35px;aspect-ratio:362.76/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.28px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d766af9fb7ee76f0.svg\"><img class=\"math display-math\" src=\"assets/equations/33bdb6cbe9ce338c.svg\" alt=\"b_{1,\\mathrm{new}}=0.1-0.1(0.064)=0.0936\" width=\"355.75\" height=\"25.35\" style=\"width:355.75px;height:25.35px;aspect-ratio:355.75/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2a2db66205fe592.svg\"><img class=\"math display-math\" src=\"assets/equations/1d57ae029d4adfac.svg\" alt=\"w_{2,\\mathrm{new}}=0.8-0.1(0.088)=0.7912\" width=\"362.76\" height=\"25.35\" style=\"width:362.76px;height:25.35px;aspect-ratio:362.76/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:243.06px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4678bc376cf0d02b.svg\"><img class=\"math display-math\" src=\"assets/equations/55b6e2f442ea2fb4.svg\" alt=\"b_{2,\\mathrm{new}}=0.2-0.1(0.08)=0.192\" width=\"331.31\" height=\"25.35\" style=\"width:331.31px;height:25.35px;aspect-ratio:331.31/25.35\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Parameter</th><th>Gradient from the original forward pass</th><th>Updated value</th></tr></thead><tbody><tr><td>w₁</td><td>0.128</td><td>0.4872</td></tr><tr><td>b₁</td><td>0.064</td><td>0.0936</td></tr><tr><td>w₂</td><td>0.088</td><td>0.7912</td></tr><tr><td>b₂</td><td>0.08</td><td>0.192</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> the original prediction is 1.08 and its loss is 0.0032. The table contains all requested gradients and updated parameters. A new forward pass would use all four new parameters together.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s14","search":"Backpropagation with one hidden neuron \n**Definition.** Backpropagation computes the derivatives of a scalar objective with respect to network parameters by applying the chain rule in reverse through the computational graph. An optimizer then uses these derivatives to update the parameters.\n\n### Network equations and the meaning of delta\nConsider one input, one hidden neuron and one output neuron:\n\n\nFor the half squared loss used in this example:\n\nDefine a neuron's delta as the derivative of the loss with respect to its **preactivation**, not with respect to its output:\n\nThe output-weight derivative contains the hidden activation because zₒ = w₂h + b₂:\n\nTo reach the hidden neuron, continue backwards through the old output weight and the hidden activation:\n\n\nThe bias derivative equals the corresponding delta because the derivative of z with respect to its additive bias is 1. All these derivatives belong to the same forward pass; an updated weight must not be used partway through this backward pass.\n\n### Complete worked numerical\n**Question.** x = 2, y = 1; w₁ = 0.5, b₁ = 0.1; w₂ = 0.8, b₂ = 0.2. Both neurons use ReLU. Use half squared loss. Find the output and all four parameter gradients, then update all four parameters using η = 0.1.\n\n\n\n### Given\n\nx = 2, y = 1.\n\nw₁ = 0.5, b₁ = 0.1.\n\nw₂ = 0.8, b₂ = 0.2.\n\nBoth neurons use ReLU.\n\nUse half squared loss.\n\nFind the output and all four parameter gradients, then update all four parameters using η = 0.1.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n\n\n**Step 1: forward propagation through the hidden neuron.**\n\n\n\n**Step 2: forward propagation through the output neuron.**\n\n\nReLU is not bounded above by 1, so this output is valid. It is not being interpreted as a probability here.\n\n**Step 3: calculate the loss and output delta.**\n\nBoth preactivations are positive, so bot"},{"title":"More outputs and vectorized backpropagation","blocks":["<p class=\"definition\"><strong>Definition.</strong> Vectorized backpropagation expresses the chain rule using matrix products and elementwise derivatives. When a hidden activation affects several outputs, its derivative contains the sum of the contributions from every downstream path.</p>","<h3>Why the hidden derivative is a sum</h3>","<p>If hidden activation hⱼ connects to output preactivations zₒ₁ and zₒ₂, changing hⱼ changes both outputs. The multivariable chain rule gives:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf829204c0f41f49.svg\" alt=\"\\frac{\\partial L}{\\partial h_j}=W_{2,1j}\\delta_{o_1}+W_{2,2j}\\delta_{o_2}\" width=\"276.44\" height=\"57.94\" style=\"width:276.44px;height:57.94px;aspect-ratio:276.44/57.94\" loading=\"lazy\"></div>","<p>For any number of connected outputs, sum their contributions and then differentiate the hidden activation:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:264.69px;--narrow-height:115.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f94e1705f6027563.svg\"><img class=\"math display-math\" src=\"assets/equations/08fe50471952c690.svg\" alt=\"\\delta_{h_j}=\\left(\\sum_k W_{2,kj}\\delta_{o_k}\\right)f&#x27;(z_{h_j})\" width=\"293.99\" height=\"73.28\" style=\"width:293.99px;height:73.28px;aspect-ratio:293.99/73.28\" loading=\"lazy\"></picture></div>","<p>Use the connecting weights from the original forward pass. Adding only the contribution of the first output would omit a dependency of the loss.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_branch_gradient.svg\" aria-label=\"Enlarge diagram: The outgoing paths both contribute to the hidden derivative. Add the weighted output deltas, then apply the hidden activation derivative.\"><img src=\"assets/figures/v_branch_gradient.svg\" alt=\"The outgoing paths both contribute to the hidden derivative. Add the weighted output deltas, then apply the hidden activation derivative.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>The outgoing paths both contribute to the hidden derivative. Add the weighted output deltas, then apply the hidden activation derivative. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Matrix equations for one training sample</h3>","<p>Use column vectors throughout. Let W₁ map d inputs to m hidden units and W₂ map those units to k outputs. The following output-delta formula assumes <strong>half sum of squared errors</strong> and an elementwise output activation f₂:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3370e1f71500a0e.svg\" alt=\"L=\\frac12\\sum_{j=1}^{k}(\\hat y_j-y_j)^2\" width=\"213.33\" height=\"75.08\" style=\"width:213.33px;height:75.08px;aspect-ratio:213.33/75.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07eda20c3b7d69f3.svg\" alt=\"\\delta_2=(\\hat y-y)\\odot f_2&#x27;(z_2)\" width=\"220.47\" height=\"25.90\" style=\"width:220.47px;height:25.90px;aspect-ratio:220.47/25.90\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.33px;--narrow-height:123.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7401adc017e3686d.svg\"><img class=\"math display-math\" src=\"assets/equations/b217a2191f391cf2.svg\" alt=\"\\frac{\\partial L}{\\partial W_2}=\\delta_2a_1^T,\\qquad\\frac{\\partial L}{\\partial b_2}=\\delta_2\" width=\"299.10\" height=\"54.41\" style=\"width:299.10px;height:54.41px;aspect-ratio:299.10/54.41\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9b8719d9f5e5e0f.svg\" alt=\"\\delta_1=(W_2^T\\delta_2)\\odot f_1&#x27;(z_1)\" width=\"229.33\" height=\"27.90\" style=\"width:229.33px;height:27.90px;aspect-ratio:229.33/27.90\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:147.38px;--narrow-height:123.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/88df80b8a0e03820.svg\"><img class=\"math display-math\" src=\"assets/equations/ae5ad96746c9621d.svg\" alt=\"\\frac{\\partial L}{\\partial W_1}=\\delta_1x^T,\\qquad\\frac{\\partial L}{\\partial b_1}=\\delta_1\" width=\"300.14\" height=\"54.41\" style=\"width:300.14px;height:54.41px;aspect-ratio:300.14/54.41\" loading=\"lazy\"></picture></div>","<p>Here ⊙ means elementwise multiplication. The product δ₂a₁ᵀ is an <strong>outer product</strong>: every receiving delta is multiplied by every sending activation.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Quantity</th><th>Shape</th><th>Reason</th></tr></thead><tbody><tr><td>W₁ and its gradient</td><td>m × d</td><td>m receiving hidden neurons, d inputs</td></tr><tr><td>W₂ and its gradient</td><td>k × m</td><td>k receiving output neurons, m hidden activations</td></tr><tr><td>δ₂</td><td>k × 1</td><td>One derivative per output preactivation</td></tr><tr><td>W₂ᵀδ₂</td><td>m × 1</td><td>The summed downstream derivative for each hidden unit</td></tr><tr><td>δ₂a₁ᵀ</td><td>(k × 1)(1 × m) = k × m</td><td>The output-weight gradient has the same shape as W₂</td></tr></tbody></table></div>","<h3>How the loss changes the output delta</h3>","<p>For MSE averaged over k output components, the squared-error derivative has the factor 2/k. For sigmoid with binary cross-entropy, or softmax with categorical cross-entropy and a normalized target, the paired derivative simplifies to prediction minus target:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d69b7fe4a0f11cd.svg\" alt=\"\\delta_{\\mathrm{output}}=\\hat y-y\" width=\"150.17\" height=\"26.81\" style=\"width:150.17px;height:26.81px;aspect-ratio:150.17/26.81\" loading=\"lazy\"></div>","<p>That simplification already includes differentiation of the paired activation and loss. Multiplying by a sigmoid derivative again would be incorrect. For sigmoid with half squared error, the sigmoid derivative is still required.</p>","<p>For a batch, sum per-example parameter gradients; divide by the batch size only if the objective is a batch mean. State the output reduction and batch reduction separately when both appear in a question.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s15","search":"More outputs and vectorized backpropagation \n**Definition.** Vectorized backpropagation expresses the chain rule using matrix products and elementwise derivatives. When a hidden activation affects several outputs, its derivative contains the sum of the contributions from every downstream path.\n\n### Why the hidden derivative is a sum\nIf hidden activation hⱼ connects to output preactivations zₒ₁ and zₒ₂, changing hⱼ changes both outputs. The multivariable chain rule gives:\n\nFor any number of connected outputs, sum their contributions and then differentiate the hidden activation:\n\nUse the connecting weights from the original forward pass. Adding only the contribution of the first output would omit a dependency of the loss.\n\n\n\n### Matrix equations for one training sample\nUse column vectors throughout. Let W₁ map d inputs to m hidden units and W₂ map those units to k outputs. The following output-delta formula assumes **half sum of squared errors** and an elementwise output activation f₂:\n\n\n\n\n\nHere ⊙ means elementwise multiplication. The product δ₂a₁ᵀ is an **outer product**: every receiving delta is multiplied by every sending activation.\n\n| Quantity | Shape | Reason |\n| W₁ and its gradient | m × d | m receiving hidden neurons, d inputs |\n| W₂ and its gradient | k × m | k receiving output neurons, m hidden activations |\n| δ₂ | k × 1 | One derivative per output preactivation |\n| W₂ᵀδ₂ | m × 1 | The summed downstream derivative for each hidden unit |\n| δ₂a₁ᵀ | (k × 1)(1 × m) = k × m | The output-weight gradient has the same shape as W₂ |\n\n### How the loss changes the output delta\nFor MSE averaged over k output components, the squared-error derivative has the factor 2/k. For sigmoid with binary cross-entropy, or softmax with categorical cross-entropy and a normalized target, the paired derivative simplifies to prediction minus target:\n\nThat simplification already includes differentiation of the paired activation and loss. Multiplying by a sigmoid derivative again would be incorrect. For sigmoid with half squared error, the sigmoid derivative is still required.\n\nFor a batch, sum per-example parameter gradients; divide by the batch size only if the objective is a batch mean. State the output reduction and batch reduction separately when both appear in a question.\n\n"},{"title":"Model answer: forward propagation, backpropagation and updating","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain how a feedforward neural network learns using forward propagation, a loss function, backpropagation and gradient descent. State the order of operations.</p>"],"answer":["<p>Training repeatedly uses labeled examples to improve a network&#x27;s weights and biases. The four operations have different jobs.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_training_loop.svg\" aria-label=\"Enlarge diagram: Four different jobs: calculate the prediction, measure the mistake, calculate gradients, and update parameters.\"><img src=\"assets/figures/v_training_loop.svg\" alt=\"Four different jobs: calculate the prediction, measure the mistake, calculate gradients, and update parameters.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Four different jobs: calculate the prediction, measure the mistake, calculate gradients, and update parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Operation</th><th>Direction or action</th><th>Result</th></tr></thead><tbody><tr><td>Forward propagation</td><td>Inputs move through successive layers</td><td>Predictions and intermediate activations</td></tr><tr><td>Loss calculation</td><td>Compare predictions with targets</td><td>A scalar objective for the example or batch</td></tr><tr><td>Backpropagation</td><td>Apply the chain rule from the loss toward earlier layers</td><td>Gradients of the objective with respect to parameters</td></tr><tr><td>Optimizer update</td><td>Use those gradients to change parameters</td><td>A new set of weights and biases</td></tr></tbody></table></div>","<h3>1. Forward propagation</h3>","<p>At each layer, calculate its weighted sums and activations. Retain these values because derivatives such as the sigmoid derivative depend on them. Complete a whole layer before calculating the next.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:72.98px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2845b5af7a9f9056.svg\"><img class=\"math display-math\" src=\"assets/equations/4698521353358290.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)},\\qquad a^{(l)}=f(z^{(l)})\" width=\"419.03\" height=\"29.16\" style=\"width:419.03px;height:29.16px;aspect-ratio:419.03/29.16\" loading=\"lazy\"></picture></div>","<h3>2. Loss</h3>","<p>Use the loss specified by the task. For one regression output, half squared loss is one possible choice:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b45e01da7c114be3.svg\" alt=\"L=\\frac12(a-y)^2\" width=\"156.64\" height=\"49.55\" style=\"width:156.64px;height:49.55px;aspect-ratio:156.64/49.55\" loading=\"lazy\"></div>","<p>Here a is the prediction and y is the target. Other stated losses produce different derivatives.</p>","<h3>3. Backpropagation</h3>","<p>Multiply local derivatives along each dependency path. If a hidden unit influences several outputs, add the contributions from those branches. For a connection, the weight gradient is the receiving neuron&#x27;s net-input derivative multiplied by the sending activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c4e0f7ded9389700.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i\" width=\"130.68\" height=\"57.94\" style=\"width:130.68px;height:57.94px;aspect-ratio:130.68/57.94\" loading=\"lazy\"></div>","<p>Here δⱼ means the derivative of loss with respect to the receiving neuron&#x27;s weighted sum. It is not automatically equal to raw prediction error; the activation and loss determine it.</p>","<h3>4. Update and repeat</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/116cb3cc8bb58606.svg\" alt=\"w_{\\mathrm{new}}=w_{\\mathrm{old}}-\\eta\\frac{\\partial L}{\\partial w}\" width=\"208.53\" height=\"51.29\" style=\"width:208.53px;height:51.29px;aspect-ratio:208.53/51.29\" loading=\"lazy\"></div>","<p>Compute all gradients using the same pre-update weights. Then update the requested parameters. Run another forward pass to calculate the new loss. Backpropagation calculates gradients; gradient descent uses them. Those are related, separate operations.</p>"],"kind":"theory","id":"tee-c4-s16","search":"Model answer: forward propagation, backpropagation and updating **Question.** Explain how a feedforward neural network learns using forward propagation, a loss function, backpropagation and gradient descent. State the order of operations.\n\n**Model answer.**\nTraining repeatedly uses labeled examples to improve a network's weights and biases. The four operations have different jobs.\n\n\n\n\n| Operation | Direction or action | Result |\n| Forward propagation | Inputs move through successive layers | Predictions and intermediate activations |\n| Loss calculation | Compare predictions with targets | A scalar objective for the example or batch |\n| Backpropagation | Apply the chain rule from the loss toward earlier layers | Gradients of the objective with respect to parameters |\n| Optimizer update | Use those gradients to change parameters | A new set of weights and biases |\n\n### 1. Forward propagation\nAt each layer, calculate its weighted sums and activations. Retain these values because derivatives such as the sigmoid derivative depend on them. Complete a whole layer before calculating the next.\n\n### 2. Loss\nUse the loss specified by the task. For one regression output, half squared loss is one possible choice:\n\nHere a is the prediction and y is the target. Other stated losses produce different derivatives.\n### 3. Backpropagation\nMultiply local derivatives along each dependency path. If a hidden unit influences several outputs, add the contributions from those branches. For a connection, the weight gradient is the receiving neuron's net-input derivative multiplied by the sending activation.\n\nHere δⱼ means the derivative of loss with respect to the receiving neuron's weighted sum. It is not automatically equal to raw prediction error; the activation and loss determine it.\n### 4. Update and repeat\n\nCompute all gradients using the same pre-update weights. Then update the requested parameters. Run another forward pass to calculate the new loss. Backpropagation calculates gradients; gradient descent uses them. Those are related, separate operations.\n"},{"title":"Counting parameters in a dense network","blocks":["<p class=\"definition\"><strong>Definition.</strong> A dense layer connects every input component to every receiving neuron. Its trainable parameters are these connection weights and the receiving neurons&#x27; independently trainable biases.</p>","<h3>Deriving the parameter count</h3>","<p>For m inputs and n receiving neurons, each receiver needs m weights. There are therefore mn weights. With one bias per receiver, there are n additional parameters:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e846c0a1de0fb579.svg\"><img class=\"math display-math\" src=\"assets/equations/b9cd556f84e19c2e.svg\" alt=\"P_{\\mathrm{dense}}=mn+n=(m+1)n\" width=\"302.10\" height=\"24.43\" style=\"width:302.10px;height:24.43px;aspect-ratio:302.10/24.43\" loading=\"lazy\"></picture></div>","<p>Activation values are computed from data and parameters; they are not additional trainable parameters. The input layer supplies data and does not acquire an extra bias merely because it appears in a diagram.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dense_count.svg\" aria-label=\"Enlarge diagram: Count all input-to-neuron connections and then one bias per receiving neuron.\"><img src=\"assets/figures/v_dense_count.svg\" alt=\"Count all input-to-neuron connections and then one bias per receiving neuron.\" width=\"1080\" height=\"575\" loading=\"lazy\"></button><figcaption>Count all input-to-neuron connections and then one bias per receiving neuron. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical</h3>","<p class=\"inline-question\"><strong>Question.</strong> A network has 10 input features, three hidden layers with 5 neurons each, and 4 outputs. Every receiving neuron has a bias. Count its trainable parameters.</p>","<h3>Given</h3>","<p>Layer sizes: 10 inputs → 5 hidden → 5 hidden → 5 hidden → 4 outputs.</p>","<p>Every hidden/output neuron has one bias.</p>","<h3>To find</h3>","<p>Count weights and biases at each receiving layer, then the total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Dense-layer parameters.</strong> Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.</p>","<p>n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/494312d0893d20d2.svg\" alt=\"P=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"184.79\" height=\"24.43\" style=\"width:184.79px;height:24.43px;aspect-ratio:184.79/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output ke liye saare inputs plus ek bias.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the consecutive layer widths.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/68fe56c651575649.svg\" alt=\"10\\longrightarrow5\\longrightarrow5\\longrightarrow5\\longrightarrow4\" width=\"287.70\" height=\"17.07\" style=\"width:287.70px;height:17.07px;aspect-ratio:287.70/17.07\" loading=\"lazy\"></div>","<p>There are four trainable dense transformations. A connection between two hidden layers is counted once, as part of the receiving layer&#x27;s parameters.</p>","<p class=\"worked-step\"><strong>Step 2: count weights and biases for each transformation.</strong></p>","<div class=\"table-scroll\"><table><thead><tr><th>Transformation</th><th>Weights</th><th>Biases</th><th>Layer total</th></tr></thead><tbody><tr><td>Input → hidden 1</td><td>10 × 5 = 50</td><td>5</td><td>55</td></tr><tr><td>Hidden 1 → hidden 2</td><td>5 × 5 = 25</td><td>5</td><td>30</td></tr><tr><td>Hidden 2 → hidden 3</td><td>5 × 5 = 25</td><td>5</td><td>30</td></tr><tr><td>Hidden 3 → output</td><td>5 × 4 = 20</td><td>4</td><td>24</td></tr></tbody></table></div>","<p class=\"worked-step\"><strong>Step 3: add the layer totals.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.28px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1c0d23dc90da3211.svg\"><img class=\"math display-math\" src=\"assets/equations/e55d02bddb539fc5.svg\" alt=\"P=55+30+30+24=139\" width=\"307.52\" height=\"18.69\" style=\"width:307.52px;height:18.69px;aspect-ratio:307.52/18.69\" loading=\"lazy\"></picture></div>","<p>Equivalently, the network has 120 weights and 19 biases, so 120 + 19 = 139.</p>","<p><strong>Final answer: 139 trainable parameters.</strong> If a question explicitly removes biases, count only the 120 weights. Optimizer states such as Adam&#x27;s moments are extra training storage, not extra parameters in this predictive network.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s17","search":"Counting parameters in a dense network \n**Definition.** A dense layer connects every input component to every receiving neuron. Its trainable parameters are these connection weights and the receiving neurons' independently trainable biases.\n\n### Deriving the parameter count\nFor m inputs and n receiving neurons, each receiver needs m weights. There are therefore mn weights. With one bias per receiver, there are n additional parameters:\n\nActivation values are computed from data and parameters; they are not additional trainable parameters. The input layer supplies data and does not acquire an extra bias merely because it appears in a diagram.\n\n\n\n### Complete numerical\n**Question.** A network has 10 input features, three hidden layers with 5 neurons each, and 4 outputs. Every receiving neuron has a bias. Count its trainable parameters.\n\n\n\n### Given\n\nLayer sizes: 10 inputs → 5 hidden → 5 hidden → 5 hidden → 4 outputs.\n\nEvery hidden/output neuron has one bias.\n\n### To find\n\nCount weights and biases at each receiving layer, then the total.\n\n### Formula — which one and why\n\n**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\nn_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.\n\n\n\n**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: identify the consecutive layer widths.**\n\nThere are four trainable dense transformations. A connection between two hidden layers is counted once, as part of the receiving layer's parameters.\n\n**Step 2: count weights and biases for each transformation.**\n| Transformation | Weights | Biases | Layer total |\n| Input → hidden 1 | 10 × 5 = 50 | 5 | 55 |\n| Hidden 1 → hidden 2 | 5 × 5 = 25 | 5 | 30 |\n| Hidden 2 → hidden 3 | 5 × 5 = 25 | 5 | 30 |\n| Hidden 3 → output | 5 × 4 = 20 | 4 | 24 |\n\n**Step 3: add the layer totals.**\n\nEquivalently, the network has 120 weights and 19 biases, so 120 + 19 = 139.\n\n**Final answer: 139 trainable parameters.** If a question explicitly removes biases, count only the 120 weights. Optimizer states such as Adam's moments are extra training storage, not extra parameters in this predictive network.\n\n"},{"title":"What you should understand before optimization","blocks":["<p>You should be able to explain why a target and prediction differ, compute a weighted sum, choose an activation, measure a loss, find a one-neuron gradient and update a weight. If these steps are weak, repeat the first training example and the ReLU backprop example. They contain the entire calculation pattern that the next chapters extend.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_training_loop.svg\" aria-label=\"Enlarge diagram: These four operations form the training loop used by the optimizers in the next chapter.\"><img src=\"assets/figures/v_training_loop.svg\" alt=\"These four operations form the training loop used by the optimizers in the next chapter.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>These four operations form the training loop used by the optimizers in the next chapter. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s18","search":"What you should understand before optimization You should be able to explain why a target and prediction differ, compute a weighted sum, choose an activation, measure a loss, find a one-neuron gradient and update a weight. If these steps are weak, repeat the first training example and the ReLU backprop example. They contain the entire calculation pattern that the next chapters extend.\n\n\n\n\n"},{"title":"Complete sigmoid training example","blocks":["<p class=\"inline-question\"><strong>Question.</strong> A sigmoid neuron has input 2, weight 0, bias 0, target 1 and half squared loss. Will gradient descent increase or decrease the weight? Use learning rate 0.1 and calculate the exact update.</p>","<h3>Given</h3>","<p>x = 2; w = 0; b = 0; y = 1.</p>","<p>Sigmoid output; half squared loss; η = 0.1.</p>","<h3>To find</h3>","<p>Find the weight-gradient sign, exact weight update and resulting weight.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 forward:</strong> net = 0(2) + 0 = 0; sigmoid output = 0.5.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_sigmoid_training.svg\" aria-label=\"Enlarge diagram: The diagram uses the same input, weight, bias and target as the question. Follow prediction, activation slope, delta and update in order.\"><img src=\"assets/figures/v_sigmoid_training.svg\" alt=\"The diagram uses the same input, weight, bias and target as the question. Follow prediction, activation slope, delta and update in order.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>The diagram uses the same input, weight, bias and target as the question. Follow prediction, activation slope, delta and update in order. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 2 backward:</strong> prediction minus target = 0.5 − 1 = −0.5. Sigmoid slope = 0.5(1 − 0.5) = 0.25. Delta = −0.5 × 0.25 = −0.125.</p>","<p class=\"worked-step\"><strong>Step 3 gradients and update:</strong> weight gradient = −0.125 × 2 = −0.25. New weight = 0 − 0.1(−0.25) = 0.025. Bias gradient = −0.125; new bias = 0.0125. Both increase. With positive input, these changes initially raise the prediction toward the target. Your intuition and arithmetic now agree.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s19","search":"Complete sigmoid training example **Question.** A sigmoid neuron has input 2, weight 0, bias 0, target 1 and half squared loss. Will gradient descent increase or decrease the weight? Use learning rate 0.1 and calculate the exact update.\n\n\n\n### Given\n\nx = 2; w = 0; b = 0; y = 1.\n\nSigmoid output; half squared loss; η = 0.1.\n\n### To find\n\nFind the weight-gradient sign, exact weight update and resulting weight.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**Step 1 forward:** net = 0(2) + 0 = 0; sigmoid output = 0.5.\n\n\n\n**Step 2 backward:** prediction minus target = 0.5 − 1 = −0.5. Sigmoid slope = 0.5(1 − 0.5) = 0.25. Delta = −0.5 × 0.25 = −0.125.\n**Step 3 gradients and update:** weight gradient = −0.125 × 2 = −0.25. New weight = 0 − 0.1(−0.25) = 0.025. Bias gradient = −0.125; new bias = 0.0125. Both increase. With positive input, these changes initially raise the prediction toward the target. Your intuition and arithmetic now agree.\n"},{"title":"Cross-entropy for probability distributions","blocks":["<p class=\"definition\"><strong>Definition.</strong> For a discrete target distribution p and a predicted distribution q over the same classes, cross-entropy is the target-weighted negative logarithm of the predicted probabilities.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ca68a6ddd1ac17cc.svg\" alt=\"H(p,q)=-\\sum_{i=1}^{K}p_i\\log q_i\" width=\"248.66\" height=\"72.79\" style=\"width:248.66px;height:72.79px;aspect-ratio:248.66/72.79\" loading=\"lazy\"></div>","<p>Here pᵢ and qᵢ refer to the same class i, and each distribution sums to 1. The target supplies the weights outside the logarithm; the prediction goes inside it. If the target is one-hot, only the correct-class term remains. For a soft target with several nonzero entries, include all its nonzero terms.</p>","<h3>Logarithm base and units</h3>","<p>Natural logarithms produce <strong>nats</strong>; base-2 logarithms produce <strong>bits</strong>. These notes use ln unless a question states another base. On a calculator with ln, use the change-of-base rule for base 2:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/85b0a11172f30b61.svg\" alt=\"\\log_2 q=\\frac{\\ln q}{\\ln 2}\" width=\"137.21\" height=\"50.24\" style=\"width:137.21px;height:50.24px;aspect-ratio:137.21/50.24\" loading=\"lazy\"></div>","<p>For a target entry pᵢ = 0, its contribution is defined as zero. If pᵢ &gt; 0 but qᵢ = 0, the loss is infinite. For numerical stability, software normally calculates cross-entropy from logits or carefully handles boundary probabilities.</p>","<h3>A target distribution with two nonzero entries</h3>","<p class=\"inline-question\"><strong>Question. A two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5]. Calculate cross-entropy using natural logarithms and using base-2 logarithms.</strong></p>","<h3>Given</h3>","<p>A two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5].</p>","<p>Calculate cross-entropy using natural logarithms and using base-2 logarithms.</p>","<h3>To find</h3>","<p>Find cross-entropy in the requested units.</p>","<h3>Formula — which one and why</h3>","<p><strong>Cross-entropy between distributions.</strong> Weight each negative log prediction by the target probability. Unlike one-hot targets, several terms can contribute.</p>","<p>pᵢ = target-distribution probability; qᵢ = predicted probability. Natural logs give nats; base-2 logs give bits.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/feb21e9c89a912d7.svg\" alt=\"H(p,q)=-\\sum_i p_i\\ln q_i\" width=\"237.82\" height=\"52.35\" style=\"width:237.82px;height:52.35px;aspect-ratio:237.82/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f4684a5e966eb42a.svg\" alt=\"H_2(p,q)=\\frac{H(p,q)}{\\ln2}\" width=\"202.81\" height=\"52.43\" style=\"width:202.81px;height:52.43px;aspect-ratio:202.81/52.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Target probability batati hai kis log-loss ka kitna hissa lena hai.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: write the two terms.</strong> Both target entries are nonzero, so neither term can be discarded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:331.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcc9ac503722bcd6.svg\"><img class=\"math display-math\" src=\"assets/equations/3a2a7c8cae7d7ea4.svg\" alt=\"H(p,q)=-[0.75\\ln(0.5)+0.25\\ln(0.5)]\" width=\"406.41\" height=\"24.43\" style=\"width:406.41px;height:24.43px;aspect-ratio:406.41/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the logarithms.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89c211e38f586f86.svg\" alt=\"\\ln(0.5)\\approx-0.693147181\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: weight each negative logarithm by its target probability.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ba03d4ba50c7c4e4.svg\"><img class=\"math display-math\" src=\"assets/equations/c34f15079f0e23f0.svg\" alt=\"-0.75\\ln(0.5)\\approx0.519860385\" width=\"298.70\" height=\"24.43\" style=\"width:298.70px;height:24.43px;aspect-ratio:298.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7dbaf11af5ca2bb7.svg\"><img class=\"math display-math\" src=\"assets/equations/ca2ff9da024bd22a.svg\" alt=\"-0.25\\ln(0.5)\\approx0.173286795\" width=\"298.70\" height=\"24.43\" style=\"width:298.70px;height:24.43px;aspect-ratio:298.70/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: add the contributions, retaining calculator precision.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.65px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/77f2dae5c0c0431a.svg\"><img class=\"math display-math\" src=\"assets/equations/2b18f4e26d74ffd0.svg\" alt=\"H(p,q)\\approx0.519860385+0.173286795\\approx0.693147181\\ \\text{nats}\" width=\"608.08\" height=\"24.43\" style=\"width:608.08px;height:24.43px;aspect-ratio:608.08/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: repeat with base 2.</strong> Since 2⁻¹ = 0.5, log₂(0.5) = −1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:282.41px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cf0bfa788dbc4b07.svg\"><img class=\"math display-math\" src=\"assets/equations/ef4d3bcee474b612.svg\" alt=\"H_2(p,q)=-[0.75(-1)+0.25(-1)]=1\\ \\text{bit}\" width=\"447.58\" height=\"24.43\" style=\"width:447.58px;height:24.43px;aspect-ratio:447.58/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> 0.693147 nats or 1 bit. The distributions are unchanged; the logarithm base changes the unit and the numerical scale.</p>","<h3>Cross-entropy, entropy and relative entropy</h3>","<p>These names are related but do not denote the same quantity. Entropy uses the target distribution in both positions. Relative entropy, also called KL divergence, measures their difference through a probability ratio.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ac39baa15925718.svg\" alt=\"H(p)=-\\sum_i p_i\\ln p_i\" width=\"217.10\" height=\"52.35\" style=\"width:217.10px;height:52.35px;aspect-ratio:217.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.03px;--narrow-height:95.55px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8933903c2570cd47.svg\"><img class=\"math display-math\" src=\"assets/equations/5174a1ccffce0c30.svg\" alt=\"D_{\\mathrm{KL}}(p\\Vert q)=\\sum_i p_i\\ln\\frac{p_i}{q_i}=H(p,q)-H(p)\" width=\"443.59\" height=\"56.45\" style=\"width:443.59px;height:56.45px;aspect-ratio:443.59/56.45\" loading=\"lazy\"></picture></div>","<p>For fixed p, H(p) is constant with respect to the model parameters, so minimizing cross-entropy also minimizes this KL divergence. KL is clarified here to distinguish the terminology; it is not a separately named unit in the official syllabus.</p>","<p class=\"inline-question\"><strong>Question. For the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.</strong></p>","<h3>Given</h3>","<p>For the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.</p>","<h3>To find</h3>","<p>Find entropy and KL divergence in nats.</p>","<h3>Formula — which one and why</h3>","<p><strong>Entropy and relative entropy.</strong> Entropy measures the target distribution’s uncertainty. Relative entropy measures the extra cross-entropy when q is used instead of p.</p>","<p>p = target distribution; q = model distribution; H(p) = entropy; DKL = Kullback–Leibler divergence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ac39baa15925718.svg\" alt=\"H(p)=-\\sum_i p_i\\ln p_i\" width=\"217.10\" height=\"52.35\" style=\"width:217.10px;height:52.35px;aspect-ratio:217.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.95px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1dc0b474b12a2bf8.svg\"><img class=\"math display-math\" src=\"assets/equations/636a195581e18582.svg\" alt=\"D_{\\mathrm{KL}}(p\\Vert q)=H(p,q)-H(p)\" width=\"291.82\" height=\"24.43\" style=\"width:291.82px;height:24.43px;aspect-ratio:291.82/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> KL = cross-entropy minus target ki own entropy.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the target entropy.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78338077753f61a2.svg\" alt=\"H(p)=-[0.75\\ln(0.75)+0.25\\ln(0.25)]\" width=\"408.75\" height=\"24.43\" style=\"width:408.75px;height:24.43px;aspect-ratio:408.75/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.35px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c8cc7ed1293c1673.svg\"><img class=\"math display-math\" src=\"assets/equations/a0496aac07524e4b.svg\" alt=\"\\ln(0.75)\\approx-0.287682072,\\qquad\\ln(0.25)\\approx-1.386294361\" width=\"586.52\" height=\"24.43\" style=\"width:586.52px;height:24.43px;aspect-ratio:586.52/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.55px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b8c34bbe332a549f.svg\"><img class=\"math display-math\" src=\"assets/equations/1669c0167b94fcff.svg\" alt=\"H(p)\\approx0.215761554+0.346573590=0.562335145\" width=\"534.93\" height=\"24.43\" style=\"width:534.93px;height:24.43px;aspect-ratio:534.93/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: subtract target entropy from cross-entropy.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a763ffee09c5ad1.svg\"><img class=\"math display-math\" src=\"assets/equations/45d882f13b18b109.svg\" alt=\"D_{\\mathrm{KL}}(p\\Vert q)\\approx0.693147181-0.562335145=0.130812036\" width=\"583.19\" height=\"24.43\" style=\"width:583.19px;height:24.43px;aspect-ratio:583.19/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> H(p) ≈ 0.562335 nats and DKL(p ∥ q) ≈ 0.130812 nats. For a one-hot target H(p) = 0, so cross-entropy and this KL divergence coincide; for this soft target they differ.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s20","search":"Cross-entropy for probability distributions **Definition.** For a discrete target distribution p and a predicted distribution q over the same classes, cross-entropy is the target-weighted negative logarithm of the predicted probabilities.\n\nHere pᵢ and qᵢ refer to the same class i, and each distribution sums to 1. The target supplies the weights outside the logarithm; the prediction goes inside it. If the target is one-hot, only the correct-class term remains. For a soft target with several nonzero entries, include all its nonzero terms.\n\n### Logarithm base and units\nNatural logarithms produce **nats**; base-2 logarithms produce **bits**. These notes use ln unless a question states another base. On a calculator with ln, use the change-of-base rule for base 2:\n\nFor a target entry pᵢ = 0, its contribution is defined as zero. If pᵢ > 0 but qᵢ = 0, the loss is infinite. For numerical stability, software normally calculates cross-entropy from logits or carefully handles boundary probabilities.\n\n### A target distribution with two nonzero entries\n**Question. A two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5]. Calculate cross-entropy using natural logarithms and using base-2 logarithms.**\n\n\n\n### Given\n\nA two-class target distribution is p = [0.75, 0.25] and the model predicts q = [0.5, 0.5].\n\nCalculate cross-entropy using natural logarithms and using base-2 logarithms.\n\n### To find\n\nFind cross-entropy in the requested units.\n\n### Formula — which one and why\n\n**Cross-entropy between distributions.** Weight each negative log prediction by the target probability. Unlike one-hot targets, several terms can contribute.\n\npᵢ = target-distribution probability; qᵢ = predicted probability. Natural logs give nats; base-2 logs give bits.\n\n\n\n\n\n**Yaad rakhne ka cue:** Target probability batati hai kis log-loss ka kitna hissa lena hai.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: write the two terms.** Both target entries are nonzero, so neither term can be discarded.\n\n\n**Step 2: calculate the logarithms.**\n\n\n**Step 3: weight each negative logarithm by its target probability.**\n\n\n\n**Step 4: add the contributions, retaining calculator precision.**\n\n\n**Step 5: repeat with base 2.** Since 2⁻¹ = 0.5, log₂(0.5) = −1.\n\n**Final answer:** 0.693147 nats or 1 bit. The distributions are unchanged; the logarithm base changes the unit and the numerical scale.\n\n### Cross-entropy, entropy and relative entropy\nThese names are related but do not denote the same quantity. Entropy uses the target distribution in both positions. Relative entropy, also called KL divergence, measures their difference through a probability ratio.\n\n\nFor fixed p, H(p) is constant with respect to the model parameters, so minimizing cross-entropy also minimizes this KL divergence. KL is clarified here to distinguish the terminology; it is not a separately named unit in the official syllabus.\n\n**Question. For the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.**\n\n\n\n### Given\n\nFor the same p = [0.75, 0.25] and q = [0.5, 0.5], find H(p) and DKL(p ∥ q) in nats.\n\n### To find\n\nFind entropy and KL divergence in nats.\n\n### Formula — which one and why\n\n**Entropy and relative entropy.** Entropy measures the target distribution’s uncertainty. Relative entropy measures the extra cross-entropy when q is used instead of p.\n\np = target distribution; q = model distribution; H(p) = entropy; DKL = Kullback–Leibler divergence.\n\n\n\n\n\n**Yaad rakhne ka cue:** KL"},{"title":"Biological neurons and the McCulloch-Pitts model","blocks":["<p class=\"definition\"><strong>Definition.</strong> An artificial neuron is a simplified computational model inspired by the collection, combination and transmission of signals in biological neurons. This analogy motivates weighted inputs and an output response; it is not a full simulation of a living neuron.</p>","<h3>Biological and artificial components</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Biological component</th><th>Simplified artificial counterpart</th><th>Function in the analogy</th></tr></thead><tbody><tr><td>Dendrites</td><td>Input connections</td><td>Receive incoming signals</td></tr><tr><td>Synapses</td><td>Connection weights</td><td>Influence how strongly each incoming signal contributes</td></tr><tr><td>Cell body or soma</td><td>Aggregation stage</td><td>Combines the weighted signals</td></tr><tr><td>Firing behavior</td><td>Threshold or activation function</td><td>Determines the model&#x27;s output response</td></tr><tr><td>Axon</td><td>Output connection</td><td>Passes the resulting signal onward</td></tr></tbody></table></div>","<p>For an artificial threshold unit, a threshold θ on the weighted sum can be written as a bias b = −θ, followed by a threshold at zero. The equality convention must be preserved.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.01px;--narrow-height:158.44px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bd6e61f8065942de.svg\"><img class=\"math display-math\" src=\"assets/equations/8deda7d73444e933.svg\" alt=\"\\sum_i w_ix_i\\ge\\theta\\quad\\Longleftrightarrow\\quad\\sum_i w_ix_i-\\theta\\ge0\" width=\"411.63\" height=\"52.35\" style=\"width:411.63px;height:52.35px;aspect-ratio:411.63/52.35\" loading=\"lazy\"></picture></div>","<h3>McCulloch–Pitts model and perceptron</h3>","<p>The McCulloch–Pitts model is an early binary threshold model. Its logical connections and threshold are prescribed to implement a desired behavior; it has no data-driven weight-update procedure. The original formulation also distinguishes excitatory inputs from inhibitory inputs, which can prevent firing. In elementary logic-gate examples using only excitatory inputs, a threshold on their sum is sufficient.</p>","<p>A perceptron introduces adjustable connection weights and a learning rule. It calculates a weighted sum, applies a threshold and updates parameters when its classification disagrees with the target. Both single threshold units have a linear decision boundary; neither single unit solves XOR in the original two-input space.</p>","<p class=\"inline-question\"><strong>Question. Implement AND and OR for binary inputs x₁, x₂ using the sum x₁ + x₂ and output 1 when the sum is at least θ. Use θ = 2 for AND and θ = 1 for OR.</strong></p>","<h3>Given</h3>","<p>Implement AND and OR for binary inputs x₁, x₂ using the sum x₁ + x₂ and output 1 when the sum is at least θ.</p>","<p>Use θ = 2 for AND and θ = 1 for OR.</p>","<h3>To find</h3>","<p>Write every row of the truth table and the requested network output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<p>Calculate the sum once for each input pair, then compare it with the relevant threshold.</p>","<h3>Binary input (0,0)</h3>","<p class=\"worked-step\"><strong>Step 1: add the inputs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e725afda84fc9ed3.svg\" alt=\"s=0+0=0\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: compare with AND threshold 2.</strong></p>","<p>0 ≥ 2 is false; AND output = 0.</p>","<p class=\"worked-step\"><strong>Step 3: compare with OR threshold 1.</strong></p>","<p>0 ≥ 1 is false; OR output = 0.</p>","<h3>Binary input (0,1)</h3>","<p class=\"worked-step\"><strong>Step 1: add the inputs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ae62ee9eceeaffe.svg\" alt=\"s=0+1=1\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: compare with AND threshold 2.</strong></p>","<p>1 ≥ 2 is false; AND output = 0.</p>","<p class=\"worked-step\"><strong>Step 3: compare with OR threshold 1.</strong></p>","<p>1 ≥ 1 is true; OR output = 1.</p>","<h3>Binary input (1,0)</h3>","<p class=\"worked-step\"><strong>Step 1: add the inputs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2707337aabb06170.svg\" alt=\"s=1+0=1\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: compare with AND threshold 2.</strong></p>","<p>1 ≥ 2 is false; AND output = 0.</p>","<p class=\"worked-step\"><strong>Step 3: compare with OR threshold 1.</strong></p>","<p>1 ≥ 1 is true; OR output = 1.</p>","<h3>Binary input (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: add the inputs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1c8553f39604f98c.svg\" alt=\"s=1+1=2\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: compare with AND threshold 2.</strong></p>","<p>2 ≥ 2 is true; AND output = 1.</p>","<p class=\"worked-step\"><strong>Step 3: compare with OR threshold 1.</strong></p>","<p>2 ≥ 1 is true; OR output = 1.</p>","<h3>Truth-table summary</h3>","<div class=\"table-scroll\"><table><thead><tr><th>x₁</th><th>x₂</th><th>x₁ + x₂</th><th>AND: sum ≥ 2</th><th>OR: sum ≥ 1</th></tr></thead><tbody><tr><td>0</td><td>0</td><td>0 + 0 = 0</td><td>0</td><td>0</td></tr><tr><td>0</td><td>1</td><td>0 + 1 = 1</td><td>0</td><td>1</td></tr><tr><td>1</td><td>0</td><td>1 + 0 = 1</td><td>0</td><td>1</td></tr><tr><td>1</td><td>1</td><td>1 + 1 = 2</td><td>1</td><td>1</td></tr></tbody></table></div>","<p>The parameters have been chosen to implement the truth tables. This calculation is a logic-gate evaluation, not a perceptron training epoch.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c4-s21","search":"Biological neurons and the McCulloch-Pitts model **Definition.** An artificial neuron is a simplified computational model inspired by the collection, combination and transmission of signals in biological neurons. This analogy motivates weighted inputs and an output response; it is not a full simulation of a living neuron.\n\n### Biological and artificial components\n| Biological component | Simplified artificial counterpart | Function in the analogy |\n| Dendrites | Input connections | Receive incoming signals |\n| Synapses | Connection weights | Influence how strongly each incoming signal contributes |\n| Cell body or soma | Aggregation stage | Combines the weighted signals |\n| Firing behavior | Threshold or activation function | Determines the model's output response |\n| Axon | Output connection | Passes the resulting signal onward |\n\nFor an artificial threshold unit, a threshold θ on the weighted sum can be written as a bias b = −θ, followed by a threshold at zero. The equality convention must be preserved.\n\n\n### McCulloch–Pitts model and perceptron\nThe McCulloch–Pitts model is an early binary threshold model. Its logical connections and threshold are prescribed to implement a desired behavior; it has no data-driven weight-update procedure. The original formulation also distinguishes excitatory inputs from inhibitory inputs, which can prevent firing. In elementary logic-gate examples using only excitatory inputs, a threshold on their sum is sufficient.\n\nA perceptron introduces adjustable connection weights and a learning rule. It calculates a weighted sum, applies a threshold and updates parameters when its classification disagrees with the target. Both single threshold units have a linear decision boundary; neither single unit solves XOR in the original two-input space.\n\n**Question. Implement AND and OR for binary inputs x₁, x₂ using the sum x₁ + x₂ and output 1 when the sum is at least θ. Use θ = 2 for AND and θ = 1 for OR.**\n\n\n\n### Given\n\nImplement AND and OR for binary inputs x₁, x₂ using the sum x₁ + x₂ and output 1 when the sum is at least θ.\n\nUse θ = 2 for AND and θ = 1 for OR.\n\n### To find\n\nWrite every row of the truth table and the requested network output.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\n\nCalculate the sum once for each input pair, then compare it with the relevant threshold.\n### Binary input (0,0)\n\n**Step 1: add the inputs.**\n\n\n\n\n\n\n\n**Step 2: compare with AND threshold 2.**\n\n0 ≥ 2 is false; AND output = 0.\n\n**Step 3: compare with OR threshold 1.**\n\n0 ≥ 1 is false; OR output = 0.\n\n\n### Binary input (0,1)\n\n**Step 1: add the inputs.**\n\n\n\n\n\n\n\n**Step 2: compare with AND threshold 2.**\n\n1 ≥ 2 is false; AND output = 0.\n\n**Step 3: compare with OR threshold 1.**\n\n1 ≥ 1 is true; OR output = 1.\n\n\n### Binary input (1,0)\n\n**Step 1: add the inputs.**\n\n\n\n\n\n\n\n**Step 2: compare with AND threshold 2.**\n\n1 ≥ 2 is false; AND output = 0.\n\n**Step 3: compare with OR threshold 1.**\n\n1 ≥ 1 is true; OR output = 1.\n\n\n### Binary input (1,1)\n\n**Step 1: add the inputs.**\n\n\n\n\n\n\n\n**Step 2: compare with AND threshold 2.**\n\n2 ≥ 2 is tru"}]},{"n":5,"title":"Optimization algorithms","sections":[{"title":"Reading an optimizer formula without getting lost","blocks":["<p>An optimizer updates the numbers the model is allowed to learn. Usually these are weights and biases. The letter θ is a convenient name for whichever parameter is currently being updated.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_optimizer_notation.svg\" aria-label=\"Enlarge diagram: Old value, current gradient and new value belong to different moments in the update.\"><img src=\"assets/figures/v_optimizer_notation.svg\" alt=\"Old value, current gradient and new value belong to different moments in the update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Old value, current gradient and new value belong to different moments in the update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Old, current and new</h3>","<p>At update t, θₜ₋₁ is the value before the update and θₜ is the value after it. The symbol gₜ is the loss gradient used in that update. If a question already supplies gₜ, use it. If it supplies a loss J(θ), differentiate J and evaluate the derivative at the stated position.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p>η, read eta, is the learning rate. It multiplies the gradient to determine the basic correction. A positive gradient is subtracted; a negative gradient makes the new value larger because subtracting a negative is addition.</p>","<h3>What a stored state means</h3>","<p>An optimizer may retain a number from its previous update. This number is called its state or memory. It is an ordinary calculated number, not an additional neuron. Momentum stores movement; AdaGrad stores a sum of squared gradients; RMSProp stores a moving average of squares; Adam stores a moving average of gradients and another of squares.</p>","<h3>A weighted average from ordinary arithmetic</h3>","<p>If the old state is 4, the new squared gradient is 9 and the decay is 0.9, retain 90% of the old state and add 10% of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0d4d3672b448c16a.svg\"><img class=\"math display-math\" src=\"assets/equations/722eae46e0545987.svg\" alt=\"0.9\\times4=3.6,\\qquad(1-0.9)\\times9=0.9\" width=\"395.09\" height=\"24.43\" style=\"width:395.09px;height:24.43px;aspect-ratio:395.09/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4044336c67492dab.svg\" alt=\"s_{\\mathrm{new}}=3.6+0.9=4.5\" width=\"231.96\" height=\"20.40\" style=\"width:231.96px;height:20.40px;aspect-ratio:231.96/20.40\" loading=\"lazy\"></div>","<p>The coefficients 0.9 and 0.1 add to 1. As updates continue, a past contribution gets multiplied by 0.9 again, so its influence fades. AdaGrad instead gives 4 + 9 = 13 because it retains the full old sum.</p>","<h3>Squared memory and signed direction</h3>","<p>For gradient −3, the square is 9. The stored scale is positive, but the update still needs the negative gradient to determine direction. Do not replace every occurrence of g with g².</p>","<h3>Epsilon and hats</h3>","<p>ε, read epsilon, is a small positive number that prevents an exactly zero denominator. A hat in Adam, such as m with a hat, labels a bias-corrected average. A hat does not mean squaring. The power βᵗ uses the update number t, so its value changes from the first update to the second.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s0","search":"Reading an optimizer formula without getting lost An optimizer updates the numbers the model is allowed to learn. Usually these are weights and biases. The letter θ is a convenient name for whichever parameter is currently being updated.\n\n\n\n### Old, current and new\nAt update t, θₜ₋₁ is the value before the update and θₜ is the value after it. The symbol gₜ is the loss gradient used in that update. If a question already supplies gₜ, use it. If it supplies a loss J(θ), differentiate J and evaluate the derivative at the stated position.\n\nη, read eta, is the learning rate. It multiplies the gradient to determine the basic correction. A positive gradient is subtracted; a negative gradient makes the new value larger because subtracting a negative is addition.\n### What a stored state means\nAn optimizer may retain a number from its previous update. This number is called its state or memory. It is an ordinary calculated number, not an additional neuron. Momentum stores movement; AdaGrad stores a sum of squared gradients; RMSProp stores a moving average of squares; Adam stores a moving average of gradients and another of squares.\n### A weighted average from ordinary arithmetic\nIf the old state is 4, the new squared gradient is 9 and the decay is 0.9, retain 90% of the old state and add 10% of the new square.\n\n\nThe coefficients 0.9 and 0.1 add to 1. As updates continue, a past contribution gets multiplied by 0.9 again, so its influence fades. AdaGrad instead gives 4 + 9 = 13 because it retains the full old sum.\n### Squared memory and signed direction\nFor gradient −3, the square is 9. The stored scale is positive, but the update still needs the negative gradient to determine direction. Do not replace every occurrence of g with g².\n### Epsilon and hats\nε, read epsilon, is a small positive number that prevents an exactly zero denominator. A hat in Adam, such as m with a hat, labels a bias-corrected average. A hat does not mean squaring. The power βᵗ uses the update number t, so its value changes from the first update to the second.\n"},{"title":"Optimizer notation: old value, memory, new value","blocks":["<h3>1. A parameter and a stored state are different</h3>","<p>θ is the parameter we want to learn. A memory such as v, s or m helps an optimizer decide how to change θ; it is not a second prediction. Each trainable parameter usually has its own corresponding memory entries.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_optimizer_notation.svg\" aria-label=\"Enlarge diagram: The time label tells you which value to use. Carry the previous memory into the current update.\"><img src=\"assets/figures/v_optimizer_notation.svg\" alt=\"The time label tells you which value to use. Carry the previous memory into the current update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The time label tells you which value to use. Carry the previous memory into the current update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At time t = 0, the problem supplies starting values. At update t = 1, read the old values, calculate the current gradient and new memory, then calculate the new parameter. At update t = 2, use the results of update 1 as the old values.</p>","<h3>2. A supplied gradient versus a supplied objective</h3>","<p>If the question says gradients are 2 and −1, use those values in order. If it instead gives J(θ) = θ², first differentiate to get g(θ) = 2θ. Recalculate g using the current parameter at each iteration. Nesterov evaluates at its lookahead point instead.</p>","<p>For θ₀ = 1 and η = 0.1 with ordinary GD, g₁ = 2 and θ₁ = 0.8. The next gradient is 2 × 0.8 = 1.6, not the old value 2. Therefore θ₂ = 0.8 − 0.1 × 1.6 = 0.64.</p>","<h3>3. A squared gradient keeps size and loses sign</h3>","<p>Both 2² and (−2)² equal 4. Squared-gradient memory tells us about scale. The signed numerator still decides the update direction. Never replace the gradient in every part of an optimizer by its square.</p>","<h3>4. Square root and epsilon belong to the denominator</h3>","<p>If s = 4 and ε = 0.01, the denominator √s + ε is 2 + 0.01 = 2.01. It is different from √(s + ε), which is √4.01. Use the placement specified by the formula. Small ε keeps a zero accumulator from causing division by zero.</p>","<h3>5. A table prevents mixing iterations</h3>","<p>Write one row per iteration. Ordinary GD needs current θ, gradient and new θ. Momentum adds old and new velocity. Adam adds both memories and their corrected values. Complete a row before starting the next; otherwise a new value from iteration 2 may accidentally be used inside iteration 1.</p>","<p>The worked examples below use this exact order, with every state shown.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s1","search":"Optimizer notation: old value, memory, new value ### 1. A parameter and a stored state are different\nθ is the parameter we want to learn. A memory such as v, s or m helps an optimizer decide how to change θ; it is not a second prediction. Each trainable parameter usually has its own corresponding memory entries.\n\n\n\nAt time t = 0, the problem supplies starting values. At update t = 1, read the old values, calculate the current gradient and new memory, then calculate the new parameter. At update t = 2, use the results of update 1 as the old values.\n\n### 2. A supplied gradient versus a supplied objective\nIf the question says gradients are 2 and −1, use those values in order. If it instead gives J(θ) = θ², first differentiate to get g(θ) = 2θ. Recalculate g using the current parameter at each iteration. Nesterov evaluates at its lookahead point instead.\nFor θ₀ = 1 and η = 0.1 with ordinary GD, g₁ = 2 and θ₁ = 0.8. The next gradient is 2 × 0.8 = 1.6, not the old value 2. Therefore θ₂ = 0.8 − 0.1 × 1.6 = 0.64.\n\n### 3. A squared gradient keeps size and loses sign\nBoth 2² and (−2)² equal 4. Squared-gradient memory tells us about scale. The signed numerator still decides the update direction. Never replace the gradient in every part of an optimizer by its square.\n\n### 4. Square root and epsilon belong to the denominator\nIf s = 4 and ε = 0.01, the denominator √s + ε is 2 + 0.01 = 2.01. It is different from √(s + ε), which is √4.01. Use the placement specified by the formula. Small ε keeps a zero accumulator from causing division by zero.\n\n### 5. A table prevents mixing iterations\nWrite one row per iteration. Ordinary GD needs current θ, gradient and new θ. Momentum adds old and new velocity. Adam adds both memories and their corrected values. Complete a row before starting the next; otherwise a new value from iteration 2 may accidentally be used inside iteration 1.\nThe worked examples below use this exact order, with every state shown.\n"},{"title":"What an optimizer is trying to do","blocks":["<p class=\"definition\"><strong>Definition.</strong> Optimization is the process of selecting model parameters to minimize a scalar objective. In neural-network training, a gradient-based optimizer updates weights and biases using derivatives of the training objective.</p>","<h3>Objective and gradient</h3>","<p>For empirical risk with an optional regularizer:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.50px;--narrow-height:111.88px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e8f2cd5bb532bd92.svg\"><img class=\"math display-math\" src=\"assets/equations/b7857d96c4edb1c7.svg\" alt=\"J(\\theta)=\\frac1N\\sum_{i=1}^{N}L_i(\\theta)+\\lambda\\Omega(\\theta)\" width=\"301.72\" height=\"72.79\" style=\"width:301.72px;height:72.79px;aspect-ratio:301.72/72.79\" loading=\"lazy\"></picture></div>","<p>The loss value indicates the current objective. Its gradient indicates local sensitivity to parameters. Backpropagation computes this gradient efficiently; the optimizer determines how the parameters are updated from it. A gradient and a loss value cannot be interchanged in the update equation.</p>","<h3>Why gradient descent subtracts the gradient</h3>","<p>For a small displacement Δθ, first-order Taylor expansion approximates the objective by:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:186.14px;--narrow-height:66.99px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9060e5490f15d100.svg\"><img class=\"math display-math\" src=\"assets/equations/2f6a587716d3d081.svg\" alt=\"J(\\theta+\\Delta\\theta)\\approx J(\\theta)+\\nabla J(\\theta)^T\\Delta\\theta\" width=\"328.31\" height=\"27.90\" style=\"width:328.31px;height:27.90px;aspect-ratio:328.31/27.90\" loading=\"lazy\"></picture></div>","<p>Choose Δθ = −η∇J(θ), with η &gt; 0. Substitution gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.29px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f0fe0e6b83fb6f66.svg\"><img class=\"math display-math\" src=\"assets/equations/6c50025de1d032a9.svg\" alt=\"J(\\theta-\\eta\\nabla J)\\approx J(\\theta)-\\eta\\|\\nabla J\\|_2^2\" width=\"315.23\" height=\"27.70\" style=\"width:315.23px;height:27.70px;aspect-ratio:315.23/27.70\" loading=\"lazy\"></picture></div>","<p>The squared norm is nonnegative. Therefore the negative-gradient direction is locally a descent direction when the gradient is nonzero. The approximation explains the sign; it does not guarantee that an arbitrarily large finite step decreases loss.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_gd.svg\" aria-label=\"Enlarge diagram: A gradient specifies a local direction; the learning rate determines the finite parameter step.\"><img src=\"assets/figures/v_gd.svg\" alt=\"A gradient specifies a local direction; the learning rate determines the finite parameter step.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>A gradient specifies a local direction; the learning rate determines the finite parameter step. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Local minima, global minima and saddle points</h3>","<p>A local minimum has objective value no larger than nearby points. A global minimum is minimal over the whole feasible domain. At a saddle point, the objective increases in some directions and decreases in others. A small gradient alone does not establish a minimum: a stationary point can also be a maximum or saddle.</p>","<p>Neural-network objectives are generally nonconvex. Training can encounter flat regions, ill-conditioned valleys, noisy gradient estimates and poor step sizes. Momentum modifies the update direction using previous steps; adaptive methods rescale parameter-specific updates. These methods improve particular optimization behavior, without guaranteeing the global optimum or best test performance.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s2","search":"What an optimizer is trying to do **Definition.** Optimization is the process of selecting model parameters to minimize a scalar objective. In neural-network training, a gradient-based optimizer updates weights and biases using derivatives of the training objective.\n\n### Objective and gradient\nFor empirical risk with an optional regularizer:\n\nThe loss value indicates the current objective. Its gradient indicates local sensitivity to parameters. Backpropagation computes this gradient efficiently; the optimizer determines how the parameters are updated from it. A gradient and a loss value cannot be interchanged in the update equation.\n\n### Why gradient descent subtracts the gradient\nFor a small displacement Δθ, first-order Taylor expansion approximates the objective by:\n\nChoose Δθ = −η∇J(θ), with η > 0. Substitution gives:\n\nThe squared norm is nonnegative. Therefore the negative-gradient direction is locally a descent direction when the gradient is nonzero. The approximation explains the sign; it does not guarantee that an arbitrarily large finite step decreases loss.\n\n\n\n### Local minima, global minima and saddle points\nA local minimum has objective value no larger than nearby points. A global minimum is minimal over the whole feasible domain. At a saddle point, the objective increases in some directions and decreases in others. A small gradient alone does not establish a minimum: a stationary point can also be a maximum or saddle.\n\nNeural-network objectives are generally nonconvex. Training can encounter flat regions, ill-conditioned valleys, noisy gradient estimates and poor step sizes. Momentum modifies the update direction using previous steps; adaptive methods rescale parameter-specific updates. These methods improve particular optimization behavior, without guaranteeing the global optimum or best test performance.\n"},{"title":"The ordinary gradient descent update","blocks":["<p class=\"definition\"><strong>Definition.</strong> Gradient descent is an iterative first-order optimization algorithm that updates parameters in the negative direction of the current objective gradient, scaled by a positive learning rate.</p>","<h3>Explanation and working</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p>Here update numbers start at t = 1: calculate g₁ at θ₀, obtain θ₁, then calculate g₂ at θ₁. The subscript counts completed updates; it is not an exponent.</p>","<p>Read it aloud: “new parameter equals old parameter minus learning rate times current gradient.” The old parameter is where you are. The gradient gives the local uphill direction. The learning rate controls how far you move in the opposite direction.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_gd.svg\" aria-label=\"Enlarge diagram: Calculate the slope first, multiply it by the learning rate, then subtract that correction.\"><img src=\"assets/figures/v_gd.svg\" alt=\"Calculate the slope first, multiply it by the learning rate, then subtract that correction.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>Calculate the slope first, multiply it by the learning rate, then subtract that correction. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> J(θ) = 0.7 θ³; θ₀ = 1; η = 0.1. Perform two iterations.</p>","<h3>Given</h3>","<p>J(θ) = 0.7θ³; initial θ₀ = 1; η = 0.1.</p>","<h3>To find</h3>","<p>Differentiate J and perform two gradient-descent iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1. Differentiate.</strong> g(θ) = 0.7 × 3 × θ² = 2.1 θ².</p>","<p class=\"worked-step\"><strong>Step 2. First update.</strong> g₁ = 2.1(1)² = 2.1. θ₁ = 1 − 0.1(2.1) = 0.79.</p>","<p class=\"worked-step\"><strong>Step 3. Second gradient.</strong> Square the new value: 0.79² = 0.6241. Multiply: g₂ = 2.1 × 0.6241 = 1.31061.</p>","<p class=\"worked-step\"><strong>Step 4. Second update.</strong> θ₂ = 0.79 − 0.1(1.31061) = 0.79 − 0.131061 = <strong>0.658939</strong>.</p>","<p>The paper calls this SGD. With only a scalar objective supplied, no sample selection is specified; the arithmetic is the stated gradient-descent update. Also, this cubic is not bounded below over all real values. Do not claim these two steps prove convergence to a global minimum.</p>","<p><strong>Common error: </strong> using the loss J itself instead of its derivative g. Another error is repeatedly using θ₀ to calculate later gradients.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s3","search":"The ordinary gradient descent update **Definition.** Gradient descent is an iterative first-order optimization algorithm that updates parameters in the negative direction of the current objective gradient, scaled by a positive learning rate.\n\n### Explanation and working\n\n\nHere update numbers start at t = 1: calculate g₁ at θ₀, obtain θ₁, then calculate g₂ at θ₁. The subscript counts completed updates; it is not an exponent.\nRead it aloud: “new parameter equals old parameter minus learning rate times current gradient.” The old parameter is where you are. The gradient gives the local uphill direction. The learning rate controls how far you move in the opposite direction.\n\n\n\n**Question.** J(θ) = 0.7 θ³; θ₀ = 1; η = 0.1. Perform two iterations.\n\n\n\n### Given\n\nJ(θ) = 0.7θ³; initial θ₀ = 1; η = 0.1.\n\n### To find\n\nDifferentiate J and perform two gradient-descent iterations.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n**Step 1. Differentiate.** g(θ) = 0.7 × 3 × θ² = 2.1 θ².\n**Step 2. First update.** g₁ = 2.1(1)² = 2.1. θ₁ = 1 − 0.1(2.1) = 0.79.\n**Step 3. Second gradient.** Square the new value: 0.79² = 0.6241. Multiply: g₂ = 2.1 × 0.6241 = 1.31061.\n**Step 4. Second update.** θ₂ = 0.79 − 0.1(1.31061) = 0.79 − 0.131061 = **0.658939**.\nThe paper calls this SGD. With only a scalar objective supplied, no sample selection is specified; the arithmetic is the stated gradient-descent update. Also, this cubic is not bounded below over all real values. Do not claim these two steps prove convergence to a global minimum.\n**Common error: ** using the loss J itself instead of its derivative g. Another error is repeatedly using θ₀ to calculate later gradients."},{"title":"Batch stochastic and mini batch gradient descent","blocks":["<p class=\"definition\"><strong>Definition.</strong> Batch, stochastic and mini-batch gradient descent differ in the subset of training examples used to estimate the gradient for each parameter update. Their update equation is the same; their gradient estimates and update frequency differ.</p>","<h3>Explanation and working</h3>","<p>All three use the same update idea. They differ in how much data contributes to one gradient.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_batches.svg\" aria-label=\"Enlarge diagram: Count outlined groups, not individual cells, to count gradient updates in one epoch.\"><img src=\"assets/figures/v_batches.svg\" alt=\"Count outlined groups, not individual cells, to count gradient updates in one epoch.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Count outlined groups, not individual cells, to count gradient updates in one epoch. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>Data for one update</th><th>Updates in one epoch with N samples</th><th>Typical behaviour</th></tr></thead><tbody><tr><td>Batch GD</td><td>All N samples</td><td>1</td><td>Stable full-data gradient; costly updates</td></tr><tr><td>Stochastic GD</td><td>One sample</td><td>N</td><td>Frequent noisy updates</td></tr><tr><td>Mini-batch GD</td><td>B samples</td><td>Ceiling of N/B if final partial batch is retained</td><td>Efficient parallel calculation with moderate noise</td></tr></tbody></table></div>","<p class=\"inline-question\"><strong>Question.</strong> N = 1,000 and B = 100. Find updates per epoch.</p>","<h3>Given</h3>","<p>N = 1,000 examples; mini-batch size B = 100; one epoch.</p>","<h3>To find</h3>","<p>Count full-batch, stochastic and mini-batch updates per epoch.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count full-batch updates.</strong></p>","<p>All 1,000 samples form one group, so one epoch has 1 update.</p>","<p class=\"worked-step\"><strong>Step 2: count stochastic updates.</strong></p>","<p>One sample per update gives 1,000 updates per epoch.</p>","<p class=\"worked-step\"><strong>Step 3: count mini-batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/044096791068cfc7.svg\" alt=\"\\frac{N}{B}=\\frac{1000}{100}=10\" width=\"181.68\" height=\"50.50\" style=\"width:181.68px;height:50.50px;aspect-ratio:181.68/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> batch = 1; SGD = 1,000; mini-batch = 10 updates per epoch.</p>","<h3>Mini-batch calculation with a remainder</h3>","<p class=\"inline-question\"><strong>Question. A dataset contains 105 samples and the mini-batch size is 20. Keeping the incomplete last batch, find the updates per epoch.</strong></p>","<h3>Given</h3>","<p>N = 105; B = 20; retain the final incomplete batch.</p>","<h3>To find</h3>","<p>The number of updates per epoch.</p>","<h3>Formula — which one and why</h3>","<p>Every processed group causes one update. A remaining nonempty group also counts.</p>","<p>The ceiling symbol rounds upward to the next integer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a73af57990a3f346.svg\" alt=\"U=\\lceil N/B\\rceil\" width=\"125.49\" height=\"24.43\" style=\"width:125.49px;height:24.43px;aspect-ratio:125.49/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bacha hua batch process kiya toh ek aur update.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count complete batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/165b56a31834874f.svg\" alt=\"5(20)=100\" width=\"124.90\" height=\"24.43\" style=\"width:124.90px;height:24.43px;aspect-ratio:124.90/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count remaining examples.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/018ad701e47e6473.svg\" alt=\"105-100=5\" width=\"147.97\" height=\"18.27\" style=\"width:147.97px;height:18.27px;aspect-ratio:147.97/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: include the nonempty last batch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/298ed637938b4bf6.svg\" alt=\"U=5+1=6\" width=\"150.43\" height=\"18.69\" style=\"width:150.43px;height:18.69px;aspect-ratio:150.43/18.69\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 6 updates. If a question explicitly drops the final incomplete batch, it instead gives 5.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s4","search":"Batch stochastic and mini batch gradient descent **Definition.** Batch, stochastic and mini-batch gradient descent differ in the subset of training examples used to estimate the gradient for each parameter update. Their update equation is the same; their gradient estimates and update frequency differ.\n\n### Explanation and working\nAll three use the same update idea. They differ in how much data contributes to one gradient.\n\n\n\n| Method | Data for one update | Updates in one epoch with N samples | Typical behaviour |\n| Batch GD | All N samples | 1 | Stable full-data gradient; costly updates |\n| Stochastic GD | One sample | N | Frequent noisy updates |\n| Mini-batch GD | B samples | Ceiling of N/B if final partial batch is retained | Efficient parallel calculation with moderate noise |\n**Question.** N = 1,000 and B = 100. Find updates per epoch.\n\n\n\n### Given\n\nN = 1,000 examples; mini-batch size B = 100; one epoch.\n\n### To find\n\nCount full-batch, stochastic and mini-batch updates per epoch.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n### Solution — step by step\n\n\n\n\n**Step 1: count full-batch updates.**\n\nAll 1,000 samples form one group, so one epoch has 1 update.\n\n**Step 2: count stochastic updates.**\n\nOne sample per update gives 1,000 updates per epoch.\n\n**Step 3: count mini-batches.**\n\n\n\n\n\n\n\n**Final answer:** batch = 1; SGD = 1,000; mini-batch = 10 updates per epoch.\n\n\n### Mini-batch calculation with a remainder\n\n**Question. A dataset contains 105 samples and the mini-batch size is 20. Keeping the incomplete last batch, find the updates per epoch.**\n\n\n\n### Given\n\nN = 105; B = 20; retain the final incomplete batch.\n\n### To find\n\nThe number of updates per epoch.\n\n### Formula — which one and why\n\nEvery processed group causes one update. A remaining nonempty group also counts.\n\nThe ceiling symbol rounds upward to the next integer.\n\n\n\n**Yaad rakhne ka cue:** Bacha hua batch process kiya toh ek aur update.\n\n### Solution — step by step\n\n\n\n**Step 1: count complete batches.**\n\n\n\n\n\n\n\n**Step 2: count remaining examples.**\n\n\n\n\n\n\n\n**Step 3: include the nonempty last batch.**\n\n\n\n\n\n\n\n**Final answer:** 6 updates. If a question explicitly drops the final incomplete batch, it instead gives 5.\n\n"},{"title":"Model answer: batch, stochastic and mini-batch training","question":["<p class=\"inline-question\"><strong>Question.</strong> Differentiate batch gradient descent, stochastic gradient descent and mini-batch gradient descent. Explain an epoch, a batch and an iteration.</p>"],"answer":["<p>All three methods update model parameters using gradients. Their difference is the number of training examples used to estimate the gradient for one update.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_batches.svg\" aria-label=\"Enlarge diagram: All methods visit the same six examples. Their grouping determines how often they update.\"><img src=\"assets/figures/v_batches.svg\" alt=\"All methods visit the same six examples. Their grouping determines how often they update.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>All methods visit the same six examples. Their grouping determines how often they update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A <strong>batch</strong> is the group of examples used together for an update. An <strong>iteration</strong>, in this context, is one optimizer update. An <strong>epoch</strong> is one complete pass through the chosen training dataset. One epoch usually contains several iterations.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Basis</th><th>Batch GD</th><th>Stochastic GD</th><th>Mini-batch GD</th></tr></thead><tbody><tr><td>Examples in one gradient</td><td>Entire training dataset</td><td>One example</td><td>A smaller group of B examples</td></tr><tr><td>Updates per epoch</td><td>One</td><td>N</td><td>Ceiling of N/B if the remainder is retained</td></tr><tr><td>Gradient behavior</td><td>Full-data gradient</td><td>Noisy sample gradient</td><td>Intermediate averaging</td></tr><tr><td>Practical implication</td><td>Updates can be expensive on large datasets</td><td>Many small, sequential updates</td><td>Common compromise for vectorized computation</td></tr></tbody></table></div>","<h3>Example to distinguish the three counts</h3>","<p>With 105 examples and batch size 20, five batches use 100 examples and a sixth uses the remaining 5. Therefore one epoch has 6 mini-batch updates. Three epochs give 18 updates. It would be 5 updates per epoch only if the problem explicitly discarded the incomplete batch.</p>","<p>The basic parameter update is unchanged:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8a6ef020e7632784.svg\" alt=\"\\theta_{\\mathrm{new}}=\\theta_{\\mathrm{old}}-\\eta g\" width=\"166.03\" height=\"22.51\" style=\"width:166.03px;height:22.51px;aspect-ratio:166.03/22.51\" loading=\"lazy\"></div>","<p>For batch or mini-batch training, g normally represents the gradient of the stated aggregate loss over that group. For sequential SGD, update after each example and use the new parameter for the next example. Consequently, one SGD epoch need not equal one batch update even when both use the same examples.</p>"],"kind":"theory","id":"tee-c5-s5","search":"Model answer: batch, stochastic and mini-batch training **Question.** Differentiate batch gradient descent, stochastic gradient descent and mini-batch gradient descent. Explain an epoch, a batch and an iteration.\n\n**Model answer.**\nAll three methods update model parameters using gradients. Their difference is the number of training examples used to estimate the gradient for one update.\n\n\n\n\nA **batch** is the group of examples used together for an update. An **iteration**, in this context, is one optimizer update. An **epoch** is one complete pass through the chosen training dataset. One epoch usually contains several iterations.\n\n| Basis | Batch GD | Stochastic GD | Mini-batch GD |\n| Examples in one gradient | Entire training dataset | One example | A smaller group of B examples |\n| Updates per epoch | One | N | Ceiling of N/B if the remainder is retained |\n| Gradient behavior | Full-data gradient | Noisy sample gradient | Intermediate averaging |\n| Practical implication | Updates can be expensive on large datasets | Many small, sequential updates | Common compromise for vectorized computation |\n\n### Example to distinguish the three counts\nWith 105 examples and batch size 20, five batches use 100 examples and a sixth uses the remaining 5. Therefore one epoch has 6 mini-batch updates. Three epochs give 18 updates. It would be 5 updates per epoch only if the problem explicitly discarded the incomplete batch.\n\nThe basic parameter update is unchanged:\n\nFor batch or mini-batch training, g normally represents the gradient of the stated aggregate loss over that group. For sequential SGD, update after each example and use the new parameter for the next example. Consequently, one SGD epoch need not equal one batch update even when both use the same examples.\n"},{"title":"A tiny dataset shows why the methods differ","blocks":["<p class=\"inline-question\"><strong>Question.</strong> Train ŷ = wx on samples (1,2) and (2,4), starting at w = 1, with η = 0.1 and mean half squared loss. Compare one batch update with one SGD epoch in the listed order.</p>","<h3>Given</h3>","<p>Model ŷ = wx; initial w = 1; η = 0.1.</p>","<p>Samples in order: (1,2), (2,4).</p>","<p>Mean half squared loss for the batch.</p>","<h3>To find</h3>","<p>Compare one batch update with a sequential SGD epoch.</p>","<h3>Formula — which one and why</h3>","<p><strong>Batch mean versus sequential SGD.</strong> A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.</p>","<p>B = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/657f63b5043d3907.svg\" alt=\"g_{\\mathrm{batch}}=\\frac1B\\sum_i g_i\" width=\"180.88\" height=\"61.92\" style=\"width:180.88px;height:61.92px;aspect-ratio:180.88/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0b4939a48933eb0a.svg\" alt=\"g_i=(wx_i-y_i)x_i\" width=\"182.50\" height=\"24.43\" style=\"width:182.50px;height:24.43px;aspect-ratio:182.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Batch: same old weight par average; SGD: har sample ke baad weight change.</p>","<h3>Solution — step by step</h3>","<h3>One batch update</h3>","<p class=\"worked-step\"><strong>Step 1: predict sample 1 with the original weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d19c8d7124e25bc5.svg\" alt=\"\\hat y_1=1(1)=1\" width=\"143.47\" height=\"25.90\" style=\"width:143.47px;height:25.90px;aspect-ratio:143.47/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate its error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dba84d8eacba9175.svg\" alt=\"e_1=1-2=-1\" width=\"172.76\" height=\"19.94\" style=\"width:172.76px;height:19.94px;aspect-ratio:172.76/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply its error by its input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fdbcda3ad0050efb.svg\" alt=\"g_1=(-1)(1)=-1\" width=\"200.18\" height=\"24.43\" style=\"width:200.18px;height:24.43px;aspect-ratio:200.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: predict sample 2 with the same original weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7be604573d864f92.svg\" alt=\"\\hat y_2=1(2)=2\" width=\"143.47\" height=\"25.90\" style=\"width:143.47px;height:25.90px;aspect-ratio:143.47/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate its error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55c62638d290dff9.svg\" alt=\"e_2=2-4=-2\" width=\"172.76\" height=\"20.21\" style=\"width:172.76px;height:20.21px;aspect-ratio:172.76/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: multiply its error by its input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f6d46df3c042284.svg\" alt=\"g_2=(-2)(2)=-4\" width=\"200.18\" height=\"24.43\" style=\"width:200.18px;height:24.43px;aspect-ratio:200.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: average the two gradients.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8cfa6ee1614fe8e3.svg\" alt=\"g=\\frac{-1+(-4)}2=-2.5\" width=\"249.15\" height=\"52.43\" style=\"width:249.15px;height:52.43px;aspect-ratio:249.15/52.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: update once.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.42px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f263219d999d6318.svg\"><img class=\"math display-math\" src=\"assets/equations/9fb7a46ddd37e16c.svg\" alt=\"w_{\\mathrm{new}}=1-0.1(-2.5)=1.25\" width=\"300.45\" height=\"24.43\" style=\"width:300.45px;height:24.43px;aspect-ratio:300.45/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_batches.svg\" aria-label=\"Enlarge diagram: This grouping sketch explains the difference. The worked dataset below supplies its own values for the actual gradient calculation.\"><img src=\"assets/figures/v_batches.svg\" alt=\"This grouping sketch explains the difference. The worked dataset below supplies its own values for the actual gradient calculation.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>This grouping sketch explains the difference. The worked dataset below supplies its own values for the actual gradient calculation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>One sequential SGD epoch</h3>","<p class=\"worked-step\"><strong>Step 1: use the first sample gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a43ae4bf3e05e38.svg\" alt=\"g_1=-1\" width=\"86.13\" height=\"21.29\" style=\"width:86.13px;height:21.29px;aspect-ratio:86.13/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: update after the first sample.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2a537796fbcbe31.svg\" alt=\"w_1=1-0.1(-1)=1.1\" width=\"248.11\" height=\"24.43\" style=\"width:248.11px;height:24.43px;aspect-ratio:248.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: predict sample 2 using the changed weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b434bd09ecf3d6fa.svg\" alt=\"\\hat y_2=1.1(2)=2.2\" width=\"181.49\" height=\"25.90\" style=\"width:181.49px;height:25.90px;aspect-ratio:181.49/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find sample 2 error.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbcb5d7c79c1f6bd.svg\" alt=\"e_2=2.2-4=-1.8\" width=\"210.77\" height=\"20.21\" style=\"width:210.77px;height:20.21px;aspect-ratio:210.77/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find the new sample 2 gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/352a3c332b7e819d.svg\" alt=\"g_2=(-1.8)(2)=-3.6\" width=\"238.20\" height=\"24.43\" style=\"width:238.20px;height:24.43px;aspect-ratio:238.20/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: update after sample 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.32px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/337ee1d4f3248df4.svg\"><img class=\"math display-math\" src=\"assets/equations/93143771f8225850.svg\" alt=\"w_2=1.1-0.1(-3.6)=1.46\" width=\"298.35\" height=\"24.43\" style=\"width:298.35px;height:24.43px;aspect-ratio:298.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> batch weight = 1.25; sequential SGD weight = 1.46. SGD changes the weight between samples.</p>","<p>Larger mini-batches use more memory and often make better use of parallel hardware. Smaller batches provide noisier gradient estimates and more updates per epoch. Wall-clock speed and generalization depend on the implementation and problem, so “SGD always converges fastest” is not a safe claim.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s6","search":"A tiny dataset shows why the methods differ **Question.** Train ŷ = wx on samples (1,2) and (2,4), starting at w = 1, with η = 0.1 and mean half squared loss. Compare one batch update with one SGD epoch in the listed order.\n\n\n\n### Given\n\nModel ŷ = wx; initial w = 1; η = 0.1.\n\nSamples in order: (1,2), (2,4).\n\nMean half squared loss for the batch.\n\n### To find\n\nCompare one batch update with a sequential SGD epoch.\n\n### Formula — which one and why\n\n**Batch mean versus sequential SGD.** A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.\n\nB = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Batch: same old weight par average; SGD: har sample ke baad weight change.\n\n### Solution — step by step\n\n\n\n\n### One batch update\n\n**Step 1: predict sample 1 with the original weight.**\n\n\n\n\n\n\n\n**Step 2: calculate its error.**\n\n\n\n\n\n\n\n**Step 3: multiply its error by its input.**\n\n\n\n\n\n\n\n**Step 4: predict sample 2 with the same original weight.**\n\n\n\n\n\n\n\n**Step 5: calculate its error.**\n\n\n\n\n\n\n\n**Step 6: multiply its error by its input.**\n\n\n\n\n\n\n\n**Step 7: average the two gradients.**\n\n\n\n\n\n\n\n**Step 8: update once.**\n\n\n\n\n\n\n\n\n\n\n\n### One sequential SGD epoch\n\n**Step 1: use the first sample gradient.**\n\n\n\n\n\n\n\n**Step 2: update after the first sample.**\n\n\n\n\n\n\n\n**Step 3: predict sample 2 using the changed weight.**\n\n\n\n\n\n\n\n**Step 4: find sample 2 error.**\n\n\n\n\n\n\n\n**Step 5: find the new sample 2 gradient.**\n\n\n\n\n\n\n\n**Step 6: update after sample 2.**\n\n\n\n\n\n\n\n**Final answer:** batch weight = 1.25; sequential SGD weight = 1.46. SGD changes the weight between samples.\nLarger mini-batches use more memory and often make better use of parallel hardware. Smaller batches provide noisier gradient estimates and more updates per epoch. Wall-clock speed and generalization depend on the implementation and problem, so “SGD always converges fastest” is not a safe claim."},{"title":"Learning rate and common training problems","blocks":["<p class=\"definition\"><strong>Definition.</strong> The learning rate is a hyperparameter controlling the scale of a gradient-based update. It affects convergence speed and stability; it is not the gradient and is not the magnitude of the loss.</p>","<h3>Explanation and working</h3>","<p>A very small rate can make progress slow. A very large rate can overshoot, oscillate or diverge. A suitable rate permits progress without uncontrolled jumps. Feature scaling can reduce long zig-zag paths. A noisy curve alone is not proof of failure; individual mini-batch losses fluctuate.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative loss traces show why smoothness and progress are different\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative loss traces show why smoothness and progress are different\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative loss traces show why smoothness and progress are different <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Observation</th><th>Possible reason</th><th>Sensible first action</th></tr></thead><tbody><tr><td>Loss barely changes</td><td>Very small rate, saturated/dead units, wrong implementation</td><td>Check gradients and data; then tune rate or activation</td></tr><tr><td>Loss jumps wildly</td><td>Rate too high or exploding gradients</td><td>Reduce rate; inspect gradient size; clip if appropriate</td></tr><tr><td>Noisy but decreasing loss</td><td>Small-batch sampling noise</td><td>Compare a smoothed trend; consider larger batches or momentum</td></tr><tr><td>Training improves but validation worsens</td><td>Overfitting</td><td>Use regularization, augmentation or early stopping</td></tr><tr><td>All identical hidden neurons learn alike</td><td>Symmetric initialization</td><td>Use suitable nonidentical initial weights</td></tr></tbody></table></div>","<p>Convergence means updates or the objective are settling under a criterion. A zero gradient can also occur at a saddle point or in a saturated region; it is not proof of a global optimum.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s7","search":"Learning rate and common training problems **Definition.** The learning rate is a hyperparameter controlling the scale of a gradient-based update. It affects convergence speed and stability; it is not the gradient and is not the magnitude of the loss.\n\n### Explanation and working\nA very small rate can make progress slow. A very large rate can overshoot, oscillate or diverge. A suitable rate permits progress without uncontrolled jumps. Feature scaling can reduce long zig-zag paths. A noisy curve alone is not proof of failure; individual mini-batch losses fluctuate.\n\n| Observation | Possible reason | Sensible first action |\n| Loss barely changes | Very small rate, saturated/dead units, wrong implementation | Check gradients and data; then tune rate or activation |\n| Loss jumps wildly | Rate too high or exploding gradients | Reduce rate; inspect gradient size; clip if appropriate |\n| Noisy but decreasing loss | Small-batch sampling noise | Compare a smoothed trend; consider larger batches or momentum |\n| Training improves but validation worsens | Overfitting | Use regularization, augmentation or early stopping |\n| All identical hidden neurons learn alike | Symmetric initialization | Use suitable nonidentical initial weights |\nConvergence means updates or the objective are settling under a criterion. A zero gradient can also occur at a saddle point or in a saturated region; it is not proof of a global optimum."},{"title":"A moving average remembers the recent past","blocks":["<p class=\"definition\"><strong>Definition.</strong> An exponentially weighted moving average (EWMA) is a recursively updated estimate in which older observations receive exponentially decreasing weights. Optimizers use it to summarize recent gradients or squared gradients.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:131.51px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278e38d8879b5e28.svg\"><img class=\"math display-math\" src=\"assets/equations/9d6a2ee32d9c0644.svg\" alt=\"m_t=\\beta m_{t-1}+(1-\\beta)g_t,\\qquad0\\le\\beta&lt;1\" width=\"415.82\" height=\"24.43\" style=\"width:415.82px;height:24.43px;aspect-ratio:415.82/24.43\" loading=\"lazy\"></picture></div>","<p>For m₀ = 0, expanding the recurrence gives:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3400900697b48b50.svg\" alt=\"m_t=(1-\\beta)\\sum_{k=1}^{t}\\beta^{t-k}g_k\" width=\"247.88\" height=\"72.28\" style=\"width:247.88px;height:72.28px;aspect-ratio:247.88/72.28\" loading=\"lazy\"></div>","<p>The most recent gradient has coefficient 1 − β; a gradient k steps older is discounted by an additional factor βᵏ. Larger β smooths more strongly but responds more slowly to a change in direction. The heuristic averaging horizon is approximately 1/(1 − β); it is not a hard cutoff in the stored history.</p>","<h3>Signed gradients versus squared gradients</h3>","<p>An average of g contains directional information: positive and negative contributions can cancel. An average of g² estimates the scale through an uncentered second moment and cannot become negative when initialized nonnegatively. Adam tracks both quantities. RMSProp tracks a squared-gradient average in its basic form.</p>","<p class=\"inline-question\"><strong>Question.</strong> Let β = 0.9, m₀ = 0 and gradients g₁ = 2, g₂ = −1. Find m₁ and m₂.</p>","<h3>Given</h3>","<p>β = 0.9; initial m₀ = 0.</p>","<p>Gradients in order: g₁ = 2, g₂ = −1.</p>","<h3>To find</h3>","<p>Find m₁ and m₂, preserving the sign of each gradient.</p>","<h3>Formula — which one and why</h3>","<p><strong>Exponential moving average.</strong> Keep the specified fraction of the old state and add the complementary fraction of the new gradient. This tracks signed direction, so negative gradients can reduce the state.</p>","<p>β (beta) = retained fraction; m = stored average; g = current gradient. m₀ is the initial state.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7999b979f742c872.svg\" alt=\"m_t=\\beta m_{t-1}+(1-\\beta)g_t\" width=\"252.64\" height=\"24.43\" style=\"width:252.64px;height:24.43px;aspect-ratio:252.64/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Beta purani memory rakhta hai; 1−beta naya gradient leta hai.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find the recent-gradient coefficient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1d3a9c6b5c275e6a.svg\" alt=\"1-0.9=0.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the old memory for step 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4351a4e3442a023e.svg\" alt=\"0.9(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: weight the first gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/687125898d5f60b7.svg\" alt=\"0.1(2)=0.2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add to obtain the first memory.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/624684fe1c8cf03d.svg\" alt=\"m_1=0+0.2=0.2\" width=\"201.83\" height=\"19.94\" style=\"width:201.83px;height:19.94px;aspect-ratio:201.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: retain the first memory for step 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/30b407cc303a0e19.svg\" alt=\"0.9(0.2)=0.18\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: weight the second gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/995079ed548eec78.svg\" alt=\"0.1(-1)=-0.1\" width=\"164.29\" height=\"24.43\" style=\"width:164.29px;height:24.43px;aspect-ratio:164.29/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: add to obtain the second memory.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0e62fb9876ad9dac.svg\" alt=\"m_2=0.18+(-0.1)=0.08\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> m₁ = 0.2; m₂ = 0.08.</p>","<p>The second average remains positive although the latest gradient is negative because the previous positive contribution still has weight. If the recurrence is applied to the squared gradients instead, the second state is 0.9(0.4) + 0.1(1) = 0.46. These states have different meanings and are not interchangeable.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s8","search":"A moving average remembers the recent past **Definition.** An exponentially weighted moving average (EWMA) is a recursively updated estimate in which older observations receive exponentially decreasing weights. Optimizers use it to summarize recent gradients or squared gradients.\n\nFor m₀ = 0, expanding the recurrence gives:\n\nThe most recent gradient has coefficient 1 − β; a gradient k steps older is discounted by an additional factor βᵏ. Larger β smooths more strongly but responds more slowly to a change in direction. The heuristic averaging horizon is approximately 1/(1 − β); it is not a hard cutoff in the stored history.\n\n### Signed gradients versus squared gradients\nAn average of g contains directional information: positive and negative contributions can cancel. An average of g² estimates the scale through an uncentered second moment and cannot become negative when initialized nonnegatively. Adam tracks both quantities. RMSProp tracks a squared-gradient average in its basic form.\n\n**Question.** Let β = 0.9, m₀ = 0 and gradients g₁ = 2, g₂ = −1. Find m₁ and m₂.\n\n\n\n### Given\n\nβ = 0.9; initial m₀ = 0.\n\nGradients in order: g₁ = 2, g₂ = −1.\n\n### To find\n\nFind m₁ and m₂, preserving the sign of each gradient.\n\n### Formula — which one and why\n\n**Exponential moving average.** Keep the specified fraction of the old state and add the complementary fraction of the new gradient. This tracks signed direction, so negative gradients can reduce the state.\n\nβ (beta) = retained fraction; m = stored average; g = current gradient. m₀ is the initial state.\n\n\n\n**Yaad rakhne ka cue:** Beta purani memory rakhta hai; 1−beta naya gradient leta hai.\n\n### Solution — step by step\n\n\n\n\n**Step 1: find the recent-gradient coefficient.**\n\n\n\n\n\n\n\n**Step 2: retain the old memory for step 1.**\n\n\n\n\n\n\n\n**Step 3: weight the first gradient.**\n\n\n\n\n\n\n\n**Step 4: add to obtain the first memory.**\n\n\n\n\n\n\n\n**Step 5: retain the first memory for step 2.**\n\n\n\n\n\n\n\n**Step 6: weight the second gradient.**\n\n\n\n\n\n\n\n**Step 7: add to obtain the second memory.**\n\n\n\n\n\n\n\n**Final answer:** m₁ = 0.2; m₂ = 0.08.\nThe second average remains positive although the latest gradient is negative because the previous positive contribution still has weight. If the recurrence is applied to the squared gradients instead, the second state is 0.9(0.4) + 0.1(1) = 0.46. These states have different meanings and are not interchangeable.\n"},{"title":"Momentum remembers movement","blocks":["<p class=\"definition\"><strong>Definition.</strong> Momentum is a gradient-based optimization method that combines the current gradient correction with a fraction of the previous parameter displacement. It can accumulate movement along persistent directions and damp some oscillations across alternating directions.</p>","<h3>Update equations and convention</h3>","<p>This course uses <strong>signed displacement velocity</strong> v. It already includes the learning rate, and the parameter update adds it to the old parameter:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c19372684b38c7e4.svg\" alt=\"g_t=J&#x27;(\\theta_{t-1})\" width=\"136.88\" height=\"25.88\" style=\"width:136.88px;height:25.88px;aspect-ratio:136.88/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p>θ is the parameter, η is the learning rate and β controls how much previous displacement is retained, normally with 0 ≤ β &lt; 1. A negative v moves θ in the negative direction. Every parameter has its own velocity; this optimizer state is distinct from the network&#x27;s trainable parameters.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_momentum.svg\" aria-label=\"Enlarge diagram: Combine the retained displacement with the current gradient correction, then apply the resulting velocity to the old parameter.\"><img src=\"assets/figures/v_momentum.svg\" alt=\"Combine the retained displacement with the current gradient correction, then apply the resulting velocity to the old parameter.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Combine the retained displacement with the current gradient correction, then apply the resulting velocity to the old parameter. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two iterations</h3>","<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1, β = 0.9. Find two iterations using signed displacement velocity.</p>","<h3>Given</h3>","<p>J(θ) = ½θ²; θ₀ = 1; v₀ = 0.</p>","<p>η = 0.1; β = 0.9; signed-displacement velocity.</p>","<h3>To find</h3>","<p>Find the gradient, velocity and actual parameter after each of two iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<p><strong>Derivative used:</strong> differentiating J gives J′(θ) = θ. The gradient must therefore be reevaluated at the current θ on each iteration.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1: gradient, velocity, parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9e80b135dd68a0a3.svg\" alt=\"g_1=J&#x27;(1)=1\" width=\"154.49\" height=\"25.88\" style=\"width:154.49px;height:25.88px;aspect-ratio:154.49/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2: use θ₁ and v₁.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14dc30bcccfa9d0f.svg\" alt=\"g_2=J&#x27;(0.9)=0.9\" width=\"192.52\" height=\"25.88\" style=\"width:192.52px;height:25.88px;aspect-ratio:192.52/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.38px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0143acec3cdc1b06.svg\"><img class=\"math display-math\" src=\"assets/equations/9d76f7ff1692b41e.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.9)=-0.18\" width=\"361.95\" height=\"24.43\" style=\"width:361.95px;height:24.43px;aspect-ratio:361.95/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<div class=\"table-scroll\"><table><thead><tr><th>Iteration</th><th>Parameter where gradient is evaluated</th><th>Gradient</th><th>New velocity</th><th>New parameter</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>1</td><td>−0.1</td><td>0.9</td></tr><tr><td>2</td><td>0.9</td><td>0.9</td><td>−0.18</td><td>0.72</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ = 0.72. At iteration 2, the retained displacement contributes −0.09 and the new gradient correction contributes another −0.09. Their sum explains the larger displacement despite the smaller current gradient.</p>","<h3>Properties and alternative notation</h3>","<p>Momentum can improve progress through long, poorly scaled valleys, but excessive learning rate or momentum can overshoot. It does not guarantee a global minimum for a general neural-network objective.</p>","<p>Some texts store a positive gradient accumulator u instead:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:169.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcab484ef321b3b2.svg\"><img class=\"math display-math\" src=\"assets/equations/0f57b8541207a6df.svg\" alt=\"u_t=\\beta u_{t-1}+g_t,\\qquad\\theta_t=\\theta_{t-1}-\\eta u_t\" width=\"380.87\" height=\"22.51\" style=\"width:380.87px;height:22.51px;aspect-ratio:380.87/22.51\" loading=\"lazy\"></picture></div>","<p>With constant η and consistent initialization, this corresponds to vₜ = −ηuₜ. A normalized moving average containing (1−β)gₜ is a different scaling convention. Use the exact recurrence stated in the question instead of combining pieces of different conventions.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s9","search":"Momentum remembers movement \n**Definition.** Momentum is a gradient-based optimization method that combines the current gradient correction with a fraction of the previous parameter displacement. It can accumulate movement along persistent directions and damp some oscillations across alternating directions.\n\n### Update equations and convention\nThis course uses **signed displacement velocity** v. It already includes the learning rate, and the parameter update adds it to the old parameter:\n\n\n\nθ is the parameter, η is the learning rate and β controls how much previous displacement is retained, normally with 0 ≤ β < 1. A negative v moves θ in the negative direction. Every parameter has its own velocity; this optimizer state is distinct from the network's trainable parameters.\n\n\n\n### Complete numerical: two iterations\n**Question.** J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1, β = 0.9. Find two iterations using signed displacement velocity.\n\n\n\n### Given\n\nJ(θ) = ½θ²; θ₀ = 1; v₀ = 0.\n\nη = 0.1; β = 0.9; signed-displacement velocity.\n\n### To find\n\nFind the gradient, velocity and actual parameter after each of two iterations.\n\n### Formula — which one and why\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n**Derivative used:** differentiating J gives J′(θ) = θ. The gradient must therefore be reevaluated at the current θ on each iteration.\n\n**Step 1: Iteration 1: gradient, velocity, parameter.**\n\n\n\n\n**Step 2: Iteration 2: use θ₁ and v₁.**\n\n\n\n\n| Iteration | Parameter where gradient is evaluated | Gradient | New velocity | New parameter |\n| 1 | 1 | 1 | −0.1 | 0.9 |\n| 2 | 0.9 | 0.9 | −0.18 | 0.72 |\n\n**Final answer:** θ₁ = 0.9 and θ₂ = 0.72. At iteration 2, the retained displacement contributes −0.09 and the new gradient correction contributes another −0.09. Their sum explains the larger displacement despite the smaller current gradient.\n\n### Properties and alternative notation\nMomentum can improve progress through long, poorly scaled valleys, but excessive learning rate or momentum can overshoot. It does not guarantee a global minimum for a general neural-network objective.\n\nSome texts store a positive gradient accumulator u instead:\n\nWith constant η and consistent initialization, this corresponds to vₜ = −ηuₜ. A normalized moving average containing (1−β)gₜ is a different scaling convention. Use the exact recurrence stated in the question instead of combining pieces of different conventions.\n\n"},{"title":"Nesterov looks before correcting","blocks":["<p class=\"definition\"><strong>Definition.</strong> Nesterov accelerated gradient is a momentum-based method that evaluates the gradient at a lookahead parameter, formed using the previous velocity, before calculating the new velocity and actual parameter update.</p>","<h3>What changes relative to momentum</h3>","<p>Ordinary momentum evaluates J′ at θₜ₋₁. Nesterov evaluates it after the anticipated displacement βvₜ₋₁. This changes the point where the objective&#x27;s slope is measured:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64563c533a276a7d.svg\" alt=\"\\theta_{\\mathrm{look},t}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"216.02\" height=\"24.25\" style=\"width:216.02px;height:24.25px;aspect-ratio:216.02/24.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ec7b790dfa7e622.svg\" alt=\"g_t=J&#x27;(\\theta_{\\mathrm{look},t})\" width=\"150.81\" height=\"26.78\" style=\"width:150.81px;height:26.78px;aspect-ratio:150.81/26.78\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p>The lookahead point is an auxiliary evaluation point, not the new actual parameter. In this signed-displacement convention, the new velocity is added to θₜ₋₁.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nesterov.svg\" aria-label=\"Enlarge diagram: Locate the lookahead point using the old velocity; measure the gradient there; use that gradient to calculate the actual update.\"><img src=\"assets/figures/v_nesterov.svg\" alt=\"Locate the lookahead point using the old velocity; measure the gradient there; use that gradient to calculate the actual update.\" width=\"1080\" height=\"530\" loading=\"lazy\"></button><figcaption>Locate the lookahead point using the old velocity; measure the gradient there; use that gradient to calculate the actual update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two iterations</h3>","<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1 and β = 0.9. Perform two Nesterov updates using signed displacement velocity.</p>","<h3>Given</h3>","<p>J(θ) = ½θ²; θ₀ = 1; v₀ = 0.</p>","<p>η = 0.1; β = 0.9; signed-displacement velocity.</p>","<h3>To find</h3>","<p>Find the gradient, velocity and actual parameter after each of two iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Nesterov lookahead.</strong> First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.</p>","<p>θ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d83df079bf260cc.svg\" alt=\"g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"138.39\" height=\"24.43\" style=\"width:138.39px;height:24.43px;aspect-ratio:138.39/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle look ahead; gradient wahan; update original position se.</p>","<h3>Solution — step by step</h3>","<p>The derivative is J′(θ) = θ. Therefore the gradient equals the lookahead value in this particular objective.</p>","<p><strong>Iteration 1 — step 1: locate the lookahead point.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0abe86d8e2a6e122.svg\" alt=\"\\theta_{\\mathrm{look},1}=1+0.9(0)=1\" width=\"240.06\" height=\"25.35\" style=\"width:240.06px;height:25.35px;aspect-ratio:240.06/25.35\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the gradient there.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9e80b135dd68a0a3.svg\" alt=\"g_1=J&#x27;(1)=1\" width=\"154.49\" height=\"25.88\" style=\"width:154.49px;height:25.88px;aspect-ratio:154.49/25.88\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the new velocity and actual parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p><strong>Iteration 2 — step 1: use the previous actual parameter and velocity.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.29px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/25448224eab650c3.svg\"><img class=\"math display-math\" src=\"assets/equations/ba38208dd4ceff26.svg\" alt=\"\\theta_{\\mathrm{look},2}=0.9+0.9(-0.1)=0.81\" width=\"328.32\" height=\"25.35\" style=\"width:328.32px;height:25.35px;aspect-ratio:328.32/25.35\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the gradient at 0.81, not at 0.9.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e8429bc60dff5c5c.svg\" alt=\"g_2=J&#x27;(0.81)=0.81\" width=\"216.95\" height=\"25.88\" style=\"width:216.95px;height:25.88px;aspect-ratio:216.95/25.88\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the new velocity.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35f06a75a728a22a.svg\"><img class=\"math display-math\" src=\"assets/equations/e92dee4c49c58b06.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.81)=-0.171\" width=\"386.38\" height=\"24.43\" style=\"width:386.38px;height:24.43px;aspect-ratio:386.38/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: update the old actual parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b7b6422b337bab9.svg\"><img class=\"math display-math\" src=\"assets/equations/2c96483424ef8929.svg\" alt=\"\\theta_2=0.9+(-0.171)=0.729\" width=\"297.73\" height=\"24.43\" style=\"width:297.73px;height:24.43px;aspect-ratio:297.73/24.43\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Iteration</th><th>Old actual θ</th><th>Lookahead θ</th><th>Gradient</th><th>New v</th><th>New actual θ</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>1</td><td>1</td><td>−0.1</td><td>0.9</td></tr><tr><td>2</td><td>0.9</td><td>0.81</td><td>0.81</td><td>−0.171</td><td>0.729</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ = 0.729. The first update matches ordinary momentum because v₀ = 0. At the second update, ordinary momentum would use gradient 0.9 and produce θ₂ = 0.72. Adding v₂ to 0.81 instead of 0.9 would count the old momentum contribution twice.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s10","search":"Nesterov looks before correcting \n**Definition.** Nesterov accelerated gradient is a momentum-based method that evaluates the gradient at a lookahead parameter, formed using the previous velocity, before calculating the new velocity and actual parameter update.\n\n### What changes relative to momentum\nOrdinary momentum evaluates J′ at θₜ₋₁. Nesterov evaluates it after the anticipated displacement βvₜ₋₁. This changes the point where the objective's slope is measured:\n\n\n\n\nThe lookahead point is an auxiliary evaluation point, not the new actual parameter. In this signed-displacement convention, the new velocity is added to θₜ₋₁.\n\n\n\n### Complete numerical: two iterations\n**Question.** J(θ) = ½θ², θ₀ = 1, v₀ = 0, η = 0.1 and β = 0.9. Perform two Nesterov updates using signed displacement velocity.\n\n\n\n### Given\n\nJ(θ) = ½θ²; θ₀ = 1; v₀ = 0.\n\nη = 0.1; β = 0.9; signed-displacement velocity.\n\n### To find\n\nFind the gradient, velocity and actual parameter after each of two iterations.\n\n### Formula — which one and why\n\n**Nesterov lookahead.** First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.\n\nθ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle look ahead; gradient wahan; update original position se.\n\n### Solution — step by step\n\n\n\n\n\nThe derivative is J′(θ) = θ. Therefore the gradient equals the lookahead value in this particular objective.\n\n**Iteration 1 — step 1: locate the lookahead point.**\n\n**Step 2: evaluate the gradient there.**\n\n**Step 3: calculate the new velocity and actual parameter.**\n\n\n\n**Iteration 2 — step 1: use the previous actual parameter and velocity.**\n\n**Step 2: evaluate the gradient at 0.81, not at 0.9.**\n\n**Step 3: calculate the new velocity.**\n\n**Step 4: update the old actual parameter.**\n\n\n| Iteration | Old actual θ | Lookahead θ | Gradient | New v | New actual θ |\n| 1 | 1 | 1 | 1 | −0.1 | 0.9 |\n| 2 | 0.9 | 0.81 | 0.81 | −0.171 | 0.729 |\n\n**Final answer:** θ₁ = 0.9 and θ₂ = 0.729. The first update matches ordinary momentum because v₀ = 0. At the second update, ordinary momentum would use gradient 0.9 and produce θ₂ = 0.72. Adding v₂ to 0.81 instead of 0.9 would count the old momentum contribution twice.\n\n"},{"title":"Model answer: momentum and Nesterov","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain momentum and Nesterov accelerated gradient. How does the point at which the gradient is measured differ?</p>"],"answer":["<p>Momentum retains a fraction of the previous movement and combines it with the current gradient correction. Movement in a persistent direction can build up, while alternating directions can partially cancel. This can reduce zig-zagging and improve progress through poorly scaled regions.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nesterov.svg\" aria-label=\"Enlarge diagram: Nesterov changes where the gradient is measured: at the look-ahead point implied by momentum.\"><img src=\"assets/figures/v_nesterov.svg\" alt=\"Nesterov changes where the gradient is measured: at the look-ahead point implied by momentum.\" width=\"1080\" height=\"530\" loading=\"lazy\"></button><figcaption>Nesterov changes where the gradient is measured: at the look-ahead point implied by momentum. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Momentum formulas</h3>","<p>This answer uses signed displacement velocity v: a negative velocity moves the parameter left. η is learning rate and β is the fraction of previous velocity retained.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c19372684b38c7e4.svg\" alt=\"g_t=J&#x27;(\\theta_{t-1})\" width=\"136.88\" height=\"25.88\" style=\"width:136.88px;height:25.88px;aspect-ratio:136.88/25.88\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<h3>Nesterov&#x27;s change</h3>","<p>Nesterov first forms a lookahead position using the old momentum. It measures the gradient there, then computes a new velocity and updates the actual old parameter.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88dc28f2501b464e.svg\" alt=\"g_t=J&#x27;(\\theta_{\\mathrm{look}})\" width=\"139.77\" height=\"25.88\" style=\"width:139.77px;height:25.88px;aspect-ratio:139.77/25.88\" loading=\"lazy\"></div>","<p>The velocity and parameter update formulas remain as displayed above. Add the new velocity to θ at the previous iteration, not to the lookahead point.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Basis</th><th>Momentum</th><th>Nesterov</th></tr></thead><tbody><tr><td>Gradient evaluated at</td><td>Current parameter</td><td>Lookahead parameter</td></tr><tr><td>Information retained</td><td>Previous velocity</td><td>Previous velocity</td></tr><tr><td>Intuition</td><td>Continue useful movement</td><td>Inspect the slope where old momentum points</td></tr><tr><td>Initial zero velocity</td><td>No movement contribution yet</td><td>First lookahead equals current parameter</td></tr></tbody></table></div>","<p>Both require suitable learning rate and momentum settings. Neither guarantees the global minimum of a general neural-network objective. Different books use different definitions of stored velocity, so the definition and update must be used together consistently.</p>"],"kind":"theory","id":"tee-c5-s11","search":"Model answer: momentum and Nesterov **Question.** Explain momentum and Nesterov accelerated gradient. How does the point at which the gradient is measured differ?\n\n**Model answer.**\nMomentum retains a fraction of the previous movement and combines it with the current gradient correction. Movement in a persistent direction can build up, while alternating directions can partially cancel. This can reduce zig-zagging and improve progress through poorly scaled regions.\n\n\n\n\n### Momentum formulas\nThis answer uses signed displacement velocity v: a negative velocity moves the parameter left. η is learning rate and β is the fraction of previous velocity retained.\n\n\n\n### Nesterov's change\nNesterov first forms a lookahead position using the old momentum. It measures the gradient there, then computes a new velocity and updates the actual old parameter.\n\n\nThe velocity and parameter update formulas remain as displayed above. Add the new velocity to θ at the previous iteration, not to the lookahead point.\n\n| Basis | Momentum | Nesterov |\n| Gradient evaluated at | Current parameter | Lookahead parameter |\n| Information retained | Previous velocity | Previous velocity |\n| Intuition | Continue useful movement | Inspect the slope where old momentum points |\n| Initial zero velocity | No movement contribution yet | First lookahead equals current parameter |\n\nBoth require suitable learning rate and momentum settings. Neither guarantees the global minimum of a general neural-network objective. Different books use different definitions of stored velocity, so the definition and update must be used together consistently.\n"},{"title":"AdaGrad adds every squared gradient","blocks":["<p class=\"definition\"><strong>Definition.</strong> AdaGrad is an adaptive first-order optimizer that scales each parameter&#x27;s update using the inverse square root of the sum of its previous and current squared gradients. Each parameter maintains its own accumulator.</p>","<h3>State, effective learning rate and update</h3>","<p>For one parameter θ, let gₜ be its current gradient and s₀ = 0:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/32f05266b341eaa2.svg\" alt=\"s_t=s_{t-1}+g_t^2\" width=\"146.31\" height=\"27.82\" style=\"width:146.31px;height:27.82px;aspect-ratio:146.31/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5cf38c4d809aeefb.svg\" alt=\"\\eta_{\\mathrm{effective},t}=\\frac{\\eta}{\\sqrt{s_t}+\\varepsilon}\" width=\"212.27\" height=\"52.24\" style=\"width:212.27px;height:52.24px;aspect-ratio:212.27/52.24\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52438222ad8d94df.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta_{\\mathrm{effective},t}g_t\" width=\"231.02\" height=\"24.25\" style=\"width:231.02px;height:24.25px;aspect-ratio:231.02/24.25\" loading=\"lazy\"></div>","<p>s stores squared-gradient history. Both positive and negative gradients increase this nonnegative sum after squaring. The effective learning rate is the coefficient multiplying the signed gradient; the actual displacement also depends on that gradient&#x27;s magnitude and sign.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad.svg\" aria-label=\"Enlarge diagram: The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients.\"><img src=\"assets/figures/v_adagrad.svg\" alt=\"The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: supplied gradients</h3>","<p class=\"inline-question\"><strong>Question.</strong> Start θ₀ = 1, s₀ = 0, η = 0.1. Given gradients g₁ = 2 and g₂ = 1, perform two AdaGrad updates. Ignore epsilon only for this hand calculation because neither denominator is zero.</p>","<h3>Given</h3>","<p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p>","<p>Supplied gradients g₁ = 2, g₂ = 1.</p>","<p>ε = 0 for this hand calculation.</p>","<h3>To find</h3>","<p>Calculate all required states and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p>","<p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p>","<h3>Solution — step by step</h3>","<p>The gradients are supplied by the question. They are not computed from an assumed objective, and g₂ is not replaced by the updated parameter.</p>","<p><strong>Iteration 1 — step 1: update the accumulator.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18b84cdbfe918936.svg\" alt=\"s_1=0+2^2=4\" width=\"164.48\" height=\"25.26\" style=\"width:164.48px;height:25.26px;aspect-ratio:164.48/25.26\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the effective learning rate.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8acc57815fd4951a.svg\" alt=\"\\eta_{\\mathrm{effective},1}=\\frac{0.1}{\\sqrt4}=0.05\" width=\"241.94\" height=\"57.72\" style=\"width:241.94px;height:57.72px;aspect-ratio:241.94/57.72\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the signed gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8aa23a9e3a9c5875.svg\" alt=\"\\theta_1=1-0.05(2)=0.9\" width=\"235.28\" height=\"24.43\" style=\"width:235.28px;height:24.43px;aspect-ratio:235.28/24.43\" loading=\"lazy\"></div>","<p><strong>Iteration 2 — step 1: retain s₁ and add the new squared gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1e29c54438050499.svg\" alt=\"s_2=4+1^2=5\" width=\"164.48\" height=\"25.26\" style=\"width:164.48px;height:25.26px;aspect-ratio:164.48/25.26\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the new coefficient.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:165.92px;--narrow-height:96.81px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d33a28de17065dc.svg\"><img class=\"math display-math\" src=\"assets/equations/3d6533ca9b2ac114.svg\" alt=\"\\eta_{\\mathrm{effective},2}=\\frac{0.1}{\\sqrt5}\\approx0.044721360\" width=\"327.47\" height=\"57.72\" style=\"width:327.47px;height:57.72px;aspect-ratio:327.47/57.72\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update from θ₁.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.01px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81f6101b82b353cb.svg\"><img class=\"math display-math\" src=\"assets/equations/f835d09c27f0313a.svg\" alt=\"\\theta_2=0.9-\\frac{0.1(1)}{\\sqrt5}\\approx0.855278640\" width=\"350.57\" height=\"60.60\" style=\"width:350.57px;height:60.60px;aspect-ratio:350.57/60.60\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ ≈ 0.855279, with accumulators s₁ = 4 and s₂ = 5.</p>","<h3>Advantage, limitation and epsilon convention</h3>","<p>Coordinate-specific scaling can be useful when some features or gradients occur infrequently. Because s never decreases, its effective learning rate is nonincreasing when η and ε are fixed, and can become too small during prolonged training. The actual displacement magnitude need not decrease monotonically because gₜ also changes.</p>","<p>ε is normally a small positive stabilizer. These notes place it outside the square root. If a question places it inside, use that specified denominator consistently; the two placements are not numerically identical.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s12","search":"AdaGrad adds every squared gradient \n**Definition.** AdaGrad is an adaptive first-order optimizer that scales each parameter's update using the inverse square root of the sum of its previous and current squared gradients. Each parameter maintains its own accumulator.\n\n### State, effective learning rate and update\nFor one parameter θ, let gₜ be its current gradient and s₀ = 0:\n\n\n\ns stores squared-gradient history. Both positive and negative gradients increase this nonnegative sum after squaring. The effective learning rate is the coefficient multiplying the signed gradient; the actual displacement also depends on that gradient's magnitude and sign.\n\n\n\n### Complete numerical: supplied gradients\n**Question.** Start θ₀ = 1, s₀ = 0, η = 0.1. Given gradients g₁ = 2 and g₂ = 1, perform two AdaGrad updates. Ignore epsilon only for this hand calculation because neither denominator is zero.\n\n\n\n### Given\n\nθ₀ = 1; initial state(s) = 0; η = 0.1.\n\nSupplied gradients g₁ = 2, g₂ = 1.\n\nε = 0 for this hand calculation.\n\n### To find\n\nCalculate all required states and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**AdaGrad.** Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.\n\nG = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.\n\n\n\n\n\n**Yaad rakhne ka cue:** Square karo, purane sum mein jodo, root se scale karo.\n\n### Solution — step by step\n\n\n\n\n\nThe gradients are supplied by the question. They are not computed from an assumed objective, and g₂ is not replaced by the updated parameter.\n\n**Iteration 1 — step 1: update the accumulator.**\n\n**Step 2: calculate the effective learning rate.**\n\n**Step 3: apply the signed gradient.**\n\n\n**Iteration 2 — step 1: retain s₁ and add the new squared gradient.**\n\n**Step 2: calculate the new coefficient.**\n\n**Step 3: update from θ₁.**\n\n\n**Final answer:** θ₁ = 0.9 and θ₂ ≈ 0.855279, with accumulators s₁ = 4 and s₂ = 5.\n\n### Advantage, limitation and epsilon convention\nCoordinate-specific scaling can be useful when some features or gradients occur infrequently. Because s never decreases, its effective learning rate is nonincreasing when η and ε are fixed, and can become too small during prolonged training. The actual displacement magnitude need not decrease monotonically because gₜ also changes.\n\nε is normally a small positive stabilizer. These notes place it outside the square root. If a question places it inside, use that specified denominator consistently; the two placements are not numerically identical.\n\n"},{"title":"RMSProp remembers recent squared gradients","blocks":["<p class=\"definition\"><strong>Definition.</strong> RMSProp is an adaptive optimizer that normalizes the current gradient by the root of an exponentially weighted moving average of squared gradients. Its decaying history addresses AdaGrad&#x27;s permanently growing accumulator.</p>","<h3>Recurrence and interpretation</h3>","<p>Using decay β and zero initial state:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b2de5dc1fbe8c99.svg\" alt=\"s_t=\\beta s_{t-1}+(1-\\beta)g_t^2\" width=\"235.06\" height=\"27.82\" style=\"width:235.06px;height:27.82px;aspect-ratio:235.06/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>β is the fraction of the previous squared-gradient average retained, not a signed velocity. Some papers use ρ for this same decay. The square is applied to the gradient before averaging; the square root is applied to the resulting average in the update.</p>","<p>If recent squared gradients are smaller than the old average, s can decrease. Thus older large gradients do not remain in the denominator with their original weight forever.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rmsprop.svg\" aria-label=\"Enlarge diagram: Retain part of the old squared-gradient average and add the weighted square of the current gradient.\"><img src=\"assets/figures/v_rmsprop.svg\" alt=\"Retain part of the old squared-gradient average and add the weighted square of the current gradient.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Retain part of the old squared-gradient average and add the weighted square of the current gradient. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two iterations</h3>","<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, s₀ = 0, η = 0.1, β = 0.9; supplied gradients are 2 then 1. Perform two RMSProp updates, with ε = 0 for this hand calculation.</p>","<h3>Given</h3>","<p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p>","<p>Supplied gradients g₁ = 2, g₂ = 1.</p>","<p>ε = 0 for this hand calculation.</p>","<p>β = 0.9.</p>","<h3>To find</h3>","<p>Calculate all required states and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p>","<p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p>","<h3>Solution — step by step</h3>","<p><strong>Iteration 1 — step 1: calculate the squared-gradient average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea96f08ec1d03a73.svg\" alt=\"s_1=0.9(0)+0.1(2^2)=0.4\" width=\"283.96\" height=\"27.70\" style=\"width:283.96px;height:27.70px;aspect-ratio:283.96/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the denominator and signed correction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d388f002971175a6.svg\"><img class=\"math display-math\" src=\"assets/equations/73269d6fb6447a99.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.4}\\approx0.632455532\" width=\"289.17\" height=\"30.34\" style=\"width:289.17px;height:30.34px;aspect-ratio:289.17/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/91debda43e9c7015.svg\"><img class=\"math display-math\" src=\"assets/equations/918a6ff758f0307c.svg\" alt=\"\\frac{\\eta g_1}{\\sqrt{s_1}}=\\frac{0.1(2)}{\\sqrt{0.4}}\\approx0.316227766\" width=\"321.06\" height=\"60.60\" style=\"width:321.06px;height:60.60px;aspect-ratio:321.06/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update the parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.76px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46ce5315f0e4b144.svg\"><img class=\"math display-math\" src=\"assets/equations/67ba0f8d71ab9792.svg\" alt=\"\\theta_1=1-0.316227766\\approx0.683772234\" width=\"387.31\" height=\"20.89\" style=\"width:387.31px;height:20.89px;aspect-ratio:387.31/20.89\" loading=\"lazy\"></picture></div>","<p><strong>Iteration 2 — step 1: use s₁, not the original zero state.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a780b29bab6859eb.svg\"><img class=\"math display-math\" src=\"assets/equations/e9da8c8b2ad0696a.svg\" alt=\"s_2=0.9(0.4)+0.1(1^2)=0.46\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the denominator and signed correction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10263e4a8476b1fa.svg\"><img class=\"math display-math\" src=\"assets/equations/ae7e6b23e0aacbac.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.46}\\approx0.678232998\" width=\"301.38\" height=\"30.34\" style=\"width:301.38px;height:30.34px;aspect-ratio:301.38/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ce8864a56ffdc251.svg\"><img class=\"math display-math\" src=\"assets/equations/8d403055f469e062.svg\" alt=\"\\frac{\\eta g_2}{\\sqrt{s_2}}=\\frac{0.1(1)}{\\sqrt{0.46}}\\approx0.147441956\" width=\"322.89\" height=\"60.60\" style=\"width:322.89px;height:60.60px;aspect-ratio:322.89/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update from θ₁, retaining calculator precision.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.68px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd5064d2dd1b316c.svg\"><img class=\"math display-math\" src=\"assets/equations/7aa9a16e4306403f.svg\" alt=\"\\theta_2\\approx0.683772234-0.147441956\\approx0.536330278\" width=\"504.06\" height=\"20.89\" style=\"width:504.06px;height:20.89px;aspect-ratio:504.06/20.89\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> θ₁ ≈ 0.683772 and θ₂ ≈ 0.536330; s₁ = 0.4 and s₂ = 0.46.</p>","<h3>Comparison with AdaGrad and Adam</h3>","<p>AdaGrad stores an unweighted cumulative sum; RMSProp stores a decaying average. Basic RMSProp has no separate first-moment average and no Adam-style bias correction. With zero initialization, the early RMSProp state can therefore be much smaller than the first squared gradient, which explains the relatively large first correction in this example. The method still requires appropriate learning-rate and decay choices; adaptive scaling does not guarantee convergence to a global optimum.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s13","search":"RMSProp remembers recent squared gradients \n**Definition.** RMSProp is an adaptive optimizer that normalizes the current gradient by the root of an exponentially weighted moving average of squared gradients. Its decaying history addresses AdaGrad's permanently growing accumulator.\n\n### Recurrence and interpretation\nUsing decay β and zero initial state:\n\n\nβ is the fraction of the previous squared-gradient average retained, not a signed velocity. Some papers use ρ for this same decay. The square is applied to the gradient before averaging; the square root is applied to the resulting average in the update.\n\nIf recent squared gradients are smaller than the old average, s can decrease. Thus older large gradients do not remain in the denominator with their original weight forever.\n\n\n\n### Complete numerical: two iterations\n**Question.** θ₀ = 1, s₀ = 0, η = 0.1, β = 0.9; supplied gradients are 2 then 1. Perform two RMSProp updates, with ε = 0 for this hand calculation.\n\n\n\n### Given\n\nθ₀ = 1; initial state(s) = 0; η = 0.1.\n\nSupplied gradients g₁ = 2, g₂ = 1.\n\nε = 0 for this hand calculation.\n\nβ = 0.9.\n\n### To find\n\nCalculate all required states and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**RMSProp.** Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.\n\ns = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.\n\n\n\n\n\n**Yaad rakhne ka cue:** Saare purane squares nahi—unki fading average.\n\n### Solution — step by step\n\n\n\n\n\n**Iteration 1 — step 1: calculate the squared-gradient average.**\n\n**Step 2: calculate the denominator and signed correction.**\n\n\n**Step 3: update the parameter.**\n\n\n**Iteration 2 — step 1: use s₁, not the original zero state.**\n\n**Step 2: calculate the denominator and signed correction.**\n\n\n**Step 3: update from θ₁, retaining calculator precision.**\n\n\n**Final answer:** θ₁ ≈ 0.683772 and θ₂ ≈ 0.536330; s₁ = 0.4 and s₂ = 0.46.\n\n### Comparison with AdaGrad and Adam\nAdaGrad stores an unweighted cumulative sum; RMSProp stores a decaying average. Basic RMSProp has no separate first-moment average and no Adam-style bias correction. With zero initialization, the early RMSProp state can therefore be much smaller than the first squared gradient, which explains the relatively large first correction in this example. The method still requires appropriate learning-rate and decay choices; adaptive scaling does not guarantee convergence to a global optimum.\n\n"},{"title":"Adam remembers both direction and squared size","blocks":["<p class=\"definition\"><strong>Definition.</strong> Adam, or adaptive moment estimation, uses bias-corrected exponentially weighted estimates of the first moment and the uncentered second moment of gradients to calculate parameter-specific updates.</p>","<h3>What the two states represent</h3>","<div class=\"table-scroll\"><table><thead><tr><th>State or coefficient</th><th>Meaning</th></tr></thead><tbody><tr><td>mₜ</td><td>Moving average of signed gradients; retains directional information</td></tr><tr><td>sₜ</td><td>Moving average of squared gradients; estimates their uncentered second moment</td></tr><tr><td>β₁</td><td>Decay coefficient for the first-moment estimate</td></tr><tr><td>β₂</td><td>Decay coefficient for the second-moment estimate</td></tr><tr><td>t</td><td>Update number, starting at 1 for the first update</td></tr><tr><td>η and ε</td><td>Base learning rate and small denominator stabilizer</td></tr></tbody></table></div>","<p>The second moment is not the variance: it averages g² without subtracting a mean. Both states start at zero unless specified otherwise. These notes use s throughout this lesson; texts that use v for Adam&#x27;s second moment mean the same state, not momentum&#x27;s displacement velocity.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adam.svg\" aria-label=\"Enlarge diagram: The current gradient feeds two distinct estimates. Correct both estimates before combining direction and scale in the parameter update.\"><img src=\"assets/figures/v_adam.svg\" alt=\"The current gradient feeds two distinct estimates. Correct both estimates before combining direction and scale in the parameter update.\" width=\"1080\" height=\"710\" loading=\"lazy\"></button><figcaption>The current gradient feeds two distinct estimates. Correct both estimates before combining direction and scale in the parameter update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Recurrences, bias correction and update</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<p>Zero initialization reduces the total weight initially attached to observed gradients. Divide by the appropriate accumulated observation weight:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<p>The update uses the corrected signed average in the numerator and the root of the corrected squared-gradient average in the denominator:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ada7a51c96cfce92.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\varepsilon}\" width=\"220.64\" height=\"66.12\" style=\"width:220.64px;height:66.12px;aspect-ratio:220.64/66.12\" loading=\"lazy\"></div>","<p>The derivation in the next lesson explains why the correction factors contain powers of the iteration number. No additional multiplication by gₜ belongs in this final update: its contribution is already inside mₜ.</p>","<h3>Complete numerical: changing gradient magnitude</h3>","<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, m₀ = s₀ = 0, η = 0.1, β₁ = 0.9, β₂ = 0.999. Given g₁ = 2 and g₂ = 1, find two Adam updates, neglecting epsilon only in the numerical arithmetic.</p>","<h3>Given</h3>","<p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p>","<p>Supplied gradients g₁ = 2, g₂ = 1.</p>","<p>ε = 0 for this hand calculation.</p>","<p>β₁ = 0.9; β₂ = 0.999; use bias correction.</p>","<h3>To find</h3>","<p>Calculate all required states and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Adam with bias correction.</strong> Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.</p>","<p>m = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1b0801ea4c5e3b1.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\epsilon}\" width=\"219.18\" height=\"66.12\" style=\"width:219.18px;height:66.12px;aspect-ratio:219.18/66.12\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Direction memory + square memory; hats lagao, phir update.</p>","<h3>Solution — step by step</h3>","<p><strong>Iteration 1 — step 1: update the two raw states.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ac027abcdfcdb75.svg\" alt=\"m_1=0.9(0)+0.1(2)=0.2\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/664a8100f810d926.svg\"><img class=\"math display-math\" src=\"assets/equations/81bd015faf03cb0a.svg\" alt=\"s_1=0.999(0)+0.001(2^2)=0.004\" width=\"357.27\" height=\"27.70\" style=\"width:357.27px;height:27.70px;aspect-ratio:357.27/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: correct both states using t = 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/daa0ad010127bd94.svg\" alt=\"\\hat m_1=\\frac{0.2}{1-0.9^1}=\\frac{0.2}{0.1}=2\" width=\"278.80\" height=\"54.93\" style=\"width:278.80px;height:54.93px;aspect-ratio:278.80/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:173.88px;--narrow-height:120.21px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e60fd90ed8957afb.svg\"><img class=\"math display-math\" src=\"assets/equations/ffb98ca5eb20d577.svg\" alt=\"\\hat s_1=\\frac{0.004}{1-0.999^1}=\\frac{0.004}{0.001}=4\" width=\"317.68\" height=\"55.20\" style=\"width:317.68px;height:55.20px;aspect-ratio:317.68/55.20\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: update the parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd2c0d46e60db2c0.svg\" alt=\"\\theta_1=1-\\frac{0.1(2)}{\\sqrt4}=0.9\" width=\"233.82\" height=\"60.60\" style=\"width:233.82px;height:60.60px;aspect-ratio:233.82/60.60\" loading=\"lazy\"></div>","<figure class=\"learning-visual lv-adam\" data-visual=\"adam\"><figcaption class=\"lv-title\">Adam iteration 1: follow the two state calculations</figcaption><p class=\"lv-instruction\">Start with the current gradient and the two states saved from the previous iteration.</p><div class=\"lv-input-states\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Current gradient</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">g1</span></div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Previous raw m</span><strong class=\"lv-value\">0</strong></div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Previous raw s</span><strong class=\"lv-value\">0</strong></div></div><div class=\"lv-adam-branches\"><div class=\"lv-adam-branch\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Signed average m1</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-input\"><span class=\"lv-label\">Bias-corrected m̂1</span><strong class=\"lv-value\">2</strong></div></div><div class=\"lv-adam-branch\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Squared-gradient average s1</span><strong class=\"lv-value\">0.004</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias-corrected ŝ1</span><strong class=\"lv-value\">4</strong></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Combine: ηm̂ / √ŝ</span><strong class=\"lv-value\">0.1</strong><span class=\"lv-detail\">ε is neglected for this specific numerical.</span></div></div><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old θ</span><strong class=\"lv-value\">1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New θ</span><strong class=\"lv-value\">0.9</strong></div></div><p class=\"lv-memory-line\"><b>Carry forward raw states:</b> m = 0.2, s = 0.004. The corrected values are used for this update.</p></figure>","<p><strong>Iteration 2 — step 1: carry forward the raw states m₁ and s₁.</strong></p>","<p>The recurrence uses the raw states 0.2 and 0.004, not the corrected values 2 and 4.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6a9a858d7c18aeb.svg\"><img class=\"math display-math\" src=\"assets/equations/4f47b7aabd4f81c4.svg\" alt=\"m_2=0.9(0.2)+0.1(1)=0.28\" width=\"314.52\" height=\"24.43\" style=\"width:314.52px;height:24.43px;aspect-ratio:314.52/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.32px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/528b23a17d8f719c.svg\"><img class=\"math display-math\" src=\"assets/equations/442e6bd08bfece88.svg\" alt=\"s_2=0.999(0.004)+0.001(1^2)=0.004996\" width=\"437.37\" height=\"27.70\" style=\"width:437.37px;height:27.70px;aspect-ratio:437.37/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: correct both states using t = 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.31px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0416e7f741fa3055.svg\"><img class=\"math display-math\" src=\"assets/equations/457ac955a89f3be2.svg\" alt=\"1-0.9^2=0.19,\\qquad1-0.999^2=0.001999\" width=\"453.06\" height=\"26.34\" style=\"width:453.06px;height:26.34px;aspect-ratio:453.06/26.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3d16280e17e8b649.svg\" alt=\"\\hat m_2=\\frac{0.28}{0.19}\\approx1.473684211\" width=\"280.45\" height=\"50.09\" style=\"width:280.45px;height:50.09px;aspect-ratio:280.45/50.09\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a22ef3b407f486c3.svg\"><img class=\"math display-math\" src=\"assets/equations/3d1151d9e31acb34.svg\" alt=\"\\hat s_2=\\frac{0.004996}{0.001999}\\approx2.499249625\" width=\"319.32\" height=\"50.36\" style=\"width:319.32px;height:50.36px;aspect-ratio:319.32/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: divide the corrected first moment by the corrected root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.53px;--narrow-height:180.47px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d8416409081efc8e.svg\"><img class=\"math display-math\" src=\"assets/equations/c636739e003f73e5.svg\" alt=\"\\frac{\\eta\\hat m_2}{\\sqrt{\\hat s_2}}\\approx\\frac{0.1(1.473684211)}{\\sqrt{2.499249625}}\\approx0.093217964\" width=\"441.89\" height=\"66.12\" style=\"width:441.89px;height:66.12px;aspect-ratio:441.89/66.12\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: update from θ₁.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c55d4ff26b9e4b3.svg\"><img class=\"math display-math\" src=\"assets/equations/60970554f64b5b60.svg\" alt=\"\\theta_2\\approx0.9-0.093217964\\approx0.806782036\" width=\"406.32\" height=\"20.89\" style=\"width:406.32px;height:20.89px;aspect-ratio:406.32/20.89\" loading=\"lazy\"></picture></div>","<figure class=\"learning-visual lv-adam\" data-visual=\"adam\"><figcaption class=\"lv-title\">Adam iteration 2: follow the two state calculations</figcaption><p class=\"lv-instruction\">Start with the current gradient and the two states saved from the previous iteration.</p><div class=\"lv-input-states\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Current gradient</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">g2</span></div><div class=\"lv-card lv-input\"><span class=\"lv-label\">Previous raw m</span><strong class=\"lv-value\">0.2</strong></div><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Previous raw s</span><strong class=\"lv-value\">0.004</strong></div></div><div class=\"lv-adam-branches\"><div class=\"lv-adam-branch\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Signed average m2</span><strong class=\"lv-value\">0.28</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-input\"><span class=\"lv-label\">Bias-corrected m̂2</span><strong class=\"lv-value\">1.473684211</strong></div></div><div class=\"lv-adam-branch\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Squared-gradient average s2</span><strong class=\"lv-value\">0.004996</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">↓</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Bias-corrected ŝ2</span><strong class=\"lv-value\">2.499249625</strong></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Combine: ηm̂ / √ŝ</span><strong class=\"lv-value\">0.093217964</strong><span class=\"lv-detail\">ε is neglected for this specific numerical.</span></div></div><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old θ</span><strong class=\"lv-value\">0.9</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New θ</span><strong class=\"lv-value\">0.806782036</strong></div></div><p class=\"lv-memory-line\"><b>Carry forward raw states:</b> m = 0.28, s = 0.004996. The corrected values are used for this update.</p></figure>","<div class=\"table-scroll\"><table><thead><tr><th>State</th><th>After iteration 1</th><th>After iteration 2</th></tr></thead><tbody><tr><td>Raw first moment m</td><td>0.2</td><td>0.28</td></tr><tr><td>Raw second moment s</td><td>0.004</td><td>0.004996</td></tr><tr><td>Corrected first moment</td><td>2</td><td>1.473684211</td></tr><tr><td>Corrected second moment</td><td>4</td><td>2.499249625</td></tr><tr><td>Parameter θ</td><td>0.9</td><td>0.806782036</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ ≈ 0.806782. Store the raw moments for the next recurrence and use the corrected moments for the current parameter update.</p>","<h3>Properties and limitations</h3>","<p>Adam combines directional averaging with coordinate-specific scaling, which can be useful with noisy or differently scaled gradients. It requires two state values per parameter in addition to the parameter itself. η, β₁, β₂ and ε remain hyperparameters. Faster reduction of training loss does not establish better generalization, and Adam does not guarantee the global optimum of a general neural-network objective.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s14","search":"Adam remembers both direction and squared size \n**Definition.** Adam, or adaptive moment estimation, uses bias-corrected exponentially weighted estimates of the first moment and the uncentered second moment of gradients to calculate parameter-specific updates.\n\n### What the two states represent\n| State or coefficient | Meaning |\n| mₜ | Moving average of signed gradients; retains directional information |\n| sₜ | Moving average of squared gradients; estimates their uncentered second moment |\n| β₁ | Decay coefficient for the first-moment estimate |\n| β₂ | Decay coefficient for the second-moment estimate |\n| t | Update number, starting at 1 for the first update |\n| η and ε | Base learning rate and small denominator stabilizer |\n\nThe second moment is not the variance: it averages g² without subtracting a mean. Both states start at zero unless specified otherwise. These notes use s throughout this lesson; texts that use v for Adam's second moment mean the same state, not momentum's displacement velocity.\n\n\n\n### Recurrences, bias correction and update\n\n\nZero initialization reduces the total weight initially attached to observed gradients. Divide by the appropriate accumulated observation weight:\n\n\nThe update uses the corrected signed average in the numerator and the root of the corrected squared-gradient average in the denominator:\n\nThe derivation in the next lesson explains why the correction factors contain powers of the iteration number. No additional multiplication by gₜ belongs in this final update: its contribution is already inside mₜ.\n\n### Complete numerical: changing gradient magnitude\n**Question.** θ₀ = 1, m₀ = s₀ = 0, η = 0.1, β₁ = 0.9, β₂ = 0.999. Given g₁ = 2 and g₂ = 1, find two Adam updates, neglecting epsilon only in the numerical arithmetic.\n\n\n\n### Given\n\nθ₀ = 1; initial state(s) = 0; η = 0.1.\n\nSupplied gradients g₁ = 2, g₂ = 1.\n\nε = 0 for this hand calculation.\n\nβ₁ = 0.9; β₂ = 0.999; use bias correction.\n\n### To find\n\nCalculate all required states and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Adam with bias correction.** Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.\n\nm = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Direction memory + square memory; hats lagao, phir update.\n\n### Solution — step by step\n\n\n\n\n\n**Iteration 1 — step 1: update the two raw states.**\n\n\n**Step 2: correct both states using t = 1.**\n\n\n**Step 3: update the parameter.**\n\n\n**Iteration 2 — step 1: carry forward the raw states m₁ and s₁.**\nThe recurrence uses the raw states 0.2 and 0.004, not the corrected values 2 and 4.\n\n\n**Step 2: correct both states using t = 2.**\n\n\n\n**Step 3: divide the corrected first moment by the corrected root.**\n\n**Step 4: update from θ₁.**\n\n\n| State | After iteration 1 | After iteration 2 |\n| Raw first moment m | 0.2 | 0.28 |\n| Raw second moment s | 0.004 | 0.004996 |\n| Corrected first moment | 2 | 1.473684211 |\n| Corrected second moment | 4 | 2.499249625 |\n| Parameter θ | 0.9 | 0.806782036 |\n\n**Final answer:** θ₁ = 0.9 and θ₂ ≈ 0.806782. Store the raw moments for the next recurrence and use the corrected moments for the current parameter update.\n\n### Properties and limitations\nAdam combines directional "},{"title":"Adam bias correction: why the denominator is one minus beta to a power","blocks":["<p class=\"definition\"><strong>Definition.</strong> Bias correction compensates for the reduced total observation weight caused by initializing an exponentially weighted accumulator to zero. Under a stationary gradient expectation, it removes the corresponding initialization bias in the moment estimate.</p>","<h3>Explanation and working</h3>","<h3>1. What the moving average actually contains</h3>","<p>Adam&#x27;s signed-gradient memory is m. Starting with m₀ = 0 and β = 0.9, the first average is 90% of zero plus 10% of the first gradient. If g₁ = 2, then m₁ = 0.2. That small value partly reflects the artificial zero initialization.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adam_correction.svg\" aria-label=\"Enlarge diagram: The first raw average is pulled toward its starting zero. Divide by the missing-weight correction factor.\"><img src=\"assets/figures/v_adam_correction.svg\" alt=\"The first raw average is pulled toward its starting zero. Divide by the missing-weight correction factor.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The first raw average is pulled toward its starting zero. Divide by the missing-weight correction factor. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/311f8a66ba1558a5.svg\" alt=\"m_1=(1-\\beta)g_1\" width=\"161.96\" height=\"24.43\" style=\"width:161.96px;height:24.43px;aspect-ratio:161.96/24.43\" loading=\"lazy\"></div>","<p>At the second step, substitute the first expression into the recurrence:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:175.78px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5bd41b82ae93376.svg\"><img class=\"math display-math\" src=\"assets/equations/8ca813db07725b2e.svg\" alt=\"m_2=\\beta(1-\\beta)g_1+(1-\\beta)g_2\" width=\"302.90\" height=\"24.43\" style=\"width:302.90px;height:24.43px;aspect-ratio:302.90/24.43\" loading=\"lazy\"></picture></div>","<h3>2. Add the coefficients</h3>","<p>After the first step, the total coefficient attached to observed gradients is 1 − β. After two steps it is β(1 − β) + (1 − β). Factor out the common term:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.24px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4c68b61c5bdf0798.svg\"><img class=\"math display-math\" src=\"assets/equations/420fad46aabea894.svg\" alt=\"\\beta(1-\\beta)+(1-\\beta)=(1-\\beta)(1+\\beta)=1-\\beta^2\" width=\"475.16\" height=\"27.70\" style=\"width:475.16px;height:27.70px;aspect-ratio:475.16/27.70\" loading=\"lazy\"></picture></div>","<p>After t steps the coefficients sum to 1 − βᵗ. Dividing the stored average by that quantity removes this zero-start coefficient deficit.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4c24c9160cc537a1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<p>The squared-gradient memory uses its own decay β₂ and the same reasoning:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3ebf23cb24a812d.svg\" alt=\"\\widehat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<h3>3. A constant-gradient example makes the purpose visible</h3>","<p>Let both gradients be 2 and use β₁ = 0.9. The first raw mean is 0.2; the second is 0.9 × 0.2 + 0.1 × 2 = 0.38.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/95360064605e4687.svg\" alt=\"\\widehat m_1=\\frac{0.2}{1-0.9}=2\" width=\"193.57\" height=\"51.56\" style=\"width:193.57px;height:51.56px;aspect-ratio:193.57/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.22px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/569c2f898bf0d2e3.svg\"><img class=\"math display-math\" src=\"assets/equations/8560767b69d9e851.svg\" alt=\"\\widehat m_2=\\frac{0.38}{1-0.9^2}=\\frac{0.38}{0.19}=2\" width=\"291.02\" height=\"54.93\" style=\"width:291.02px;height:54.93px;aspect-ratio:291.02/54.93\" loading=\"lazy\"></picture></div>","<p>Both corrected values now equal the constant observed gradient. If gradients differ over time, the corrected result is a weighted average, not necessarily the latest gradient.</p>","<h3>4. Two betas mean two separate powers</h3>","<p>At update 2 with β₁ = 0.9 and β₂ = 0.999, the first correction denominator is 1 − 0.9² = 0.19. The second is 1 − 0.999² = 0.001999. Do not use 0.19 for both memories, and do not keep using the first-step denominators.</p>","<h3>5. Correct first, then combine</h3>","<p>The parameter update uses the corrected signed mean divided by the square root of the corrected squared mean, plus ε in the stated position. The square root is taken after correcting s. The numerator is not the loss, and no extra multiplication by g follows.</p>","<p>This derivation explains the formula; the following solved Adam examples show the complete arithmetic when gradients change sign or magnitude.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s15","search":"Adam bias correction: why the denominator is one minus beta to a power **Definition.** Bias correction compensates for the reduced total observation weight caused by initializing an exponentially weighted accumulator to zero. Under a stationary gradient expectation, it removes the corresponding initialization bias in the moment estimate.\n\n### Explanation and working\n### 1. What the moving average actually contains\nAdam's signed-gradient memory is m. Starting with m₀ = 0 and β = 0.9, the first average is 90% of zero plus 10% of the first gradient. If g₁ = 2, then m₁ = 0.2. That small value partly reflects the artificial zero initialization.\n\n\n\n\nAt the second step, substitute the first expression into the recurrence:\n\n### 2. Add the coefficients\nAfter the first step, the total coefficient attached to observed gradients is 1 − β. After two steps it is β(1 − β) + (1 − β). Factor out the common term:\n\nAfter t steps the coefficients sum to 1 − βᵗ. Dividing the stored average by that quantity removes this zero-start coefficient deficit.\n\nThe squared-gradient memory uses its own decay β₂ and the same reasoning:\n\n\n### 3. A constant-gradient example makes the purpose visible\nLet both gradients be 2 and use β₁ = 0.9. The first raw mean is 0.2; the second is 0.9 × 0.2 + 0.1 × 2 = 0.38.\n\n\nBoth corrected values now equal the constant observed gradient. If gradients differ over time, the corrected result is a weighted average, not necessarily the latest gradient.\n\n### 4. Two betas mean two separate powers\nAt update 2 with β₁ = 0.9 and β₂ = 0.999, the first correction denominator is 1 − 0.9² = 0.19. The second is 1 − 0.999² = 0.001999. Do not use 0.19 for both memories, and do not keep using the first-step denominators.\n\n### 5. Correct first, then combine\nThe parameter update uses the corrected signed mean divided by the square root of the corrected squared mean, plus ε in the stated position. The square root is taken after correcting s. The numerator is not the loss, and no extra multiplication by g follows.\nThis derivation explains the formula; the following solved Adam examples show the complete arithmetic when gradients change sign or magnitude.\n"},{"title":"Model answer: AdaGrad, RMSProp and Adam","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare AdaGrad, RMSProp and Adam. Explain what each method stores and how that memory changes a parameter update.</p>"],"answer":["<p>AdaGrad, RMSProp and Adam are adaptive gradient-based optimizers. Each stores separate state for each trainable parameter and uses that state to scale its update. Let gₜ be the current gradient for parameter θ, η the base learning rate and ε a small positive stabilizer. The equations below put ε outside the square root.</p>","<h3>AdaGrad: cumulative squared-gradient history</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/32f05266b341eaa2.svg\" alt=\"s_t=s_{t-1}+g_t^2\" width=\"146.31\" height=\"27.82\" style=\"width:146.31px;height:27.82px;aspect-ratio:146.31/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Starting at s₀ = 0, every squared gradient contributes permanently. Parameters with frequent large gradients acquire smaller effective learning rates. This can be useful for sparse features, but the growing denominator can make later updates too small. The base learning rate still has to be chosen.</p>","<h3>RMSProp: a decaying squared-gradient average</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b2de5dc1fbe8c99.svg\" alt=\"s_t=\\beta s_{t-1}+(1-\\beta)g_t^2\" width=\"235.06\" height=\"27.82\" style=\"width:235.06px;height:27.82px;aspect-ratio:235.06/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Old contributions decay by repeated multiplication by β. The state can decrease when recent squared gradients are small, avoiding AdaGrad&#x27;s permanent accumulation. Basic RMSProp has one squared-gradient state and no separate signed-gradient average.</p>","<h3>Adam: first and second moments with bias correction</h3>","<p>Initialize m₀ = s₀ = 0 and count the first update as t = 1:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.17px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a84b9734c9141df3.svg\"><img class=\"math display-math\" src=\"assets/equations/eddaf3b9789092ac.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"329.01\" height=\"53.25\" style=\"width:329.01px;height:53.25px;aspect-ratio:329.01/53.25\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ada7a51c96cfce92.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\varepsilon}\" width=\"220.64\" height=\"66.12\" style=\"width:220.64px;height:66.12px;aspect-ratio:220.64/66.12\" loading=\"lazy\"></div>","<p>The first moment stores signed directional information; the second stores squared-gradient scale. Correction compensates for their zero initialization. The corrected first moment is already the numerator&#x27;s gradient estimate, so the update is not multiplied by gₜ again. Raw moments are carried into the next iteration.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Aspect</th><th>AdaGrad</th><th>RMSProp</th><th>Adam</th></tr></thead><tbody><tr><td>Squared-gradient history</td><td>Cumulative sum</td><td>Decaying average</td><td>Decaying average</td></tr><tr><td>Separate signed-gradient average</td><td>No</td><td>No in the basic method</td><td>Yes</td></tr><tr><td>Standard initialization correction</td><td>No</td><td>No in the basic method</td><td>Corrects both moments</td></tr><tr><td>State values per parameter</td><td>One</td><td>One</td><td>Two</td></tr><tr><td>Main concern</td><td>Effective rate can become very small</td><td>Learning rate and decay need tuning</td><td>More state; hyperparameters still matter</td></tr></tbody></table></div>","<p>All three adapt updates coordinate by coordinate. None removes the need for validation or guarantees a global minimum for a general neural-network objective.</p>"],"kind":"theory","id":"tee-c5-s16","search":"Model answer: AdaGrad, RMSProp and Adam \n**Question.** Compare AdaGrad, RMSProp and Adam. Explain what each method stores and how that memory changes a parameter update.\n\n**Model answer.**\nAdaGrad, RMSProp and Adam are adaptive gradient-based optimizers. Each stores separate state for each trainable parameter and uses that state to scale its update. Let gₜ be the current gradient for parameter θ, η the base learning rate and ε a small positive stabilizer. The equations below put ε outside the square root.\n\n### AdaGrad: cumulative squared-gradient history\n\n\nStarting at s₀ = 0, every squared gradient contributes permanently. Parameters with frequent large gradients acquire smaller effective learning rates. This can be useful for sparse features, but the growing denominator can make later updates too small. The base learning rate still has to be chosen.\n\n### RMSProp: a decaying squared-gradient average\n\n\nOld contributions decay by repeated multiplication by β. The state can decrease when recent squared gradients are small, avoiding AdaGrad's permanent accumulation. Basic RMSProp has one squared-gradient state and no separate signed-gradient average.\n\n### Adam: first and second moments with bias correction\nInitialize m₀ = s₀ = 0 and count the first update as t = 1:\n\n\n\n\nThe first moment stores signed directional information; the second stores squared-gradient scale. Correction compensates for their zero initialization. The corrected first moment is already the numerator's gradient estimate, so the update is not multiplied by gₜ again. Raw moments are carried into the next iteration.\n\n| Aspect | AdaGrad | RMSProp | Adam |\n| Squared-gradient history | Cumulative sum | Decaying average | Decaying average |\n| Separate signed-gradient average | No | No in the basic method | Yes |\n| Standard initialization correction | No | No in the basic method | Corrects both moments |\n| State values per parameter | One | One | Two |\n| Main concern | Effective rate can become very small | Learning rate and decay need tuning | More state; hyperparameters still matter |\n\nAll three adapt updates coordinate by coordinate. None removes the need for validation or guarantees a global minimum for a general neural-network objective.\n\n"},{"title":"One comparison to rebuild all optimizer formulas","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>What is remembered</th><th>What changes the step</th></tr></thead><tbody><tr><td>GD or SGD</td><td>No optimizer memory in the basic rule</td><td>Current gradient × η</td></tr><tr><td>Momentum</td><td>Previous movement</td><td>Old velocity plus current correction</td></tr><tr><td>Nesterov</td><td>Previous movement</td><td>Gradient evaluated at lookahead</td></tr><tr><td>AdaGrad</td><td>Sum of all squared gradients</td><td>Divide current gradient by accumulated root</td></tr><tr><td>RMSProp</td><td>Moving average of squared gradients</td><td>Divide current gradient by recent root</td></tr><tr><td>Adam</td><td>Moving averages of gradients and squares</td><td>Divide corrected mean by corrected root</td></tr></tbody></table></div>","<p><strong>Working order.</strong> Start each method on a separate line with its states initialized. The solved examples use the same supplied gradients to show how their stored states differ. They do not have to give the same parameter value. The prescribed gradient sequence is practice data; if a question instead gives J(θ), recalculate its gradient at the appropriate current or lookahead parameter.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad_rms.svg\" aria-label=\"Enlarge diagram: Compare the memory rules first. Then use the matching memory in the denominator of the update.\"><img src=\"assets/figures/v_adagrad_rms.svg\" alt=\"Compare the memory rules first. Then use the matching memory in the denominator of the update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Compare the memory rules first. Then use the matching memory in the denominator of the update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s17","search":"One comparison to rebuild all optimizer formulas | Method | What is remembered | What changes the step |\n| GD or SGD | No optimizer memory in the basic rule | Current gradient × η |\n| Momentum | Previous movement | Old velocity plus current correction |\n| Nesterov | Previous movement | Gradient evaluated at lookahead |\n| AdaGrad | Sum of all squared gradients | Divide current gradient by accumulated root |\n| RMSProp | Moving average of squared gradients | Divide current gradient by recent root |\n| Adam | Moving averages of gradients and squares | Divide corrected mean by corrected root |\n**Working order.** Start each method on a separate line with its states initialized. The solved examples use the same supplied gradients to show how their stored states differ. They do not have to give the same parameter value. The prescribed gradient sequence is practice data; if a question instead gives J(θ), recalculate its gradient at the appropriate current or lookahead parameter.\n\n\n"},{"title":"AdaGrad and RMSProp with a negative gradient","blocks":["<p>The gradient has a sign, but its square is nonnegative. Both methods store squared gradients to control update size. The signed gradient is still used separately in the update numerator to preserve direction.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad_rms.svg\" aria-label=\"Enlarge diagram: The gradient sign remains in the numerator. Its square contributes a nonnegative value to the memory.\"><img src=\"assets/figures/v_adagrad_rms.svg\" alt=\"The gradient sign remains in the numerator. Its square contributes a nonnegative value to the memory.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The gradient sign remains in the numerator. Its square contributes a nonnegative value to the memory. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For an old stored state of 4 and a new gradient of −3, first square the gradient: (−3) × (−3) = 9.</p>","<p><strong>AdaGrad:</strong> add the new square to the entire old sum: 4 + 9 = 13.</p>","<p><strong>RMSProp with decay 0.9:</strong> keep 0.9 × 4 = 3.6 of the old state; add (1 − 0.9) × 9 = 0.1 × 9 = 0.9 of the new square. The new state is 3.6 + 0.9 = 4.5.</p>","<p>AdaGrad retains all earlier squares in a growing sum. RMSProp gradually discounts earlier squares. This difference explains why their effective step sizes change differently during training.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c5-s18","search":"AdaGrad and RMSProp with a negative gradient The gradient has a sign, but its square is nonnegative. Both methods store squared gradients to control update size. The signed gradient is still used separately in the update numerator to preserve direction.\n\n\n\nFor an old stored state of 4 and a new gradient of −3, first square the gradient: (−3) × (−3) = 9.\n**AdaGrad:** add the new square to the entire old sum: 4 + 9 = 13.\n**RMSProp with decay 0.9:** keep 0.9 × 4 = 3.6 of the old state; add (1 − 0.9) × 9 = 0.1 × 9 = 0.9 of the new square. The new state is 3.6 + 0.9 = 4.5.\nAdaGrad retains all earlier squares in a growing sum. RMSProp gradually discounts earlier squares. This difference explains why their effective step sizes change differently during training.\n"}]},{"n":6,"title":"Regularization and generalization","sections":[{"title":"Recognizing overfitting and underfitting","blocks":["<p class=\"definition\"><strong>Definitions.</strong> Generalization is a model&#x27;s ability to perform on unseen examples from the relevant task distribution. Underfitting occurs when the model fails to capture the task&#x27;s important relationships. Overfitting occurs when fitting the training data produces substantially poorer generalization, often by modeling noise or incidental details.</p>","<h3>Interpreting learning curves</h3>","<p>Underfitting commonly gives high training and validation errors. Overfitting commonly gives low training error with a substantially higher validation error, or validation loss that rises while training loss continues to fall. These patterns are diagnostic clues; distribution shift, leakage and an unrepresentative split can also affect the curves.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/overfitting.svg\" aria-label=\"Enlarge diagram: Compare training and validation behavior when selecting model capacity or a stopping point.\"><img src=\"assets/figures/overfitting.svg\" alt=\"Compare training and validation behavior when selecting model capacity or a stopping point.\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Compare training and validation behavior when selecting model capacity or a stopping point. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Observation</th><th>Plausible explanation</th><th>Appropriate response</th></tr></thead><tbody><tr><td>Both errors remain high</td><td>Insufficient capacity, weak features or inadequate optimization</td><td>Improve representation, train appropriately, reconsider architecture or reduce excessive regularization</td></tr><tr><td>Training error low; validation error high</td><td>Overfitting or a distribution/split problem</td><td>Inspect the split; use suitable regularization, more representative data or early stopping</td></tr><tr><td>Both losses fluctuate or diverge</td><td>Optimization instability</td><td>Examine learning rate, data scaling and gradient magnitude</td></tr></tbody></table></div>","<h3>Bias–variance perspective</h3>","<p>Insufficient model flexibility can create high approximation bias. A highly flexible model can be sensitive to the particular training sample, increasing variance. Regularization trades some training fit for constraints that can improve generalization. A more complex network is not automatically more accurate on unseen data.</p>","<p>The validation set is used to choose hyperparameters and checkpoints. The test set should remain outside these choices. Repeatedly selecting models from test results turns the test data into part of the selection process and weakens its role as an unbiased final evaluation.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c6-s0","search":"Recognizing overfitting and underfitting **Definitions.** Generalization is a model's ability to perform on unseen examples from the relevant task distribution. Underfitting occurs when the model fails to capture the task's important relationships. Overfitting occurs when fitting the training data produces substantially poorer generalization, often by modeling noise or incidental details.\n\n### Interpreting learning curves\nUnderfitting commonly gives high training and validation errors. Overfitting commonly gives low training error with a substantially higher validation error, or validation loss that rises while training loss continues to fall. These patterns are diagnostic clues; distribution shift, leakage and an unrepresentative split can also affect the curves.\n\n\n\n| Observation | Plausible explanation | Appropriate response |\n| Both errors remain high | Insufficient capacity, weak features or inadequate optimization | Improve representation, train appropriately, reconsider architecture or reduce excessive regularization |\n| Training error low; validation error high | Overfitting or a distribution/split problem | Inspect the split; use suitable regularization, more representative data or early stopping |\n| Both losses fluctuate or diverge | Optimization instability | Examine learning rate, data scaling and gradient magnitude |\n\n### Bias–variance perspective\nInsufficient model flexibility can create high approximation bias. A highly flexible model can be sensitive to the particular training sample, increasing variance. Regularization trades some training fit for constraints that can improve generalization. A more complex network is not automatically more accurate on unseen data.\n\nThe validation set is used to choose hyperparameters and checkpoints. The test set should remain outside these choices. Repeatedly selecting models from test results turns the test data into part of the selection process and weakens its role as an unbiased final evaluation.\n"},{"title":"L1 and L2 add a cost for large weights","blocks":["<p class=\"definition\"><strong>Definition.</strong> Regularization modifies a training objective or learning procedure to constrain the fitted model and improve generalization. L1 and L2 regularization add parameter-norm penalties to the data loss.</p>","<h3>Explanation and working</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:119.35px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/73a39a472fd87b8c.svg\"><img class=\"math display-math\" src=\"assets/equations/e5d7bc3aa72256c3.svg\" alt=\"J_{L1}=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|,\\qquad J_{L2}=J_{\\mathrm{data}}+\\lambda\\sum_iw_i^2\" width=\"537.60\" height=\"52.35\" style=\"width:537.60px;height:52.35px;aspect-ratio:537.60/52.35\" loading=\"lazy\"></picture></div>","<p>Lambda controls how strongly you discourage weight size. L1 encourages sparsity, meaning many weights can become exactly zero under suitable optimization. L2 shrinks weights smoothly and usually leaves small nonzero values. Larger lambda can reduce overfitting, but excessive regularization can underfit.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_penalties.svg\" aria-label=\"Enlarge diagram: The same two weights produce different costs because one rule uses absolute values and the other uses squares.\"><img src=\"assets/figures/v_penalties.svg\" alt=\"The same two weights produce different costs because one rule uses absolute values and the other uses squares.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The same two weights produce different costs because one rule uses absolute values and the other uses squares. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Data loss = 0.5; weights [2, −1]; λ = 0.1. Compute L1-regularized and L2-regularized objectives using the displayed convention.</p>","<h3>Given</h3>","<p>Data loss = 0.5; weights = [2,−1]; λ = 0.1.</p>","<p>The L2 convention here has no factor ½.</p>","<h3>To find</h3>","<p>Find L1/L2 penalties and the two regularized objective values.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>L2 penalty without a factor of one-half.</strong> This stated convention multiplies the sum of squares by λ, so differentiating contributes 2λw. Do not use the half-scaled gradient for this objective.</p>","<p>λ = penalty strength; J_data = original data loss; wᵢ = weight i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/008650efadbf4e29.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_iw_i^2\" width=\"212.95\" height=\"52.35\" style=\"width:212.95px;height:52.35px;aspect-ratio:212.95/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3465dcd568b96ffb.svg\" alt=\"\\frac{\\partial J}{\\partial w_i}=g_{\\mathrm{data},i}+2\\lambda w_i\" width=\"222.52\" height=\"54.60\" style=\"width:222.52px;height:54.60px;aspect-ratio:222.52/54.60\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half nahi diya toh L2 derivative mein 2 lambda × weight.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: take absolute values for L1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0f14566cc7516925.svg\" alt=\"|2|=2,\\qquad|-1|=1\" width=\"230.82\" height=\"24.41\" style=\"width:230.82px;height:24.41px;aspect-ratio:230.82/24.41\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the absolute values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23688a205b4ece73.svg\" alt=\"2+1=3\" width=\"99.10\" height=\"18.27\" style=\"width:99.10px;height:18.27px;aspect-ratio:99.10/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply by lambda.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/10346aae4a408d26.svg\" alt=\"0.1(3)=0.3\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the data loss.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8ed142793124641.svg\" alt=\"J_{L1}=0.5+0.3=0.8\" width=\"224.72\" height=\"20.36\" style=\"width:224.72px;height:20.36px;aspect-ratio:224.72/20.36\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: square both weights for L2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e11b2a71ed1c964f.svg\" alt=\"2^2=4,\\qquad(-1)^2=1\" width=\"233.13\" height=\"27.70\" style=\"width:233.13px;height:27.70px;aspect-ratio:233.13/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: add the squares.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c79fa7cad3c69e9.svg\" alt=\"4+1=5\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: multiply by lambda without adding a half.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3298085ce085f2d.svg\" alt=\"0.1(5)=0.5\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: add the data loss.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fde60160d7428d14.svg\" alt=\"J_{L2}=0.5+0.5=1.0\" width=\"224.72\" height=\"20.36\" style=\"width:224.72px;height:20.36px;aspect-ratio:224.72/20.36\" loading=\"lazy\"></div>","<p>For this L2 convention, the additional gradient is 2 λw. If the objective uses λ/2 times the squared sum, the additional gradient is λw instead. The factor is decided by the stated objective.</p>","<h3>L2 gradient update without a half factor</h3>","<p class=\"inline-question\"><strong>Question. A weight is 2, its data-loss gradient is 0.3, λ = 0.1 and η = 0.01. The objective adds λw². Perform one update.</strong></p>","<h3>Given</h3>","<p>w = 2; data gradient = 0.3; λ = 0.1; η = 0.01. The penalty has no factor ½.</p>","<h3>To find</h3>","<p>Penalty gradient, total gradient and updated weight.</p>","<h3>Formula — which one and why</h3>","<p>The derivative of λw² is 2λw. Add it to the data gradient before applying gradient descent.</p>","<p>λ is penalty strength; η is learning rate; g is the full objective gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e2245fb17ab44d83.svg\" alt=\"g_{\\mathrm{penalty}}=2\\lambda w\" width=\"146.39\" height=\"24.15\" style=\"width:146.39px;height:24.15px;aspect-ratio:146.39/24.15\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ed52defd9fef6cb.svg\" alt=\"g=g_{\\mathrm{data}}+g_{\\mathrm{penalty}}\" width=\"191.25\" height=\"21.44\" style=\"width:191.25px;height:21.44px;aspect-ratio:191.25/21.44\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Penalty ka gradient data gradient mein jodo, phir update.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the penalty gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b8811e22460d0c91.svg\" alt=\"2(0.1)(2)=0.4\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the data gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74fdb43956c5f462.svg\" alt=\"g=0.3+0.4=0.7\" width=\"200.37\" height=\"21.55\" style=\"width:200.37px;height:21.55px;aspect-ratio:200.37/21.55\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale by the learning rate.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9603f5d8320b5539.svg\" alt=\"\\eta g=0.01(0.7)=0.007\" width=\"238.31\" height=\"24.43\" style=\"width:238.31px;height:24.43px;aspect-ratio:238.31/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: subtract from the old weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28a66f5f8853795a.svg\" alt=\"w_{\\mathrm{new}}=2-0.007=1.993\" width=\"267.85\" height=\"20.37\" style=\"width:267.85px;height:20.37px;aspect-ratio:267.85/20.37\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Updated weight = 1.993. Bias penalties are omitted unless the objective includes them.</p>","<h3>Deriving the L2 update</h3>","<p>Under the objective written above, the data gradient and penalty gradient add:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/56481f4684193b6b.svg\" alt=\"\\nabla_w J=\\nabla_w J_{\\mathrm{data}}+2\\lambda w\" width=\"240.58\" height=\"20.81\" style=\"width:240.58px;height:20.81px;aspect-ratio:240.58/20.81\" loading=\"lazy\"></div>","<p>For ordinary gradient descent, regrouping the update gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:285.41px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/745f5ba3fa313836.svg\"><img class=\"math display-math\" src=\"assets/equations/e175e10221a61929.svg\" alt=\"w_{t+1}=w_t-\\eta(\\nabla_w J_{\\mathrm{data}}+2\\lambda w_t)=(1-2\\eta\\lambda)w_t-\\eta\\nabla_w J_{\\mathrm{data}}\" width=\"617.26\" height=\"24.43\" style=\"width:617.26px;height:24.43px;aspect-ratio:617.26/24.43\" loading=\"lazy\"></picture></div>","<p>This shows the shrinkage associated with this L2 convention. For an objective containing λ‖w‖²/2, replace 2λ by λ. This algebra explains the equivalence to appropriately scaled weight decay for ordinary gradient descent; adding an L2 term inside an adaptive optimizer is generally different from decoupled weight decay.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c6-s1","search":"L1 and L2 add a cost for large weights **Definition.** Regularization modifies a training objective or learning procedure to constrain the fitted model and improve generalization. L1 and L2 regularization add parameter-norm penalties to the data loss.\n\n### Explanation and working\n\nLambda controls how strongly you discourage weight size. L1 encourages sparsity, meaning many weights can become exactly zero under suitable optimization. L2 shrinks weights smoothly and usually leaves small nonzero values. Larger lambda can reduce overfitting, but excessive regularization can underfit.\n\n\n\n**Question.** Data loss = 0.5; weights [2, −1]; λ = 0.1. Compute L1-regularized and L2-regularized objectives using the displayed convention.\n\n\n\n### Given\n\nData loss = 0.5; weights = [2,−1]; λ = 0.1.\n\nThe L2 convention here has no factor ½.\n\n### To find\n\nFind L1/L2 penalties and the two regularized objective values.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**L2 penalty without a factor of one-half.** This stated convention multiplies the sum of squares by λ, so differentiating contributes 2λw. Do not use the half-scaled gradient for this objective.\n\nλ = penalty strength; J_data = original data loss; wᵢ = weight i.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half nahi diya toh L2 derivative mein 2 lambda × weight.\n\n### Solution — step by step\n\n\n\n\n**Step 1: take absolute values for L1.**\n\n\n\n\n\n\n\n**Step 2: add the absolute values.**\n\n\n\n\n\n\n\n**Step 3: multiply by lambda.**\n\n\n\n\n\n\n\n**Step 4: add the data loss.**\n\n\n\n\n\n\n\n\n**Step 5: square both weights for L2.**\n\n\n\n\n\n\n\n**Step 6: add the squares.**\n\n\n\n\n\n\n\n**Step 7: multiply by lambda without adding a half.**\n\n\n\n\n\n\n\n**Step 8: add the data loss.**\n\n\n\n\n\n\n\n\nFor this L2 convention, the additional gradient is 2 λw. If the objective uses λ/2 times the squared sum, the additional gradient is λw instead. The factor is decided by the stated objective.\n\n\n### L2 gradient update without a half factor\n\n**Question. A weight is 2, its data-loss gradient is 0.3, λ = 0.1 and η = 0.01. The objective adds λw². Perform one update.**\n\n\n\n### Given\n\nw = 2; data gradient = 0.3; λ = 0.1; η = 0.01. The penalty has no factor ½.\n\n### To find\n\nPenalty gradient, total gradient and updated weight.\n\n### Formula — which one and why\n\nThe derivative of λw² is 2λw. Add it to the data gradient before applying gradient descent.\n\nλ is penalty strength; η is learning rate; g is the full objective gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Penalty ka gradient data gradient mein jodo, phir update.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the penalty gradient.**\n\n\n\n\n\n\n\n**Step 2: add the data gradient.**\n\n\n\n\n\n\n\n**Step 3: scale by the learning rate.**\n\n\n\n\n\n\n\n**Step 4: subtract from the old weight.**\n\n\n\n\n\n\n\n**Final answer:** Updated weight = 1.993. Bias penalties are omitted unless the objective includes them.\n\n\n\n### Deriving the L2 update\nUnder the objective written above, the data gradient and penalty gradient add:\n\nFor ordinary gradient descent, regrouping the update gives:\n\nThis shows the shrinkage associated with this L2 convention. For an objective containing λ‖w‖²/2, replace 2λ by λ."},{"title":"Model answer: regularization and the L1–L2 difference","question":["<p class=\"inline-question\"><strong>Question.</strong> What is regularization? Compare L1 and L2 regularization, including the objective, gradient effect and influence of regularization strength.</p>"],"answer":["<p>Regularization restricts or discourages certain fitted solutions to improve generalization. Weight penalties add a cost for parameter size to the training objective. The optimizer must balance fitting the data against that extra cost.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_penalties.svg\" aria-label=\"Enlarge diagram: Follow the stated penalty convention, including lambda and any half factor, when you form the objective.\"><img src=\"assets/figures/v_penalties.svg\" alt=\"Follow the stated penalty convention, including lambda and any half factor, when you form the objective.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow the stated penalty convention, including lambda and any half factor, when you form the objective. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Objectives used in this course</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52bb091c05d16021.svg\" alt=\"J_{L1}=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"244.38\" height=\"52.35\" style=\"width:244.38px;height:52.35px;aspect-ratio:244.38/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9438fe7d9420663e.svg\" alt=\"J_{L2}=J_{\\mathrm{data}}+\\lambda\\sum_iw_i^2\" width=\"233.47\" height=\"52.35\" style=\"width:233.47px;height:52.35px;aspect-ratio:233.47/52.35\" loading=\"lazy\"></div>","<p>Jdata measures prediction error. λ controls the strength of the additional penalty. The sums are over the weights included by the stated question.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Basis</th><th>L1</th><th>L2</th></tr></thead><tbody><tr><td>Quantity penalized</td><td>Absolute weight magnitude</td><td>Squared weight magnitude</td></tr><tr><td>Penalty derivative at nonzero w</td><td>λ sign(w)</td><td>2λw under the displayed convention</td></tr><tr><td>Typical effect</td><td>Encourages sparse solutions</td><td>Smoothly shrinks weight magnitudes</td></tr><tr><td>Zero weights</td><td>Can promote exact zeros with suitable optimization</td><td>Usually leaves small nonzero weights</td></tr></tbody></table></div>","<p>The total gradient is the data-loss gradient plus the penalty gradient. With w = 2, data gradient 0.3 and λ = 0.1, the displayed L2 penalty adds 2 × 0.1 × 2 = 0.4. The total gradient is 0.7; update using that total.</p>","<p>Increasing λ strengthens the preference for smaller weights. Excessive regularization can prevent learning useful patterns and cause underfitting. L1 is not differentiable at zero, where a subgradient or suitable optimization method is used. If the examination writes λ/2 before the L2 sum, its penalty gradient becomes λw. Derive the factor from the printed objective.</p>"],"kind":"theory","id":"tee-c6-s2","search":"Model answer: regularization and the L1–L2 difference **Question.** What is regularization? Compare L1 and L2 regularization, including the objective, gradient effect and influence of regularization strength.\n\n**Model answer.**\nRegularization restricts or discourages certain fitted solutions to improve generalization. Weight penalties add a cost for parameter size to the training objective. The optimizer must balance fitting the data against that extra cost.\n\n\n\n\n### Objectives used in this guide\n\n\nJdata measures prediction error. λ controls the strength of the additional penalty. The sums are over the weights included by the stated question.\n\n| Basis | L1 | L2 |\n| Quantity penalized | Absolute weight magnitude | Squared weight magnitude |\n| Penalty derivative at nonzero w | λ sign(w) | 2λw under the displayed convention |\n| Typical effect | Encourages sparse solutions | Smoothly shrinks weight magnitudes |\n| Zero weights | Can promote exact zeros with suitable optimization | Usually leaves small nonzero weights |\n\nThe total gradient is the data-loss gradient plus the penalty gradient. With w = 2, data gradient 0.3 and λ = 0.1, the displayed L2 penalty adds 2 × 0.1 × 2 = 0.4. The total gradient is 0.7; update using that total.\n\nIncreasing λ strengthens the preference for smaller weights. Excessive regularization can prevent learning useful patterns and cause underfitting. L1 is not differentiable at zero, where a subgradient or suitable optimization method is used. If the examination writes λ/2 before the L2 sum, its penalty gradient becomes λw. Derive the factor from the printed objective.\n"},{"title":"Dropout removes activations during training","blocks":["<p class=\"definition\"><strong>Definition.</strong> Dropout is a stochastic regularization method that randomly sets selected unit activations to zero during training. It discourages reliance on specific co-adapted activations; the inference behavior depends on the scaling convention used during training.</p>","<h3>Explanation and working</h3>","<p>Dropout randomly sets selected activations to zero during training. This discourages dependence on one particular set of neurons. A dropped activation is not a permanently deleted neuron, and dropout does not reduce the model’s stored parameter count.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dropout.svg\" aria-label=\"Enlarge diagram: Match each activation with its mask entry. Zero entries are removed; kept entries are divided by the keep probability.\"><img src=\"assets/figures/v_dropout.svg\" alt=\"Match each activation with its mask entry. Zero entries are removed; kept entries are divided by the keep probability.\" width=\"1080\" height=\"650\" loading=\"lazy\"></button><figcaption>Match each activation with its mask entry. Zero entries are removed; kept entries are divided by the keep probability. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Let drop probability be p and keep probability be q = 1 − p. A mask entry 1 means keep, 0 means drop. There are two internally consistent scaling conventions.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.63px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b6b21f6d03d2989f.svg\"><img class=\"math display-math\" src=\"assets/equations/cb674fd2e32b87a1.svg\" alt=\"a_{\\mathrm{train}}=m\\odot a\\quad\\text{and}\\quad a_{\\mathrm{test}}=q a\\quad\\text{in classical dropout}\" width=\"563.28\" height=\"21.70\" style=\"width:563.28px;height:21.70px;aspect-ratio:563.28/21.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.52px;--narrow-height:169.55px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7c8360afe0eaec6b.svg\"><img class=\"math display-math\" src=\"assets/equations/4b6a9d814bc5c7bb.svg\" alt=\"a_{\\mathrm{train}}=\\frac{m\\odot a}{q}\\quad\\text{and}\\quad a_{\\mathrm{test}}=a\\quad\\text{in inverted dropout}\" width=\"564.68\" height=\"52.26\" style=\"width:564.68px;height:52.26px;aspect-ratio:564.68/52.26\" loading=\"lazy\"></picture></div>","<p class=\"inline-question\"><strong>Question.</strong> Activations [0.8, −0.4, 0.6, 0.2] have dropout rate 50%. Choose mask [1,0,1,0] and compute outputs.</p>","<h3>Given</h3>","<p>Activations = [0.8,−0.4,0.6,0.2].</p>","<p>Dropout rate = 50%, so keep probability q = 0.5.</p>","<p>Chosen mask = [1,0,1,0].</p>","<h3>To find</h3>","<p>Find training outputs under inverted dropout.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1.</strong> q = 1 − 0.5 = 0.5. Apply mask elementwise: [1 × 0.8, 0 × (−0.4), 1 × 0.6, 0 × 0.2] = [0.8,0,0.6,0]. This is the unscaled training output, used by the supplied re-exam key.</p>","<p class=\"worked-step\"><strong>Step 2.</strong> For inverted dropout, divide the kept outputs by q: [0.8/0.5,0,0.6/0.5,0] = <strong>[1.6,0,1.2,0]</strong>. Inference then uses the full network without that extra scaling. State the convention in an answer.</p>","<p>Random dropout does not require exactly half the units to disappear in every small layer; each unit is kept or dropped according to the sampling rule. This mask is one possible outcome. If an exam explicitly specifies exactly two dropped units, follow that condition.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c6-s3","search":"Dropout removes activations during training **Definition.** Dropout is a stochastic regularization method that randomly sets selected unit activations to zero during training. It discourages reliance on specific co-adapted activations; the inference behavior depends on the scaling convention used during training.\n\n### Explanation and working\nDropout randomly sets selected activations to zero during training. This discourages dependence on one particular set of neurons. A dropped activation is not a permanently deleted neuron, and dropout does not reduce the model’s stored parameter count.\n\n\n\nLet drop probability be p and keep probability be q = 1 − p. A mask entry 1 means keep, 0 means drop. There are two internally consistent scaling conventions.\n\n\n**Question.** Activations [0.8, −0.4, 0.6, 0.2] have dropout rate 50%. Choose mask [1,0,1,0] and compute outputs.\n\n\n\n### Given\n\nActivations = [0.8,−0.4,0.6,0.2].\n\nDropout rate = 50%, so keep probability q = 0.5.\n\nChosen mask = [1,0,1,0].\n\n### To find\n\nFind training outputs under inverted dropout.\n\n### Formula — which one and why\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n### Solution — step by step\n\n\n\n\n**Step 1.** q = 1 − 0.5 = 0.5. Apply mask elementwise: [1 × 0.8, 0 × (−0.4), 1 × 0.6, 0 × 0.2] = [0.8,0,0.6,0]. This is the unscaled training output, used by the supplied re-exam key.\n**Step 2.** For inverted dropout, divide the kept outputs by q: [0.8/0.5,0,0.6/0.5,0] = **[1.6,0,1.2,0]**. Inference then uses the full network without that extra scaling. State the convention in an answer.\nRandom dropout does not require exactly half the units to disappear in every small layer; each unit is kept or dropped according to the sampling rule. This mask is one possible outcome. If an exam explicitly specifies exactly two dropped units, follow that condition."},{"title":"Early stopping uses the best validation point","blocks":["<p class=\"definition\"><strong>Definition.</strong> Early stopping is a regularization and model-selection procedure that terminates training when a monitored validation criterion no longer improves according to a specified rule, typically retaining the best checkpoint.</p>","<h3>Explanation and working</h3>","<p>Monitor validation loss after epochs. When it stops improving for a chosen patience interval, stop training and restore the best validation checkpoint. Training loss can fluctuate; it does not always decrease monotonically. Never select the stopping epoch by repeatedly consulting the test set.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_early_stop.svg\" aria-label=\"Enlarge diagram: Training loss keeps falling while validation loss starts rising. Keep the checkpoint from the validation minimum.\"><img src=\"assets/figures/v_early_stop.svg\" alt=\"Training loss keeps falling while validation loss starts rising. Keep the checkpoint from the validation minimum.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>Training loss keeps falling while validation loss starts rising. Keep the checkpoint from the validation minimum. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Validation losses after epochs 1–5 are [0.8,0.6,0.5,0.53,0.55]. Patience is 2 with no required minimum improvement. When do you stop and what do you restore?</p>","<h3>Given</h3>","<p>Validation losses at epochs 1–5 = [0.8,0.6,0.5,0.53,0.55].</p>","<p>Patience = 2; no required minimum improvement.</p>","<h3>To find</h3>","<p>Find the stop epoch and the best checkpoint to restore.</p>","<h3>Formula — which one and why</h3>","<p><strong>Early stopping rule.</strong> Compare each validation loss with the best one so far. A new best resets the waiting count; a non-improvement increases it. Stop when the count reaches patience and restore the best checkpoint.</p>","<p>Patience = allowed consecutive epochs without improvement. With minimum improvement zero, a strictly smaller validation loss counts as improvement.</p>","<p><strong>Yaad rakhne ka cue:</strong> Best validation save; patience khatam toh stop aur best restore.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: process epoch 1.</strong></p>","<p>Loss 0.8 establishes the first best checkpoint; wait = 0.</p>","<p class=\"worked-step\"><strong>Step 2: process epoch 2.</strong></p>","<p>0.6 &lt; 0.8: save epoch 2; wait = 0.</p>","<p class=\"worked-step\"><strong>Step 3: process epoch 3.</strong></p>","<p>0.5 &lt; 0.6: save epoch 3; wait = 0.</p>","<p class=\"worked-step\"><strong>Step 4: process epoch 4.</strong></p>","<p>0.53 &gt; 0.5: no improvement; wait = 1.</p>","<p class=\"worked-step\"><strong>Step 5: process epoch 5.</strong></p>","<p>0.55 &gt; 0.5: no improvement; wait = 2, equal to patience. Stop.</p>","<p class=\"worked-step\"><strong>Step 6: restore the best checkpoint.</strong></p>","<p>The smallest observed validation loss is 0.5 at epoch 3. Restore its weights.</p>","<p><strong>Final answer:</strong> stop after epoch 5; restore epoch 3. These are different epochs.</p>","<h3>Early stopping with [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]</h3>","<p class=\"inline-question\"><strong>Question. Validation losses are [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]. With patience 2 and strict improvement, identify the stopping epoch and checkpoint to restore.</strong></p>","<h3>Given</h3>","<p>Validation losses in epoch order = [0.8, 0.7, 0.72, 0.68, 0.69, 0.7].</p>","<p>Patience = 2; smaller loss is better; ties are not improvements.</p>","<h3>To find</h3>","<p>The stopping epoch and best checkpoint.</p>","<h3>Formula — which one and why</h3>","<p>Save an epoch when its validation loss is strictly lower than the best so far. Stop after the stated number of consecutive non-improving epochs.</p>","<p>Patience counts consecutive non-improvements. A new best resets the count.</p>","<p><strong>Yaad rakhne ka cue:</strong> Naya best mila toh save aur wait zero; patience khatam toh best restore.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: process epoch 1.</strong></p>","<p>Validation loss = 0.8; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 1, loss 0.8.</p>","<p class=\"worked-step\"><strong>Step 2: process epoch 2.</strong></p>","<p>Validation loss = 0.7; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 2, loss 0.7.</p>","<p class=\"worked-step\"><strong>Step 3: process epoch 3.</strong></p>","<p>Validation loss = 0.72; no strict improvement: wait count becomes 1. Best checkpoint is epoch 2, loss 0.7.</p>","<p class=\"worked-step\"><strong>Step 4: process epoch 4.</strong></p>","<p>Validation loss = 0.68; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 4, loss 0.68.</p>","<p class=\"worked-step\"><strong>Step 5: process epoch 5.</strong></p>","<p>Validation loss = 0.69; no strict improvement: wait count becomes 1. Best checkpoint is epoch 4, loss 0.68.</p>","<p class=\"worked-step\"><strong>Step 6: process epoch 6.</strong></p>","<p>Validation loss = 0.7; no strict improvement: wait count becomes 2. Best checkpoint is epoch 4, loss 0.68.</p>","<p><strong>Final answer:</strong> Stop after epoch 6; restore epoch 4, with validation loss 0.68.</p>","<h3>Early stopping with [0.6, 0.6, 0.61, 0.62]</h3>","<p class=\"inline-question\"><strong>Question. Validation losses are [0.6, 0.6, 0.61, 0.62]. With patience 2 and strict improvement, identify the stopping epoch and checkpoint to restore.</strong></p>","<h3>Given</h3>","<p>Validation losses in epoch order = [0.6, 0.6, 0.61, 0.62].</p>","<p>Patience = 2; smaller loss is better; ties are not improvements.</p>","<h3>To find</h3>","<p>The stopping epoch and best checkpoint.</p>","<h3>Formula — which one and why</h3>","<p>Save an epoch when its validation loss is strictly lower than the best so far. Stop after the stated number of consecutive non-improving epochs.</p>","<p>Patience counts consecutive non-improvements. A new best resets the count.</p>","<p><strong>Yaad rakhne ka cue:</strong> Naya best mila toh save aur wait zero; patience khatam toh best restore.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: process epoch 1.</strong></p>","<p>Validation loss = 0.6; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 1, loss 0.6.</p>","<p class=\"worked-step\"><strong>Step 2: process epoch 2.</strong></p>","<p>Validation loss = 0.6; no strict improvement: wait count becomes 1. Best checkpoint is epoch 1, loss 0.6.</p>","<p class=\"worked-step\"><strong>Step 3: process epoch 3.</strong></p>","<p>Validation loss = 0.61; no strict improvement: wait count becomes 2. Best checkpoint is epoch 1, loss 0.6.</p>","<p><strong>Final answer:</strong> Stop after epoch 3; restore epoch 1, with validation loss 0.6.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c6-s4","search":"Early stopping uses the best validation point **Definition.** Early stopping is a regularization and model-selection procedure that terminates training when a monitored validation criterion no longer improves according to a specified rule, typically retaining the best checkpoint.\n\n### Explanation and working\nMonitor validation loss after epochs. When it stops improving for a chosen patience interval, stop training and restore the best validation checkpoint. Training loss can fluctuate; it does not always decrease monotonically. Never select the stopping epoch by repeatedly consulting the test set.\n\n\n\n**Question.** Validation losses after epochs 1–5 are [0.8,0.6,0.5,0.53,0.55]. Patience is 2 with no required minimum improvement. When do you stop and what do you restore?\n\n\n\n### Given\n\nValidation losses at epochs 1–5 = [0.8,0.6,0.5,0.53,0.55].\n\nPatience = 2; no required minimum improvement.\n\n### To find\n\nFind the stop epoch and the best checkpoint to restore.\n\n### Formula — which one and why\n\n**Early stopping rule.** Compare each validation loss with the best one so far. A new best resets the waiting count; a non-improvement increases it. Stop when the count reaches patience and restore the best checkpoint.\n\nPatience = allowed consecutive epochs without improvement. With minimum improvement zero, a strictly smaller validation loss counts as improvement.\n\n**Yaad rakhne ka cue:** Best validation save; patience khatam toh stop aur best restore.\n\n### Solution — step by step\n\n\n\n\n**Step 1: process epoch 1.**\n\nLoss 0.8 establishes the first best checkpoint; wait = 0.\n\n**Step 2: process epoch 2.**\n\n0.6 < 0.8: save epoch 2; wait = 0.\n\n**Step 3: process epoch 3.**\n\n0.5 < 0.6: save epoch 3; wait = 0.\n\n**Step 4: process epoch 4.**\n\n0.53 > 0.5: no improvement; wait = 1.\n\n**Step 5: process epoch 5.**\n\n0.55 > 0.5: no improvement; wait = 2, equal to patience. Stop.\n\n**Step 6: restore the best checkpoint.**\n\nThe smallest observed validation loss is 0.5 at epoch 3. Restore its weights.\n\n**Final answer:** stop after epoch 5; restore epoch 3. These are different epochs.\n\n### Early stopping with [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]\n\n**Question. Validation losses are [0.8, 0.7, 0.72, 0.68, 0.69, 0.7]. With patience 2 and strict improvement, identify the stopping epoch and checkpoint to restore.**\n\n\n\n### Given\n\nValidation losses in epoch order = [0.8, 0.7, 0.72, 0.68, 0.69, 0.7].\n\nPatience = 2; smaller loss is better; ties are not improvements.\n\n### To find\n\nThe stopping epoch and best checkpoint.\n\n### Formula — which one and why\n\nSave an epoch when its validation loss is strictly lower than the best so far. Stop after the stated number of consecutive non-improving epochs.\n\nPatience counts consecutive non-improvements. A new best resets the count.\n\n**Yaad rakhne ka cue:** Naya best mila toh save aur wait zero; patience khatam toh best restore.\n\n### Solution — step by step\n\n\n\n**Step 1: process epoch 1.**\n\nValidation loss = 0.8; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 1, loss 0.8.\n\n**Step 2: process epoch 2.**\n\nValidation loss = 0.7; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is epoch 2, loss 0.7.\n\n**Step 3: process epoch 3.**\n\nValidation loss = 0.72; no strict improvement: wait count becomes 1. Best checkpoint is epoch 2, loss 0.7.\n\n**Step 4: process epoch 4.**\n\nValidation loss = 0.68; strict improvement: save this checkpoint and reset wait count to 0. Best checkpoint is ep"},{"title":"Model answer: generalization and early stopping","question":["<p class=\"inline-question\"><strong>Question.</strong> Distinguish underfitting and overfitting. Explain how validation data and early stopping help control overfitting.</p>"],"answer":["<p>Underfitting occurs when a model has not captured enough useful structure in the training data. Both training and validation errors are usually high relative to a sensible task baseline. Causes can include insufficient capacity, inadequate features, excessive regularization or incomplete optimization.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_early_stop.svg\" aria-label=\"Enlarge diagram: The best training score is not necessarily the best score on unseen validation examples.\"><img src=\"assets/figures/v_early_stop.svg\" alt=\"The best training score is not necessarily the best score on unseen validation examples.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>The best training score is not necessarily the best score on unseen validation examples. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Overfitting occurs when a model fits training-specific details or noise that do not generalize. Training error is low while validation error is substantially higher. A mismatch between training and validation data can produce a similar gap, so the split must also be examined.</p>","<h3>How early stopping works</h3>","<p>1. Train using the training set; do not learn parameters from the validation targets as training samples.</p>","<p>2. After an epoch or another chosen interval, evaluate validation loss.</p>","<p>3. Save the parameters whenever validation loss reaches a new best value.</p>","<p>4. Count consecutive intervals with no qualifying improvement.</p>","<p>5. When the count reaches the chosen patience, stop and restore the saved best parameters.</p>","<p>For validation losses 0.8, 0.6, 0.5, 0.53 and 0.55, epoch 3 is best. With patience 2, epochs 4 and 5 supply two non-improvements: stop after epoch 5 and restore epoch 3. The stopping epoch and the retained model epoch are different.</p>","<p>Other remedies for overfitting include appropriate L1/L2 penalties, dropout, augmentation and more representative training data. Underfitting may instead require a better model, adequate training or less regularization. Use the test set for final evaluation after those choices, not for repeatedly choosing the stopping point.</p>"],"kind":"theory","id":"tee-c6-s5","search":"Model answer: generalization and early stopping **Question.** Distinguish underfitting and overfitting. Explain how validation data and early stopping help control overfitting.\n\n**Model answer.**\nUnderfitting occurs when a model has not captured enough useful structure in the training data. Both training and validation errors are usually high relative to a sensible task baseline. Causes can include insufficient capacity, inadequate features, excessive regularization or incomplete optimization.\n\n\n\n\nOverfitting occurs when a model fits training-specific details or noise that do not generalize. Training error is low while validation error is substantially higher. A mismatch between training and validation data can produce a similar gap, so the split must also be examined.\n\n### How early stopping works\n1. Train using the training set; do not learn parameters from the validation targets as training samples.\n2. After an epoch or another chosen interval, evaluate validation loss.\n3. Save the parameters whenever validation loss reaches a new best value.\n4. Count consecutive intervals with no qualifying improvement.\n5. When the count reaches the chosen patience, stop and restore the saved best parameters.\n\nFor validation losses 0.8, 0.6, 0.5, 0.53 and 0.55, epoch 3 is best. With patience 2, epochs 4 and 5 supply two non-improvements: stop after epoch 5 and restore epoch 3. The stopping epoch and the retained model epoch are different.\n\nOther remedies for overfitting include appropriate L1/L2 penalties, dropout, augmentation and more representative training data. Underfitting may instead require a better model, adequate training or less regularization. Use the test set for final evaluation after those choices, not for repeatedly choosing the stopping point.\n"},{"title":"Choosing a remedy","blocks":["<p>For overfitting: try L1/L2, dropout, suitable data augmentation, a smaller model, more representative training data and early stopping. For underfitting: improve features or architecture, train adequately, check optimization, or reduce excessive regularization. Evaluate changes on validation data.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_remedies.svg\" aria-label=\"Enlarge diagram: Read the training and validation pattern before selecting a remedy.\"><img src=\"assets/figures/v_remedies.svg\" alt=\"Read the training and validation pattern before selecting a remedy.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Read the training and validation pattern before selecting a remedy. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Data augmentation makes label-preserving variations of training examples, such as suitable crops or brightness changes in images. It must respect the task: flipping a digit or a medical image may change meaning. Augmentation happens within the training split; do not leak augmented copies into validation.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Change</th><th>Usual bias tendency</th><th>Usual variance tendency</th></tr></thead><tbody><tr><td>Stronger weight regularization</td><td>Increase</td><td>Decrease</td></tr><tr><td>More hidden units with other factors fixed</td><td>Decrease</td><td>Increase</td></tr><tr><td>Dropout</td><td>Increase</td><td>Decrease</td></tr><tr><td>More representative data from same distribution</td><td>Roughly unchanged model bias</td><td>Decrease</td></tr></tbody></table></div>","<p>These are classical tendencies for exam discussion, not exact laws for every deep-network training run. Distinguish model capacity from optimization failure.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c6-s6","search":"Choosing a remedy For overfitting: try L1/L2, dropout, suitable data augmentation, a smaller model, more representative training data and early stopping. For underfitting: improve features or architecture, train adequately, check optimization, or reduce excessive regularization. Evaluate changes on validation data.\n\n\n\nData augmentation makes label-preserving variations of training examples, such as suitable crops or brightness changes in images. It must respect the task: flipping a digit or a medical image may change meaning. Augmentation happens within the training split; do not leak augmented copies into validation.\n| Change | Usual bias tendency | Usual variance tendency |\n| Stronger weight regularization | Increase | Decrease |\n| More hidden units with other factors fixed | Decrease | Increase |\n| Dropout | Increase | Decrease |\n| More representative data from same distribution | Roughly unchanged model bias | Decrease |\nThese are classical tendencies for exam discussion, not exact laws for every deep-network training run. Distinguish model capacity from optimization failure.\n\n"},{"title":"Inverted dropout during training and inference","blocks":["<p class=\"definition\"><strong>Definition.</strong> Inverted dropout divides retained training activations by their keep probability so that their expectation equals the original activation. At inference, dropout is disabled and no compensating activation scaling is required.</p>","<h3>Explanation and working</h3>","<p>Inverted dropout first chooses which activations to keep, then divides each kept activation by the keep probability. This compensates for the missing activations in expectation. A dropped activation becomes zero.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dropout_expectation.svg\" aria-label=\"Enlarge diagram: Follow both possible training outcomes for activation 3. Their average remains 3; inference uses that ordinary activation.\"><img src=\"assets/figures/v_dropout_expectation.svg\" alt=\"Follow both possible training outcomes for activation 3. Their average remains 3; inference uses that ordinary activation.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow both possible training outcomes for activation 3. Their average remains 3; inference uses that ordinary activation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For activation 3 and keep probability q = 0.5, a kept value becomes 3 ÷ 0.5 = 6. A dropped value becomes 0. Since half the masks keep it, the average is 0.5 × 6 + 0.5 × 0 = 3, equal to the original activation.</p>","<p>At inference, dropout is disabled and the ordinary activation 3 is used. Under this inverted-dropout convention, no extra multiplication by q is required at inference.</p>","<h3>Expectation calculation</h3>","<p>For a fixed activation a and a Bernoulli keep mask m with P(m = 1) = q:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.90px;--narrow-height:122.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8a9a35419aebc53b.svg\"><img class=\"math display-math\" src=\"assets/equations/55c82e5345c55ebe.svg\" alt=\"\\mathbb E\\left[\\frac{ma}{q}\\right]=\\frac aq\\mathbb E[m]=\\frac aq\\,q=a\" width=\"316.00\" height=\"58.62\" style=\"width:316.00px;height:58.62px;aspect-ratio:316.00/58.62\" loading=\"lazy\"></picture></div>","<p>The equality concerns the activation&#x27;s expectation over masks. It does not say every sampled layer preserves its sum, nor does it generally make a nonlinear network&#x27;s complete stochastic prediction equal to its deterministic inference prediction.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c6-s7","search":"Inverted dropout during training and inference **Definition.** Inverted dropout divides retained training activations by their keep probability so that their expectation equals the original activation. At inference, dropout is disabled and no compensating activation scaling is required.\n\n### Explanation and working\nInverted dropout first chooses which activations to keep, then divides each kept activation by the keep probability. This compensates for the missing activations in expectation. A dropped activation becomes zero.\n\n\n\nFor activation 3 and keep probability q = 0.5, a kept value becomes 3 ÷ 0.5 = 6. A dropped value becomes 0. Since half the masks keep it, the average is 0.5 × 6 + 0.5 × 0 = 3, equal to the original activation.\nAt inference, dropout is disabled and the ordinary activation 3 is used. Under this inverted-dropout convention, no extra multiplication by q is required at inference.\n\n### Expectation calculation\nFor a fixed activation a and a Bernoulli keep mask m with P(m = 1) = q:\n\nThe equality concerns the activation's expectation over masks. It does not say every sampled layer preserves its sum, nor does it generally make a nonlinear network's complete stochastic prediction equal to its deterministic inference prediction.\n"},{"title":"Model answer: dropout with training and inference explained","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain dropout as a regularization technique. Distinguish its behavior during training and inference, and explain inverted-dropout scaling.</p>"],"answer":["<p>Dropout randomly replaces selected activations by zero during training. It discourages excessive reliance on particular units and their joint activity. The mask changes between training applications; it does not permanently remove neurons or stored weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_dropout_expectation.svg\" aria-label=\"Enlarge diagram: The mask temporarily keeps or drops this activation during training. Inference uses the ordinary value without the random mask.\"><img src=\"assets/figures/v_dropout_expectation.svg\" alt=\"The mask temporarily keeps or drops this activation during training. Inference uses the ordinary value without the random mask.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The mask temporarily keeps or drops this activation during training. Inference uses the ordinary value without the random mask. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Let p be the probability of dropping an activation and q = 1 − p the probability of keeping it. A mask value m = 1 means keep; m = 0 means drop.</p>","<h3>Inverted dropout during training</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fda2e84f024891bd.svg\" alt=\"a&#x27;=\\frac{ma}{q}\" width=\"97.42\" height=\"48.82\" style=\"width:97.42px;height:48.82px;aspect-ratio:97.42/48.82\" loading=\"lazy\"></div>","<p>A kept activation is divided by q and a dropped activation becomes zero. This preserves the activation&#x27;s expectation over masks.</p>","<p>For a = 3 and q = 0.5, the kept result is 3/0.5 = 6 and the dropped result is 0. Their probability-weighted average is:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83765955bdb2c901.svg\" alt=\"0.5(6)+0.5(0)=3\" width=\"199.58\" height=\"24.43\" style=\"width:199.58px;height:24.43px;aspect-ratio:199.58/24.43\" loading=\"lazy\"></div>","<h3>Inference</h3>","<p>Disable dropout and use the ordinary activation. Under inverted dropout there is no further division or multiplication by q at inference. Under the alternative classical convention, training does not rescale kept activations and inference includes the compensating scaling; do not combine the two conventions.</p>","<p>Dropout has no trainable mask parameters. A dropped path contributes zero current data gradient through that activation, although a separately specified weight penalty can still contribute a parameter gradient. Excessive dropout can make optimization or fitting difficult. Choose its rate using validation data.</p>"],"kind":"theory","id":"tee-c6-s8","search":"Model answer: dropout with training and inference explained **Question.** Explain dropout as a regularization technique. Distinguish its behavior during training and inference, and explain inverted-dropout scaling.\n\n**Model answer.**\nDropout randomly replaces selected activations by zero during training. It discourages excessive reliance on particular units and their joint activity. The mask changes between training applications; it does not permanently remove neurons or stored weights.\n\n\n\n\nLet p be the probability of dropping an activation and q = 1 − p the probability of keeping it. A mask value m = 1 means keep; m = 0 means drop.\n\n### Inverted dropout during training\n\nA kept activation is divided by q and a dropped activation becomes zero. This preserves the activation's expectation over masks.\n\nFor a = 3 and q = 0.5, the kept result is 3/0.5 = 6 and the dropped result is 0. Their probability-weighted average is:\n\n### Inference\nDisable dropout and use the ordinary activation. Under inverted dropout there is no further division or multiplication by q at inference. Under the alternative classical convention, training does not rescale kept activations and inference includes the compensating scaling; do not combine the two conventions.\n\nDropout has no trainable mask parameters. A dropped path contributes zero current data gradient through that activation, although a separately specified weight penalty can still contribute a parameter gradient. Excessive dropout can make optimization or fitting difficult. Choose its rate using validation data.\n"}]},{"n":7,"title":"Convolutional neural networks","sections":[{"title":"Reading image shapes before doing CNN arithmetic","blocks":["<p class=\"definition\"><strong>Definition.</strong> An image or intermediate CNN representation is a tensor indexed by spatial position and channel. This course writes its shape as height × width × channels, excluding the batch dimension.</p>","<h3>Explanation and working</h3>","<h3>Height, width and channels</h3>","<p>The shape 4 × 5 × 3 means 4 rows, 5 columns and 3 channels. It contains 4 × 5 × 3 = 60 numbers. A grayscale image commonly has one intensity channel; an RGB image has red, green and blue channels. Intermediate CNN channels are learned feature maps, not necessarily colors.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_image_shape.svg\" aria-label=\"Enlarge diagram: Count height, width and channels separately. Three channels are stacked at the same spatial positions.\"><img src=\"assets/figures/v_image_shape.svg\" alt=\"Count height, width and channels separately. Three channels are stacked at the same spatial positions.\" width=\"1080\" height=\"585\" loading=\"lazy\"></button><figcaption>Count height, width and channels separately. Three channels are stacked at the same spatial positions. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>One position versus the whole map</h3>","<p>A filter placed at one location computes one output value. Sliding that same filter over all valid locations creates one feature map. A second filter creates a second feature map. Therefore the number of filters equals the number of output channels.</p>","<h3>Why filter depth matches input channels</h3>","<p>A 3 × 3 filter applied to a 3-channel input has 3 × 3 × 3 = 27 weights. At one location, it combines 27 input values into one sum. A single bias is then added for that filter. It does not produce three separate output channels just because the input has three channels.</p>","<h3>Reading a complete shape calculation</h3>","<p>The spatial-size formula computes height and width. It does not compute the channel count.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N = current input size; P = padding on one side; K = filter size; S = stride. The floor symbol means keep only complete placements. Add one because the initial placement is also an output position.</p>","<h3>Shape, parameters and computation are three different counts</h3>","<p><strong>Shape</strong> counts the arrangement of output values. <strong>Parameters</strong> count learned weights and biases. <strong>Computation</strong> counts how many arithmetic operations are performed. Reusing the same filter at 100 positions creates 100 outputs but does not create 100 new sets of weights.</p>","<p>In a multi-layer question, write the output shape of a layer first. That becomes the next layer&#x27;s input shape. This is why the second convolution uses the first convolution&#x27;s channel count, not the original image&#x27;s channel count.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s0","search":"Reading image shapes before doing CNN arithmetic **Definition.** An image or intermediate CNN representation is a tensor indexed by spatial position and channel. This course writes its shape as height × width × channels, excluding the batch dimension.\n\n### Explanation and working\n### Height, width and channels\nThe shape 4 × 5 × 3 means 4 rows, 5 columns and 3 channels. It contains 4 × 5 × 3 = 60 numbers. A grayscale image commonly has one intensity channel; an RGB image has red, green and blue channels. Intermediate CNN channels are learned feature maps, not necessarily colors.\n\n\n\n### One position versus the whole map\nA filter placed at one location computes one output value. Sliding that same filter over all valid locations creates one feature map. A second filter creates a second feature map. Therefore the number of filters equals the number of output channels.\n### Why filter depth matches input channels\nA 3 × 3 filter applied to a 3-channel input has 3 × 3 × 3 = 27 weights. At one location, it combines 27 input values into one sum. A single bias is then added for that filter. It does not produce three separate output channels just because the input has three channels.\n### Reading a complete shape calculation\nThe spatial-size formula computes height and width. It does not compute the channel count.\n\nN = current input size; P = padding on one side; K = filter size; S = stride. The floor symbol means keep only complete placements. Add one because the initial placement is also an output position.\n### Shape, parameters and computation are three different counts\n**Shape** counts the arrangement of output values. **Parameters** count learned weights and biases. **Computation** counts how many arithmetic operations are performed. Reusing the same filter at 100 positions creates 100 outputs but does not create 100 new sets of weights.\nIn a multi-layer question, write the output shape of a layer first. That becomes the next layer's input shape. This is why the second convolution uses the first convolution's channel count, not the original image's channel count.\n"},{"title":"A computer sees an image as numbers","blocks":["<p class=\"definition\"><strong>Definition.</strong> A digital image is a spatially arranged numerical tensor. In a CNN, convolutions transform input channels into learned feature maps using local connectivity and spatially shared kernel parameters.</p>","<h3>Explanation and working</h3>","<p>A pixel is one position in an image. A grayscale image stores one intensity per position. A colour RGB image usually stores three numbers per position: red, green and blue. Therefore 32 × 32 × 3 means height 32, width 32 and 3 input channels. It contains 32 × 32 × 3 = 3,072 numbers, not 32 neurons.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_image_grid.svg\" aria-label=\"Enlarge diagram: Each visible pixel corresponds to a matrix entry. Brightness is a number the network can calculate with.\"><img src=\"assets/figures/v_image_grid.svg\" alt=\"Each visible pixel corresponds to a matrix entry. Brightness is a number the network can calculate with.\" width=\"1080\" height=\"575\" loading=\"lazy\"></button><figcaption>Each visible pixel corresponds to a matrix entry. Brightness is a number the network can calculate with. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A <strong>feature</strong> is a useful pattern, such as an edge or texture. A <strong>feature map</strong> is a grid of responses that says where a learned filter matches the input. Early CNN layers often detect local simple patterns; later layers combine them into parts and more complex patterns.</p>","<p>A filter, also called a kernel in many exam questions, is a small set of learned weights. Slide it across the image, multiply corresponding numbers, and add. The same weights are reused at every spatial position. This is <strong>weight sharing</strong>.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s1","search":"A computer sees an image as numbers **Definition.** A digital image is a spatially arranged numerical tensor. In a CNN, convolutions transform input channels into learned feature maps using local connectivity and spatially shared kernel parameters.\n\n### Explanation and working\nA pixel is one position in an image. A grayscale image stores one intensity per position. A colour RGB image usually stores three numbers per position: red, green and blue. Therefore 32 × 32 × 3 means height 32, width 32 and 3 input channels. It contains 32 × 32 × 3 = 3,072 numbers, not 32 neurons.\n\n\n\nA **feature** is a useful pattern, such as an edge or texture. A **feature map** is a grid of responses that says where a learned filter matches the input. Early CNN layers often detect local simple patterns; later layers combine them into parts and more complex patterns.\nA filter, also called a kernel in many exam questions, is a small set of learned weights. Slide it across the image, multiply corresponding numbers, and add. The same weights are reused at every spatial position. This is **weight sharing**."},{"title":"The convolution calculation","blocks":["<p class=\"definition\"><strong>Definition.</strong> A convolutional layer calculates local weighted sums with a spatially shared kernel and optional bias. Standard deep-learning implementations ordinarily use cross-correlation, without flipping the kernel; examination calculations must follow the stated convention.</p>","<h3>Explanation and working</h3>","<p>In deep-learning software, the operation normally called convolution is cross-correlation: use the kernel as written, without flipping it. This is the convention in this course’s CNN numericals and the supplied latest answer key. Mathematical convolution would rotate the kernel; state that convention if a question explicitly requests it.</p>","<p class=\"inline-question\"><strong>Question.</strong> Apply a 2 × 2 kernel Matrix 1 shown below to the 3 × 3 image Matrix 2 shown below, with stride 1, no padding and zero bias.</p>","<h3>Given</h3>","<p>Input X = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/0cf23d37eabd00e4.svg\" alt=\"\\begin{bmatrix}1 &amp; 2 &amp; 3\\\\4 &amp; 5 &amp; 6\\\\7 &amp; 8 &amp; 9\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>.</p>","<p>Kernel K = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5c899cfe4dee6d06.svg\" alt=\"\\begin{bmatrix}1 &amp; 0\\\\0 &amp; -1\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>.</p>","<p>Stride = 1; padding = 0; bias = 0; no kernel flip.</p>","<h3>To find</h3>","<p>Find the 2 × 2 output map.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_cd39cabe48.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_cd39cabe48.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"340\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbe5e0aa8714ed4e.svg\" alt=\"X=\\begin{bmatrix}1&amp;2&amp;3\\\\4&amp;5&amp;6\\\\7&amp;8&amp;9\\end{bmatrix},\\quad K=\\begin{bmatrix}1&amp;0\\\\0&amp;-1\\end{bmatrix}\" width=\"354.80\" height=\"92.85\" style=\"width:354.80px;height:92.85px;aspect-ratio:354.80/92.85\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 1. Top-left window.</strong> 1(1) + 2(0) + 4(0) + 5(−1) = 1 − 5 = −4.</p>","<p class=\"worked-step\"><strong>Step 2. Move right by one.</strong> 2(1) + 3(0) + 5(0) + 6(−1) = 2 − 6 = −4.</p>","<p class=\"worked-step\"><strong>Step 3. Move down and return left.</strong> 4(1) + 5(0) + 7(0) + 8(−1) = 4 − 8 = −4.</p>","<p class=\"worked-step\"><strong>Step 4. Bottom-right window.</strong> 5(1) + 6(0) + 8(0) + 9(−1) = 5 − 9 = −4. Output is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/7f45e7b63383ada2.svg\" alt=\"\\begin{bmatrix}-4 &amp; -4\\\\-4 &amp; -4\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>. If ReLU follows, that next layer changes all four entries to zero; do not silently apply it when it was not requested.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/convolution.svg\" aria-label=\"Enlarge diagram: Four windows produce four output cells\"><img src=\"assets/figures/convolution.svg\" alt=\"Four windows produce four output cells\" width=\"960\" height=\"630\" loading=\"lazy\"></button><figcaption>Four windows produce four output cells <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s2","search":"The convolution calculation **Definition.** A convolutional layer calculates local weighted sums with a spatially shared kernel and optional bias. Standard deep-learning implementations ordinarily use cross-correlation, without flipping the kernel; examination calculations must follow the stated convention.\n\n### Explanation and working\nIn deep-learning software, the operation normally called convolution is cross-correlation: use the kernel as written, without flipping it. This is the convention in this book’s CNN numericals and the supplied latest answer key. Mathematical convolution would rotate the kernel; state that convention if a question explicitly requests it.\n**Question.** Apply a 2 × 2 kernel Matrix 1 shown below to the 3 × 3 image Matrix 2 shown below, with stride 1, no padding and zero bias.\n\n\n\n### Given\n\nInput X = .\n\nKernel K = .\n\nStride = 1; padding = 0; bias = 0; no kernel flip.\n\n### To find\n\nFind the 2 × 2 output map.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n**Step 1. Top-left window.** 1(1) + 2(0) + 4(0) + 5(−1) = 1 − 5 = −4.\n**Step 2. Move right by one.** 2(1) + 3(0) + 5(0) + 6(−1) = 2 − 6 = −4.\n**Step 3. Move down and return left.** 4(1) + 5(0) + 7(0) + 8(−1) = 4 − 8 = −4.\n**Step 4. Bottom-right window.** 5(1) + 6(0) + 8(0) + 9(−1) = 5 − 9 = −4. Output is . If ReLU follows, that next layer changes all four entries to zero; do not silently apply it when it was not requested.\n"},{"title":"Stride padding and floor","blocks":["<p class=\"definition\"><strong>Definition.</strong> Stride is the spacing between consecutive kernel positions. Padding extends the input boundary. Together with kernel size and dilation, they determine the spatial dimensions of a convolutional output.</p>","<h3>Explanation and working</h3>","<p>Stride is how far the filter moves each time. Stride 2 visits starting positions 0, 2, 4 and so on. Padding adds border values, usually zeros. Padding 1 means one new row or column on each side, adding 2 to a spatial dimension.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_stride_padding.svg\" aria-label=\"Enlarge diagram: The border adds to both sides of the input. The stride changes the next starting position of the filter window.\"><img src=\"assets/figures/v_stride_padding.svg\" alt=\"The border adds to both sides of the input. The stride changes the next starting position of the filter window.\" width=\"1080\" height=\"645\" loading=\"lazy\"></button><figcaption>The border adds to both sides of the input. The stride changes the next starting position of the filter window. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is input size; P is padding per side; K is kernel size; S is stride. Floor means take the greatest integer not above the result: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a8acf65164593cb2.svg\" alt=\"\\left\\lfloor 2.5\\right\\rfloor\" width=\"41.16\" height=\"19.00\" style=\"width:41.16px;height:19.00px;aspect-ratio:41.16/19.00\" loading=\"lazy\"></span> = 2. It counts only positions where the entire window fits. The formula assumes dilation 1, the standard setting in these papers. Apply it separately to height and width for rectangular images or kernels.</p>","<p><strong>Why plus one?</strong> Even when the kernel exactly fits the image, there is one placement. If N = K, P = 0, S = 1, the formula is 0 + 1 = 1.</p>","<h3>Output dimension with a fractional intermediate result</h3>","<p class=\"inline-question\"><strong>Question. A convolution has input side N = 6, kernel side K = 3, stride S = 2 and padding P = 0. Find its output side.</strong></p>","<h3>Given</h3>","<p>N = 6; K = 3; S = 2; P = 0; dilation = 1.</p>","<h3>To find</h3>","<p>The integer output side length.</p>","<h3>Formula — which one and why</h3>","<p>The formula counts complete kernel placements. Flooring removes an incomplete final placement.</p>","<p>N is input side; P is padding on each side; K is kernel side; S is stride.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Padding dono side; stride se divide; floor; phir +1.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: include padding and subtract kernel size.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4027b9bc8f6fe22.svg\" alt=\"6+2(0)-3=3\" width=\"172.42\" height=\"24.43\" style=\"width:172.42px;height:24.43px;aspect-ratio:172.42/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the stride.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d103d3b0cd150006.svg\" alt=\"\\frac32=1.5\" width=\"86.78\" height=\"49.53\" style=\"width:86.78px;height:49.53px;aspect-ratio:86.78/49.53\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: take the floor.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2ff7c16eb83493b5.svg\" alt=\"\\lfloor1.5\\rfloor=1\" width=\"97.73\" height=\"24.43\" style=\"width:97.73px;height:24.43px;aspect-ratio:97.73/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: count the first placement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f3dfc60f0024b2c.svg\" alt=\"N_{\\mathrm{out}}=1+1=2\" width=\"178.31\" height=\"20.54\" style=\"width:178.31px;height:20.54px;aspect-ratio:178.31/20.54\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Output side = 2; a square input gives a 2 × 2 map per filter.</p>","<h3>Padding on both sides</h3>","<p class=\"inline-question\"><strong>Question. A square convolution input has side 5, kernel side 3, stride 1 and padding 1 on each side. Find the padded-input size and output size.</strong></p>","<h3>Given</h3>","<p>N = 5; K = 3; S = 1; P = 1 on each side.</p>","<h3>To find</h3>","<p>Padded input and output dimensions.</p>","<h3>Formula — which one and why</h3>","<p>Padding adds P entries on each of two opposite sides; the output counts complete kernel placements.</p>","<p>N = unpadded side; K = kernel side; S = stride; P = per-side padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6bbc5ec5f7e71fe.svg\" alt=\"N_{\\mathrm{padded}}=N+2P\" width=\"191.11\" height=\"23.71\" style=\"width:191.11px;height:23.71px;aspect-ratio:191.11/23.71\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.00px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/500258811ea3eb2f.svg\"><img class=\"math display-math\" src=\"assets/equations/a8df1422782a8067.svg\" alt=\"N_{\\mathrm{out}}=\\lfloor(N+2P-K)/S\\rfloor+1\" width=\"323.70\" height=\"24.43\" style=\"width:323.70px;height:24.43px;aspect-ratio:323.70/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Padded input aur output ka size alag cheez hain.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count both padding edges.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/741118212eb25f73.svg\" alt=\"2P=2(1)=2\" width=\"151.39\" height=\"24.43\" style=\"width:151.39px;height:24.43px;aspect-ratio:151.39/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the padded input side.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a0c02a700e3aef2c.svg\" alt=\"N+2P=5+2=7\" width=\"213.83\" height=\"18.69\" style=\"width:213.83px;height:18.69px;aspect-ratio:213.83/18.69\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: subtract kernel width.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b2ddd3dd39f8f0c.svg\" alt=\"7-3=4\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide by stride and take the floor.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ce7e863527f4bb8.svg\" alt=\"\\lfloor4/1\\rfloor=4\" width=\"103.15\" height=\"24.43\" style=\"width:103.15px;height:24.43px;aspect-ratio:103.15/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: include the first placement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/94437545b203f62e.svg\" alt=\"N_{out}=4+1=5\" width=\"177.84\" height=\"20.54\" style=\"width:177.84px;height:20.54px;aspect-ratio:177.84/20.54\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Padded input = 7 × 7; output = 5 × 5 per filter.</p>","<p>“Valid” usually means P = 0. For odd K and S = 1, padding (K − 1)/2 preserves the spatial size. For S greater than 1, software “same” padding can be asymmetric and commonly gives ceiling(N/S); do not force the stride-1 rule into that case.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s3","search":"Stride padding and floor **Definition.** Stride is the spacing between consecutive kernel positions. Padding extends the input boundary. Together with kernel size and dilation, they determine the spatial dimensions of a convolutional output.\n\n### Explanation and working\nStride is how far the filter moves each time. Stride 2 visits starting positions 0, 2, 4 and so on. Padding adds border values, usually zeros. Padding 1 means one new row or column on each side, adding 2 to a spatial dimension.\n\n\n\n\nN is input size; P is padding per side; K is kernel size; S is stride. Floor means take the greatest integer not above the result: \\(\\left\\lfloor 2.5\\right\\rfloor\\) = 2. It counts only positions where the entire window fits. The formula assumes dilation 1, the standard setting in these papers. Apply it separately to height and width for rectangular images or kernels.\n**Why plus one?** Even when the kernel exactly fits the image, there is one placement. If N = K, P = 0, S = 1, the formula is 0 + 1 = 1.\n\n\n### Output dimension with a fractional intermediate result\n\n**Question. A convolution has input side N = 6, kernel side K = 3, stride S = 2 and padding P = 0. Find its output side.**\n\n\n\n### Given\n\nN = 6; K = 3; S = 2; P = 0; dilation = 1.\n\n### To find\n\nThe integer output side length.\n\n### Formula — which one and why\n\nThe formula counts complete kernel placements. Flooring removes an incomplete final placement.\n\nN is input side; P is padding on each side; K is kernel side; S is stride.\n\n\n\n**Yaad rakhne ka cue:** Padding dono side; stride se divide; floor; phir +1.\n\n### Solution — step by step\n\n\n\n**Step 1: include padding and subtract kernel size.**\n\n\n\n\n\n\n\n**Step 2: divide by the stride.**\n\n\n\n\n\n\n\n**Step 3: take the floor.**\n\n\n\n\n\n\n\n**Step 4: count the first placement.**\n\n\n\n\n\n\n\n**Final answer:** Output side = 2; a square input gives a 2 × 2 map per filter.\n\n\n\n\n### Padding on both sides\n\n**Question. A square convolution input has side 5, kernel side 3, stride 1 and padding 1 on each side. Find the padded-input size and output size.**\n\n\n\n### Given\n\nN = 5; K = 3; S = 1; P = 1 on each side.\n\n### To find\n\nPadded input and output dimensions.\n\n### Formula — which one and why\n\nPadding adds P entries on each of two opposite sides; the output counts complete kernel placements.\n\nN = unpadded side; K = kernel side; S = stride; P = per-side padding.\n\n\n\n\n\n**Yaad rakhne ka cue:** Padded input aur output ka size alag cheez hain.\n\n### Solution — step by step\n\n\n\n**Step 1: count both padding edges.**\n\n\n\n\n\n\n\n**Step 2: calculate the padded input side.**\n\n\n\n\n\n\n\n**Step 3: subtract kernel width.**\n\n\n\n\n\n\n\n**Step 4: divide by stride and take the floor.**\n\n\n\n\n\n\n\n**Step 5: include the first placement.**\n\n\n\n\n\n\n\n**Final answer:** Padded input = 7 × 7; output = 5 × 5 per filter.\n\n\n“Valid” usually means P = 0. For odd K and S = 1, padding (K − 1)/2 preserves the spatial size. For S greater than 1, software “same” padding can be asymmetric and commonly gives ceiling(N/S); do not force the stride-1 rule into that case."},{"title":"Convolution over several channels","blocks":["<p class=\"definition\"><strong>Definition.</strong> A standard convolutional filter spans every input channel. At one spatial position, channel-wise weighted sums are accumulated and one filter bias is added, producing one scalar output in that filter&#x27;s feature map.</p>","<h3>Explanation and working</h3>","<p>A 3 × 3 filter receiving RGB input has depth 3, so it contains 3 × 3 × 3 weights. At one position, compute a weighted sum in each of the three channels, add those sums, and then add the filter’s one bias. One filter produces one output channel. Sixteen filters produce sixteen output channels.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_channels.svg\" aria-label=\"Enlarge diagram: Add the channel contributions into one output cell. The filter bias is added once after those contributions.\"><img src=\"assets/figures/v_channels.svg\" alt=\"Add the channel contributions into one output cell. The filter bias is added once after those contributions.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Add the channel contributions into one output cell. The filter bias is added once after those contributions. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Tiny example.</strong> At one position the red, green and blue channel sums are 2, −1 and 4. With bias 0.5, the output is 2 − 1 + 4 + 0.5 = 5.5. Do not keep three separate outputs for this one filter; they have been added.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s4","search":"Convolution over several channels **Definition.** A standard convolutional filter spans every input channel. At one spatial position, channel-wise weighted sums are accumulated and one filter bias is added, producing one scalar output in that filter's feature map.\n\n### Explanation and working\nA 3 × 3 filter receiving RGB input has depth 3, so it contains 3 × 3 × 3 weights. At one position, compute a weighted sum in each of the three channels, add those sums, and then add the filter’s one bias. One filter produces one output channel. Sixteen filters produce sixteen output channels.\n\n\n\n**Tiny example.** At one position the red, green and blue channel sums are 2, −1 and 4. With bias 0.5, the output is 2 − 1 + 4 + 0.5 = 5.5. Do not keep three separate outputs for this one filter; they have been added."},{"title":"One filter over multiple channels: all contributions go into one cell","blocks":["<p class=\"definition\"><strong>Definition.</strong> Multi-channel convolution contracts the kernel&#x27;s spatial and input-channel dimensions to produce one output value per filter at each spatial location. Different filters have independent learned kernels.</p>","<h3>Explanation and working</h3>","<h3>1. Separate spatial size from depth</h3>","<p>Imagine a 1 × 1 spatial location with three input channels [2, 5, 1]. A 1 × 1 filter still has one weight for each channel. Suppose its weights are [0.1, −0.2, 0.5] and its bias is 0.3.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_channel_products.svg\" aria-label=\"Enlarge diagram: Multiply each channel by its own weight, add the three contributions, then add the single bias. These are the numbers in the example.\"><img src=\"assets/figures/v_channel_products.svg\" alt=\"Multiply each channel by its own weight, add the three contributions, then add the single bias. These are the numbers in the example.\" width=\"1080\" height=\"640\" loading=\"lazy\"></button><figcaption>Multiply each channel by its own weight, add the three contributions, then add the single bias. These are the numbers in the example. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.75px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/86f1a8b54476b2cb.svg\"><img class=\"math display-math\" src=\"assets/equations/36e8e2cc2919ceb8.svg\" alt=\"z=0.1(2)+(-0.2)(5)+0.5(1)+0.3\" width=\"390.16\" height=\"24.43\" style=\"width:390.16px;height:24.43px;aspect-ratio:390.16/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c377dccccbc387a.svg\" alt=\"z=0.2-1+0.5+0.3=0\" width=\"284.26\" height=\"18.27\" style=\"width:284.26px;height:18.27px;aspect-ratio:284.26/18.27\" loading=\"lazy\"></div>","<p>The three channels contributed to one output value. A single filter creates one output channel, even when its input has several channels.</p>","<h3>2. A larger filter has one spatial grid per input channel</h3>","<p>A 3 × 3 filter on a three-channel input has three 3 × 3 weight grids, totaling 27 weights. At one output location, calculate the nine products for channel 1, nine for channel 2 and nine for channel 3. Add all 27 products and then add the filter&#x27;s one bias.</p>","<p>The channel-wise sums are intermediate contributions; do not treat them as three final output channels unless three distinct filters were specified.</p>","<h3>3. What changes when there are several filters?</h3>","<p>Each filter has its own full-depth weight set and bias. Four filters give four independent sums at each output location, so the result has four channels. The filters all receive the same input depth.</p>","<p>For three input channels and four 3 × 3 filters, parameters are (27 + 1) × 4 = 112. Moving those filters over more image locations reuses these same 112 parameters.</p>","<h3>4. One-by-one does not mean one weight</h3>","<p>A 1 × 1 convolution with 64 input channels and 16 filters has 64 weights and one bias per filter: (64 + 1) × 16 = 1,040 parameters. It mixes channel information at each spatial position. With 16 outputs it reduces depth from 64 to 16; height and width stay unchanged when stride is 1 and no padding is needed.</p>","<p>This is the channel-reduction idea used by Inception bottlenecks and some residual projections. Spatial kernel size, input depth and output-channel count must all be read separately.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s5","search":"One filter over multiple channels: all contributions go into one cell **Definition.** Multi-channel convolution contracts the kernel's spatial and input-channel dimensions to produce one output value per filter at each spatial location. Different filters have independent learned kernels.\n\n### Explanation and working\n### 1. Separate spatial size from depth\nImagine a 1 × 1 spatial location with three input channels [2, 5, 1]. A 1 × 1 filter still has one weight for each channel. Suppose its weights are [0.1, −0.2, 0.5] and its bias is 0.3.\n\n\n\n\n\nThe three channels contributed to one output value. A single filter creates one output channel, even when its input has several channels.\n\n### 2. A larger filter has one spatial grid per input channel\nA 3 × 3 filter on a three-channel input has three 3 × 3 weight grids, totaling 27 weights. At one output location, calculate the nine products for channel 1, nine for channel 2 and nine for channel 3. Add all 27 products and then add the filter's one bias.\nThe channel-wise sums are intermediate contributions; do not treat them as three final output channels unless three distinct filters were specified.\n\n### 3. What changes when there are several filters?\nEach filter has its own full-depth weight set and bias. Four filters give four independent sums at each output location, so the result has four channels. The filters all receive the same input depth.\nFor three input channels and four 3 × 3 filters, parameters are (27 + 1) × 4 = 112. Moving those filters over more image locations reuses these same 112 parameters.\n\n### 4. One-by-one does not mean one weight\nA 1 × 1 convolution with 64 input channels and 16 filters has 64 weights and one bias per filter: (64 + 1) × 16 = 1,040 parameters. It mixes channel information at each spatial position. With 16 outputs it reduces depth from 64 to 16; height and width stay unchanged when stride is 1 and no padding is needed.\nThis is the channel-reduction idea used by Inception bottlenecks and some residual projections. Spatial kernel size, input depth and output-channel count must all be read separately.\n"},{"title":"Choosing more or fewer filters","blocks":["<p class=\"definition\"><strong>Definition.</strong> The number of convolutional filters determines the number of output channels. Kernel height, kernel width, stride and padding determine spatial processing; input-channel count determines each filter&#x27;s depth.</p>","<h3>Explanation and working</h3>","<p>Each filter produces one output channel and can learn a different pattern. More filters increase representational capacity, output depth, parameter count and activation memory. They may improve performance but can overfit small datasets or exceed a compute budget. Choose counts using validation results and resource constraints. More filters in one layer increase its width, not the number of network layers.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_filters.svg\" aria-label=\"Enlarge diagram: Each filter has the full incoming depth. Each produces one map, so the number of filters sets the output depth.\"><img src=\"assets/figures/v_filters.svg\" alt=\"Each filter has the full incoming depth. Each produces one map, so the number of filters sets the output depth.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>Each filter has the full incoming depth. Each produces one map, so the number of filters sets the output depth. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s6","search":"Choosing more or fewer filters **Definition.** The number of convolutional filters determines the number of output channels. Kernel height, kernel width, stride and padding determine spatial processing; input-channel count determines each filter's depth.\n\n### Explanation and working\nEach filter produces one output channel and can learn a different pattern. More filters increase representational capacity, output depth, parameter count and activation memory. They may improve performance but can overfit small datasets or exceed a compute budget. Choose counts using validation results and resource constraints. More filters in one layer increase its width, not the number of network layers.\n\n\n"},{"title":"Pooling needs comparisons or averages","blocks":["<p class=\"definition\"><strong>Definition.</strong> Pooling is a local aggregation operation that summarizes each spatial window, usually independently per channel. Max pooling selects the largest value; average pooling calculates a mean. Standard pooling has no learned weights or biases.</p>","<h3>Explanation and working</h3>","<p>Max pooling selects the largest value inside each window. Average pooling adds window entries and divides by their count. Ordinary max and average pooling have no learned weights or biases. Pool each input channel independently, so the number of channels is unchanged.</p>","<p class=\"inline-question\"><strong>Question.</strong> Pool this 4 × 4 map with 2 × 2 windows, stride 2 and no padding:</p>","<h3>Given</h3>","<p>The 4 × 4 input map is printed below.</p>","<p>Window = 2 × 2; stride = 2; padding = 0.</p>","<h3>To find</h3>","<p>Find the pooled output by the operation(s) requested.</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbeeead3eba02270.svg\" alt=\"A=\\begin{bmatrix}21&amp;11&amp;15&amp;10\\\\12&amp;9&amp;10&amp;11\\\\11&amp;13&amp;18&amp;12\\\\7&amp;4&amp;15&amp;12\\end{bmatrix}\" width=\"254.55\" height=\"127.06\" style=\"width:254.55px;height:127.06px;aspect-ratio:254.55/127.06\" loading=\"lazy\"></div>","<h3>Top-left window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[21, 11, 12, 9]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf103da2c4c32945.svg\" alt=\"y_{\\max}=21\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f9a0a96d6f9e048.svg\" alt=\"21+11+12+9=53\" width=\"232.15\" height=\"18.27\" style=\"width:232.15px;height:18.27px;aspect-ratio:232.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3fb67b8edc22789.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{53}4=13.25\" width=\"196.42\" height=\"49.55\" style=\"width:196.42px;height:49.55px;aspect-ratio:196.42/49.55\" loading=\"lazy\"></div>","<h3>Top-right window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[15, 10, 10, 11]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a17ef02b89e67e2.svg\" alt=\"y_{\\max}=15\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18d73c8a689f86bd.svg\" alt=\"15+10+10+11=46\" width=\"244.36\" height=\"18.54\" style=\"width:244.36px;height:18.54px;aspect-ratio:244.36/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4bcedeb9a26a70b6.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{46}4=11.5\" width=\"184.20\" height=\"49.82\" style=\"width:184.20px;height:49.82px;aspect-ratio:184.20/49.82\" loading=\"lazy\"></div>","<h3>Bottom-left window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[11, 13, 7, 4]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/37fcb9070f6a3c0a.svg\" alt=\"y_{\\max}=13\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba50b6f7e4060a25.svg\" alt=\"11+13+7+4=35\" width=\"219.93\" height=\"18.54\" style=\"width:219.93px;height:18.54px;aspect-ratio:219.93/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90fc093dce5b3464.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{35}4=8.75\" width=\"184.20\" height=\"49.55\" style=\"width:184.20px;height:49.55px;aspect-ratio:184.20/49.55\" loading=\"lazy\"></div>","<h3>Bottom-right window</h3>","<p class=\"worked-step\"><strong>Step 1: select the four entries.</strong></p>","<p>[18, 12, 15, 12]</p>","<p class=\"worked-step\"><strong>Step 2: choose the largest entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6e005f373e798e70.svg\" alt=\"y_{\\max}=18\" width=\"103.17\" height=\"21.29\" style=\"width:103.17px;height:21.29px;aspect-ratio:103.17/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add all entries.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/437a8b87df7ffce7.svg\" alt=\"18+12+15+12=57\" width=\"244.36\" height=\"18.52\" style=\"width:244.36px;height:18.52px;aspect-ratio:244.36/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide the sum by four for the average.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aaffd26053e275ce.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{57}4=14.25\" width=\"196.42\" height=\"49.80\" style=\"width:196.42px;height:49.80px;aspect-ratio:196.42/49.80\" loading=\"lazy\"></div>","<p>Outputs are max <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/89ec596cf1c6ec68.svg\" alt=\"\\begin{bmatrix}21 &amp; 15\\\\13 &amp; 18\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span> and average <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/94682b0fab3f0b97.svg\" alt=\"\\begin{bmatrix}13.25 &amp; 11.5\\\\8.75 &amp; 14.25\\end{bmatrix}\" width=\"125.66\" height=\"45.61\" style=\"width:125.66px;height:45.61px;aspect-ratio:125.66/45.61\" loading=\"lazy\"></span>.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/pooling.svg\" aria-label=\"Enlarge diagram: Each pooling window reduces several values to one\"><img src=\"assets/figures/pooling.svg\" alt=\"Each pooling window reduces several values to one\" width=\"960\" height=\"500\" loading=\"lazy\"></button><figcaption>Each pooling window reduces several values to one <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Pooling reduces spatial size and later computation and can provide limited robustness to small shifts. It can lose exact position information. It does not guarantee complete translation invariance.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s7","search":"Pooling needs comparisons or averages **Definition.** Pooling is a local aggregation operation that summarizes each spatial window, usually independently per channel. Max pooling selects the largest value; average pooling calculates a mean. Standard pooling has no learned weights or biases.\n\n### Explanation and working\nMax pooling selects the largest value inside each window. Average pooling adds window entries and divides by their count. Ordinary max and average pooling have no learned weights or biases. Pool each input channel independently, so the number of channels is unchanged.\n**Question.** Pool this 4 × 4 map with 2 × 2 windows, stride 2 and no padding:\n\n\n\n### Given\n\nThe 4 × 4 input map is printed below.\n\nWindow = 2 × 2; stride = 2; padding = 0.\n\n### To find\n\nFind the pooled output by the operation(s) requested.\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n\n### Top-left window\n\n**Step 1: select the four entries.**\n\n[21, 11, 12, 9]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\n### Top-right window\n\n**Step 1: select the four entries.**\n\n[15, 10, 10, 11]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\n### Bottom-left window\n\n**Step 1: select the four entries.**\n\n[11, 13, 7, 4]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\n### Bottom-right window\n\n**Step 1: select the four entries.**\n\n[18, 12, 15, 12]\n\n**Step 2: choose the largest entry.**\n\n\n\n\n\n\n\n**Step 3: add all entries.**\n\n\n\n\n\n\n\n**Step 4: divide the sum by four for the average.**\n\n\n\n\n\n\n\n\nOutputs are max  and average .\n\nPooling reduces spatial size and later computation and can provide limited robustness to small shifts. It can lose exact position information. It does not guarantee complete translation invariance."},{"title":"Parameters are different from activation values","blocks":["<p class=\"definition\"><strong>Definition.</strong> Parameters are learned coefficients shared across evaluations. Activations are input-dependent values computed during a forward pass. The number of activation values therefore differs from the number of trainable parameters.</p>","<h3>Explanation and working</h3>","<p>An activation is a number produced for a particular input. A parameter is a learned number reused across inputs. A 100 × 100 feature map can be produced by a filter with only a few weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters_activations.svg\" aria-label=\"Enlarge diagram: The ten learned parameters are reused at nine spatial positions. The resulting nine numbers are activations.\"><img src=\"assets/figures/v_parameters_activations.svg\" alt=\"The ten learned parameters are reused at nine spatial positions. The resulting nine numbers are activations.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The ten learned parameters are reused at nine spatial positions. The resulting nine numbers are activations. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<p>The +1 is one bias per filter. If bias is explicitly disabled, remove it. Height and width of the image do not enter the parameter formula; they enter the number of output activations and the amount of computation.</p>","<h3>One filter, then all filters</h3>","<p class=\"inline-question\"><strong>Question. A 3 × 3 convolution receives 3 input channels and has 16 filters, each with one bias. Find its trainable parameters and output-channel count.</strong></p>","<h3>Given</h3>","<p>Kernel = 3 × 3; input channels = 3; filters = 16; one bias per filter.</p>","<h3>To find</h3>","<p>Weights, biases, total trainable parameters and output channels.</p>","<h3>Formula — which one and why</h3>","<p>Each filter spans every input channel and owns one bias. Spatial reuse does not create extra weights.</p>","<p>Kₕ,Kw are kernel dimensions; Cᵢₙ is input depth; Cₒᵤₜ is the number of filters.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a603987eb773068.svg\" alt=\"P=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.27\" height=\"24.43\" style=\"width:258.27px;height:24.43px;aspect-ratio:258.27/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek filter ka count banao, phir filters se multiply.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count weights in one filter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ee13fc57d61624d3.svg\" alt=\"3(3)(3)=27\" width=\"131.70\" height=\"24.43\" style=\"width:131.70px;height:24.43px;aspect-ratio:131.70/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: include its one bias.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5f8acbeb6a1db0ac.svg\" alt=\"27+1=28\" width=\"123.54\" height=\"18.52\" style=\"width:123.54px;height:18.52px;aspect-ratio:123.54/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: count all weights.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f7cebde5567e220a.svg\" alt=\"27(16)=432\" width=\"137.12\" height=\"24.43\" style=\"width:137.12px;height:24.43px;aspect-ratio:137.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: count all biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96319009caa148f5.svg\" alt=\"1(16)=16\" width=\"112.68\" height=\"24.43\" style=\"width:112.68px;height:24.43px;aspect-ratio:112.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add and state channel count.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17c5c3c49aac5f53.svg\" alt=\"P=432+16=448\" width=\"211.13\" height=\"18.69\" style=\"width:211.13px;height:18.69px;aspect-ratio:211.13/18.69\" loading=\"lazy\"></div>","<p>Each filter produces one channel, so output channels = 16.</p>","<p><strong>Final answer:</strong> 432 weights + 16 biases = 448 trainable parameters; 16 output channels.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/676bf495296f4651.svg\"><img class=\"math display-math\" src=\"assets/equations/3d36d7d9ab25e138.svg\" alt=\"P_{\\mathrm{pool}}=0,\\quad P_{\\mathrm{flatten}}=0,\\quad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"502.29\" height=\"25.35\" style=\"width:502.29px;height:25.35px;aspect-ratio:502.29/25.35\" loading=\"lazy\"></picture></div>","<p>Flatten rearranges H × W × C activation values into one vector of length HWC. It does not learn anything. A following dense layer connects to every one of those values.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s8","search":"Parameters are different from activation values **Definition.** Parameters are learned coefficients shared across evaluations. Activations are input-dependent values computed during a forward pass. The number of activation values therefore differs from the number of trainable parameters.\n\n### Explanation and working\nAn activation is a number produced for a particular input. A parameter is a learned number reused across inputs. A 100 × 100 feature map can be produced by a filter with only a few weights.\n\n\n\n\nThe +1 is one bias per filter. If bias is explicitly disabled, remove it. Height and width of the image do not enter the parameter formula; they enter the number of output activations and the amount of computation.\n\n\n### One filter, then all filters\n\n**Question. A 3 × 3 convolution receives 3 input channels and has 16 filters, each with one bias. Find its trainable parameters and output-channel count.**\n\n\n\n### Given\n\nKernel = 3 × 3; input channels = 3; filters = 16; one bias per filter.\n\n### To find\n\nWeights, biases, total trainable parameters and output channels.\n\n### Formula — which one and why\n\nEach filter spans every input channel and owns one bias. Spatial reuse does not create extra weights.\n\nKₕ,Kw are kernel dimensions; Cᵢₙ is input depth; Cₒᵤₜ is the number of filters.\n\n\n\n**Yaad rakhne ka cue:** Ek filter ka count banao, phir filters se multiply.\n\n### Solution — step by step\n\n\n\n**Step 1: count weights in one filter.**\n\n\n\n\n\n\n\n**Step 2: include its one bias.**\n\n\n\n\n\n\n\n**Step 3: count all weights.**\n\n\n\n\n\n\n\n**Step 4: count all biases.**\n\n\n\n\n\n\n\n**Step 5: add and state channel count.**\n\n\n\n\n\nEach filter produces one channel, so output channels = 16.\n\n**Final answer:** 432 weights + 16 biases = 448 trainable parameters; 16 output channels.\n\n\n\nFlatten rearranges H × W × C activation values into one vector of length HWC. It does not learn anything. A following dense layer connects to every one of those values."},{"title":"One complete CNN pipeline","blocks":["<p class=\"inline-question\"><strong>Question.</strong> Input 128 × 128 × 3 → convolution 3 × 3, 16 filters, stride 1, no padding → pooling 2 × 2, stride 2 → convolution 3 × 3, 32 filters, stride 1, no padding → pooling 2 × 2, stride 2 → dense 240 → dense 120 → dense 5 with softmax. Find every output shape and trainable parameter count. Assume one bias per receiving filter or dense neuron.</p>","<h3>Given</h3>","<p>Input = 128 × 128 × 3.</p>","<p>Conv: 3 × 3,16 filters,stride 1,valid → pool 2,stride 2.</p>","<p>Conv: 3 × 3,32 filters,stride 1,valid → pool 2,stride 2.</p>","<p>Flatten → dense 240 → dense 120 → dense 5.</p>","<p>One bias per learned filter/dense neuron.</p>","<h3>To find</h3>","<p>Find every output shape and layer parameter count, then the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1. Conv 1 size.</strong> (128 − 3)/1 + 1 = 126; output 126 × 126 × 16. Parameters = (3 × 3 × 3 + 1) × 16 = 448.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_cnn_pipeline.svg\" aria-label=\"Enlarge diagram: Follow all eight layers from the question. Each row keeps the output shape separate from its learned-parameter count.\"><img src=\"assets/figures/v_cnn_pipeline.svg\" alt=\"Follow all eight layers from the question. Each row keeps the output shape separate from its learned-parameter count.\" width=\"1080\" height=\"1080\" loading=\"lazy\"></button><figcaption>Follow all eight layers from the question. Each row keeps the output shape separate from its learned-parameter count. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 2. Pool 1 size.</strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/9e62fef4c3e773c7.svg\" alt=\"\\left\\lfloor\\frac{126 - 2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span> = 63; output 63 × 63 × 16. Parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 3. Conv 2 size.</strong> (63 − 3)/1 + 1 = 61; output 61 × 61 × 32. Input channels are now 16, not the original 3. Parameters = (3 × 3 × 16 + 1) × 32 = 4,640.</p>","<p class=\"worked-step\"><strong>Step 4. Pool 2 size.</strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4d2232cedf251bfa.svg\" alt=\"\\left\\lfloor\\frac{61 - 2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span> = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/dfb80f08b9b0c4e1.svg\" alt=\"\\left\\lfloor 29.5\\right\\rfloor\" width=\"50.67\" height=\"19.00\" style=\"width:50.67px;height:19.00px;aspect-ratio:50.67/19.00\" loading=\"lazy\"></span> + 1 = 30; output 30 × 30 × 32. Parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 5. Flatten.</strong> 30 × 30 × 32 = 28,800 values. Parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 6. Dense 240.</strong> 28,800 weights per neuron plus one bias, multiplied by 240: (28,800 + 1) × 240 = 6,912,240.</p>","<p class=\"worked-step\"><strong>Step 7. Dense 120.</strong> (240 + 1) × 120 = 28,920.</p>","<p class=\"worked-step\"><strong>Step 8. Classifier.</strong> (120 + 1) × 5 = 605. Softmax itself adds no extra parameters; these 605 belong to the dense class-score layer.</p>","<p class=\"worked-step\"><strong>Step 9. Total.</strong> 448 + 4,640 + 6,912,240 + 28,920 + 605 = <strong>6,946,853</strong>. Most parameters come from the first dense layer.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s9","search":"One complete CNN pipeline **Question.** Input 128 × 128 × 3 → convolution 3 × 3, 16 filters, stride 1, no padding → pooling 2 × 2, stride 2 → convolution 3 × 3, 32 filters, stride 1, no padding → pooling 2 × 2, stride 2 → dense 240 → dense 120 → dense 5 with softmax. Find every output shape and trainable parameter count. Assume one bias per receiving filter or dense neuron.\n\n\n\n### Given\n\nInput = 128 × 128 × 3.\n\nConv: 3 × 3,16 filters,stride 1,valid → pool 2,stride 2.\n\nConv: 3 × 3,32 filters,stride 1,valid → pool 2,stride 2.\n\nFlatten → dense 240 → dense 120 → dense 5.\n\nOne bias per learned filter/dense neuron.\n\n### To find\n\nFind every output shape and layer parameter count, then the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n**Step 1. Conv 1 size.** (128 − 3)/1 + 1 = 126; output 126 × 126 × 16. Parameters = (3 × 3 × 3 + 1) × 16 = 448.\n\n\n\n**Step 2. Pool 1 size.** \\(\\left\\lfloor\\frac{126 - 2}{2}\\right\\rfloor+1\\) = 63; output 63 × 63 × 16. Parameters = 0.\n**Step 3. Conv 2 size.** (63 − 3)/1 + 1 = 61; output 61 × 61 × 32. Input channels are now 16, not the original 3. Parameters = (3 × 3 × 16 + 1) × 32 = 4,640.\n**Step 4. Pool 2 size.** \\(\\left\\lfloor\\frac{61 - 2}{2}\\right\\rfloor+1\\) = \\(\\left\\lfloor 29.5\\right\\rfloor\\) + 1 = 30; output 30 × 30 × 32. Parameters = 0.\n**Step 5. Flatten.** 30 × 30 × 32 = 28,800 values. Parameters = 0.\n**Step 6. Dense 240.** 28,800 weights per neuron plus one bias, multiplied by 240: (28,800 + 1) × 240 = 6,912,240.\n**Step 7. Dense 120.** (240 + 1) × 120 = 28,920.\n**Step 8. Classifier.** (120 + 1) × 5 = 605. Softmax itself adds no extra parameters; these 605 belong to the dense class-score layer.\n**Step 9. Total.** 448 + 4,640 + 6,912,240 + 28,920 + 605 = **6,946,853**. Most parameters come from the first dense layer."},{"title":"CNN versus a fully connected image network","blocks":["<p class=\"definition\"><strong>Definition.</strong> A convolutional neural network uses local receptive fields and spatial parameter sharing, unlike a dense layer&#x27;s independent connection weights. These architectural constraints exploit spatial structure and can greatly reduce parameter counts.</p>","<h3>Explanation and working</h3>","<p>A fully connected layer can learn image features, but flattening pixels and connecting every pixel to every neuron ignores the useful local structure built into a CNN and can require many parameters. CNNs exploit local connections and shared filters. They learn hierarchical features and reuse a pattern detector at many locations.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_fc_cnn.svg\" aria-label=\"Enlarge diagram: Compare where connections go and which weights are reused.\"><img src=\"assets/figures/v_fc_cnn.svg\" alt=\"Compare where connections go and which weights are reused.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Compare where connections go and which weights are reused. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For a 32 × 32 × 3 input, a dense layer with 100 neurons has (3,072 + 1) × 100 = 307,300 parameters. A convolution with 100 filters of size 3 × 3 has (27 + 1) × 100 = 2,800 parameters. The outputs are different shapes, so this is a parameter-efficiency illustration, not two identical computational tasks.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s10","search":"CNN versus a fully connected image network **Definition.** A convolutional neural network uses local receptive fields and spatial parameter sharing, unlike a dense layer's independent connection weights. These architectural constraints exploit spatial structure and can greatly reduce parameter counts.\n\n### Explanation and working\nA fully connected layer can learn image features, but flattening pixels and connecting every pixel to every neuron ignores the useful local structure built into a CNN and can require many parameters. CNNs exploit local connections and shared filters. They learn hierarchical features and reuse a pattern detector at many locations.\n\n\n\nFor a 32 × 32 × 3 input, a dense layer with 100 neurons has (3,072 + 1) × 100 = 307,300 parameters. A convolution with 100 filters of size 3 × 3 has (27 + 1) × 100 = 2,800 parameters. The outputs are different shapes, so this is a parameter-efficiency illustration, not two identical computational tasks.\n"},{"title":"Model answer: CNN structure and parameter sharing","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain the main layers of a convolutional neural network and why CNNs are suitable for image data. Compare them with a fully connected image network.</p>"],"answer":["<p>A CNN processes spatially arranged data using filters that examine local regions. The same filter weights are reused at different positions. This combination of local connectivity and weight sharing builds an image-specific structure into the model and can greatly reduce the number of learned weights.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_weight_sharing.svg\" aria-label=\"Enlarge diagram: The highlighted patch uses the same filter that will be reused at the next position.\"><img src=\"assets/figures/v_weight_sharing.svg\" alt=\"The highlighted patch uses the same filter that will be reused at the next position.\" width=\"1080\" height=\"590\" loading=\"lazy\"></button><figcaption>The highlighted patch uses the same filter that will be reused at the next position. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Typical layer sequence</h3>","<p><strong>Input → convolution → nonlinear activation → optional pooling → further feature extraction → classifier.</strong></p>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Operation</th><th>Learned parameters?</th></tr></thead><tbody><tr><td>Convolution</td><td>Multiply a local window by a filter, sum and add its bias</td><td>Filter weights and usually one bias per filter</td></tr><tr><td>ReLU</td><td>Replace negative values by zero</td><td>No ordinary ReLU parameters</td></tr><tr><td>Pooling</td><td>Summarize each window by maximum or average</td><td>None for ordinary max/average pooling</td></tr><tr><td>Flatten</td><td>Rearrange H × W × C values into a vector</td><td>None</td></tr><tr><td>Dense layer</td><td>Form weighted combinations of all incoming values</td><td>Weights and receiving-neuron biases</td></tr><tr><td>Softmax</td><td>Convert class scores into probabilities</td><td>No additional weights of its own</td></tr></tbody></table></div>","<p>Early filters can learn local patterns such as edges. Later layers combine features over larger receptive fields. A filter responding at several image positions uses one shared set of weights, not a new set at every location.</p>","<p>Flattening an image and using a dense layer does not enforce this local, shared structure. A dense layer has a separate connection weight for each input–output pair. CNNs can therefore be more parameter-efficient for visual patterns, although they still need suitable data and training. Pooling can provide some robustness to small shifts; it does not guarantee complete invariance to every translation.</p>"],"kind":"theory","id":"tee-c7-s11","search":"Model answer: CNN structure and parameter sharing **Question.** Explain the main layers of a convolutional neural network and why CNNs are suitable for image data. Compare them with a fully connected image network.\n\n**Model answer.**\nA CNN processes spatially arranged data using filters that examine local regions. The same filter weights are reused at different positions. This combination of local connectivity and weight sharing builds an image-specific structure into the model and can greatly reduce the number of learned weights.\n\n\n\n\n### Typical layer sequence\n**Input → convolution → nonlinear activation → optional pooling → further feature extraction → classifier.**\n\n| Layer | Operation | Learned parameters? |\n| Convolution | Multiply a local window by a filter, sum and add its bias | Filter weights and usually one bias per filter |\n| ReLU | Replace negative values by zero | No ordinary ReLU parameters |\n| Pooling | Summarize each window by maximum or average | None for ordinary max/average pooling |\n| Flatten | Rearrange H × W × C values into a vector | None |\n| Dense layer | Form weighted combinations of all incoming values | Weights and receiving-neuron biases |\n| Softmax | Convert class scores into probabilities | No additional weights of its own |\n\nEarly filters can learn local patterns such as edges. Later layers combine features over larger receptive fields. A filter responding at several image positions uses one shared set of weights, not a new set at every location.\n\nFlattening an image and using a dense layer does not enforce this local, shared structure. A dense layer has a separate connection weight for each input–output pair. CNNs can therefore be more parameter-efficient for visual patterns, although they still need suitable data and training. Pooling can provide some robustness to small shifts; it does not guarantee complete invariance to every translation.\n"},{"title":"Output size and parameter count are different","blocks":["<p class=\"definition\"><strong>Definition.</strong> Output shape specifies the size of a layer&#x27;s computed tensor. Parameter count specifies the number of independent trainable coefficients. Spatial weight sharing allows a convolutional layer to produce many activations from comparatively few parameters.</p>","<h3>Explanation and working</h3>","<p class=\"inline-question\"><strong>Question.</strong> A 7 × 7 × 3 input passes through two 3 × 3 filters, stride 2 and padding 1. Find output shape and parameter count, including bias.</p>","<h3>Given</h3>","<p>Input = 7 × 7 × 3; two 3 × 3 filters.</p>","<p>Stride = 2; padding = 1; include biases.</p>","<h3>To find</h3>","<p>Find the output shape and trainable parameter count.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 spatial size:</strong> padding adds two, giving 7 + 2 − 3 = 6. Divide by stride: 6 ÷ 2 = 3. Apply floor and add the first position: 3 + 1 = 4. There are two filters, so output is 4 × 4 × 2.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters_activations.svg\" aria-label=\"Enlarge diagram: Output size counts produced values; parameter count counts adjustable weights and biases.\"><img src=\"assets/figures/v_parameters_activations.svg\" alt=\"Output size counts produced values; parameter count counts adjustable weights and biases.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Output size counts produced values; parameter count counts adjustable weights and biases. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 2 parameters:</strong> one filter has 3 × 3 × 3 = 27 weights and one bias, giving 28. Two filters have 56 parameters. The 4 × 4 output positions reuse those weights; they do not create 16 new sets of parameters.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s12","search":"Output size and parameter count are different **Definition.** Output shape specifies the size of a layer's computed tensor. Parameter count specifies the number of independent trainable coefficients. Spatial weight sharing allows a convolutional layer to produce many activations from comparatively few parameters.\n\n### Explanation and working\n**Question.** A 7 × 7 × 3 input passes through two 3 × 3 filters, stride 2 and padding 1. Find output shape and parameter count, including bias.\n\n\n\n### Given\n\nInput = 7 × 7 × 3; two 3 × 3 filters.\n\nStride = 2; padding = 1; include biases.\n\n### To find\n\nFind the output shape and trainable parameter count.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n**Step 1 spatial size:** padding adds two, giving 7 + 2 − 3 = 6. Divide by stride: 6 ÷ 2 = 3. Apply floor and add the first position: 3 + 1 = 4. There are two filters, so output is 4 × 4 × 2.\n\n\n\n**Step 2 parameters:** one filter has 3 × 3 × 3 = 27 weights and one bias, giving 28. Two filters have 56 parameters. The 4 × 4 output positions reuse those weights; they do not create 16 new sets of parameters.\n\n"},{"title":"Model answer: shape, activations and parameters","question":["<p class=\"inline-question\"><strong>Question.</strong> Distinguish a CNN layer&#x27;s output shape, number of output activations and number of trainable parameters. Explain the formulas used to calculate them.</p>"],"answer":["<p>Output shape tells how the produced values are arranged. The activation count tells how many values were produced for one input. Parameter count tells how many learned weights and biases define the layer. These are three different questions.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_parameters_activations.svg\" aria-label=\"Enlarge diagram: Keep output shape, activation count and parameter count as three separate quantities.\"><img src=\"assets/figures/v_parameters_activations.svg\" alt=\"Keep output shape, activation count and parameter count as three separate quantities.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Keep output shape, activation count and parameter count as three separate quantities. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Spatial output shape</h3>","<p>For an ordinary convolution with dilation 1:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is the incoming spatial size, P is padding on each side, K is kernel size and S is stride. Apply the rule independently to height and width. The number of output channels is the number of filters.</p>","<h3>Output activations</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c9b86a3e71336c4.svg\" alt=\"A=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}\" width=\"192.74\" height=\"21.35\" style=\"width:192.74px;height:21.35px;aspect-ratio:192.74/21.35\" loading=\"lazy\"></div>","<p>This is the number of output values for one example, excluding any batch dimension.</p>","<h3>Trainable parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<p>Each filter spans every incoming channel. The +1 is one bias per filter. Remove it if biases are disabled. Spatial output dimensions do not appear here because filters share their weights across positions.</p>","<h3>Small example</h3>","<p>A 7 × 7 × 3 input, two 3 × 3 filters, stride 2 and padding 1 gives output 4 × 4 × 2. It contains 32 activations but has (3 × 3 × 3 + 1) × 2 = 56 parameters. These counts do not need to match. In a multilayer question, the current layer&#x27;s output channels become the next convolution&#x27;s input channels.</p>"],"kind":"theory","id":"tee-c7-s13","search":"Model answer: shape, activations and parameters **Question.** Distinguish a CNN layer's output shape, number of output activations and number of trainable parameters. Explain the formulas used to calculate them.\n\n**Model answer.**\nOutput shape tells how the produced values are arranged. The activation count tells how many values were produced for one input. Parameter count tells how many learned weights and biases define the layer. These are three different questions.\n\n\n\n\n### Spatial output shape\nFor an ordinary convolution with dilation 1:\n\nN is the incoming spatial size, P is padding on each side, K is kernel size and S is stride. Apply the rule independently to height and width. The number of output channels is the number of filters.\n\n### Output activations\n\nThis is the number of output values for one example, excluding any batch dimension.\n\n### Trainable parameters\n\nEach filter spans every incoming channel. The +1 is one bias per filter. Remove it if biases are disabled. Spatial output dimensions do not appear here because filters share their weights across positions.\n\n### Small example\nA 7 × 7 × 3 input, two 3 × 3 filters, stride 2 and padding 1 gives output 4 × 4 × 2. It contains 32 activations but has (3 × 3 × 3 + 1) × 2 = 56 parameters. These counts do not need to match. In a multilayer question, the current layer's output channels become the next convolution's input channels.\n"},{"title":"Faculty example: a complete binary-image convolution","blocks":["<p class=\"inline-question\"><strong>Question. Apply the shown 3 × 3 filter to the 5 × 5 image. Use stride 1, no padding and zero bias. Calculate every output value without flipping the filter. (Practice: 5 marks)</strong></p>","<h3>Given</h3>","<p>Image X = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/acdfbb90974d971f.svg\" alt=\"\\begin{bmatrix}1 &amp; 1 &amp; 1 &amp; 0 &amp; 0\\\\0 &amp; 1 &amp; 1 &amp; 1 &amp; 0\\\\0 &amp; 0 &amp; 1 &amp; 1 &amp; 1\\\\0 &amp; 0 &amp; 1 &amp; 1 &amp; 0\\\\0 &amp; 1 &amp; 1 &amp; 0 &amp; 0\\end{bmatrix}\" width=\"148.88\" height=\"125.43\" style=\"width:148.88px;height:125.43px;aspect-ratio:148.88/125.43\" loading=\"lazy\"></span>.</p>","<p>Filter K = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/305a3f29286c4e55.svg\" alt=\"\\begin{bmatrix}1 &amp; 0 &amp; 1\\\\0 &amp; 1 &amp; 0\\\\1 &amp; 0 &amp; 1\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>. These are the values in the Unit 4 lecture example.</p>","<h3>To find</h3>","<p>The output shape and all nine feature-map values.</p>","<h3>Formula — which one and why</h3>","<p>The output-size formula counts complete filter placements. At each placement, multiply matching image/filter cells and add the products. A filter entry of zero makes that particular product zero; it does not remove the image cell from the input.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>Here N is input side, K is kernel side, P is padding per side and S is stride. The symbol K in the shape formula is the size 3, whereas the matrix K above contains the filter&#x27;s coefficients.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p>For this particular filter, only the four corners and the centre of each 3 × 3 window contribute. We can therefore write each sum using those five entries after explaining the four zero products. Below, their order is always <strong>top-left, top-right, centre, bottom-left, bottom-right</strong> within the current window.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_binary_windows.svg\" aria-label=\"Enlarge diagram: Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions.\"><img src=\"assets/figures/u4_binary_windows.svg\" alt=\"Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions.\" width=\"900\" height=\"405\" loading=\"lazy\"></button><figcaption>Each output cell corresponds to a different 3 × 3 window. The filter coefficients are reused at all nine positions. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: find the shape.</strong> (5 − 3)/1 + 1 = 3. The output is 3 × 3.</p>","<p class=\"worked-step\"><strong>Step 2: top-left output, showing all nine products.</strong> 1×1 + 1×0 + 1×1 + 0×0 + 1×1 + 1×0 + 0×1 + 0×0 + 1×1 = 1+0+1+0+1+0+0+0+1 = <strong>4</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: top-middle output.</strong> Move the window one column right. Corners and centre are 1,0,1,0,1. Sum = 1+0+1+0+1 = <strong>3</strong>.</p>","<p class=\"worked-step\"><strong>Step 4: top-right output.</strong> Move one more column right. Corners and centre are 1,0,1,1,1. Sum = 1+0+1+1+1 = <strong>4</strong>.</p>","<p class=\"worked-step\"><strong>Step 5: middle-left output.</strong> Return to column 1 and move down one row. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = <strong>2</strong>.</p>","<p class=\"worked-step\"><strong>Step 6: middle-middle output.</strong> Corners and centre are 1,1,1,0,1. Sum = 1+1+1+0+1 = <strong>4</strong>.</p>","<p class=\"worked-step\"><strong>Step 7: middle-right output.</strong> Corners and centre are 1,0,1,1,0. Sum = 1+0+1+1+0 = <strong>3</strong>.</p>","<p class=\"worked-step\"><strong>Step 8: bottom-left output.</strong> Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = <strong>2</strong>.</p>","<p class=\"worked-step\"><strong>Step 9: bottom-middle output.</strong> Corners and centre are 0,1,1,1,0. Sum = 0+1+1+1+0 = <strong>3</strong>.</p>","<p class=\"worked-step\"><strong>Step 10: bottom-right output.</strong> Corners and centre are 1,1,1,1,0. Sum = 1+1+1+1+0 = <strong>4</strong>.</p>","<p><strong>Final answer:</strong> Y = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/12aa767f92286deb.svg\" alt=\"\\begin{bmatrix}4 &amp; 3 &amp; 4\\\\2 &amp; 4 &amp; 3\\\\2 &amp; 3 &amp; 4\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>. All nine outputs use the same nine filter weights. They do not introduce nine different filters.</p>","<p><strong>Yaad rakho:</strong> Window badalta hai; filter ke numbers same rehte hain.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s14","search":"Faculty example: a complete binary-image convolution **Question. Apply the shown 3 × 3 filter to the 5 × 5 image. Use stride 1, no padding and zero bias. Calculate every output value without flipping the filter. (Practice: 5 marks)**\n\n### Given\nImage X = .\n\nFilter K = . These are the values in the Unit 4 lecture example.\n\n### To find\nThe output shape and all nine feature-map values.\n\n### Formula — which one and why\nThe output-size formula counts complete filter placements. At each placement, multiply matching image/filter cells and add the products. A filter entry of zero makes that particular product zero; it does not remove the image cell from the input.\n\n\n\nHere N is input side, K is kernel side, P is padding per side and S is stride. The symbol K in the shape formula is the size 3, whereas the matrix K above contains the filter's coefficients.\n\n\n\nFor this particular filter, only the four corners and the centre of each 3 × 3 window contribute. We can therefore write each sum using those five entries after explaining the four zero products. Below, their order is always **top-left, top-right, centre, bottom-left, bottom-right** within the current window.\n\n\n\n### Solution — step by step\n**Step 1: find the shape.** (5 − 3)/1 + 1 = 3. The output is 3 × 3.\n\n**Step 2: top-left output, showing all nine products.** 1×1 + 1×0 + 1×1 + 0×0 + 1×1 + 1×0 + 0×1 + 0×0 + 1×1 = 1+0+1+0+1+0+0+0+1 = **4**.\n\n**Step 3: top-middle output.** Move the window one column right. Corners and centre are 1,0,1,0,1. Sum = 1+0+1+0+1 = **3**.\n\n**Step 4: top-right output.** Move one more column right. Corners and centre are 1,0,1,1,1. Sum = 1+0+1+1+1 = **4**.\n\n**Step 5: middle-left output.** Return to column 1 and move down one row. Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = **2**.\n\n**Step 6: middle-middle output.** Corners and centre are 1,1,1,0,1. Sum = 1+1+1+0+1 = **4**.\n\n**Step 7: middle-right output.** Corners and centre are 1,0,1,1,0. Sum = 1+0+1+1+0 = **3**.\n\n**Step 8: bottom-left output.** Corners and centre are 0,1,0,0,1. Sum = 0+1+0+0+1 = **2**.\n\n**Step 9: bottom-middle output.** Corners and centre are 0,1,1,1,0. Sum = 0+1+1+1+0 = **3**.\n\n**Step 10: bottom-right output.** Corners and centre are 1,1,1,1,0. Sum = 1+1+1+1+0 = **4**.\n\n**Final answer:** Y = . All nine outputs use the same nine filter weights. They do not introduce nine different filters.\n\n**Yaad rakho:** Window badalta hai; filter ke numbers same rehte hain.\n"},{"title":"Faculty example: combine three RGB channel sums","blocks":["<p class=\"inline-question\"><strong>Question. At one position, a convolutional filter receives the following red, green and blue 3 × 3 patches and matching kernel slices. Calculate one output value with bias 1. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>Red patch = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/54e18a92743f2660.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 156 &amp; 155\\\\0 &amp; 153 &amp; 154\\end{bmatrix}\" width=\"129.88\" height=\"72.21\" style=\"width:129.88px;height:72.21px;aspect-ratio:129.88/72.21\" loading=\"lazy\"></span>; red kernel = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/05d6756a9472b44c.svg\" alt=\"\\begin{bmatrix}-1 &amp; -1 &amp; 1\\\\0 &amp; 1 &amp; -1\\\\0 &amp; 1 &amp; 1\\end{bmatrix}\" width=\"136.22\" height=\"72.21\" style=\"width:136.22px;height:72.21px;aspect-ratio:136.22/72.21\" loading=\"lazy\"></span>.</p>","<p>Green patch = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ca174e19344d6ef9.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 167 &amp; 166\\\\0 &amp; 164 &amp; 165\\end{bmatrix}\" width=\"129.88\" height=\"72.21\" style=\"width:129.88px;height:72.21px;aspect-ratio:129.88/72.21\" loading=\"lazy\"></span>; green kernel = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/7b136c068c1d807b.svg\" alt=\"\\begin{bmatrix}1 &amp; 0 &amp; 0\\\\1 &amp; -1 &amp; -1\\\\1 &amp; 0 &amp; -1\\end{bmatrix}\" width=\"121.44\" height=\"72.21\" style=\"width:121.44px;height:72.21px;aspect-ratio:121.44/72.21\" loading=\"lazy\"></span>.</p>","<p>Blue patch = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/8798bafaa1889aed.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 163 &amp; 162\\\\0 &amp; 160 &amp; 161\\end{bmatrix}\" width=\"129.88\" height=\"72.21\" style=\"width:129.88px;height:72.21px;aspect-ratio:129.88/72.21\" loading=\"lazy\"></span>; blue kernel = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/fccc1fad371104fc.svg\" alt=\"\\begin{bmatrix}0 &amp; 1 &amp; 1\\\\0 &amp; 1 &amp; 0\\\\1 &amp; -1 &amp; 1\\end{bmatrix}\" width=\"106.65\" height=\"72.21\" style=\"width:106.65px;height:72.21px;aspect-ratio:106.65/72.21\" loading=\"lazy\"></span>. Bias = 1.</p>","<p>These are three slices of <strong>one</strong> full-depth filter, not three independent output filters.</p>","<h3>To find</h3>","<p>The contribution of each input channel and the final scalar output at this position.</p>","<h3>Formula — which one and why</h3>","<p>Multiply corresponding entries within each channel. Add the three channel sums because this filter spans all input channels. Add its single bias once, after accumulating the channel contributions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/15d63177c46d68fd.svg\" alt=\"z=s_R+s_G+s_B+b\" width=\"224.31\" height=\"21.01\" style=\"width:224.31px;height:21.01px;aspect-ratio:224.31/21.01\" loading=\"lazy\"></div>","<p>The quantities s_R, s_G and s_B are intermediate weighted sums, not separate final output channels.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: red-channel products.</strong> The top row and first column contribute zero. The remaining terms are 156×1 + 155×(−1) + 153×1 + 154×1.</p>","<p class=\"worked-step\"><strong>Step 2: red-channel sum.</strong> 156 − 155 + 153 + 154 = <strong>308</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: green-channel products.</strong> The remaining patch terms are 167×(−1) + 166×(−1) + 164×0 + 165×(−1).</p>","<p class=\"worked-step\"><strong>Step 4: green-channel sum.</strong> −167 −166 +0 −165 = <strong>−498</strong>.</p>","<p class=\"worked-step\"><strong>Step 5: blue-channel products.</strong> The nonzero-patch terms are 163×1 + 162×0 + 160×(−1) + 161×1.</p>","<p class=\"worked-step\"><strong>Step 6: blue-channel sum.</strong> 163 +0 −160 +161 = <strong>164</strong>.</p>","<p class=\"worked-step\"><strong>Step 7: add the channel contributions.</strong> 308 −498 +164 = −26.</p>","<p class=\"worked-step\"><strong>Step 8: add one filter bias.</strong> −26 +1 = <strong>−25</strong>.</p>","<p><strong>Final answer:</strong> The convolution output is −25. If a subsequent ReLU is explicitly requested, that activation produces max(0,−25) = 0. The convolution value and activated value are different stages.</p>","<p><strong>Yaad rakho:</strong> Teen channels ka contribution jodo; ek filter ka bias ek baar jodo.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s15","search":"Faculty example: combine three RGB channel sums **Question. At one position, a convolutional filter receives the following red, green and blue 3 × 3 patches and matching kernel slices. Calculate one output value with bias 1. (Practice: 3 marks)**\n\n### Given\nRed patch = ; red kernel = .\n\nGreen patch = ; green kernel = .\n\nBlue patch = ; blue kernel = . Bias = 1.\n\nThese are three slices of **one** full-depth filter, not three independent output filters.\n\n### To find\nThe contribution of each input channel and the final scalar output at this position.\n\n### Formula — which one and why\nMultiply corresponding entries within each channel. Add the three channel sums because this filter spans all input channels. Add its single bias once, after accumulating the channel contributions.\n\n\n\nThe quantities s_R, s_G and s_B are intermediate weighted sums, not separate final output channels.\n\n### Solution — step by step\n**Step 1: red-channel products.** The top row and first column contribute zero. The remaining terms are 156×1 + 155×(−1) + 153×1 + 154×1.\n\n**Step 2: red-channel sum.** 156 − 155 + 153 + 154 = **308**.\n\n**Step 3: green-channel products.** The remaining patch terms are 167×(−1) + 166×(−1) + 164×0 + 165×(−1).\n\n**Step 4: green-channel sum.** −167 −166 +0 −165 = **−498**.\n\n**Step 5: blue-channel products.** The nonzero-patch terms are 163×1 + 162×0 + 160×(−1) + 161×1.\n\n**Step 6: blue-channel sum.** 163 +0 −160 +161 = **164**.\n\n**Step 7: add the channel contributions.** 308 −498 +164 = −26.\n\n**Step 8: add one filter bias.** −26 +1 = **−25**.\n\n**Final answer:** The convolution output is −25. If a subsequent ReLU is explicitly requested, that activation produces max(0,−25) = 0. The convolution value and activated value are different stages.\n\n**Yaad rakho:** Teen channels ka contribution jodo; ek filter ka bias ek baar jodo.\n"},{"title":"Max, min and average pooling on the same lecture grid","blocks":["<p class=\"definition\"><strong>Definition.</strong> Pooling summarizes each local window separately within each channel. Max pooling keeps its largest value, min pooling its smallest value, and average pooling its arithmetic mean. Ordinary versions have no trainable weights or biases.</p>","<p class=\"inline-question\"><strong>Question. Apply 2 × 2 max, min and average pooling with stride 2 and no padding to the following 4 × 4 input. Give all three output matrices. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>X = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/33f58372f0707267.svg\" alt=\"\\begin{bmatrix}12 &amp; 20 &amp; 30 &amp; 0\\\\8 &amp; 12 &amp; 2 &amp; 0\\\\34 &amp; 70 &amp; 37 &amp; 4\\\\112 &amp; 100 &amp; 25 &amp; 12\\end{bmatrix}\" width=\"177.39\" height=\"98.83\" style=\"width:177.39px;height:98.83px;aspect-ratio:177.39/98.83\" loading=\"lazy\"></span>. Window = 2 × 2; stride = 2; padding = 0.</p>","<h3>To find</h3>","<p>The shared output shape and each of the four cells for each pooling method.</p>","<h3>Formula — which one and why</h3>","<p>Each output summarizes four input numbers. Use max for the largest, min for the smallest, and sum divided by 4 for the average. The window moves two cells, so these four windows do not overlap.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/208abbe18f11b701.svg\" alt=\"y_{\\max}=\\max(x_1,x_2,x_3,x_4)\" width=\"274.40\" height=\"24.43\" style=\"width:274.40px;height:24.43px;aspect-ratio:274.40/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/619bb1c028de4233.svg\" alt=\"y_{\\min}=\\min(x_1,x_2,x_3,x_4)\" width=\"266.30\" height=\"24.43\" style=\"width:266.30px;height:24.43px;aspect-ratio:266.30/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0dcf475f3132c0a4.svg\" alt=\"y_{\\mathrm{avg}}=\\frac{x_1+x_2+x_3+x_4}{4}\" width=\"271.92\" height=\"47.52\" style=\"width:271.92px;height:47.52px;aspect-ratio:271.92/47.52\" loading=\"lazy\"></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_pooling_windows.svg\" aria-label=\"Enlarge diagram: The four colours identify four separate pooling windows. Each window creates one cell in each output map.\"><img src=\"assets/figures/u4_pooling_windows.svg\" alt=\"The four colours identify four separate pooling windows. Each window creates one cell in each output map.\" width=\"900\" height=\"425\" loading=\"lazy\"></button><figcaption>The four colours identify four separate pooling windows. Each window creates one cell in each output map. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: output size.</strong> (4 −2)/2 +1 = 2. Each output has shape 2 × 2.</p>","<p class=\"worked-step\"><strong>Step 2: top-left window [12,20,8,12].</strong> Largest = 20; smallest = 8. Sum = 12+20+8+12 = 52. Average = 52/4 = 13.</p>","<p class=\"worked-step\"><strong>Step 3: top-right window [30,0,2,0].</strong> Largest = 30; smallest = 0. Sum = 30+0+2+0 = 32. Average = 32/4 = 8.</p>","<p class=\"worked-step\"><strong>Step 4: bottom-left window [34,70,112,100].</strong> Largest = 112; smallest = 34. Sum = 34+70+112+100 = 316. Average = 316/4 = 79.</p>","<p class=\"worked-step\"><strong>Step 5: bottom-right window [37,4,25,12].</strong> Largest = 37; smallest = 4. Sum = 37+4+25+12 = 78. Average = 78/4 = <strong>19.5</strong>. Do not silently round this to 20.</p>","<p class=\"worked-step\"><strong>Step 6: put each result back in its window&#x27;s position.</strong> Max = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/63c5529d08234533.svg\" alt=\"\\begin{bmatrix}20 &amp; 30\\\\112 &amp; 37\\end{bmatrix}\" width=\"86.59\" height=\"45.61\" style=\"width:86.59px;height:45.61px;aspect-ratio:86.59/45.61\" loading=\"lazy\"></span>. Min = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/54afd252549c8a81.svg\" alt=\"\\begin{bmatrix}8 &amp; 0\\\\34 &amp; 4\\end{bmatrix}\" width=\"67.58\" height=\"45.61\" style=\"width:67.58px;height:45.61px;aspect-ratio:67.58/45.61\" loading=\"lazy\"></span>. Average = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/7d1100eaf9980bd3.svg\" alt=\"\\begin{bmatrix}13 &amp; 8\\\\79 &amp; 19.5\\end{bmatrix}\" width=\"91.87\" height=\"45.61\" style=\"width:91.87px;height:45.61px;aspect-ratio:91.87/45.61\" loading=\"lazy\"></span>.</p>","<p><strong>Final answer:</strong> Three 2 × 2 maps as above; zero trainable parameters for each pooling operation.</p>","<h3>Why the choice matters</h3>","<p>Max retains the largest activation in a feature window, which can still be negative if every entry is negative. Min retains the lowest response. Average retains an overall response but can dilute a sharp local peak. On raw intensity images, min can retain a dark stroke and max can retain a bright stroke. A learned CNN feature map represents filter responses; the best pooling choice is not determined solely by the original background colour.</p>","<p>Pooling has no parameters to update, but gradients can still pass through it. For a unique max, the upstream gradient is routed to the winning input. For an average over four inputs, each receives one-fourth of that gradient. Fewer pooled activations can reduce a later dense layer&#x27;s parameter count; they do not change the size of an earlier convolution&#x27;s filter.</p>","<p><strong>Yaad rakho:</strong> Max = sabse bada; min = sabse chhota; average = sab jodo, count se divide.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s16","search":"Max, min and average pooling on the same lecture grid **Definition.** Pooling summarizes each local window separately within each channel. Max pooling keeps its largest value, min pooling its smallest value, and average pooling its arithmetic mean. Ordinary versions have no trainable weights or biases.\n\n**Question. Apply 2 × 2 max, min and average pooling with stride 2 and no padding to the following 4 × 4 input. Give all three output matrices. (Practice: 3 marks)**\n\n### Given\nX = . Window = 2 × 2; stride = 2; padding = 0.\n\n### To find\nThe shared output shape and each of the four cells for each pooling method.\n\n### Formula — which one and why\nEach output summarizes four input numbers. Use max for the largest, min for the smallest, and sum divided by 4 for the average. The window moves two cells, so these four windows do not overlap.\n\n\n\n\n\n\n\n### Solution — step by step\n**Step 1: output size.** (4 −2)/2 +1 = 2. Each output has shape 2 × 2.\n\n**Step 2: top-left window [12,20,8,12].** Largest = 20; smallest = 8. Sum = 12+20+8+12 = 52. Average = 52/4 = 13.\n\n**Step 3: top-right window [30,0,2,0].** Largest = 30; smallest = 0. Sum = 30+0+2+0 = 32. Average = 32/4 = 8.\n\n**Step 4: bottom-left window [34,70,112,100].** Largest = 112; smallest = 34. Sum = 34+70+112+100 = 316. Average = 316/4 = 79.\n\n**Step 5: bottom-right window [37,4,25,12].** Largest = 37; smallest = 4. Sum = 37+4+25+12 = 78. Average = 78/4 = **19.5**. Do not silently round this to 20.\n\n**Step 6: put each result back in its window's position.** Max = . Min = . Average = .\n\n**Final answer:** Three 2 × 2 maps as above; zero trainable parameters for each pooling operation.\n\n### Why the choice matters\nMax retains the largest activation in a feature window, which can still be negative if every entry is negative. Min retains the lowest response. Average retains an overall response but can dilute a sharp local peak. On raw intensity images, min can retain a dark stroke and max can retain a bright stroke. A learned CNN feature map represents filter responses; the best pooling choice is not determined solely by the original background colour.\n\nPooling has no parameters to update, but gradients can still pass through it. For a unique max, the upstream gradient is routed to the winning input. For an average over four inputs, each receives one-fourth of that gradient. Fewer pooled activations can reduce a later dense layer's parameter count; they do not change the size of an earlier convolution's filter.\n\n**Yaad rakho:** Max = sabse bada; min = sabse chhota; average = sab jodo, count se divide.\n"},{"title":"Faculty CNN table: shapes, activations and 62958 parameters","blocks":["<p class=\"inline-question\"><strong>Question. A CNN receives a 32 × 32 × 3 image. It uses Conv1: eight 5 × 5 filters, stride 1, no padding; Pool1: 2 × 2, stride 2; Conv2: sixteen 5 × 5 filters, stride 1, no padding; Pool2: 2 × 2, stride 2; flatten; dense 120; dense 84; dense 10 followed by softmax. Include one bias per filter or receiving dense neuron. Find every output shape, activation count and trainable-parameter count. (Practice: 10 marks)</strong></p>","<h3>Given</h3>","<p>Input = 32 × 32 × 3. Both convolutions are ordinary full-channel convolutions. Pooling has no padding. Dense widths are 120, 84 and 10. No batch-normalization layer is present in this particular question.</p>","<h3>To find</h3>","<p>Output shape and number of output values for each layer, its trainable parameters, and the total parameters.</p>","<h3>Formula — which one and why</h3>","<p>Use the spatial-size formula for each convolution/pool. Use one full-depth kernel plus one bias per convolutional filter. Flattening counts all remaining values before the first dense layer. Each dense neuron then receives one weight per input plus one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c9b86a3e71336c4.svg\" alt=\"A=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}\" width=\"192.74\" height=\"21.35\" style=\"width:192.74px;height:21.35px;aspect-ratio:192.74/21.35\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<p>A counts produced activations. P_conv and P_dense count independent learned coefficients. They are not the same quantity. Pooling, flattening and softmax itself add zero learned parameters here.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: input.</strong> Shape = 32 × 32 × 3. Values = 32×32×3 = 3,072. Trainable parameters = 0.</p>","<p class=\"worked-step\"><strong>Step 2: Conv1 spatial size.</strong> (32−5)/1 +1 = 28. Eight filters give shape 28 × 28 × 8. Activations = 28×28×8 = 6,272.</p>","<p class=\"worked-step\"><strong>Step 3: Conv1 parameters.</strong> One filter contains 5×5×3 = 75 weights. Add one bias: 76. Multiply by eight filters: 76×8 = <strong>608</strong>.</p>","<p class=\"worked-step\"><strong>Step 4: Pool1.</strong> (28−2)/2 +1 = 14. Shape = 14 × 14 × 8. Activations = 14×14×8 = 1,568. Parameters = 0; channel count remains eight.</p>","<p class=\"worked-step\"><strong>Step 5: Conv2 spatial size.</strong> (14−5)/1 +1 = 10. Sixteen filters give shape 10 × 10 × 16. Activations = 1,600.</p>","<p class=\"worked-step\"><strong>Step 6: Conv2 parameters.</strong> Its input has <strong>eight</strong> channels. Each filter has 5×5×8 = 200 weights, then one bias. Total = 201×16 = <strong>3,216</strong>.</p>","<p class=\"worked-step\"><strong>Step 7: Pool2 and flatten.</strong> (10−2)/2 +1 = 5. Pool shape = 5 × 5 × 16. Flattened length = 5×5×16 = <strong>400</strong>. Neither operation adds parameters.</p>","<p class=\"worked-step\"><strong>Step 8: dense 120.</strong> Weights = 400×120 = 48,000. Biases = 120. Parameters = <strong>48,120</strong>. Output contains 120 activations.</p>","<p class=\"worked-step\"><strong>Step 9: dense 84.</strong> Weights = 120×84 = 10,080. Biases = 84. Parameters = <strong>10,164</strong>. Output contains 84 activations.</p>","<p class=\"worked-step\"><strong>Step 10: dense 10 and softmax.</strong> Weights = 84×10 = 840. Biases = 10. Dense parameters = <strong>850</strong>. Softmax converts the ten logits into ten probabilities and adds <strong>zero</strong> parameters. A table naming the combined classifier row “Softmax” attributes these 850 parameters to its preceding dense transformation.</p>","<p class=\"worked-step\"><strong>Step 11: add only the trainable counts.</strong> 608+3,216 = 3,824; +48,120 = 51,944; +10,164 = 62,108; +850 = <strong>62,958</strong>.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Output shape</th><th>Activations</th><th>Parameters</th></tr></thead><tbody><tr><td>Input</td><td>32 × 32 × 3</td><td>3,072</td><td>0</td></tr><tr><td>Conv1</td><td>28 × 28 × 8</td><td>6,272</td><td>608</td></tr><tr><td>Pool1</td><td>14 × 14 × 8</td><td>1,568</td><td>0</td></tr><tr><td>Conv2</td><td>10 × 10 × 16</td><td>1,600</td><td>3,216</td></tr><tr><td>Pool2 / flatten</td><td>5 × 5 × 16 / 400</td><td>400</td><td>0</td></tr><tr><td>Dense 120</td><td>120</td><td>120</td><td>48,120</td></tr><tr><td>Dense 84</td><td>84</td><td>84</td><td>10,164</td></tr><tr><td>Dense 10 → softmax</td><td>10</td><td>10</td><td>850 + 0</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> The network has <strong>62,958 trainable parameters</strong>. This is the specified classroom CNN, not a universal parameter total for every LeNet-like network.</p>","<p><strong>Yaad rakho:</strong> Shape aage carry karo; weights aur activations ko alag columns mein rakho.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s17","search":"Faculty CNN table: shapes, activations and 62958 parameters **Question. A CNN receives a 32 × 32 × 3 image. It uses Conv1: eight 5 × 5 filters, stride 1, no padding; Pool1: 2 × 2, stride 2; Conv2: sixteen 5 × 5 filters, stride 1, no padding; Pool2: 2 × 2, stride 2; flatten; dense 120; dense 84; dense 10 followed by softmax. Include one bias per filter or receiving dense neuron. Find every output shape, activation count and trainable-parameter count. (Practice: 10 marks)**\n\n### Given\nInput = 32 × 32 × 3. Both convolutions are ordinary full-channel convolutions. Pooling has no padding. Dense widths are 120, 84 and 10. No batch-normalization layer is present in this particular question.\n\n### To find\nOutput shape and number of output values for each layer, its trainable parameters, and the total parameters.\n\n### Formula — which one and why\nUse the spatial-size formula for each convolution/pool. Use one full-depth kernel plus one bias per convolutional filter. Flattening counts all remaining values before the first dense layer. Each dense neuron then receives one weight per input plus one bias.\n\n\n\n\n\n\nA counts produced activations. P_conv and P_dense count independent learned coefficients. They are not the same quantity. Pooling, flattening and softmax itself add zero learned parameters here.\n\n### Solution — step by step\n**Step 1: input.** Shape = 32 × 32 × 3. Values = 32×32×3 = 3,072. Trainable parameters = 0.\n\n**Step 2: Conv1 spatial size.** (32−5)/1 +1 = 28. Eight filters give shape 28 × 28 × 8. Activations = 28×28×8 = 6,272.\n\n**Step 3: Conv1 parameters.** One filter contains 5×5×3 = 75 weights. Add one bias: 76. Multiply by eight filters: 76×8 = **608**.\n\n**Step 4: Pool1.** (28−2)/2 +1 = 14. Shape = 14 × 14 × 8. Activations = 14×14×8 = 1,568. Parameters = 0; channel count remains eight.\n\n**Step 5: Conv2 spatial size.** (14−5)/1 +1 = 10. Sixteen filters give shape 10 × 10 × 16. Activations = 1,600.\n\n**Step 6: Conv2 parameters.** Its input has **eight** channels. Each filter has 5×5×8 = 200 weights, then one bias. Total = 201×16 = **3,216**.\n\n**Step 7: Pool2 and flatten.** (10−2)/2 +1 = 5. Pool shape = 5 × 5 × 16. Flattened length = 5×5×16 = **400**. Neither operation adds parameters.\n\n**Step 8: dense 120.** Weights = 400×120 = 48,000. Biases = 120. Parameters = **48,120**. Output contains 120 activations.\n\n**Step 9: dense 84.** Weights = 120×84 = 10,080. Biases = 84. Parameters = **10,164**. Output contains 84 activations.\n\n**Step 10: dense 10 and softmax.** Weights = 84×10 = 840. Biases = 10. Dense parameters = **850**. Softmax converts the ten logits into ten probabilities and adds **zero** parameters. A table naming the combined classifier row “Softmax” attributes these 850 parameters to its preceding dense transformation.\n\n**Step 11: add only the trainable counts.** 608+3,216 = 3,824; +48,120 = 51,944; +10,164 = 62,108; +850 = **62,958**.\n\n| Layer | Output shape | Activations | Parameters |\n|---|---|---|---|\n| Input | 32 × 32 × 3 | 3,072 | 0 |\n| Conv1 | 28 × 28 × 8 | 6,272 | 608 |\n| Pool1 | 14 × 14 × 8 | 1,568 | 0 |\n| Conv2 | 10 × 10 × 16 | 1,600 | 3,216 |\n| Pool2 / flatten | 5 × 5 × 16 / 400 | 400 | 0 |\n| Dense 120 | 120 | 120 | 48,120 |\n| Dense 84 | 84 | 84 | 10,164 |\n| Dense 10 → softmax | 10 | 10 | 850 + 0 |\n\n**Final answer:** The network has **62,958 trainable parameters**. This is the specified classroom CNN, not a universal parameter total for every LeNet-like network.\n\n**Yaad rakho:** Shape aage carry karo; weights aur activati"},{"title":"Even-sized kernels: SAME padding is not always symmetric","blocks":["<p class=\"definition\"><strong>Definition.</strong> A numerical padding value specifies how many entries to add at each boundary. SAME is an output-size convention. At stride 1, SAME preserves height and width; an even-sized kernel can require unequal padding on opposite sides.</p>","<p>For a 2 by 2 kernel at stride 1, preserving the input size requires <strong>one padding entry in total per axis</strong>, not one on each side. For example, add no row above and one row below, and no column on the left and one on the right. Reversing which side receives the extra entry preserves the output size too, but changes which input cells contribute at each output location; follow the question&#x27;s convention.</p>","<p><strong>Hinglish cue:</strong> P = 1 means dono taraf ek; SAME means output ka size bachao. Dono instructions ko same mat samjho.</p>","<h3>Example 1: one entry on every side</h3>","<p class=\"inline-question\"><strong>Question. A 5 × 5 single-channel input is processed by one 2 × 2 convolution filter. The stride is 1. Exactly one zero is padded on each of the four sides. Find the padded-input size and output size. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>Input height and width N = 5; kernel size K = 2; stride S = 1; padding P = 1 on each side; dilation = 1; one output filter.</p>","<h3>To find</h3>","<p>The padded input dimensions and the convolution output dimensions.</p>","<h3>Formula — which one and why</h3>","<p>The two opposite borders contribute P entries each. The output formula counts complete filter placements after padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6bbc5ec5f7e71fe.svg\" alt=\"N_{\\mathrm{padded}}=N+2P\" width=\"191.11\" height=\"23.71\" style=\"width:191.11px;height:23.71px;aspect-ratio:191.11/23.71\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is one input dimension; P is padding on each side; K is kernel size; S is stride. Apply the same calculation separately to height and width. One filter produces one output channel.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count the two padding borders.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/741118212eb25f73.svg\" alt=\"2P=2(1)=2\" width=\"151.39\" height=\"24.43\" style=\"width:151.39px;height:24.43px;aspect-ratio:151.39/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: find the padded side length.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e288268af2ced78c.svg\" alt=\"N_{\\mathrm{padded}}=5+2=7\" width=\"208.07\" height=\"23.71\" style=\"width:208.07px;height:23.71px;aspect-ratio:208.07/23.71\" loading=\"lazy\"></div>","<p>The padded input is 7 × 7 × 1.</p>","<p class=\"worked-step\"><strong>Step 3: subtract the kernel size.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b07e3025ba7ec8bf.svg\" alt=\"7-2=5\" width=\"99.10\" height=\"18.52\" style=\"width:99.10px;height:18.52px;aspect-ratio:99.10/18.52\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: divide by stride, take the floor and count the first placement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c9e9b01d59dde654.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{5}{1}\\right\\rfloor+1=5+1=6\" width=\"304.44\" height=\"58.62\" style=\"width:304.44px;height:58.62px;aspect-ratio:304.44/58.62\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: write height, width and channels.</strong></p>","<p>Both spatial dimensions equal 6. There is one filter, so there is one output channel.</p>","<p><strong>Final answer:</strong> padded input = <strong>7 × 7 × 1</strong>; output = <strong>6 × 6 × 1</strong>. This explicitly specified padding does not implement SAME for this even kernel.</p>","<h3>Example 2: preserve the size with SAME padding</h3>","<p class=\"inline-question\"><strong>Question. The same 5 × 5 single-channel input is processed by one 2 × 2 convolution filter with stride 1 and SAME padding. Find the total padding required along each axis and the output size. Use zero padding above and to the left, with any required extra padding below and to the right. (Practice: 3 marks)</strong></p>","<h3>Given</h3>","<p>Input side N = 5; kernel side K = 2; stride S = 1; desired output side Nout = 5; dilation = 1; one filter. Padding before the input is 0; padding after the input must be found.</p>","<h3>To find</h3>","<p>Padding above, below, left and right; padded-input shape; final output shape.</p>","<h3>Formula — which one and why</h3>","<p>For unequal padding, replace 2P by the sum of the before and after padding. Pbefore and Pafter are the entries added on the two opposite sides of one axis.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fb9e63f94b876bf.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+P_{\\mathrm{before}}+P_{\\mathrm{after}}-K}{S}\\right\\rfloor+1\" width=\"409.73\" height=\"58.62\" style=\"width:409.73px;height:58.62px;aspect-ratio:409.73/58.62\" loading=\"lazy\"></div>","<p>At stride 1, the quantities are integers. To keep Nout = N, the total padding must equal K − 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9c76650bca9e58b.svg\" alt=\"P_{\\mathrm{total}}=P_{\\mathrm{before}}+P_{\\mathrm{after}}=K-1\" width=\"328.26\" height=\"20.54\" style=\"width:328.26px;height:20.54px;aspect-ratio:328.26/20.54\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate total padding along the height.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebca391be173fb93.svg\" alt=\"P_{\\mathrm{total}}=2-1=1\" width=\"184.93\" height=\"20.54\" style=\"width:184.93px;height:20.54px;aspect-ratio:184.93/20.54\" loading=\"lazy\"></div>","<p>Only one extra row in total is needed.</p>","<p class=\"worked-step\"><strong>Step 2: place the row using the stated convention.</strong></p>","<p>Padding above = 0; padding below = 1.</p>","<p class=\"worked-step\"><strong>Step 3: apply the same calculation to width.</strong></p>","<p>Only one extra column in total is needed. Padding left = 0; padding right = 1.</p>","<p class=\"worked-step\"><strong>Step 4: find the padded-input shape.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bd37f3052feb0554.svg\" alt=\"H_{\\mathrm{padded}}=5+0+1=6\" width=\"250.85\" height=\"23.71\" style=\"width:250.85px;height:23.71px;aspect-ratio:250.85/23.71\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ab52e1fac6848205.svg\" alt=\"W_{\\mathrm{padded}}=5+0+1=6\" width=\"253.61\" height=\"23.71\" style=\"width:253.61px;height:23.71px;aspect-ratio:253.61/23.71\" loading=\"lazy\"></div>","<p>The padded input is 6 × 6 × 1.</p>","<p class=\"worked-step\"><strong>Step 5: count the output positions along each axis.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9a5597c2b0d54bcf.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{5+0+1-2}{1}\\right\\rfloor+1=4+1=5\" width=\"430.69\" height=\"58.62\" style=\"width:430.69px;height:58.62px;aspect-ratio:430.69/58.62\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: include the output channel.</strong></p>","<p>One filter creates one output channel.</p>","<p><strong>Final answer:</strong> add <strong>0 above, 1 below, 0 left and 1 right</strong>; padded input = <strong>6 × 6 × 1</strong>; output = <strong>5 × 5 × 1</strong>.</p>","<p>The two questions have the same input and kernel but different padding instructions. Read the stated boundary padding before applying the formula.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c7-s18","search":"Even-sized kernels: SAME padding is not always symmetric \n**Definition.** A numerical padding value specifies how many entries to add at each boundary. SAME is an output-size convention. At stride 1, SAME preserves height and width; an even-sized kernel can require unequal padding on opposite sides.\n\nFor a 2 by 2 kernel at stride 1, preserving the input size requires **one padding entry in total per axis**, not one on each side. For example, add no row above and one row below, and no column on the left and one on the right. Reversing which side receives the extra entry preserves the output size too, but changes which input cells contribute at each output location; follow the question's convention.\n\n**Hinglish cue:** P = 1 means dono taraf ek; SAME means output ka size bachao. Dono instructions ko same mat samjho.\n\n### Example 1: one entry on every side\n\n**Question. A 5 × 5 single-channel input is processed by one 2 × 2 convolution filter. The stride is 1. Exactly one zero is padded on each of the four sides. Find the padded-input size and output size. (Practice: 3 marks)**\n\n### Given\n\nInput height and width N = 5; kernel size K = 2; stride S = 1; padding P = 1 on each side; dilation = 1; one output filter.\n\n### To find\n\nThe padded input dimensions and the convolution output dimensions.\n\n### Formula — which one and why\n\nThe two opposite borders contribute P entries each. The output formula counts complete filter placements after padding.\n\n\n\n\n\nN is one input dimension; P is padding on each side; K is kernel size; S is stride. Apply the same calculation separately to height and width. One filter produces one output channel.\n\n### Solution — step by step\n\n**Step 1: count the two padding borders.**\n\n\n\n**Step 2: find the padded side length.**\n\n\n\nThe padded input is 7 × 7 × 1.\n\n**Step 3: subtract the kernel size.**\n\n\n\n**Step 4: divide by stride, take the floor and count the first placement.**\n\n\n\n**Step 5: write height, width and channels.**\n\nBoth spatial dimensions equal 6. There is one filter, so there is one output channel.\n\n**Final answer:** padded input = **7 × 7 × 1**; output = **6 × 6 × 1**. This explicitly specified padding does not implement SAME for this even kernel.\n\n### Example 2: preserve the size with SAME padding\n\n**Question. The same 5 × 5 single-channel input is processed by one 2 × 2 convolution filter with stride 1 and SAME padding. Find the total padding required along each axis and the output size. Use zero padding above and to the left, with any required extra padding below and to the right. (Practice: 3 marks)**\n\n### Given\n\nInput side N = 5; kernel side K = 2; stride S = 1; desired output side Nout = 5; dilation = 1; one filter. Padding before the input is 0; padding after the input must be found.\n\n### To find\n\nPadding above, below, left and right; padded-input shape; final output shape.\n\n### Formula — which one and why\n\nFor unequal padding, replace 2P by the sum of the before and after padding. Pbefore and Pafter are the entries added on the two opposite sides of one axis.\n\n\n\nAt stride 1, the quantities are integers. To keep Nout = N, the total padding must equal K − 1.\n\n\n\n### Solution — step by step\n\n**Step 1: calculate total padding along the height.**\n\n\n\nOnly one extra row in total is needed.\n\n**Step 2: place the row using the stated convention.**\n\nPadding above = 0; padding below = 1.\n\n**Step 3: apply the same calculation to width.**\n\nOnly one extra column in total is needed. Padding left = 0; padding right = 1.\n\n**St"}]},{"n":8,"title":"CNN architectures and transfer learning","sections":[{"title":"AlexNet and the reason for its components","blocks":["<p class=\"definition\"><strong>Definition.</strong> AlexNet is a deep convolutional architecture introduced for ImageNet classification, conventionally described as five convolutional layers followed by three fully connected layers. Its historical significance is the effective combination of learned convolutional features, nonlinear activations, GPU training and regularization at large scale.</p>","<h3>Architecture and information flow</h3>","<p>Input image → convolution and ReLU stages → spatial pooling → fully connected representations → class scores and softmax. The original model used local response normalization in selected early stages and overlapping max pooling. Grouped computation across two GPUs was part of the original implementation. Exact sizes must follow the architecture specified in an examination question.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/alexnet.svg\" aria-label=\"Enlarge diagram: Convolution extracts representations before the fully connected classification stages.\"><img src=\"assets/figures/alexnet.svg\" alt=\"Convolution extracts representations before the fully connected classification stages.\" width=\"960\" height=\"480\" loading=\"lazy\"></button><figcaption>Convolution extracts representations before the fully connected classification stages. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Role of the components</h3>","<p><strong>ReLU</strong> supplies a nonlinear transformation and avoids sigmoid-style saturation for positive preactivations. <strong>Convolution</strong> uses local connectivity and spatial weight sharing. <strong>Pooling</strong> reduces spatial dimensions and increases tolerance to small local changes. <strong>Dropout</strong> regularizes the fully connected layers. <strong>Data augmentation</strong> supplies transformed training examples to reduce dependence on a fixed view. These components perform different jobs and should not be described as interchangeable methods of reducing overfitting.</p>","<h3>Limitations and exam distinction</h3>","<p>The dense layers contribute a large number of parameters; the model has substantial memory and computation requirements. AlexNet is much shallower than later residual architectures. Its original use of local response normalization is different from batch normalization. For a comparison answer, identify its sequential convolutional design, then contrast it with Inception&#x27;s parallel branches and ResNet&#x27;s residual addition.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s0","search":"AlexNet and the reason for its components **Definition.** AlexNet is a deep convolutional architecture introduced for ImageNet classification, conventionally described as five convolutional layers followed by three fully connected layers. Its historical significance is the effective combination of learned convolutional features, nonlinear activations, GPU training and regularization at large scale.\n\n### Architecture and information flow\nInput image → convolution and ReLU stages → spatial pooling → fully connected representations → class scores and softmax. The original model used local response normalization in selected early stages and overlapping max pooling. Grouped computation across two GPUs was part of the original implementation. Exact sizes must follow the architecture specified in an examination question.\n\n\n\n### Role of the components\n**ReLU** supplies a nonlinear transformation and avoids sigmoid-style saturation for positive preactivations. **Convolution** uses local connectivity and spatial weight sharing. **Pooling** reduces spatial dimensions and increases tolerance to small local changes. **Dropout** regularizes the fully connected layers. **Data augmentation** supplies transformed training examples to reduce dependence on a fixed view. These components perform different jobs and should not be described as interchangeable methods of reducing overfitting.\n\n### Limitations and exam distinction\nThe dense layers contribute a large number of parameters; the model has substantial memory and computation requirements. AlexNet is much shallower than later residual architectures. Its original use of local response normalization is different from batch normalization. For a comparison answer, identify its sequential convolutional design, then contrast it with Inception's parallel branches and ResNet's residual addition.\n"},{"title":"Inception examines several spatial scales","blocks":["<p class=\"definition\"><strong>Definition.</strong> An Inception module is a convolutional building block that processes the same input through parallel branches using different receptive-field operations and concatenates their output feature maps along the channel dimension.</p>","<h3>Structure and working</h3>","<p>A conventional early Inception module includes 1 × 1, 3 × 3 and 5 × 5 convolution branches and a pooling branch. Suitable stride and padding preserve compatible spatial dimensions. The branch outputs are then concatenated. If branch channel counts are c₁, c₂, c₃ and c₄, the output depth is c₁ + c₂ + c₃ + c₄.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Branches operate on the same input. Matching spatial outputs are joined along the channel axis.\"><img src=\"assets/figures/inception.svg\" alt=\"Branches operate on the same input. Matching spatial outputs are joined along the channel axis.\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Branches operate on the same input. Matching spatial outputs are joined along the channel axis. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Why use several branches?</h3>","<p>Different branch receptive fields can capture patterns at different spatial scales. A 1 × 1 convolution mixes channel information at each position. Before an expensive larger kernel, it can reduce the number of input channels and therefore the parameter count and multiplication cost. The bottleneck calculation is developed in the following section.</p>","<h3>Concatenation is not addition</h3>","<p>Concatenation increases channel depth and retains each branch&#x27;s feature maps separately. Elementwise addition requires equal shapes and combines corresponding values. Inception commonly uses concatenation; a standard residual block uses addition. A question giving branch sizes tests this distinction as well as the convolution formula.</p>","<p>Early Inception designs reduce reliance on a large fully connected classifier through global average pooling. The parallel design still needs compatible branch shapes and carefully chosen channel widths; increasing the number of branches or filters increases computation.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s1","search":"Inception examines several spatial scales **Definition.** An Inception module is a convolutional building block that processes the same input through parallel branches using different receptive-field operations and concatenates their output feature maps along the channel dimension.\n\n### Structure and working\nA conventional early Inception module includes 1 × 1, 3 × 3 and 5 × 5 convolution branches and a pooling branch. Suitable stride and padding preserve compatible spatial dimensions. The branch outputs are then concatenated. If branch channel counts are c₁, c₂, c₃ and c₄, the output depth is c₁ + c₂ + c₃ + c₄.\n\n\n\n### Why use several branches?\nDifferent branch receptive fields can capture patterns at different spatial scales. A 1 × 1 convolution mixes channel information at each position. Before an expensive larger kernel, it can reduce the number of input channels and therefore the parameter count and multiplication cost. The bottleneck calculation is developed in the following section.\n\n### Concatenation is not addition\nConcatenation increases channel depth and retains each branch's feature maps separately. Elementwise addition requires equal shapes and combines corresponding values. Inception commonly uses concatenation; a standard residual block uses addition. A question giving branch sizes tests this distinction as well as the convolution formula.\n\nEarly Inception designs reduce reliance on a large fully connected classifier through global average pooling. The parallel design still needs compatible branch shapes and carefully chosen channel widths; increasing the number of branches or filters increases computation.\n"},{"title":"Why one by one convolution saves work","blocks":["<p class=\"definition\"><strong>Definition.</strong> A 1 × 1 convolution combines the input channels independently at each spatial location. A bottleneck uses fewer output channels before a larger spatial convolution, reducing its parameter and multiplication counts.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bottleneck.svg\" aria-label=\"Enlarge diagram: Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size.\"><img src=\"assets/figures/v_bottleneck.svg\" alt=\"Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size.\" width=\"1080\" height=\"790\" loading=\"lazy\"></button><figcaption>Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question. Input is 28 × 28 × 192. Compare a direct same-padded 5 × 5 convolution with 32 filters against a 1 × 1 reduction to 16 channels followed by the same 5 × 5 convolution. Count MACs and ignore bias additions.</strong></p>","<h3>Given</h3>","<p>Both paths produce 28 × 28 × 32. The direct layer receives 192 channels; the bottleneck&#x27;s spatial layer receives 16 channels. Stride is 1 and padding preserves spatial size.</p>","<h3>To find</h3>","<p>Direct MACs, total two-stage bottleneck MACs and percentage saved.</p>","<h3>Formula — which one and why</h3>","<p>Each output scalar uses one product per input-channel kernel entry. Multiply that cost by the number of output positions and channels. The two bottleneck layers require separate counts, which are added.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<p>One MAC counts one multiply–accumulate pair. A convention counting multiplication and addition separately gives approximately twice as many FLOPs.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: direct layer.</strong> Each output uses 5 × 5 × 192 = 4,800 products. There are 28 × 28 × 32 = 25,088 outputs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f08b61aa51f8fc4.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=25088(4800)=120422400\" width=\"417.37\" height=\"24.43\" style=\"width:417.37px;height:24.43px;aspect-ratio:417.37/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: 1 × 1 reduction.</strong> There are 16 receiving filters, each spanning all 192 original channels.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aaefb7a933a188a0.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=28(28)(16)(192)=2408448\" width=\"418.42\" height=\"24.43\" style=\"width:418.42px;height:24.43px;aspect-ratio:418.42/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: reduced-depth spatial layer.</strong> Its 32 filters now span 16 channels.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6f81bb572b38322.svg\" alt=\"\\mathrm{MACs}_{5\\times5}=28(28)(32)(25)(16)=10035200\" width=\"461.86\" height=\"24.43\" style=\"width:461.86px;height:24.43px;aspect-ratio:461.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the two bottleneck costs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3917ad1b6a4cc0eb.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=2408448+10035200=12443648\" width=\"524.30\" height=\"21.35\" style=\"width:524.30px;height:21.35px;aspect-ratio:524.30/21.35\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the saving.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe529a7c8d14263e.svg\" alt=\"\\mathrm{saving}=120422400-12443648=107978752\" width=\"480.03\" height=\"21.58\" style=\"width:480.03px;height:21.58px;aspect-ratio:480.03/21.58\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e22e38a0d749a968.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{107978752}{120422400}\\approx89.666667\\%\" width=\"534.95\" height=\"50.34\" style=\"width:534.95px;height:50.34px;aspect-ratio:534.95/50.34\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> direct = 120,422,400 MACs; bottleneck = 12,443,648 MACs, saving about 89.67%. Spatial size is unchanged; the saving comes from reducing the channels entering the expensive 5 × 5 layer. If the reduction width is not supplied, use a symbol for it and label any numerical choice as an assumption.</p>","<h3>A second bottleneck with different dimensions</h3>","<p class=\"inline-question\"><strong>Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with a 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.</strong></p>","<h3>Given</h3>","<p>Spatial output = 8 × 8; original channels = 16; final filters = 8; bottleneck channels = 4; stride = 1.</p>","<h3>To find</h3>","<p>Direct MACs, bottleneck MACs and saving.</p>","<h3>Formula — which one and why</h3>","<p>Use the same MAC formula above once for the direct path and once for each bottleneck stage. Every branch must include all of its layers.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: direct spatial convolution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dffc8608ebe7e697.svg\" alt=\"8(8)(8)(3)(3)(16)=73728\" width=\"274.24\" height=\"24.43\" style=\"width:274.24px;height:24.43px;aspect-ratio:274.24/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: 1 × 1 reduction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbfbed2568dc51ee.svg\" alt=\"8(8)(4)(1)(1)(16)=4096\" width=\"262.02\" height=\"24.43\" style=\"width:262.02px;height:24.43px;aspect-ratio:262.02/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: reduced-depth 3 × 3 convolution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60dc7f05c85051f9.svg\" alt=\"8(8)(8)(3)(3)(4)=18432\" width=\"262.02\" height=\"24.43\" style=\"width:262.02px;height:24.43px;aspect-ratio:262.02/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the stages and subtract from the direct cost.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4821e959cb7a516.svg\" alt=\"4096+18432=22528\" width=\"233.50\" height=\"18.54\" style=\"width:233.50px;height:18.54px;aspect-ratio:233.50/18.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be3a4d13f46b02ba.svg\" alt=\"73728-22528=51200\" width=\"245.71\" height=\"18.52\" style=\"width:245.71px;height:18.52px;aspect-ratio:245.71/18.52\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> direct = 73,728 MACs; bottleneck = 22,528 MACs; saving = 51,200 MACs, about 69.44%. Both paths produce 8 × 8 × 8, but they are different learned transformations and need not produce identical feature values.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s2","search":"Why one by one convolution saves work **Definition.** A 1 × 1 convolution combines the input channels independently at each spatial location. A bottleneck uses fewer output channels before a larger spatial convolution, reducing its parameter and multiplication counts.\n\n\n\n**Question. Input is 28 × 28 × 192. Compare a direct same-padded 5 × 5 convolution with 32 filters against a 1 × 1 reduction to 16 channels followed by the same 5 × 5 convolution. Count MACs and ignore bias additions.**\n\n### Given\nBoth paths produce 28 × 28 × 32. The direct layer receives 192 channels; the bottleneck's spatial layer receives 16 channels. Stride is 1 and padding preserves spatial size.\n\n### To find\nDirect MACs, total two-stage bottleneck MACs and percentage saved.\n\n### Formula — which one and why\nEach output scalar uses one product per input-channel kernel entry. Multiply that cost by the number of output positions and channels. The two bottleneck layers require separate counts, which are added.\n\nOne MAC counts one multiply–accumulate pair. A convention counting multiplication and addition separately gives approximately twice as many FLOPs.\n\n### Solution — step by step\n**Step 1: direct layer.** Each output uses 5 × 5 × 192 = 4,800 products. There are 28 × 28 × 32 = 25,088 outputs.\n\n\n**Step 2: 1 × 1 reduction.** There are 16 receiving filters, each spanning all 192 original channels.\n\n\n**Step 3: reduced-depth spatial layer.** Its 32 filters now span 16 channels.\n\n\n**Step 4: add the two bottleneck costs.**\n\n\n**Step 5: calculate the saving.**\n\n\n\n**Final answer:** direct = 120,422,400 MACs; bottleneck = 12,443,648 MACs, saving about 89.67%. Spatial size is unchanged; the saving comes from reducing the channels entering the expensive 5 × 5 layer. If the reduction width is not supplied, use a symbol for it and label any numerical choice as an assumption.\n\n### A second bottleneck with different dimensions\n**Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with a 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.**\n\n### Given\nSpatial output = 8 × 8; original channels = 16; final filters = 8; bottleneck channels = 4; stride = 1.\n\n### To find\nDirect MACs, bottleneck MACs and saving.\n\n### Formula — which one and why\nUse the same MAC formula above once for the direct path and once for each bottleneck stage. Every branch must include all of its layers.\n\n### Solution — step by step\n**Step 1: direct spatial convolution.**\n\n\n**Step 2: 1 × 1 reduction.**\n\n\n**Step 3: reduced-depth 3 × 3 convolution.**\n\n\n**Step 4: add the stages and subtract from the direct cost.**\n\n\n**Final answer:** direct = 73,728 MACs; bottleneck = 22,528 MACs; saving = 51,200 MACs, about 69.44%. Both paths produce 8 × 8 × 8, but they are different learned transformations and need not produce identical feature values.\n"},{"title":"ResNet adds a shortcut","blocks":["<p class=\"definition\"><strong>Definition.</strong> A residual network uses shortcut connections to learn a residual mapping relative to a block&#x27;s input. A basic residual block adds the block transformation F(x) to a shortcut representation of x.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d9d34020eaab826.svg\" alt=\"y=F(x)+x\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div>","<p>If the desired mapping is H(x), the residual branch represents F(x) = H(x) − x. When the useful mapping is close to identity, a small residual can be easier to optimize than reconstructing identity through the entire branch.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The two paths must have equal output shape before elementwise addition.\"><img src=\"assets/figures/residual.svg\" alt=\"The two paths must have equal output shape before elementwise addition.\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The two paths must have equal output shape before elementwise addition. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Effect on gradient propagation</h3>","<p>For the identity-shortcut formulation, the derivative includes a direct identity contribution.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/505f1041667e53bb.svg\" alt=\"\\frac{\\partial y}{\\partial x}=\\frac{\\partial F}{\\partial x}+I\" width=\"156.21\" height=\"51.29\" style=\"width:156.21px;height:51.29px;aspect-ratio:156.21/51.29\" loading=\"lazy\"></div>","<p>This provides a path for information and derivatives that does not require passing through every weight layer in the residual branch. It helps optimize deep networks and addresses the degradation problem. It does not imply that every possible ResNet is immune to vanishing gradients.</p>","<h3>Projection when dimensions differ</h3>","<p>If channels or spatial dimensions change, use a projection shortcut, often a 1 × 1 convolution with suitable stride.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ffeadda67cc02f9.svg\" alt=\"y=F(x)+W_sx\" width=\"172.89\" height=\"24.43\" style=\"width:172.89px;height:24.43px;aspect-ratio:172.89/24.43\" loading=\"lazy\"></div>","<p>An identity shortcut has no learned parameters. A projection does. For Cᵢ input channels and Cₒ output channels, a biased 1 × 1 projection has CᵢCₒ + Cₒ parameters. The residual branch&#x27;s output must match the projection output for addition.</p>","<p class=\"inline-question\"><strong>Question.</strong> Let x = [1, 2, 3] and F(x) = [0.1, −0.2, 0.3]. Find the residual sum.</p>","<h3>Given</h3>","<p>x = [1,2,3]; residual branch F(x) = [0.1,−0.2,0.3].</p>","<h3>To find</h3>","<p>Find the three components of x+F(x).</p>","<h3>Formula — which one and why</h3>","<p><strong>Residual addition.</strong> Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.</p>","<p>x = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec48bb473e2d7934.svg\" alt=\"y=x+F(x)\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position ke numbers add; shape same rehni chahiye.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add the first matching pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/db025849e060d366.svg\" alt=\"1+0.1=1.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the second matching pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ab49a448719b780e.svg\" alt=\"2+(-0.2)=1.8\" width=\"175.14\" height=\"24.43\" style=\"width:175.14px;height:24.43px;aspect-ratio:175.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the third matching pair.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d117d7aaf6f65395.svg\" alt=\"3+0.3=3.3\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: assemble in the original order.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f3d1f51931e7a8d.svg\" alt=\"y=[1.1,1.8,3.3]\" width=\"173.56\" height=\"24.43\" style=\"width:173.56px;height:24.43px;aspect-ratio:173.56/24.43\" loading=\"lazy\"></div>","<p>The vector length remains 3. Concatenating these vectors would give length 6 and would implement a different operation. Any post-addition activation specified in the architecture is applied after this sum.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s3","search":"ResNet adds a shortcut **Definition.** A residual network uses shortcut connections to learn a residual mapping relative to a block's input. A basic residual block adds the block transformation F(x) to a shortcut representation of x.\n\nIf the desired mapping is H(x), the residual branch represents F(x) = H(x) − x. When the useful mapping is close to identity, a small residual can be easier to optimize than reconstructing identity through the entire branch.\n\n\n\n### Effect on gradient propagation\nFor the identity-shortcut formulation, the derivative includes a direct identity contribution.\n\nThis provides a path for information and derivatives that does not require passing through every weight layer in the residual branch. It helps optimize deep networks and addresses the degradation problem. It does not imply that every possible ResNet is immune to vanishing gradients.\n\n### Projection when dimensions differ\nIf channels or spatial dimensions change, use a projection shortcut, often a 1 × 1 convolution with suitable stride.\n\nAn identity shortcut has no learned parameters. A projection does. For Cᵢ input channels and Cₒ output channels, a biased 1 × 1 projection has CᵢCₒ + Cₒ parameters. The residual branch's output must match the projection output for addition.\n\n**Question.** Let x = [1, 2, 3] and F(x) = [0.1, −0.2, 0.3]. Find the residual sum.\n\n\n\n### Given\n\nx = [1,2,3]; residual branch F(x) = [0.1,−0.2,0.3].\n\n### To find\n\nFind the three components of x+F(x).\n\n### Formula — which one and why\n\n**Residual addition.** Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.\n\nx = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.\n\n\n\n**Yaad rakhne ka cue:** Same position ke numbers add; shape same rehni chahiye.\n\n### Solution — step by step\n\n\n\n\n**Step 1: add the first matching pair.**\n\n\n\n\n\n\n\n**Step 2: add the second matching pair.**\n\n\n\n\n\n\n\n**Step 3: add the third matching pair.**\n\n\n\n\n\n\n\n**Step 4: assemble in the original order.**\n\n\n\n\n\n\n\n\nThe vector length remains 3. Concatenating these vectors would give length 6 and would implement a different operation. Any post-addition activation specified in the architecture is applied after this sum.\n"},{"title":"Transfer learning from a small dataset","blocks":["<p class=\"definition\"><strong>Definition.</strong> Transfer learning reuses representations or parameters learned on a source task to support a target task. With a pretrained neural network, common strategies are fixed feature extraction and fine-tuning selected pretrained layers.</p>","<h3>Explanation and working</h3>","<p>Transfer learning reuses a model or representation learned on one task for a related new task. A pretrained CNN may already detect useful edges, textures and shapes, saving data and training effort.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Full scenario.</strong> Build a face-attendance model with few images per student. Explain a training plan.</p>","<p class=\"worked-step\"><strong>Step 1. Define and split the data.</strong> Collect varied, permitted images and separate training/validation/test by suitable independent captures. Keep duplicates out of different splits. Apply the pretrained model’s required input size and normalization.</p>","<p class=\"worked-step\"><strong>Step 2. Choose a suitable pretrained backbone.</strong> For a course example, use VGG 16 or ResNet as an image-feature extractor. ImageNet-pretrained VGG 16 was trained on ImageNet, not automatically on a face-specific dataset. A face-trained model can be a more task-specific choice if available.</p>","<p class=\"worked-step\"><strong>Step 3. Replace the classifier.</strong> Remove the original class head. Add a new classifier matching the required student classes, or an appropriate embedding-based recognition system if that is the chosen formulation. For the exam classification example, use a softmax head and cross-entropy.</p>","<p class=\"worked-step\"><strong>Step 4. Freeze and train.</strong> Freeze the base weights and train the new head first. Use suitable augmentation, regularization and validation monitoring.</p>","<p class=\"worked-step\"><strong>Step 5. Fine-tune if justified.</strong> Unfreeze selected later layers and train at a smaller learning rate. Early layers may remain frozen. Compare validation performance and restore the best checkpoint.</p>","<p class=\"worked-step\"><strong>Step 6. Evaluate.</strong> Use the held-out test set once for the final estimate. Include unfamiliar faces and a rejection rule if describing a real attendance system; a closed-set classroom example alone does not solve unknown-person recognition.</p>","<p>Feature extraction keeps the backbone fixed. Fine-tuning changes some pretrained weights. Training the entire model from scratch is a third option when enough representative data and compute are available, but it is usually harder for the stated small-dataset scenario.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s4","search":"Transfer learning from a small dataset **Definition.** Transfer learning reuses representations or parameters learned on a source task to support a target task. With a pretrained neural network, common strategies are fixed feature extraction and fine-tuning selected pretrained layers.\n\n### Explanation and working\nTransfer learning reuses a model or representation learned on one task for a related new task. A pretrained CNN may already detect useful edges, textures and shapes, saving data and training effort.\n\n\n\n**Full scenario.** Build a face-attendance model with few images per student. Explain a training plan.\n**Step 1. Define and split the data.** Collect varied, permitted images and separate training/validation/test by suitable independent captures. Keep duplicates out of different splits. Apply the pretrained model’s required input size and normalization.\n**Step 2. Choose a suitable pretrained backbone.** For a course example, use VGG 16 or ResNet as an image-feature extractor. ImageNet-pretrained VGG 16 was trained on ImageNet, not automatically on a face-specific dataset. A face-trained model can be a more task-specific choice if available.\n**Step 3. Replace the classifier.** Remove the original class head. Add a new classifier matching the required student classes, or an appropriate embedding-based recognition system if that is the chosen formulation. For the exam classification example, use a softmax head and cross-entropy.\n**Step 4. Freeze and train.** Freeze the base weights and train the new head first. Use suitable augmentation, regularization and validation monitoring.\n**Step 5. Fine-tune if justified.** Unfreeze selected later layers and train at a smaller learning rate. Early layers may remain frozen. Compare validation performance and restore the best checkpoint.\n**Step 6. Evaluate.** Use the held-out test set once for the final estimate. Include unfamiliar faces and a rejection rule if describing a real attendance system; a closed-set classroom example alone does not solve unknown-person recognition.\nFeature extraction keeps the backbone fixed. Fine-tuning changes some pretrained weights. Training the entire model from scratch is a third option when enough representative data and compute are available, but it is usually harder for the stated small-dataset scenario."},{"title":"Model answer: feature extraction and fine-tuning","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain transfer learning for image classification with limited labeled data. Distinguish feature extraction from fine-tuning and describe the training procedure.</p>"],"answer":["<p>Transfer learning reuses knowledge represented by a model trained on a source task to support a related target task. A pretrained CNN can provide useful visual representations, reducing the target data and training effort needed compared with learning all features from random initialization.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Procedure</h3>","<p>1. Define the target classes and create separate training, validation and test splits. Prevent duplicate or closely related captures from leaking across splits.</p>","<p>2. Choose a suitable pretrained backbone and apply its required input size and preprocessing.</p>","<p>3. Replace the original classifier with a new head whose output count matches the target classes.</p>","<p>4. Freeze the backbone and train the new head. Only the unfrozen parameters receive optimizer updates.</p>","<p>5. If validation results justify it, unfreeze selected later backbone layers and continue training with a suitably smaller learning rate.</p>","<p>6. Select hyperparameters and checkpoints using validation data. Evaluate the selected model on the held-out test set.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Feature extraction</th><th>Fine-tuning</th></tr></thead><tbody><tr><td>Pretrained backbone weights remain fixed</td><td>Some or all selected pretrained weights are updated</td></tr><tr><td>New classifier learns from fixed representations</td><td>Representations can adapt to the target task</td></tr><tr><td>Usually fewer trainable parameters</td><td>Usually more trainable parameters and greater risk of overfitting on a small dataset</td></tr></tbody></table></div>","<p>The benefit depends on how useful the source features are for the target data. Transfer is not guaranteed to help every unrelated task. For a numerical, count all stored parameters separately from the trainable subset; freezing a layer does not delete its weights.</p>"],"kind":"theory","id":"tee-c8-s5","search":"Model answer: feature extraction and fine-tuning **Question.** Explain transfer learning for image classification with limited labeled data. Distinguish feature extraction from fine-tuning and describe the training procedure.\n\n**Model answer.**\nTransfer learning reuses knowledge represented by a model trained on a source task to support a related target task. A pretrained CNN can provide useful visual representations, reducing the target data and training effort needed compared with learning all features from random initialization.\n\n\n\n\n### Procedure\n1. Define the target classes and create separate training, validation and test splits. Prevent duplicate or closely related captures from leaking across splits.\n2. Choose a suitable pretrained backbone and apply its required input size and preprocessing.\n3. Replace the original classifier with a new head whose output count matches the target classes.\n4. Freeze the backbone and train the new head. Only the unfrozen parameters receive optimizer updates.\n5. If validation results justify it, unfreeze selected later backbone layers and continue training with a suitably smaller learning rate.\n6. Select hyperparameters and checkpoints using validation data. Evaluate the selected model on the held-out test set.\n\n| Feature extraction | Fine-tuning |\n| Pretrained backbone weights remain fixed | Some or all selected pretrained weights are updated |\n| New classifier learns from fixed representations | Representations can adapt to the target task |\n| Usually fewer trainable parameters | Usually more trainable parameters and greater risk of overfitting on a small dataset |\n\nThe benefit depends on how useful the source features are for the target data. Transfer is not guaranteed to help every unrelated task. For a numerical, count all stored parameters separately from the trainable subset; freezing a layer does not delete its weights.\n"},{"title":"How to draw the architecture diagrams","blocks":["<p>For AlexNet, draw a sequence of convolution/pooling stages followed by dense layers and classifier. For Inception, draw four parallel branches and a channel-concatenation join. For ResNet, draw one transformation branch and one shortcut meeting at a plus sign. For transfer learning, draw frozen pretrained base → new trainable head, then mark selected base layers optionally unfrozen for fine-tuning.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_architectures.svg\" aria-label=\"Enlarge diagram: Draw the sequential path, parallel branches or additive shortcut that explains the architecture.\"><img src=\"assets/figures/v_architectures.svg\" alt=\"Draw the sequential path, parallel branches or additive shortcut that explains the architecture.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Draw the sequential path, parallel branches or additive shortcut that explains the architecture. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s6","search":"How to draw the architecture diagrams For AlexNet, draw a sequence of convolution/pooling stages followed by dense layers and classifier. For Inception, draw four parallel branches and a channel-concatenation join. For ResNet, draw one transformation branch and one shortcut meeting at a plus sign. For transfer learning, draw frozen pretrained base → new trainable head, then mark selected base layers optionally unfrozen for fine-tuning.\n\n\n\n\n"},{"title":"Inception concatenation and residual addition","blocks":["<p class=\"definition\"><strong>Definition.</strong> Channel concatenation joins feature tensors while preserving their separate channels. Residual addition sums corresponding entries. These operations impose different shape constraints and produce different output depths.</p>","<h3>Explanation and working</h3>","<p>Concatenation joins feature channels; elementwise addition sums matching entries. They are different operations.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_join_add.svg\" aria-label=\"Enlarge diagram: Concatenation stacks channels. Residual addition combines matching values and preserves the matched shape.\"><img src=\"assets/figures/v_join_add.svg\" alt=\"Concatenation stacks channels. Residual addition combines matching values and preserves the matched shape.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Concatenation stacks channels. Residual addition combines matching values and preserves the matched shape. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Four Inception branches of spatial size 14 × 14 have 16, 32, 8 and 8 channels. First add the channel counts: 16 + 32 = 48; 48 + 8 = 56; 56 + 8 = 64. Height and width stay 14. The concatenated output is 14 × 14 × 64.</p>","<p>A residual addition requires matching shapes. A 14 × 14 × 64 tensor cannot be directly added to a 14 × 14 × 32 tensor. A projection, often a 1 × 1 convolution, can transform one path to the matching shape before addition.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s7","search":"Inception concatenation and residual addition **Definition.** Channel concatenation joins feature tensors while preserving their separate channels. Residual addition sums corresponding entries. These operations impose different shape constraints and produce different output depths.\n\n### Explanation and working\nConcatenation joins feature channels; elementwise addition sums matching entries. They are different operations.\n\n\n\nFour Inception branches of spatial size 14 × 14 have 16, 32, 8 and 8 channels. First add the channel counts: 16 + 32 = 48; 48 + 8 = 56; 56 + 8 = 64. Height and width stay 14. The concatenated output is 14 × 14 × 64.\nA residual addition requires matching shapes. A 14 × 14 × 64 tensor cannot be directly added to a 14 × 14 × 32 tensor. A projection, often a 1 × 1 convolution, can transform one path to the matching shape before addition.\n"},{"title":"Model answer: AlexNet, Inception and ResNet","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare the main ideas of AlexNet, Inception and ResNet. Explain how to recognize their architecture diagrams.</p>"],"answer":["<p>All three are CNN architectures, but their characteristic structures differ.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_architectures.svg\" aria-label=\"Enlarge diagram: Each block illustrates the defining design idea; the full architecture diagrams give its detailed layout.\"><img src=\"assets/figures/v_architectures.svg\" alt=\"Each block illustrates the defining design idea; the full architecture diagrams give its detailed layout.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Each block illustrates the defining design idea; the full architecture diagrams give its detailed layout. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Architecture</th><th>Main idea</th><th>What to show in a diagram</th></tr></thead><tbody><tr><td>AlexNet</td><td>Successive convolutional feature extraction followed by dense classification</td><td>Five convolutional layers and three fully connected layers, with the stated pooling/normalization stages</td></tr><tr><td>Inception v1</td><td>Parallel branches analyze features at different spatial scales</td><td>1 × 1, reduced 3 × 3, reduced 5 × 5 and pooling branches joined by channel concatenation</td></tr><tr><td>ResNet</td><td>Learn a residual transformation and add a shortcut</td><td>A transformation branch and input shortcut meeting at a plus sign</td></tr></tbody></table></div>","<p>AlexNet&#x27;s exam-relevant features include ReLU, GPU-based training, augmentation and dropout in the fully connected part. A parameter calculation must follow the given channel connectivity; a grouped implementation and a simplified fully connected-channel diagram need not have the same count.</p>","<p>Inception uses 1 × 1 convolutions to mix channels and, when a smaller number of filters is chosen, reduce the channel depth before expensive spatial filters. Branch outputs must have compatible height and width for concatenation. Concatenation adds channel counts by joining their lists.</p>","<p>ResNet computes a learned transformation F(x) and combines it with the shortcut:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d30a7ff979462f45.svg\" alt=\"H(x)=F(x)+x\" width=\"182.40\" height=\"24.43\" style=\"width:182.40px;height:24.43px;aspect-ratio:182.40/24.43\" loading=\"lazy\"></div>","<p>This is entrywise addition. The two shapes must match; a projection can adapt a shortcut when they do not. The shortcut supplies an additional route for information and gradients and makes identity-like mappings easy to represent.</p>","<p><strong>Key distinction:</strong> an Inception join concatenates feature maps; a residual join adds corresponding values. Their diagram symbols and output-channel calculations must therefore differ.</p>"],"kind":"theory","id":"tee-c8-s8","search":"Model answer: AlexNet, Inception and ResNet **Question.** Compare the main ideas of AlexNet, Inception and ResNet. Explain how to recognize their architecture diagrams.\n\n**Model answer.**\nAll three are CNN architectures, but their characteristic structures differ.\n\n\n\n\n| Architecture | Main idea | What to show in a diagram |\n| AlexNet | Successive convolutional feature extraction followed by dense classification | Five convolutional layers and three fully connected layers, with the stated pooling/normalization stages |\n| Inception v1 | Parallel branches analyze features at different spatial scales | 1 × 1, reduced 3 × 3, reduced 5 × 5 and pooling branches joined by channel concatenation |\n| ResNet | Learn a residual transformation and add a shortcut | A transformation branch and input shortcut meeting at a plus sign |\n\nAlexNet's exam-relevant features include ReLU, GPU-based training, augmentation and dropout in the fully connected part. A parameter calculation must follow the given channel connectivity; a grouped implementation and a simplified fully connected-channel diagram need not have the same count.\n\nInception uses 1 × 1 convolutions to mix channels and, when a smaller number of filters is chosen, reduce the channel depth before expensive spatial filters. Branch outputs must have compatible height and width for concatenation. Concatenation adds channel counts by joining their lists.\n\nResNet computes a learned transformation F(x) and combines it with the shortcut:\n\nThis is entrywise addition. The two shapes must match; a projection can adapt a shortcut when they do not. The shortcut supplies an additional route for information and gradients and makes identity-like mappings easy to represent.\n\n**Key distinction:** an Inception join concatenates feature maps; a residual join adds corresponding values. Their diagram symbols and output-channel calculations must therefore differ.\n"},{"title":"Applications of convolutional neural networks","blocks":["<p class=\"definition\"><strong>Definition.</strong> A CNN application combines a convolutional feature extractor with an output head designed for a particular prediction task. Shared local filters learn spatial patterns; the output head determines what is predicted and the loss determines how it is trained.</p>","<h3>Classification, detection and segmentation</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Task</th><th>Required output</th><th>What distinguishes it</th></tr></thead><tbody><tr><td>Image classification</td><td>One label or class distribution for the image</td><td>Answers what category the whole image belongs to</td></tr><tr><td>Object detection</td><td>Object classes and bounding-box coordinates</td><td>Also identifies where each detected object is located</td></tr><tr><td>Semantic segmentation</td><td>A class label or distribution for each pixel</td><td>Produces a spatial label map rather than one image-wide class</td></tr><tr><td>Face recognition</td><td>Identity class or a learned face representation</td><td>Compares or classifies learned visual features</td></tr></tbody></table></div>","<p>A softmax image classifier alone does not produce boxes or pixel labels. Detection and segmentation require appropriate task heads, targets and objectives. In an applications question, explain the prediction required instead of listing model names without their purpose.</p>","<h3>Examples across domains</h3>","<p><strong>Medical imaging:</strong> classify an image or use a segmentation model to identify regions of interest. The target may be an image-level label or a pixel mask, so the architecture and loss must match that choice.</p>","<p><strong>Autonomous perception:</strong> use camera images for tasks such as detecting pedestrians and vehicles or segmenting road regions. These outputs are inputs to a larger perception and decision system.</p>","<p><strong>Manufacturing:</strong> classify product images as defective or non-defective, or localize defects when position information is needed.</p>","<p><strong>Document analysis:</strong> classify cropped handwritten characters; a complete document-reading system must also locate and order text regions.</p>","<p><strong>Remote sensing:</strong> classify land-use regions or segment different surface categories in satellite images. Spatial context and texture can help distinguish classes.</p>","<h3>Complete exam-style application answer</h3>","<p class=\"inline-question\"><strong>Question. Describe how a CNN can classify product photographs into three classes: acceptable, scratched and cracked. Explain the input, network stages, output activation, loss, training and evaluation.</strong></p>","<p class=\"worked-step\"><strong>Step 1: define data and labels.</strong> Each example contains an image and one of the three class labels. Use separate training, validation and test sets, keeping near-duplicate photographs of the same item out of different splits. Apply the chosen model&#x27;s input size and scaling consistently.</p>","<p class=\"worked-step\"><strong>Step 2: extract spatial features.</strong> Convolutional layers calculate local responses using shared kernels. Nonlinear activations allow more complex combinations of those responses. Further convolution stages combine local patterns; pooling may reduce spatial dimensions.</p>","<p class=\"worked-step\"><strong>Step 3: produce three class scores.</strong> Convert the final representation into a feature vector, using flattening or an appropriate global pooling operation, and apply a dense layer with three outputs. These raw outputs are logits.</p>","<p class=\"worked-step\"><strong>Step 4: calculate class probabilities and loss.</strong> For mutually exclusive classes, use softmax and categorical cross-entropy. A one-hot label selects the probability of the correct class.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.11px;--narrow-height:153.31px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f4b48b92a27eca9.svg\"><img class=\"math display-math\" src=\"assets/equations/c00adcf16ff90eab.svg\" alt=\"q_k=\\frac{e^{z_k}}{\\sum_{j=1}^{3}e^{z_j}},\\qquad L=-\\sum_{k=1}^{3}y_k\\ln q_k\" width=\"399.14\" height=\"74.70\" style=\"width:399.14px;height:74.70px;aspect-ratio:399.14/74.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: train the parameters.</strong> Run forward propagation, evaluate the loss, backpropagate derivatives and update the trainable convolutional and dense parameters using the selected optimizer. Use validation results for hyperparameters and stopping decisions.</p>","<p class=\"worked-step\"><strong>Step 6: evaluate the selected model.</strong> Assess the final model on held-out photographs. Report overall classification performance and inspect which defects are confused. With limited data, a pretrained CNN can provide features and selected layers can be fine-tuned.</p>","<p><strong>Numerical extension. If the last pooled feature vector has 64 components, how many parameters does the three-class dense head have, including bias?</strong></p>","<p class=\"worked-step\"><strong>Step 1:</strong> each output receives 64 weights, so three outputs require 64 × 3 = 192 weights.</p>","<p class=\"worked-step\"><strong>Step 2:</strong> each of the three outputs has one bias, giving 3 biases.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5453c1fee1f9ccef.svg\"><img class=\"math display-math\" src=\"assets/equations/5a75359a035a6d76.svg\" alt=\"P_{\\mathrm{head}}=64(3)+3=(64+1)3=195\" width=\"383.14\" height=\"24.43\" style=\"width:383.14px;height:24.43px;aspect-ratio:383.14/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> 195 trainable parameters in this head. Softmax adds no trainable parameters. The backbone&#x27;s parameters are counted separately.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s9","search":"Applications of convolutional neural networks **Definition.** A CNN application combines a convolutional feature extractor with an output head designed for a particular prediction task. Shared local filters learn spatial patterns; the output head determines what is predicted and the loss determines how it is trained.\n\n### Classification, detection and segmentation\n| Task | Required output | What distinguishes it |\n| Image classification | One label or class distribution for the image | Answers what category the whole image belongs to |\n| Object detection | Object classes and bounding-box coordinates | Also identifies where each detected object is located |\n| Semantic segmentation | A class label or distribution for each pixel | Produces a spatial label map rather than one image-wide class |\n| Face recognition | Identity class or a learned face representation | Compares or classifies learned visual features |\n\nA softmax image classifier alone does not produce boxes or pixel labels. Detection and segmentation require appropriate task heads, targets and objectives. In an applications question, explain the prediction required instead of listing model names without their purpose.\n\n### Examples across domains\n**Medical imaging:** classify an image or use a segmentation model to identify regions of interest. The target may be an image-level label or a pixel mask, so the architecture and loss must match that choice.\n\n**Autonomous perception:** use camera images for tasks such as detecting pedestrians and vehicles or segmenting road regions. These outputs are inputs to a larger perception and decision system.\n\n**Manufacturing:** classify product images as defective or non-defective, or localize defects when position information is needed.\n\n**Document analysis:** classify cropped handwritten characters; a complete document-reading system must also locate and order text regions.\n\n**Remote sensing:** classify land-use regions or segment different surface categories in satellite images. Spatial context and texture can help distinguish classes.\n\n### Complete exam-style application answer\n**Question. Describe how a CNN can classify product photographs into three classes: acceptable, scratched and cracked. Explain the input, network stages, output activation, loss, training and evaluation.**\n\n**Step 1: define data and labels.** Each example contains an image and one of the three class labels. Use separate training, validation and test sets, keeping near-duplicate photographs of the same item out of different splits. Apply the chosen model's input size and scaling consistently.\n\n**Step 2: extract spatial features.** Convolutional layers calculate local responses using shared kernels. Nonlinear activations allow more complex combinations of those responses. Further convolution stages combine local patterns; pooling may reduce spatial dimensions.\n\n**Step 3: produce three class scores.** Convert the final representation into a feature vector, using flattening or an appropriate global pooling operation, and apply a dense layer with three outputs. These raw outputs are logits.\n\n**Step 4: calculate class probabilities and loss.** For mutually exclusive classes, use softmax and categorical cross-entropy. A one-hot label selects the probability of the correct class.\n\n\n**Step 5: train the parameters.** Run forward propagation, evaluate the loss, backpropagate derivatives and update the trainable convolutional and dense parameters using the selected optimizer. Us"},{"title":"Reading LeNet and AlexNet layer diagrams","blocks":["<p><strong>A layer diagram describes two different things:</strong> the size of the data moving through the network and the trainable operations that transform that data. A number such as 9,216 beside a flatten operation describes data length; it does not automatically mean another dense layer with 9,216 neurons.</p>","<h3>LeNet: follow the image as it becomes a class prediction</h3>","<p>The classroom LeNet layout begins with a 32 × 32 grayscale image. A valid 5 × 5 convolution with six filters produces 28 × 28 × 6. A 2 × 2 pooling operation with stride 2 produces 14 × 14 × 6. The next valid 5 × 5 convolution produces 10 × 10 × 16, and pooling reduces this to 5 × 5 × 16. A 5 × 5 convolution across those 16 channels produces 1 × 1 × 120. The final representation passes through 84 units and then ten class outputs.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Stage</th><th>What happens</th><th>Output shape</th></tr></thead><tbody><tr><td>Input</td><td>One grayscale image</td><td>32 × 32 × 1</td></tr><tr><td>C1</td><td>Six 5 × 5 filters, stride 1, no padding</td><td>28 × 28 × 6</td></tr><tr><td>S2</td><td>2 × 2 average pooling, stride 2</td><td>14 × 14 × 6</td></tr><tr><td>C3</td><td>Sixteen 5 × 5 filters, stride 1, no padding</td><td>10 × 10 × 16</td></tr><tr><td>S4</td><td>2 × 2 average pooling, stride 2</td><td>5 × 5 × 16</td></tr><tr><td>C5</td><td>120 filters covering the complete 5 × 5 spatial map</td><td>1 × 1 × 120</td></tr><tr><td>F6</td><td>Dense transformation</td><td>84 values</td></tr><tr><td>Classifier</td><td>Modern classroom softmax classifier</td><td>Ten probabilities</td></tr></tbody></table></div>","<p>The original LeNet-5 used details such as partial channel connectivity, trainable subsampling and an RBF output. A modern full-channel implementation with ordinary pooling and softmax is a different parameter-count convention. For a numerical, follow the question&#x27;s diagram and state the convention. The complete LeNet parameter numerical in the solved-paper section uses the modern classroom convention.</p>","<h3>AlexNet: identify the flatten step correctly</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/alexnet.svg\" aria-label=\"Enlarge diagram: Five convolutional layers extract image features; three dense layers produce the classifier output. Flattening only rearranges the final feature maps.\"><img src=\"assets/figures/alexnet.svg\" alt=\"Five convolutional layers extract image features; three dense layers produce the classifier output. Flattening only rearranges the final feature maps.\" width=\"960\" height=\"480\" loading=\"lazy\"></button><figcaption>Five convolutional layers extract image features; three dense layers produce the classifier output. Flattening only rearranges the final feature maps. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For the faculty&#x27;s 227 × 227 × 3 classroom input, the main shape sequence is 55 × 55 × 96 → 27 × 27 × 96 → 27 × 27 × 256 → 13 × 13 × 256 → 13 × 13 × 384 → 13 × 13 × 384 → 13 × 13 × 256 → 6 × 6 × 256. Flattening gives 9,216 values; the three dense outputs are 4,096, 4,096 and 1,000. There is no extra learned 9,216-unit layer between flattening and the first 4,096-unit layer.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). An AlexNet-style first layer receives a 227 × 227 RGB image and uses 96 filters of size 11 × 11, stride 4 and no padding. Find its output shape, trainable parameters including bias, and the number of output activation values.</strong></p>","<h3>Given</h3>","<p>Input height and width = 227; input channels = 3; kernel = 11; stride = 4; padding = 0; output filters = 96. One bias is used per filter.</p>","<h3>To find</h3>","<p>The three-dimensional output shape, parameter count and activation count.</p>","<h3>Formula — which one and why</h3>","<p>The output-size formula counts valid window positions. Parameter count counts stored filter coefficients, reused at every position. Activation count counts the values produced for one image.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/368322f7f93c9e79.svg\" alt=\"H_o=W_o=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"344.41\" height=\"58.62\" style=\"width:344.41px;height:58.62px;aspect-ratio:344.41/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fd2a21cf67217e86.svg\" alt=\"A=H_oW_oC_{\\mathrm{out}}\" width=\"159.56\" height=\"21.35\" style=\"width:159.56px;height:21.35px;aspect-ratio:159.56/21.35\" loading=\"lazy\"></div>","<p>Here N is input side length, P is padding per side, K is kernel side length, S is stride, and C denotes channel count. The symbol P in the output formula means padding; the labelled quantity P_conv means parameters.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate one spatial side.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8187570cd03b5f03.svg\" alt=\"\\frac{227-11}{4}+1=\\frac{216}{4}+1=54+1=55\" width=\"421.99\" height=\"49.80\" style=\"width:421.99px;height:49.80px;aspect-ratio:421.99/49.80\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: attach the output depth.</strong> There is one output map per filter, so the output is <strong>55 × 55 × 96</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: count the weights in one filter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8b467d436e9d44e.svg\" alt=\"11(11)(3)=363\" width=\"168.34\" height=\"24.43\" style=\"width:168.34px;height:24.43px;aspect-ratio:168.34/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add one bias and multiply by 96 filters.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a95b022f4ca93164.svg\" alt=\"P_{\\mathrm{conv}}=(363+1)(96)=34944\" width=\"320.20\" height=\"24.43\" style=\"width:320.20px;height:24.43px;aspect-ratio:320.20/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: count activation values for one image.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/200bca238c47286b.svg\" alt=\"A=55(55)(96)=290400\" width=\"268.12\" height=\"24.43\" style=\"width:268.12px;height:24.43px;aspect-ratio:268.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> output = 55 × 55 × 96; parameters = 34,944; activations = 290,400. The weights are reused, so parameters and activations are different counts. The full faculty-style ungrouped AlexNet table totals 62,378,344 parameters; the original grouped model uses different channel connectivity.</p>","<p><strong>Yaad rakho:</strong> shape = kitne answers nikle; parameters = kitne numbers seekhe.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s10","search":"Reading LeNet and AlexNet layer diagrams \n**A layer diagram describes two different things:** the size of the data moving through the network and the trainable operations that transform that data. A number such as 9,216 beside a flatten operation describes data length; it does not automatically mean another dense layer with 9,216 neurons.\n\n### LeNet: follow the image as it becomes a class prediction\n\nThe classroom LeNet layout begins with a 32 × 32 grayscale image. A valid 5 × 5 convolution with six filters produces 28 × 28 × 6. A 2 × 2 pooling operation with stride 2 produces 14 × 14 × 6. The next valid 5 × 5 convolution produces 10 × 10 × 16, and pooling reduces this to 5 × 5 × 16. A 5 × 5 convolution across those 16 channels produces 1 × 1 × 120. The final representation passes through 84 units and then ten class outputs.\n\n| Stage | What happens | Output shape |\n| Input | One grayscale image | 32 × 32 × 1 |\n| C1 | Six 5 × 5 filters, stride 1, no padding | 28 × 28 × 6 |\n| S2 | 2 × 2 average pooling, stride 2 | 14 × 14 × 6 |\n| C3 | Sixteen 5 × 5 filters, stride 1, no padding | 10 × 10 × 16 |\n| S4 | 2 × 2 average pooling, stride 2 | 5 × 5 × 16 |\n| C5 | 120 filters covering the complete 5 × 5 spatial map | 1 × 1 × 120 |\n| F6 | Dense transformation | 84 values |\n| Classifier | Modern classroom softmax classifier | Ten probabilities |\n\nThe original LeNet-5 used details such as partial channel connectivity, trainable subsampling and an RBF output. A modern full-channel implementation with ordinary pooling and softmax is a different parameter-count convention. For a numerical, follow the question's diagram and state the convention. The complete LeNet parameter numerical in the solved-paper section uses the modern classroom convention.\n\n### AlexNet: identify the flatten step correctly\n\n\n\nFor the faculty's 227 × 227 × 3 classroom input, the main shape sequence is 55 × 55 × 96 → 27 × 27 × 96 → 27 × 27 × 256 → 13 × 13 × 256 → 13 × 13 × 384 → 13 × 13 × 384 → 13 × 13 × 256 → 6 × 6 × 256. Flattening gives 9,216 values; the three dense outputs are 4,096, 4,096 and 1,000. There is no extra learned 9,216-unit layer between flattening and the first 4,096-unit layer.\n\n**Question (practice, 3 marks). An AlexNet-style first layer receives a 227 × 227 RGB image and uses 96 filters of size 11 × 11, stride 4 and no padding. Find its output shape, trainable parameters including bias, and the number of output activation values.**\n\n### Given\nInput height and width = 227; input channels = 3; kernel = 11; stride = 4; padding = 0; output filters = 96. One bias is used per filter.\n\n### To find\nThe three-dimensional output shape, parameter count and activation count.\n\n### Formula — which one and why\nThe output-size formula counts valid window positions. Parameter count counts stored filter coefficients, reused at every position. Activation count counts the values produced for one image.\n\n\n\nHere N is input side length, P is padding per side, K is kernel side length, S is stride, and C denotes channel count. The symbol P in the output formula means padding; the labelled quantity P_conv means parameters.\n\n### Solution — step by step\n**Step 1: calculate one spatial side.**\n\n\n**Step 2: attach the output depth.** There is one output map per filter, so the output is **55 × 55 × 96**.\n\n**Step 3: count the weights in one filter.**\n\n\n**Step 4: add one bias and multiply by 96 filters.**\n\n\n**Step 5: count activation values for one image.**\n\n\n**Final answer:** output = 55 × 55 ×"},{"title":"Top-1 and top-5 error: what an ImageNet result means","blocks":["<p><strong>Top-1 prediction</strong> is the class with the highest score. A top-1 mistake occurs when that class is wrong. <strong>Top-5 prediction</strong> is the list of the five highest-scoring classes. A top-5 mistake occurs only when the correct class is absent from that list. It is not the average error of five separate models.</p>","<p>For an image of a cat, the ordered list dog, cat, fox, horse, bird is a top-1 error but a top-5 success. The ordered list dog, fox, horse, bird, car is an error under both measures.</p>","<p class=\"inline-question\"><strong>Question (practice, 2 marks). A classifier evaluates 100 images. The correct class is ranked first for 78 images and appears somewhere in the first five positions for 92 images. Calculate top-1 error and top-5 error.</strong></p>","<h3>Given</h3>","<p>Total images = 100; top-1 successes = 78; top-5 successes = 92. The 78 first-place successes are already included in the 92 top-five successes.</p>","<h3>To find</h3>","<p>The percentage of mistakes under each rule.</p>","<h3>Formula — which one and why</h3>","<p>Subtract successful images from the total to obtain mistakes. Divide mistakes by the total and multiply by 100 to express a percentage.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fb17785121a672d.svg\" alt=\"E_k=\\frac{N-C_k}{N}\\times100\\%\" width=\"239.34\" height=\"50.50\" style=\"width:239.34px;height:50.50px;aspect-ratio:239.34/50.50\" loading=\"lazy\"></div>","<p>N means total evaluated images; C_k means images whose correct class appears among the top k predictions.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: top-1 mistakes.</strong> 100 − 78 = 22.</p>","<p class=\"worked-step\"><strong>Step 2: top-1 error percentage.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e21c77c5c190c14b.svg\" alt=\"E_1=\\frac{22}{100}\\times100\\%=22\\%\" width=\"272.94\" height=\"50.09\" style=\"width:272.94px;height:50.09px;aspect-ratio:272.94/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: top-5 mistakes.</strong> 100 − 92 = 8.</p>","<p class=\"worked-step\"><strong>Step 4: top-5 error percentage.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbf5783f9d42ea19.svg\" alt=\"E_5=\\frac{8}{100}\\times100\\%=8\\%\" width=\"260.72\" height=\"50.09\" style=\"width:260.72px;height:50.09px;aspect-ratio:260.72/50.09\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> top-1 error = 22%; top-5 error = 8%. A broader acceptable list makes top-5 error no greater than top-1 error for the same evaluated predictions.</p>","<p><strong>Yaad rakho:</strong> top-five mein sahi naam mil gaya toh top-five success.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s11","search":"Top-1 and top-5 error: what an ImageNet result means \n**Top-1 prediction** is the class with the highest score. A top-1 mistake occurs when that class is wrong. **Top-5 prediction** is the list of the five highest-scoring classes. A top-5 mistake occurs only when the correct class is absent from that list. It is not the average error of five separate models.\n\nFor an image of a cat, the ordered list dog, cat, fox, horse, bird is a top-1 error but a top-5 success. The ordered list dog, fox, horse, bird, car is an error under both measures.\n\n**Question (practice, 2 marks). A classifier evaluates 100 images. The correct class is ranked first for 78 images and appears somewhere in the first five positions for 92 images. Calculate top-1 error and top-5 error.**\n\n### Given\nTotal images = 100; top-1 successes = 78; top-5 successes = 92. The 78 first-place successes are already included in the 92 top-five successes.\n\n### To find\nThe percentage of mistakes under each rule.\n\n### Formula — which one and why\nSubtract successful images from the total to obtain mistakes. Divide mistakes by the total and multiply by 100 to express a percentage.\n\nN means total evaluated images; C_k means images whose correct class appears among the top k predictions.\n\n### Solution — step by step\n**Step 1: top-1 mistakes.** 100 − 78 = 22.\n\n**Step 2: top-1 error percentage.**\n\n\n**Step 3: top-5 mistakes.** 100 − 92 = 8.\n\n**Step 4: top-5 error percentage.**\n\n\n**Final answer:** top-1 error = 22%; top-5 error = 8%. A broader acceptable list makes top-5 error no greater than top-1 error for the same evaluated predictions.\n\n**Yaad rakho:** top-five mein sahi naam mil gaya toh top-five success.\n"},{"title":"VGG16: small filters in a regular sequence","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_vgg16.svg\" aria-label=\"Enlarge diagram: Follow the five blocks and their output sizes. The 16 counts learned layers, not pooling or flattening.\"><img src=\"assets/figures/u4_vgg16.svg\" alt=\"Follow the five blocks and their output sizes. The 16 counts learned layers, not pooling or flattening.\" width=\"900\" height=\"350\" loading=\"lazy\"></button><figcaption>Follow the five blocks and their output sizes. The 16 counts learned layers, not pooling or flattening. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"definition\"><strong>Definition.</strong> VGG16 is a convolutional architecture with 13 convolutional layers and three dense layers. Its standard convolution blocks contain 2, 2, 3, 3 and 3 convolutions. Pooling, activations and flattening are not counted in the name&#x27;s 16 weight layers.</p>","<p>Each convolution uses a 3 × 3 kernel, stride 1 and padding 1, preserving height and width. Each block ends with 2 × 2 max pooling of stride 2. The final classifier is 4,096 → 4,096 → 1,000 for the original 1,000-class task.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Block</th><th>Convolutions</th><th>Channels after its convolutions</th><th>Size after its pooling</th></tr></thead><tbody><tr><td>1</td><td>Two</td><td>64</td><td>112 × 112 × 64</td></tr><tr><td>2</td><td>Two</td><td>128</td><td>56 × 56 × 128</td></tr><tr><td>3</td><td>Three</td><td>256</td><td>28 × 28 × 256</td></tr><tr><td>4</td><td>Three</td><td>512</td><td>14 × 14 × 512</td></tr><tr><td>5</td><td>Three</td><td>512</td><td>7 × 7 × 512</td></tr></tbody></table></div>","<p>This table starts with 224 × 224 × 3. The flattened length is 7 × 7 × 512 = 25,088. Flattening has zero learned parameters. Stacking small filters provides repeated nonlinear transformations while progressively combining spatial information. A limitation is the large dense classifier and its memory cost.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). VGG16&#x27;s first block contains two same-padded 3 × 3 convolutions with 64 output filters each, followed by 2 × 2 max pooling with stride 2. Input is 224 × 224 × 3. Find both convolution parameter counts including bias and the pooled output shape.</strong></p>","<h3>Given</h3>","<p>Conv1: 3 input channels, 64 output channels. Conv2: 64 input channels, 64 output channels. Both have kernel 3, stride 1 and padding 1. Pooling has kernel 2, stride 2 and no padding.</p>","<h3>To find</h3>","<p>Trainable parameters in each convolution and the output after pooling.</p>","<h3>Formula — which one and why</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<p>Use each layer&#x27;s own input depth; the second layer receives the first layer&#x27;s 64 maps. Use the spatial-output formula for pooling. Max pooling introduces no trainable parameters.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: first convolution.</strong> Each filter has 3 × 3 × 3 = 27 weights and one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e82763edab004507.svg\" alt=\"P_1=(27+1)(64)=1792\" width=\"269.36\" height=\"24.43\" style=\"width:269.36px;height:24.43px;aspect-ratio:269.36/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: second convolution.</strong> Each filter now spans 64 channels, giving 3 × 3 × 64 = 576 weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ff96ebed9174c6f1.svg\" alt=\"P_2=(576+1)(64)=36928\" width=\"293.80\" height=\"24.43\" style=\"width:293.80px;height:24.43px;aspect-ratio:293.80/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add parameters.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc9e657e6b2a7ee5.svg\" alt=\"P_{\\mathrm{block}}=1792+36928=38720\" width=\"323.63\" height=\"20.54\" style=\"width:323.63px;height:20.54px;aspect-ratio:323.63/20.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: calculate pooled side length.</strong> The same-padded convolutions retained side length 224.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/71feab89feae610a.svg\" alt=\"\\frac{224-2}{2}+1=111+1=112\" width=\"312.13\" height=\"49.82\" style=\"width:312.13px;height:49.82px;aspect-ratio:312.13/49.82\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 1,792 and 36,928 parameters; total = 38,720; pooled shape = <strong>112 × 112 × 64</strong>.</p>","<p><strong>Exam convention:</strong> use the architecture explicitly supplied in a calculation. For the standard VGG16 architecture, remember <strong>2–2–3–3–3 convolutions and 2 × 2 pooling</strong>; 25,088 is the flattened feature length.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s12","search":"VGG16: small filters in a regular sequence \n\n\n**Definition.** VGG16 is a convolutional architecture with 13 convolutional layers and three dense layers. Its standard convolution blocks contain 2, 2, 3, 3 and 3 convolutions. Pooling, activations and flattening are not counted in the name's 16 weight layers.\n\nEach convolution uses a 3 × 3 kernel, stride 1 and padding 1, preserving height and width. Each block ends with 2 × 2 max pooling of stride 2. The final classifier is 4,096 → 4,096 → 1,000 for the original 1,000-class task.\n\n| Block | Convolutions | Channels after its convolutions | Size after its pooling |\n| 1 | Two | 64 | 112 × 112 × 64 |\n| 2 | Two | 128 | 56 × 56 × 128 |\n| 3 | Three | 256 | 28 × 28 × 256 |\n| 4 | Three | 512 | 14 × 14 × 512 |\n| 5 | Three | 512 | 7 × 7 × 512 |\n\nThis table starts with 224 × 224 × 3. The flattened length is 7 × 7 × 512 = 25,088. Flattening has zero learned parameters. Stacking small filters provides repeated nonlinear transformations while progressively combining spatial information. A limitation is the large dense classifier and its memory cost.\n\n**Question (practice, 3 marks). VGG16's first block contains two same-padded 3 × 3 convolutions with 64 output filters each, followed by 2 × 2 max pooling with stride 2. Input is 224 × 224 × 3. Find both convolution parameter counts including bias and the pooled output shape.**\n\n### Given\nConv1: 3 input channels, 64 output channels. Conv2: 64 input channels, 64 output channels. Both have kernel 3, stride 1 and padding 1. Pooling has kernel 2, stride 2 and no padding.\n\n### To find\nTrainable parameters in each convolution and the output after pooling.\n\n### Formula — which one and why\n\nUse each layer's own input depth; the second layer receives the first layer's 64 maps. Use the spatial-output formula for pooling. Max pooling introduces no trainable parameters.\n\n### Solution — step by step\n**Step 1: first convolution.** Each filter has 3 × 3 × 3 = 27 weights and one bias.\n\n\n**Step 2: second convolution.** Each filter now spans 64 channels, giving 3 × 3 × 64 = 576 weights.\n\n\n**Step 3: add parameters.**\n\n\n**Step 4: calculate pooled side length.** The same-padded convolutions retained side length 224.\n\n\n**Final answer:** 1,792 and 36,928 parameters; total = 38,720; pooled shape = **112 × 112 × 64**.\n\n**Exam convention:** use the architecture explicitly supplied in a calculation. For the standard VGG16 architecture, remember **2–2–3–3–3 convolutions and 2 × 2 pooling**; 25,088 is the flattened feature length.\n"},{"title":"Global average pooling: one average for each channel","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_gap.svg\" aria-label=\"Enlarge diagram: Average each channel separately: these are the exact values used in the worked example.\"><img src=\"assets/figures/u4_gap.svg\" alt=\"Average each channel separately: these are the exact values used in the worked example.\" width=\"900\" height=\"330\" loading=\"lazy\"></button><figcaption>Average each channel separately: these are the exact values used in the worked example. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"definition\"><strong>Definition.</strong> Global average pooling, or GAP, replaces every complete spatial feature map by its mean. An H × W × C tensor becomes C numbers. The channels remain separate; we do not average all channels into one number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/002749b4b374cf54.svg\" alt=\"g_c=\\frac{1}{HW}\\sum_{i=1}^{H}\\sum_{j=1}^{W}a_{i,j,c}\" width=\"239.71\" height=\"74.90\" style=\"width:239.71px;height:74.90px;aspect-ratio:239.71/74.90\" loading=\"lazy\"></div>","<p>The letter c selects a channel; i and j select its row and column; a is the value at that location. Add all H × W entries in that channel and divide by H × W. GAP has no learned weights or biases. A classifier after GAP can still have trainable parameters. In GoogLeNet, 7 × 7 × 1,024 becomes 1 × 1 × 1,024 before the final 1,000-class linear classifier.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). A 2 × 2 × 2 tensor has channel A = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e857333332fbdd17.svg\" alt=\"\\begin{bmatrix}1 &amp; 3\\\\5 &amp; 7\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> and channel B = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c890243a56df9f91.svg\" alt=\"\\begin{bmatrix}2 &amp; 4\\\\6 &amp; 8\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Apply GAP, then find the parameters of a three-output dense classifier receiving the result, including one bias per output.</strong></p>","<h3>Given</h3>","<p>H = 2, W = 2, C = 2. Each of the two channels contains four values. The classifier has three outputs.</p>","<h3>To find</h3>","<p>The GAP result and dense-head parameter count.</p>","<h3>Formula — which one and why</h3>","<p>Use one mean per channel. The dense layer receives two numbers, so each of its three outputs needs two weights and one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add channel A.</strong> 1 + 3 + 5 + 7 = 16.</p>","<p class=\"worked-step\"><strong>Step 2: average channel A.</strong> 16 ÷ 4 = 4.</p>","<p class=\"worked-step\"><strong>Step 3: add channel B.</strong> 2 + 4 + 6 + 8 = 20.</p>","<p class=\"worked-step\"><strong>Step 4: average channel B.</strong> 20 ÷ 4 = 5. Thus GAP outputs <strong>[4,5]</strong>.</p>","<p class=\"worked-step\"><strong>Step 5: count the classifier&#x27;s weights.</strong> 2 inputs × 3 outputs = 6 weights.</p>","<p class=\"worked-step\"><strong>Step 6: add three biases.</strong> 6 + 3 = <strong>9 parameters</strong>. GAP itself contributes zero.</p>","<p><strong>Final answer:</strong> GAP = [4,5]; GAP shape = 1 × 1 × 2; classifier parameters = 9. If we flattened all eight inputs instead, that head would require (8 + 1) × 3 = 27 parameters.</p>","<p><strong>Yaad rakho:</strong> ek channel ka poora average; channels ko aapas mein mat milao.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s13","search":"Global average pooling: one average for each channel \n\n\n**Definition.** Global average pooling, or GAP, replaces every complete spatial feature map by its mean. An H × W × C tensor becomes C numbers. The channels remain separate; we do not average all channels into one number.\n\n\n\nThe letter c selects a channel; i and j select its row and column; a is the value at that location. Add all H × W entries in that channel and divide by H × W. GAP has no learned weights or biases. A classifier after GAP can still have trainable parameters. In GoogLeNet, 7 × 7 × 1,024 becomes 1 × 1 × 1,024 before the final 1,000-class linear classifier.\n\n**Question (practice, 3 marks). A 2 × 2 × 2 tensor has channel A =  and channel B = . Apply GAP, then find the parameters of a three-output dense classifier receiving the result, including one bias per output.**\n\n### Given\nH = 2, W = 2, C = 2. Each of the two channels contains four values. The classifier has three outputs.\n\n### To find\nThe GAP result and dense-head parameter count.\n\n### Formula — which one and why\nUse one mean per channel. The dense layer receives two numbers, so each of its three outputs needs two weights and one bias.\n\n\n### Solution — step by step\n**Step 1: add channel A.** 1 + 3 + 5 + 7 = 16.\n\n**Step 2: average channel A.** 16 ÷ 4 = 4.\n\n**Step 3: add channel B.** 2 + 4 + 6 + 8 = 20.\n\n**Step 4: average channel B.** 20 ÷ 4 = 5. Thus GAP outputs **[4,5]**.\n\n**Step 5: count the classifier's weights.** 2 inputs × 3 outputs = 6 weights.\n\n**Step 6: add three biases.** 6 + 3 = **9 parameters**. GAP itself contributes zero.\n\n**Final answer:** GAP = [4,5]; GAP shape = 1 × 1 × 2; classifier parameters = 9. If we flattened all eight inputs instead, that head would require (8 + 1) × 3 = 27 parameters.\n\n**Yaad rakho:** ek channel ka poora average; channels ko aapas mein mat milao.\n"},{"title":"The faculty's 480-channel bottleneck numerical","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/u4_bottleneck_480.svg\" aria-label=\"Enlarge diagram: Both paths start from 14 × 14 × 480 and end at 14 × 14 × 48. The bottleneck cost includes both layers.\"><img src=\"assets/figures/u4_bottleneck_480.svg\" alt=\"Both paths start from 14 × 14 × 480 and end at 14 × 14 × 48. The bottleneck cost includes both layers.\" width=\"900\" height=\"465\" loading=\"lazy\"></button><figcaption>Both paths start from 14 × 14 × 480 and end at 14 × 14 × 48. The bottleneck cost includes both layers. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). Compare a direct same-padded 5 × 5 convolution with 48 filters on a 14 × 14 × 480 input against a 1 × 1 reduction to 16 channels followed by the same 5 × 5, 48-filter layer. Use stride 1. Count MACs, ignore bias additions, and find the percentage reduction.</strong></p>","<h3>Given</h3>","<p>Both paths produce 14 × 14 × 48. Direct spatial filters span 480 channels; reduced spatial filters span 16. The reduction has 16 output filters.</p>","<h3>To find</h3>","<p>MACs for the direct path, both bottleneck stages, their total and percentage saved.</p>","<h3>Formula — which one and why</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48494d663392b9d5.svg\" alt=\"M=H_oW_oC_oK^2C_i\" width=\"209.44\" height=\"25.46\" style=\"width:209.44px;height:25.46px;aspect-ratio:209.44/25.46\" loading=\"lazy\"></div>","<p>M is the MAC count. H_oW_oC_o counts output values; K²C_i is the products used for each output. One MAC means one multiply-accumulate pair. Count both layers of the bottleneck.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78cf62ab96d05d20.svg\" alt=\"\\mathrm{saving}\\%=100\\frac{M_{\\mathrm{direct}}-M_{\\mathrm{bottleneck}}}{M_{\\mathrm{direct}}}\" width=\"370.49\" height=\"53.83\" style=\"width:370.49px;height:53.83px;aspect-ratio:370.49/53.83\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: direct output count.</strong> 14 × 14 × 48 = 9,408.</p>","<p class=\"worked-step\"><strong>Step 2: products per direct output.</strong> 5 × 5 × 480 = 12,000.</p>","<p class=\"worked-step\"><strong>Step 3: direct MACs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7c9631645fc9930b.svg\" alt=\"9408(12000)=112896000\" width=\"271.50\" height=\"24.43\" style=\"width:271.50px;height:24.43px;aspect-ratio:271.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: reduction-layer MACs.</strong> Each of 14 × 14 × 16 outputs combines 480 values.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8486a56714848659.svg\" alt=\"14(14)(16)(480)=1505280\" width=\"285.09\" height=\"24.43\" style=\"width:285.09px;height:24.43px;aspect-ratio:285.09/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: reduced spatial-layer MACs.</strong> Each of 9,408 outputs now combines 5 × 5 × 16 = 400 values.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d32e7e22a58c8e10.svg\" alt=\"9408(400)=3763200\" width=\"222.63\" height=\"24.43\" style=\"width:222.63px;height:24.43px;aspect-ratio:222.63/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: add both bottleneck costs.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7061d250d8255604.svg\" alt=\"1505280+3763200=5268480\" width=\"319.01\" height=\"18.54\" style=\"width:319.01px;height:18.54px;aspect-ratio:319.01/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate the saving.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a866c1ac7a2fce39.svg\" alt=\"112896000-5268480=107627520\" width=\"367.88\" height=\"18.54\" style=\"width:367.88px;height:18.54px;aspect-ratio:367.88/18.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18ccfe0746a80b04.svg\" alt=\"100\\frac{107627520}{112896000}\\approx95.333333\\%\" width=\"314.83\" height=\"50.34\" style=\"width:314.83px;height:50.34px;aspect-ratio:314.83/50.34\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> direct = <strong>112.896 million MACs</strong>; bottleneck = <strong>5.26848 million MACs</strong>; saving ≈ <strong>95.33%</strong>. The lecture&#x27;s 112.9M and 5.3M are rounded versions. This arithmetic proves reduced computation; equal prediction accuracy is not guaranteed by the count alone.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s14","search":"The faculty's 480-channel bottleneck numerical \n\n\n**Question (practice, 3 marks). Compare a direct same-padded 5 × 5 convolution with 48 filters on a 14 × 14 × 480 input against a 1 × 1 reduction to 16 channels followed by the same 5 × 5, 48-filter layer. Use stride 1. Count MACs, ignore bias additions, and find the percentage reduction.**\n\n### Given\nBoth paths produce 14 × 14 × 48. Direct spatial filters span 480 channels; reduced spatial filters span 16. The reduction has 16 output filters.\n\n### To find\nMACs for the direct path, both bottleneck stages, their total and percentage saved.\n\n### Formula — which one and why\n\nM is the MAC count. H_oW_oC_o counts output values; K²C_i is the products used for each output. One MAC means one multiply-accumulate pair. Count both layers of the bottleneck.\n\n\n### Solution — step by step\n**Step 1: direct output count.** 14 × 14 × 48 = 9,408.\n\n**Step 2: products per direct output.** 5 × 5 × 480 = 12,000.\n\n**Step 3: direct MACs.**\n\n\n**Step 4: reduction-layer MACs.** Each of 14 × 14 × 16 outputs combines 480 values.\n\n\n**Step 5: reduced spatial-layer MACs.** Each of 9,408 outputs now combines 5 × 5 × 16 = 400 values.\n\n\n**Step 6: add both bottleneck costs.**\n\n\n**Step 7: calculate the saving.**\n\n\n\n**Final answer:** direct = **112.896 million MACs**; bottleneck = **5.26848 million MACs**; saving ≈ **95.33%**. The lecture's 112.9M and 5.3M are rounded versions. This arithmetic proves reduced computation; equal prediction accuracy is not guaranteed by the count alone.\n"},{"title":"Batch normalization inside a residual network","blocks":["<p class=\"definition\"><strong>Definition.</strong> Batch normalization normalizes a feature using training-batch statistics, then applies a learned scale and shift. It operates on intermediate activations and is different from normalizing the original dataset once before training.</p>","<p>For one feature with m values in a training batch:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a91b1c9216cbd799.svg\" alt=\"\\mu_B=\\frac{1}{m}\\sum_{i=1}^{m}x_i\" width=\"160.06\" height=\"68.62\" style=\"width:160.06px;height:68.62px;aspect-ratio:160.06/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcfc8cc5fd3adc8.svg\" alt=\"\\sigma_B^2=\\frac{1}{m}\\sum_{i=1}^{m}(x_i-\\mu_B)^2\" width=\"244.63\" height=\"68.62\" style=\"width:244.63px;height:68.62px;aspect-ratio:244.63/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13126b94bcd9d415.svg\" alt=\"\\hat{x}_i=\\frac{x_i-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\" width=\"159.11\" height=\"75.23\" style=\"width:159.11px;height:75.23px;aspect-ratio:159.11/75.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7fd3e426f48f08b9.svg\" alt=\"y_i=\\gamma\\hat{x}_i+\\beta\" width=\"131.48\" height=\"25.07\" style=\"width:131.48px;height:25.07px;aspect-ratio:131.48/25.07\" loading=\"lazy\"></div>","<p>The batch mean μ_B is the centre; batch variance σ²_B measures squared spread. Epsilon ε is a small positive stability constant <strong>inside the square root</strong>. Gamma γ is a learned scale and beta β is a learned shift. For convolutional BN, statistics are usually computed separately for each channel across batch and spatial positions. Ordinary inference uses stored running statistics rather than the current test batch.</p>","<p class=\"inline-question\"><strong>Question (practice, 3 marks). For one feature, a training batch contains [2,4]. Use ε = 0.00001, γ = 2 and β = 0.5. Calculate both batch-normalized outputs using population variance.</strong></p>","<h3>Given</h3>","<p>x₁ = 2; x₂ = 4; m = 2; ε = 0.00001; γ = 2; β = 0.5.</p>","<h3>To find</h3>","<p>Batch mean, variance, normalized values and scale-and-shift outputs.</p>","<h3>Formula — which one and why</h3>","<p>Use the four formulas above in order. Population variance divides by m = 2, not m − 1. Scale and shift follow normalization because the model can learn the useful final feature scale.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: mean.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dcbc368ca301a562.svg\" alt=\"\\mu_B=\\frac{2+4}{2}=3\" width=\"172.31\" height=\"49.82\" style=\"width:172.31px;height:49.82px;aspect-ratio:172.31/49.82\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: deviations.</strong> 2 − 3 = −1 and 4 − 3 = 1.</p>","<p class=\"worked-step\"><strong>Step 3: squared deviations and variance.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8c2f38c1c4da922.svg\" alt=\"\\sigma_B^2=\\frac{(-1)^2+1^2}{2}=\\frac{1+1}{2}=1\" width=\"328.53\" height=\"54.49\" style=\"width:328.53px;height:54.49px;aspect-ratio:328.53/54.49\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: stable denominator.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64e8bea52d19d8d8.svg\" alt=\"d=\\sqrt{1+0.00001}\\approx1.00000499999\" width=\"374.30\" height=\"25.90\" style=\"width:374.30px;height:25.90px;aspect-ratio:374.30/25.90\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: normalize separately.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3676422778896944.svg\" alt=\"\\hat{x}_1=\\frac{-1}{d}\\approx-0.99999500004\" width=\"304.20\" height=\"49.80\" style=\"width:304.20px;height:49.80px;aspect-ratio:304.20/49.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3c9c2142072c8bc9.svg\" alt=\"\\hat{x}_2=\\frac{1}{d}\\approx0.99999500004\" width=\"266.67\" height=\"49.80\" style=\"width:266.67px;height:49.80px;aspect-ratio:266.67/49.80\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: scale the first normalized value, then shift it.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4655c2949211af8b.svg\" alt=\"y_1=2(-0.99999500004)+0.5\\approx-1.49999000008\" width=\"524.96\" height=\"24.43\" style=\"width:524.96px;height:24.43px;aspect-ratio:524.96/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: scale the second normalized value, then shift it.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3848a4f079b59c74.svg\" alt=\"y_2=2(0.99999500004)+0.5\\approx2.49999000008\" width=\"486.93\" height=\"24.43\" style=\"width:486.93px;height:24.43px;aspect-ratio:486.93/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> output ≈ <strong>[−1.49999,2.49999]</strong>. Its mean is β = 0.5; the final output need not have zero mean after the learned shift. The normalized values themselves have mean zero here.</p>","<p><strong>Yaad rakho:</strong> centre hatao → spread se divide → learned scale lagao → shift add karo.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s15","search":"Batch normalization inside a residual network \n**Definition.** Batch normalization normalizes a feature using training-batch statistics, then applies a learned scale and shift. It operates on intermediate activations and is different from normalizing the original dataset once before training.\n\nFor one feature with m values in a training batch:\n\n\n\n\n\nThe batch mean μ_B is the centre; batch variance σ²_B measures squared spread. Epsilon ε is a small positive stability constant **inside the square root**. Gamma γ is a learned scale and beta β is a learned shift. For convolutional BN, statistics are usually computed separately for each channel across batch and spatial positions. Ordinary inference uses stored running statistics rather than the current test batch.\n\n**Question (practice, 3 marks). For one feature, a training batch contains [2,4]. Use ε = 0.00001, γ = 2 and β = 0.5. Calculate both batch-normalized outputs using population variance.**\n\n### Given\nx₁ = 2; x₂ = 4; m = 2; ε = 0.00001; γ = 2; β = 0.5.\n\n### To find\nBatch mean, variance, normalized values and scale-and-shift outputs.\n\n### Formula — which one and why\nUse the four formulas above in order. Population variance divides by m = 2, not m − 1. Scale and shift follow normalization because the model can learn the useful final feature scale.\n\n### Solution — step by step\n**Step 1: mean.**\n\n\n**Step 2: deviations.** 2 − 3 = −1 and 4 − 3 = 1.\n\n**Step 3: squared deviations and variance.**\n\n\n**Step 4: stable denominator.**\n\n\n**Step 5: normalize separately.**\n\n\n\n**Step 6: scale the first normalized value, then shift it.**\n\n\n**Step 7: scale the second normalized value, then shift it.**\n\n\n**Final answer:** output ≈ **[−1.49999,2.49999]**. Its mean is β = 0.5; the final output need not have zero mean after the learned shift. The normalized values themselves have mean zero here.\n\n**Yaad rakho:** centre hatao → spread se divide → learned scale lagao → shift add karo.\n"},{"title":"Residual-block order and architecture qualifications","blocks":["<p>The original post-activation basic block has this sequence: <strong>convolution → BN → ReLU → convolution → BN → add shortcut → ReLU</strong>. Thus the second branch convolution is not followed by a separate ReLU before the addition in this particular block. A pre-activation ResNet is another design; use the stated diagram.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: Add the shortcut to the residual branch, then apply the post-addition ReLU when the specified block requires it.\"><img src=\"assets/figures/residual.svg\" alt=\"Add the shortcut to the residual branch, then apply the post-addition ReLU when the specified block requires it.\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>Add the shortcut to the residual branch, then apply the post-addition ReLU when the specified block requires it. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>An identity shortcut has no learned parameters. A projection shortcut changes the shape using learned weights. Original ImageNet ResNets include an initial max-pooling operation; a basic residual block does not need a max-pooling layer inside it. ResNet-18/34 use two-convolution basic blocks, whereas deeper standard variants use bottleneck blocks. Avoid treating every ResNet as the same two-layer diagram.</p>","<p>The main advantage is easier optimization of deep networks: shortcuts provide an additional information and gradient path. This reduces the degradation problem but does not prove immunity to every vanishing/exploding-gradient case. Large networks still need compute, memory, suitable data and regularization. Reusing early features can help; it does not guarantee that every deeper model generalizes better.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s16","search":"Residual-block order and architecture qualifications \nThe original post-activation basic block has this sequence: **convolution → BN → ReLU → convolution → BN → add shortcut → ReLU**. Thus the second branch convolution is not followed by a separate ReLU before the addition in this particular block. A pre-activation ResNet is another design; use the stated diagram.\n\n\n\nAn identity shortcut has no learned parameters. A projection shortcut changes the shape using learned weights. Original ImageNet ResNets include an initial max-pooling operation; a basic residual block does not need a max-pooling layer inside it. ResNet-18/34 use two-convolution basic blocks, whereas deeper standard variants use bottleneck blocks. Avoid treating every ResNet as the same two-layer diagram.\n\nThe main advantage is easier optimization of deep networks: shortcuts provide an additional information and gradient path. This reduces the degradation problem but does not prove immunity to every vanishing/exploding-gradient case. Large networks still need compute, memory, suitable data and regularization. Reusing early features can help; it does not guarantee that every deeper model generalizes better.\n"},{"title":"Choosing frozen layers from dataset size and similarity","blocks":["<p>Early image layers commonly learn reusable edges and textures. Later layers become more specialized to source-task categories. “Earlier” means closer to the input, regardless of whether a drawing places those layers at the top or bottom.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Target dataset</th><th>Sensible starting choice</th><th>Reason</th></tr></thead><tbody><tr><td>Small and similar</td><td>Freeze the backbone; train a new head first</td><td>Useful features already exist, while few examples make overfitting likely</td></tr><tr><td>Large and similar</td><td>Train a new head, then fine-tune more layers if validation improves</td><td>More data can support more trainable parameters</td></tr><tr><td>Small and different</td><td>Try a more relevant pretrained model or fixed earlier/intermediate features; tune cautiously</td><td>Later source features may be unsuitable, but small data still makes extensive tuning risky</td></tr><tr><td>Large and different</td><td>Compare broad fine-tuning with training from scratch</td><td>Sufficient data permits stronger adaptation; the value of source features must be tested</td></tr></tbody></table></div>","<p>These are starting strategies, not universal rules. Fine-tuning an early layer means updating its pretrained weights, not automatically learning it “from scratch”. With very little data, simply unfreezing early layers because the task differs can overfit. Choose changes using validation performance and apply the required preprocessing consistently.</p>","<p><strong>Example.</strong> With 100 labelled microscopic images, an ImageNet model may provide reusable low-level patterns, but its animal/object classifier is inappropriate. Replace the head, test fixed representations and monitor validation before increasing the number of trainable layers. With a large representative image dataset, broader fine-tuning becomes a more reasonable candidate.</p>","<p><strong>Yaad rakho:</strong> data kam toh kam weights hilao; task alag toh features ki suitability pehle dekho.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s17","search":"Choosing frozen layers from dataset size and similarity \nEarly image layers commonly learn reusable edges and textures. Later layers become more specialized to source-task categories. “Earlier” means closer to the input, regardless of whether a drawing places those layers at the top or bottom.\n\n| Target dataset | Sensible starting choice | Reason |\n| Small and similar | Freeze the backbone; train a new head first | Useful features already exist, while few examples make overfitting likely |\n| Large and similar | Train a new head, then fine-tune more layers if validation improves | More data can support more trainable parameters |\n| Small and different | Try a more relevant pretrained model or fixed earlier/intermediate features; tune cautiously | Later source features may be unsuitable, but small data still makes extensive tuning risky |\n| Large and different | Compare broad fine-tuning with training from scratch | Sufficient data permits stronger adaptation; the value of source features must be tested |\n\nThese are starting strategies, not universal rules. Fine-tuning an early layer means updating its pretrained weights, not automatically learning it “from scratch”. With very little data, simply unfreezing early layers because the task differs can overfit. Choose changes using validation performance and apply the required preprocessing consistently.\n\n**Example.** With 100 labelled microscopic images, an ImageNet model may provide reusable low-level patterns, but its animal/object classifier is inappropriate. Replace the head, test fixed representations and monitor validation before increasing the number of trainable layers. With a large representative image dataset, broader fine-tuning becomes a more reasonable candidate.\n\n**Yaad rakho:** data kam toh kam weights hilao; task alag toh features ki suitability pehle dekho.\n"},{"title":"Four ways to reuse a pretrained model","blocks":["<p class=\"definition\"><strong>Definition.</strong> A pretrained model has already learned parameters from an earlier training task. We can reuse its complete classifier, reuse its feature extractor, or use its learned weights as the starting point for further training. The choice determines which output labels are available and which parameters change.</p>","<p><strong>First identify two parts.</strong> The <strong>backbone</strong> converts an input image into useful features. The <strong>head</strong> converts those features into the required prediction, such as class scores. A new task can reuse the backbone while replacing the head.</p>","<p><strong>Yaad rakhne ka cue:</strong> Purane model ka poora answer use karna, sirf features lena, ya uske weights ko aage train karna—yeh teen decisions alag hain.</p>","<p>The faculty reference divides these choices into the following four uses. The two feature-extractor uses differ in whether features are saved separately or computed inside the new model.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Use</th><th>What happens to the pretrained part?</th><th>What learns for the target task?</th><th>Concrete example</th></tr></thead><tbody><tr><td>Direct classifier</td><td>Keep the complete model and its existing output head. Run it on new inputs.</td><td>Nothing is updated during ordinary prediction.</td><td>A model already trained to classify cats and dogs labels new cat/dog photographs. It can do this because the required labels match its existing outputs.</td></tr><tr><td>Standalone feature extractor</td><td>Run images through the fixed backbone and save the resulting feature vectors. A feature vector is an ordered list of numbers describing the image.</td><td>Train a separate classifier using these saved vectors.</td><td>Extract one vector per product photograph, then train a classifier to distinguish acceptable, scratched and cracked products. The extractor stays unchanged.</td></tr><tr><td>Integrated feature extractor</td><td>Place the pretrained backbone inside the new network and freeze it. Add a new head. The backbone calculates features whenever the new model runs.</td><td>Train the new head while the backbone&#x27;s weights remain fixed.</td><td>Use a frozen image backbone followed by a new three-output head for acceptable, scratched and cracked products. The complete image-to-class pipeline is one model.</td></tr><tr><td>Weight initialization followed by fine-tuning</td><td>Start from the pretrained weights, then allow selected pretrained layers to update. Replace or adapt the head as required.</td><td>Train the new head and the unfrozen part of the backbone.</td><td>After first training a product-defect head, unfreeze the last backbone block and train it with a smaller learning rate to adapt to the factory&#x27;s photographs.</td></tr></tbody></table></div>","<h3>Why the existing class labels matter</h3>","<p>A cat/dog head has two outputs with learned meanings: cat and dog. Giving it a photograph of a scratched product does not create a new output called “scratched.” For the product task, use an appropriate new head and train it on labeled product examples. Direct reuse of the original classifier is suitable only when its output meanings and preprocessing match the required task. When the task and data distribution are unchanged, this is ordinary inference rather than adaptation to a new task.</p>","<h3>Standalone versus integrated features</h3>","<p>Both methods can keep the backbone frozen. In the standalone method, feature vectors are calculated first and saved as a separate dataset; a later classifier reads that dataset. In the integrated method, each image passes through the backbone and head within one pipeline. Freezing means that the backbone parameters receive no training updates; it does not mean that the backbone stops performing calculations or that its stored weights disappear.</p>","<h3>When transfer learning is useful</h3>","<p>It is useful when labeled target data are limited and a pretrained model has learned representations relevant to the target task. It can reduce training time and the amount of target data needed. Improvement is not guaranteed: unrelated source features, unsuitable preprocessing or excessive fine-tuning on a small dataset can hurt performance. Choose the frozen or fine-tuned configuration using validation data, then evaluate the chosen model on the held-out test set.</p>","<p><strong>Exam answer structure:</strong> define transfer learning → identify the backbone and head → explain the selected reuse mode → state which weights remain fixed and which learn → give a matching example and a limitation.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c8-s18","search":"Four ways to reuse a pretrained model \n**Definition.** A pretrained model has already learned parameters from an earlier training task. We can reuse its complete classifier, reuse its feature extractor, or use its learned weights as the starting point for further training. The choice determines which output labels are available and which parameters change.\n\n**First identify two parts.** The **backbone** converts an input image into useful features. The **head** converts those features into the required prediction, such as class scores. A new task can reuse the backbone while replacing the head.\n\n**Yaad rakhne ka cue:** Purane model ka poora answer use karna, sirf features lena, ya uske weights ko aage train karna—yeh teen decisions alag hain.\n\nThe faculty reference divides these choices into the following four uses. The two feature-extractor uses differ in whether features are saved separately or computed inside the new model.\n\n| Use | What happens to the pretrained part? | What learns for the target task? | Concrete example |\n| Direct classifier | Keep the complete model and its existing output head. Run it on new inputs. | Nothing is updated during ordinary prediction. | A model already trained to classify cats and dogs labels new cat/dog photographs. It can do this because the required labels match its existing outputs. |\n| Standalone feature extractor | Run images through the fixed backbone and save the resulting feature vectors. A feature vector is an ordered list of numbers describing the image. | Train a separate classifier using these saved vectors. | Extract one vector per product photograph, then train a classifier to distinguish acceptable, scratched and cracked products. The extractor stays unchanged. |\n| Integrated feature extractor | Place the pretrained backbone inside the new network and freeze it. Add a new head. The backbone calculates features whenever the new model runs. | Train the new head while the backbone's weights remain fixed. | Use a frozen image backbone followed by a new three-output head for acceptable, scratched and cracked products. The complete image-to-class pipeline is one model. |\n| Weight initialization followed by fine-tuning | Start from the pretrained weights, then allow selected pretrained layers to update. Replace or adapt the head as required. | Train the new head and the unfrozen part of the backbone. | After first training a product-defect head, unfreeze the last backbone block and train it with a smaller learning rate to adapt to the factory's photographs. |\n\n### Why the existing class labels matter\n\nA cat/dog head has two outputs with learned meanings: cat and dog. Giving it a photograph of a scratched product does not create a new output called “scratched.” For the product task, use an appropriate new head and train it on labeled product examples. Direct reuse of the original classifier is suitable only when its output meanings and preprocessing match the required task. When the task and data distribution are unchanged, this is ordinary inference rather than adaptation to a new task.\n\n### Standalone versus integrated features\n\nBoth methods can keep the backbone frozen. In the standalone method, feature vectors are calculated first and saved as a separate dataset; a later classifier reads that dataset. In the integrated method, each image passes through the backbone and head within one pipeline. Freezing means that the backbone parameters receive no training updates; it does not mean that "}]},{"n":9,"title":"Recurrent neural networks","sections":[{"title":"Complete the entire sequence chapter","blocks":["<p>All sections in this chapter belong to the TEE preparation route. Learn vanilla RNNs first, then the shared-gradient calculation, then LSTM and GRU. Do not skip the gates or BPTT because the MT2 route ends earlier.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_comparison.svg\" aria-label=\"Enlarge diagram: Begin with the vanilla state, then learn why the gated variants carry and update memory differently.\"><img src=\"assets/figures/v_rnn_comparison.svg\" alt=\"Begin with the vanilla state, then learn why the gated variants carry and update memory differently.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Begin with the vanilla state, then learn why the gated variants carry and update memory differently. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s0","search":"Complete the entire sequence chapter All sections in this chapter belong to the TEE preparation route. Learn vanilla RNNs first, then the shared-gradient calculation, then LSTM and GRU. Do not skip the gates or BPTT because the MT2 route ends earlier.\n\n\n"},{"title":"What makes a sequence different","blocks":["<p class=\"definition\"><strong>Definition.</strong> A recurrent neural network (RNN) is a neural architecture that models sequential data by updating a hidden state from the current input and the previous state, using shared parameters across time steps.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c5a9455cdb766031.svg\" alt=\"h_t=\\phi(W_{xh}x_t+W_{hh}h_{t-1}+b_h)\" width=\"327.28\" height=\"24.43\" style=\"width:327.28px;height:24.43px;aspect-ratio:327.28/24.43\" loading=\"lazy\"></div>","<p>The state hₜ is a learned representation of information available up to time t. It is not a guaranteed lossless record of the entire sequence. The initial state is supplied, initialized to zero or learned, according to the model or question.</p>","<h3>Why order matters</h3>","<p>In language, audio and time series, the meaning of an observation can depend on earlier observations and their order. A basic feedforward network treating each input independently has no recurrent state. An RNN allows the output at a time step to depend on previous processing through hₜ₋₁.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Unrolling shows successive evaluations of one recurrent cell with shared parameters.\"><img src=\"assets/figures/rnn.svg\" alt=\"Unrolling shows successive evaluations of one recurrent cell with shared parameters.\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Unrolling shows successive evaluations of one recurrent cell with shared parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Parameter sharing</h3>","<p>The unrolled cells use the same Wₓₕ, Wₕₕ and bₕ at every time step. A longer input sequence increases the number of evaluations, not the number of independently learned copies of these parameters. Each new hidden state must be calculated before it is used by the next step.</p>","<h3>MT2 interpretation</h3>","<p>For TEE, study the state equation, time-step computation, shared parameters and sequence-to-output configurations, then BPTT, vanishing/exploding gradients, LSTM and GRU. All are part of Unit 5. The faculty update received on 12 October focuses MT2 on Units 3 and 4; this complete recurrent-network chapter is TEE preparation.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s1","search":"What makes a sequence different **Definition.** A recurrent neural network (RNN) is a neural architecture that models sequential data by updating a hidden state from the current input and the previous state, using shared parameters across time steps.\n\nThe state hₜ is a learned representation of information available up to time t. It is not a guaranteed lossless record of the entire sequence. The initial state is supplied, initialized to zero or learned, according to the model or question.\n\n### Why order matters\nIn language, audio and time series, the meaning of an observation can depend on earlier observations and their order. A basic feedforward network treating each input independently has no recurrent state. An RNN allows the output at a time step to depend on previous processing through hₜ₋₁.\n\n\n\n### Parameter sharing\nThe unrolled cells use the same Wₓₕ, Wₕₕ and bₕ at every time step. A longer input sequence increases the number of evaluations, not the number of independently learned copies of these parameters. Each new hidden state must be calculated before it is used by the next step.\n\n### MT2 interpretation\nFor TEE, study the state equation, time-step computation, shared parameters and sequence-to-output configurations, then BPTT, vanishing/exploding gradients, LSTM and GRU. All are part of Unit 5. The faculty update received on 12 October focuses MT2 on Units 3 and 4; this complete recurrent-network chapter is TEE preparation.\n"},{"title":"Model answer: why recurrent networks use a hidden state","question":["<p class=\"inline-question\"><strong>Question.</strong> What is a recurrent neural network? Explain how a hidden state allows it to process a sequence and distinguish it from a feedforward network.</p>"],"answer":["<p>An RNN processes ordered inputs using a hidden state that is carried from one time step to the next. The current state combines information from the new input with information retained from earlier inputs. The same recurrent weights are reused across time steps.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_state.svg\" aria-label=\"Enlarge diagram: The previous hidden state brings earlier information into the current calculation alongside the new input.\"><img src=\"assets/figures/v_rnn_state.svg\" alt=\"The previous hidden state brings earlier information into the current calculation alongside the new input.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>The previous hidden state brings earlier information into the current calculation alongside the new input. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For a simple tanh RNN:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/015d839835ad8254.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h)\" width=\"361.62\" height=\"24.43\" style=\"width:361.62px;height:24.43px;aspect-ratio:361.62/24.43\" loading=\"lazy\"></div>","<div class=\"table-scroll\"><table><thead><tr><th>Symbol</th><th>Meaning</th></tr></thead><tbody><tr><td>xₜ</td><td>Input at the current time step</td></tr><tr><td>hₜ₋₁</td><td>Hidden state passed from the previous step</td></tr><tr><td>Wxh</td><td>Weights connecting the current input to the hidden state</td></tr><tr><td>Whh</td><td>Weights connecting the previous state to the current state</td></tr><tr><td>bₕ</td><td>Hidden-state bias</td></tr><tr><td>hₜ</td><td>New state after the activation</td></tr></tbody></table></div>","<p>For words in a sentence, earlier words affect the state used when the next word arrives. Changing the order can therefore change the final representation. The state is a learned summary; it is not a guaranteed exact copy of every earlier input.</p>","<p>A feedforward network maps inputs through its layers without this recurrent state transition. An RNN can accept a sequence, reuse its parameters at each step and produce either an output at each step or an output from a final state, depending on the task. Examples include sentiment classification, next-word prediction and time-series modeling.</p>","<p>Unrolling an RNN draws its repeated use at t = 1, 2, 3 and so on. Those boxes share parameters; drawing three time steps does not create three independently learned copies of Whh.</p>"],"kind":"theory","id":"tee-c9-s2","search":"Model answer: why recurrent networks use a hidden state **Question.** What is a recurrent neural network? Explain how a hidden state allows it to process a sequence and distinguish it from a feedforward network.\n\n**Model answer.**\nAn RNN processes ordered inputs using a hidden state that is carried from one time step to the next. The current state combines information from the new input with information retained from earlier inputs. The same recurrent weights are reused across time steps.\n\n\n\n\nFor a simple tanh RNN:\n\n| Symbol | Meaning |\n| xₜ | Input at the current time step |\n| hₜ₋₁ | Hidden state passed from the previous step |\n| Wxh | Weights connecting the current input to the hidden state |\n| Whh | Weights connecting the previous state to the current state |\n| bₕ | Hidden-state bias |\n| hₜ | New state after the activation |\n\nFor words in a sentence, earlier words affect the state used when the next word arrives. Changing the order can therefore change the final representation. The state is a learned summary; it is not a guaranteed exact copy of every earlier input.\n\nA feedforward network maps inputs through its layers without this recurrent state transition. An RNN can accept a sequence, reuse its parameters at each step and produce either an output at each step or an output from a final state, depending on the task. Examples include sentiment classification, next-word prediction and time-series modeling.\n\nUnrolling an RNN draws its repeated use at t = 1, 2, 3 and so on. Those boxes share parameters; drawing three time steps does not create three independently learned copies of Whh.\n"},{"title":"Reading recurrent memory and gates","blocks":["<h3>Time means position in the sequence</h3>","<p>t = 1 is the first input; t = 2 is the second. The state h₀ is the starting memory, often given as zero. At each step the input changes and the state changes, while the learned weights are reused.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_gate.svg\" aria-label=\"Enlarge diagram: A gate is a multiplier. Its value controls how much of a particular contribution gets through.\"><img src=\"assets/figures/v_gate.svg\" alt=\"A gate is a multiplier. Its value controls how much of a particular contribution gets through.\" width=\"1080\" height=\"540\" loading=\"lazy\"></button><figcaption>A gate is a multiplier. Its value controls how much of a particular contribution gets through. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Raw score and activated state</h3>","<p>First multiply and add to form a raw score. Then apply tanh or the activation specified in the question. The activated result is the hidden state passed to the next time step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3fed90dc3ade6a15.svg\"><img class=\"math display-math\" src=\"assets/equations/3bf188b606a0ff69.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b_h,\\qquad h_t=\\tanh(a_t)\" width=\"496.31\" height=\"24.43\" style=\"width:496.31px;height:24.43px;aspect-ratio:496.31/24.43\" loading=\"lazy\"></picture></div>","<p>Wxh means the weight mapping input x to hidden state h. Whh maps the previous hidden state to the new hidden calculation. These labels describe a connection; they do not mean multiply the letters together.</p>","<h3>What a gate does</h3>","<p>A gate is a multiplier controlling how much of a value passes through. Gate 0 keeps none of that contribution; gate 1 keeps all; gate 0.25 keeps a quarter. For example, 0.25 × 8 = 2. Sigmoid-generated gates lie between 0 and 1 for finite raw scores.</p>","<h3>A gate is different from its raw score</h3>","<p>If a gate&#x27;s raw score is 0, sigmoid gives 1/(1 + 1) = 0.5. A supplied gate value 0, however, is already zero and must not be passed through sigmoid again. Read whether the question gives <strong>preactivations</strong> or <strong>gate outputs</strong>.</p>","<h3>Memory values can be negative</h3>","<p>The gate may be nonnegative while the value being gated is negative. Multiplying 0.2 by −0.5 gives −0.1. This is normal: the gate chooses an amount, and the candidate content supplies its sign.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s3","search":"Reading recurrent memory and gates ### Time means position in the sequence\nt = 1 is the first input; t = 2 is the second. The state h₀ is the starting memory, often given as zero. At each step the input changes and the state changes, while the learned weights are reused.\n\n\n\n### Raw score and activated state\nFirst multiply and add to form a raw score. Then apply tanh or the activation specified in the question. The activated result is the hidden state passed to the next time step.\n\nWxh means the weight mapping input x to hidden state h. Whh maps the previous hidden state to the new hidden calculation. These labels describe a connection; they do not mean multiply the letters together.\n### What a gate does\nA gate is a multiplier controlling how much of a value passes through. Gate 0 keeps none of that contribution; gate 1 keeps all; gate 0.25 keeps a quarter. For example, 0.25 × 8 = 2. Sigmoid-generated gates lie between 0 and 1 for finite raw scores.\n### A gate is different from its raw score\nIf a gate's raw score is 0, sigmoid gives 1/(1 + 1) = 0.5. A supplied gate value 0, however, is already zero and must not be passed through sigmoid again. Read whether the question gives **preactivations** or **gate outputs**.\n### Memory values can be negative\nThe gate may be nonnegative while the value being gated is negative. Multiplying 0.2 by −0.5 gives −0.1. This is normal: the gate chooses an amount, and the candidate content supplies its sign.\n"},{"title":"The vanilla RNN equations from scratch","blocks":["<p class=\"definition\"><strong>Definition.</strong> A vanilla recurrent neural network updates a hidden state from the current sequence input and the previous hidden state, using the same trainable parameters at every time step. An output transformation converts that state into the task&#x27;s prediction.</p>","<h3>Hidden-state and output equations</h3>","<p>For a tanh recurrent layer:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.24px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99a78e2772b9da6e.svg\"><img class=\"math display-math\" src=\"assets/equations/16c56e35b4a96bc6.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b_h\" width=\"292.57\" height=\"22.04\" style=\"width:292.57px;height:22.04px;aspect-ratio:292.57/22.04\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p>aₜ is the preactivation and hₜ is the activated hidden state. Wₓₕ transforms the new input; Wₕₕ transforms the previous state. Both contributions have the same hidden dimension before they are added. bₕ has one component per hidden unit.</p>","<p>For classification at time t, an output layer can produce logits and probabilities:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.07px;--narrow-height:64.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f6b889b0139771ed.svg\"><img class=\"math display-math\" src=\"assets/equations/41eb927502818778.svg\" alt=\"z_t=W_{hy}h_t+b_y,\\qquad p_t=\\operatorname{softmax}(z_t)\" width=\"404.72\" height=\"25.53\" style=\"width:404.72px;height:25.53px;aspect-ratio:404.72/25.53\" loading=\"lazy\"></picture></div>","<p>A regression output may instead be linear. A question asking only for hidden states does not require an output-layer prediction, and such a prediction cannot be calculated without the output transformation.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_state.svg\" aria-label=\"Enlarge diagram: The current input and previous activated state enter different weight transformations. Their sum is activated to obtain the next state.\"><img src=\"assets/figures/v_rnn_state.svg\" alt=\"The current input and previous activated state enter different weight transformations. Their sum is activated to obtain the next state.\" width=\"1080\" height=\"570\" loading=\"lazy\"></button><figcaption>The current input and previous activated state enter different weight transformations. Their sum is activated to obtain the next state. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical: two recurrent time steps</h3>","<p class=\"inline-question\"><strong>Question.</strong> Let h₀ = 0, Wₓₕ = 0.5, Wₕₕ = 0.2, bₕ = 0, x₁ = 1 and x₂ = 2. Calculate h₁ and h₂ using tanh activation.</p>","<h3>Given</h3>","<p>h₀ = 0; Wxh = 0.5; Whh = 0.2; b = 0.</p>","<p>x₁ = 1; x₂ = 2; activation = tanh.</p>","<h3>To find</h3>","<p>Find h₁ and h₂ in order.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: Time step 1 — calculate the preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.04px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a11d26405f8ffbf6.svg\"><img class=\"math display-math\" src=\"assets/equations/6d7c2d3322af892b.svg\" alt=\"a_1=0.5(1)+0.2(0)+0=0.5\" width=\"316.85\" height=\"24.43\" style=\"width:316.85px;height:24.43px;aspect-ratio:316.85/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Apply the recurrent activation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc76aa14d3af5acb.svg\"><img class=\"math display-math\" src=\"assets/equations/7c336c24f0f94322.svg\" alt=\"h_1=\\tanh(0.5)\\approx0.462117157\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<p>This activated value, not a₁ = 0.5, is passed to the next time step.</p>","<p class=\"worked-step\"><strong>Step 2: Time step 2 — combine the new input and previous state.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a530e8ec85bf260b.svg\" alt=\"a_2=0.5(2)+0.2h_1+0\" width=\"246.55\" height=\"24.43\" style=\"width:246.55px;height:24.43px;aspect-ratio:246.55/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/67ad1cca6bc26681.svg\"><img class=\"math display-math\" src=\"assets/equations/45ba45a94914183c.svg\" alt=\"a_2\\approx1+0.2(0.462117157)\\approx1.092423431\" width=\"439.02\" height=\"24.43\" style=\"width:439.02px;height:24.43px;aspect-ratio:439.02/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Apply tanh to the complete new preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/47f73b96c961ac1f.svg\"><img class=\"math display-math\" src=\"assets/equations/7c7eb453d84ea5ea.svg\" alt=\"h_2=\\tanh(a_2)\\approx0.797760954\" width=\"310.37\" height=\"24.43\" style=\"width:310.37px;height:24.43px;aspect-ratio:310.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Time step</th><th>Current input</th><th>Previous state</th><th>Preactivation</th><th>New state</th></tr></thead><tbody><tr><td>1</td><td>1</td><td>0</td><td>0.5</td><td>0.462117157</td></tr><tr><td>2</td><td>2</td><td>0.462117157</td><td>1.092423431</td><td>0.797760954</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> h₁ ≈ 0.462117 and h₂ ≈ 0.797761. Keep the full calculator value of h₁ while computing the second step. Although a₂ is greater than 1, h₂ is between −1 and 1 because tanh is applied after the affine sum. Both time steps use the same weights; this calculation contains no parameter update.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s4","search":"The vanilla RNN equations from scratch \n**Definition.** A vanilla recurrent neural network updates a hidden state from the current sequence input and the previous hidden state, using the same trainable parameters at every time step. An output transformation converts that state into the task's prediction.\n\n### Hidden-state and output equations\nFor a tanh recurrent layer:\n\n\naₜ is the preactivation and hₜ is the activated hidden state. Wₓₕ transforms the new input; Wₕₕ transforms the previous state. Both contributions have the same hidden dimension before they are added. bₕ has one component per hidden unit.\n\nFor classification at time t, an output layer can produce logits and probabilities:\n\nA regression output may instead be linear. A question asking only for hidden states does not require an output-layer prediction, and such a prediction cannot be calculated without the output transformation.\n\n\n\n### Complete numerical: two recurrent time steps\n**Question.** Let h₀ = 0, Wₓₕ = 0.5, Wₕₕ = 0.2, bₕ = 0, x₁ = 1 and x₂ = 2. Calculate h₁ and h₂ using tanh activation.\n\n\n\n### Given\n\nh₀ = 0; Wxh = 0.5; Whh = 0.2; b = 0.\n\nx₁ = 1; x₂ = 2; activation = tanh.\n\n### To find\n\nFind h₁ and h₂ in order.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: Time step 1 — calculate the preactivation.**\n\n**Apply the recurrent activation.**\n\nThis activated value, not a₁ = 0.5, is passed to the next time step.\n\n**Step 2: Time step 2 — combine the new input and previous state.**\n\n\n**Apply tanh to the complete new preactivation.**\n\n\n| Time step | Current input | Previous state | Preactivation | New state |\n| 1 | 1 | 0 | 0.5 | 0.462117157 |\n| 2 | 2 | 0.462117157 | 1.092423431 | 0.797760954 |\n\n**Final answer:** h₁ ≈ 0.462117 and h₂ ≈ 0.797761. Keep the full calculator value of h₁ while computing the second step. Although a₂ is greater than 1, h₂ is between −1 and 1 because tanh is applied after the affine sum. Both time steps use the same weights; this calculation contains no parameter update.\n\n"},{"title":"A complete vector RNN calculation","blocks":["<p class=\"inline-question\"><strong>Question from R26 Q5a.</strong> xₜ = [0,1], hₜ₋₁ = [0,1], no bias is supplied, Wxh is shown below, Whh is shown below. Use tanh and rows as receiving neurons.</p>","<h3>Given</h3>","<p>Input x = [0,1]ᵀ; previous h = [0,1]ᵀ.</p>","<p>Wxh = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4f3aa9485d9c39f6.svg\" alt=\"\\begin{bmatrix}0.6 &amp; 0.4\\\\0.3 &amp; 0.7\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>.</p>","<p>Whh = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/339cb87bfb0225e4.svg\" alt=\"\\begin{bmatrix}0.5 &amp; 0.3\\\\0.2 &amp; 0.4\\end{bmatrix}\" width=\"87.65\" height=\"45.61\" style=\"width:87.65px;height:45.61px;aspect-ratio:87.65/45.61\" loading=\"lazy\"></span>; bias = 0.</p>","<p>Apply tanh separately to the two sums.</p>","<h3>To find</h3>","<p>Find the new two-component hidden state; output-layer parameters are not supplied.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_deac39f14c.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_deac39f14c.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 new input: </strong> Wxh x = [0.6 × 0 + 0.4 × 1, 0.3 × 0 + 0.7 × 1] = [0.4,0.7].</p>","<p class=\"worked-step\"><strong>Step 2 old memory: </strong> Whh hprevious = [0.5 × 0 + 0.3 × 1, 0.2 × 0 + 0.4 × 1] = [0.3,0.4].</p>","<p class=\"worked-step\"><strong>Step 3 add: </strong> a = [0.4+0.3, 0.7+0.4] = [0.7,1.1].</p>","<p class=\"worked-step\"><strong>Step 4 activate each element: </strong> h = [tanh(0.7), tanh(1.1)] = <strong>[0.604368,0.800499]</strong>. An output-layer prediction cannot be numerically calculated without its weights and bias.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s5","search":"A complete vector RNN calculation **Question from R26 Q5a.** xₜ = [0,1], hₜ₋₁ = [0,1], no bias is supplied, Wxh is shown below, Whh is shown below. Use tanh and rows as receiving neurons.\n\n\n\n### Given\n\nInput x = [0,1]ᵀ; previous h = [0,1]ᵀ.\n\nWxh = .\n\nWhh = ; bias = 0.\n\nApply tanh separately to the two sums.\n\n### To find\n\nFind the new two-component hidden state; output-layer parameters are not supplied.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1 new input: ** Wxh x = [0.6 × 0 + 0.4 × 1, 0.3 × 0 + 0.7 × 1] = [0.4,0.7].\n**Step 2 old memory: ** Whh hprevious = [0.5 × 0 + 0.3 × 1, 0.2 × 0 + 0.4 × 1] = [0.3,0.4].\n**Step 3 add: ** a = [0.4+0.3, 0.7+0.4] = [0.7,1.1].\n**Step 4 activate each element: ** h = [tanh(0.7), tanh(1.1)] = **[0.604368,0.800499]**. An output-layer prediction cannot be numerically calculated without its weights and bias."},{"title":"How an RNN is trained","blocks":["<p class=\"definition\"><strong>Definition.</strong> Backpropagation through time (BPTT) differentiates the loss of an RNN by applying backpropagation to its temporally unrolled computational graph and summing contributions to shared parameters.</p>","<h3>Explanation and working</h3>","<p>Unroll the recurrent network for the sequence length. Run the forward calculation in time order. Calculate the specified loss. Differentiate backwards through the unrolled graph. Add contributions to each shared weight from every time it was used. Update each shared weight once for the selected sequence or batch. This is backpropagation through time, or BPTT.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bptt.svg\" aria-label=\"Enlarge diagram: Unroll forward through time, then accumulate backward contributions for the shared parameters.\"><img src=\"assets/figures/v_bptt.svg\" alt=\"Unroll forward through time, then accumulate backward contributions for the shared parameters.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>Unroll forward through time, then accumulate backward contributions for the shared parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For tanh, let δₜ mean the gradient with respect to the hidden preactivation. The following form allows losses at several time steps; a missing output loss contributes zero.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05416576e2064832.svg\" alt=\"\\delta_t=\\left(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1}\\right)\\odot(1-h_t^2)\" width=\"386.74\" height=\"31.63\" style=\"width:386.74px;height:31.63px;aspect-ratio:386.74/31.63\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.84px;--narrow-height:216.86px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b44f91dfbf3ef75.svg\"><img class=\"math display-math\" src=\"assets/equations/dc28790fa408d967.svg\" alt=\"\\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T},\\quad \\frac{\\partial L}{\\partial W_{xh}}=\\sum_t\\delta_t x_t^{T},\\quad \\frac{\\partial L}{\\partial b_h}=\\sum_t\\delta_t\" width=\"602.48\" height=\"62.51\" style=\"width:602.48px;height:62.51px;aspect-ratio:602.48/62.51\" loading=\"lazy\"></picture></div>","<p>The symbol ⊙ means pairwise multiplication. The transpose T turns a column into a row. δnext carries the effect of future time steps. The summation is essential because these are shared parameters.</p>","<h3>One BPTT delta at h = 0.5</h3>","<p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, h_t = 0.5, current output-path derivative = 0.2, next-step delta = 0.3 and recurrent weight = 0.4. Find the current preactivation delta.</strong></p>","<h3>Given</h3>","<p>Activated h_t = 0.5; q_t = 0.2; δ_(t+1) = 0.3; recurrent weight u = 0.4.</p>","<h3>To find</h3>","<p>Current preactivation delta δ_t.</p>","<h3>Formula — which one and why</h3>","<p>Two paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.</p>","<p>q_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Future aur current dono add; tanh slope uske baad.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the future path contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bb48ef38d6d22273.svg\" alt=\"0.4(0.3)=0.12\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the current output contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fdbe3cda286c3c16.svg\" alt=\"0.2+0.12=0.32\" width=\"180.57\" height=\"18.27\" style=\"width:180.57px;height:18.27px;aspect-ratio:180.57/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the current tanh slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f60b4793b26f591.svg\" alt=\"1-(0.5)^2=0.75\" width=\"179.02\" height=\"27.70\" style=\"width:179.02px;height:27.70px;aspect-ratio:179.02/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: multiply by that slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e726c1bb32ed233e.svg\" alt=\"\\delta_t=(0.32)(0.75)=0.24\" width=\"252.63\" height=\"24.43\" style=\"width:252.63px;height:24.43px;aspect-ratio:252.63/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> δ_t = 0.24.</p>","<h3>One BPTT delta at h = -0.2</h3>","<p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, h_t = -0.2, current output-path derivative = 0.1, next-step delta = 0 and recurrent weight = 0.5. Find the current preactivation delta.</strong></p>","<h3>Given</h3>","<p>Activated h_t = -0.2; q_t = 0.1; δ_(t+1) = 0; recurrent weight u = 0.5.</p>","<h3>To find</h3>","<p>Current preactivation delta δ_t.</p>","<h3>Formula — which one and why</h3>","<p>Two paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.</p>","<p>q_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Future aur current dono add; tanh slope uske baad.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the future path contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ad7c98370e2604f.svg\" alt=\"0.5(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the current output contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d31df4938e5db9a.svg\" alt=\"0.1+0=0.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the current tanh slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb671dc68ac70d16.svg\" alt=\"1-(-0.2)^2=0.96\" width=\"198.03\" height=\"27.70\" style=\"width:198.03px;height:27.70px;aspect-ratio:198.03/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: multiply by that slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c494eb0b53453545.svg\" alt=\"\\delta_t=(0.1)(0.96)=0.096\" width=\"252.63\" height=\"24.43\" style=\"width:252.63px;height:24.43px;aspect-ratio:252.63/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> δ_t = 0.096.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s6","search":"How an RNN is trained **Definition.** Backpropagation through time (BPTT) differentiates the loss of an RNN by applying backpropagation to its temporally unrolled computational graph and summing contributions to shared parameters.\n\n### Explanation and working\nUnroll the recurrent network for the sequence length. Run the forward calculation in time order. Calculate the specified loss. Differentiate backwards through the unrolled graph. Add contributions to each shared weight from every time it was used. Update each shared weight once for the selected sequence or batch. This is backpropagation through time, or BPTT.\n\n\n\nFor tanh, let δₜ mean the gradient with respect to the hidden preactivation. The following form allows losses at several time steps; a missing output loss contributes zero.\n\n\nThe symbol ⊙ means pairwise multiplication. The transpose T turns a column into a row. δnext carries the effect of future time steps. The summation is essential because these are shared parameters.\n\n\n\n### One BPTT delta at h = 0.5\n\n**Question. In a scalar tanh RNN, h_t = 0.5, current output-path derivative = 0.2, next-step delta = 0.3 and recurrent weight = 0.4. Find the current preactivation delta.**\n\n\n\n### Given\n\nActivated h_t = 0.5; q_t = 0.2; δ_(t+1) = 0.3; recurrent weight u = 0.4.\n\n### To find\n\nCurrent preactivation delta δ_t.\n\n### Formula — which one and why\n\nTwo paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.\n\nq_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.\n\n\n\n**Yaad rakhne ka cue:** Future aur current dono add; tanh slope uske baad.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the future path contribution.**\n\n\n\n\n\n\n\n**Step 2: add the current output contribution.**\n\n\n\n\n\n\n\n**Step 3: calculate the current tanh slope.**\n\n\n\n\n\n\n\n**Step 4: multiply by that slope.**\n\n\n\n\n\n\n\n**Final answer:** δ_t = 0.24.\n\n\n\n### One BPTT delta at h = -0.2\n\n**Question. In a scalar tanh RNN, h_t = -0.2, current output-path derivative = 0.1, next-step delta = 0 and recurrent weight = 0.5. Find the current preactivation delta.**\n\n\n\n### Given\n\nActivated h_t = -0.2; q_t = 0.1; δ_(t+1) = 0; recurrent weight u = 0.5.\n\n### To find\n\nCurrent preactivation delta δ_t.\n\n### Formula — which one and why\n\nTwo paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.\n\nq_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.\n\n\n\n**Yaad rakhne ka cue:** Future aur current dono add; tanh slope uske baad.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the future path contribution.**\n\n\n\n\n\n\n\n**Step 2: add the current output contribution.**\n\n\n\n\n\n\n\n**Step 3: calculate the current tanh slope.**\n\n\n\n\n\n\n\n**Step 4: multiply by that slope.**\n\n\n\n\n\n\n\n**Final answer:** δ_t = 0.096.\n\n\n"},{"title":"BPTT with every arithmetic step visible","blocks":["<p class=\"inline-question\"><strong>Question.</strong> A scalar RNN uses the linear state equation hₜ = u xₜ + v hₜ₋₁ + b. Its prediction is ŷ = h₂ and its loss is L = ½(ŷ−1)². Given u = 0.2, v = 0.5, b = 0, h₀ = 0, x₁ = 1 and x₂ = 2, calculate the gradients of u, v and b using BPTT, then update them once using learning rate η = 0.1.</p>","<h3>Given</h3>","<p>hₜ = uxₜ+vhₜ₋₁+b; prediction = h₂.</p>","<p>u = 0.2; v = 0.5; b = 0; h₀ = 0; x₁ = 1; x₂ = 2.</p>","<p>Target = 1; half squared loss; η = 0.1.</p>","<h3>To find</h3>","<p>Find gradients for u,v,b and update each once.</p>","<h3>Formula — which one and why</h3>","<p><strong>Backpropagation through time.</strong> Unroll the recurrence, send the loss derivative backward through its links and add contributions for each shared parameter before updating it once.</p>","<p>For h_t=ux_t+vh_(t−1)+b with loss only at the last state: δ_t = loss derivative at that state. The linear recurrence has activation slope 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61b2086787d829b8.svg\" alt=\"\\delta_T=h_T-y\" width=\"127.73\" height=\"22.53\" style=\"width:127.73px;height:22.53px;aspect-ratio:127.73/22.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba589b262a27bc88.svg\" alt=\"\\delta_t=v\\delta_{t+1}\" width=\"104.75\" height=\"22.60\" style=\"width:104.75px;height:22.60px;aspect-ratio:104.75/22.60\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad879502d644f051.svg\" alt=\"g_u=\\sum_t\\delta_tx_t\" width=\"136.86\" height=\"51.74\" style=\"width:136.86px;height:51.74px;aspect-ratio:136.86/51.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3065785a32d83c15.svg\" alt=\"g_v=\\sum_t\\delta_th_{t-1}\" width=\"157.54\" height=\"51.74\" style=\"width:157.54px;height:51.74px;aspect-ratio:157.54/51.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc44b288566e90ca.svg\" alt=\"g_b=\\sum_t\\delta_t\" width=\"112.15\" height=\"51.74\" style=\"width:112.15px;height:51.74px;aspect-ratio:112.15/51.74\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Time ke har use ka gradient jodo; shared weight ko ek baar update karo.</p>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Model and dependency structure</h3>","<p>u is the input weight, v is the recurrent weight and b is the hidden bias. Each is shared by both time steps. The hidden activation is linear in this question, so its derivative is 1. There is a loss only at time step 2; time step 1 influences that loss through h₂.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bptt_worked.svg\" aria-label=\"Enlarge diagram: Follow the two shared-parameter state calculations forward, then sum the backward contributions from each use of u, v and b.\"><img src=\"assets/figures/v_bptt_worked.svg\" alt=\"Follow the two shared-parameter state calculations forward, then sum the backward contributions from each use of u, v and b.\" width=\"1080\" height=\"765\" loading=\"lazy\"></button><figcaption>Follow the two shared-parameter state calculations forward, then sum the backward contributions from each use of u, v and b. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Step 1: complete the forward pass</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9a1296eaa212dfb3.svg\" alt=\"h_1=ux_1+vh_0+b\" width=\"202.76\" height=\"21.01\" style=\"width:202.76px;height:21.01px;aspect-ratio:202.76/21.01\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.19px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81bb99ddeeaa7079.svg\"><img class=\"math display-math\" src=\"assets/equations/600933d472001379.svg\" alt=\"h_1=0.2(1)+0.5(0)+0=0.2\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aa5a122e6af7b01d.svg\" alt=\"h_2=ux_2+vh_1+b\" width=\"202.76\" height=\"20.63\" style=\"width:202.76px;height:20.63px;aspect-ratio:202.76/20.63\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca0b29f546ae57d0.svg\"><img class=\"math display-math\" src=\"assets/equations/16e9c43648c8dc50.svg\" alt=\"h_2=0.2(2)+0.5(0.2)+0=0.5\" width=\"337.01\" height=\"24.43\" style=\"width:337.01px;height:24.43px;aspect-ratio:337.01/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd42e4fe3cfc09.svg\" alt=\"L=\\frac12(0.5-1)^2=0.125\" width=\"263.43\" height=\"49.55\" style=\"width:263.43px;height:49.55px;aspect-ratio:263.43/49.55\" loading=\"lazy\"></div>","<h3>Step 2: differentiate the loss at the final step</h3>","<p>Because the output is h₂ and the state activation is linear:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44dd9c1e67b5f92d.svg\" alt=\"\\delta_2=\\frac{\\partial L}{\\partial h_2}=h_2-1=-0.5\" width=\"285.66\" height=\"54.41\" style=\"width:285.66px;height:54.41px;aspect-ratio:285.66/54.41\" loading=\"lazy\"></div>","<h3>Step 3: propagate the derivative to the earlier state</h3>","<p>The local derivative of h₂ with respect to h₁ is the recurrent weight v = 0.5. Applying the chain rule:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5911c2f4d8e13a0a.svg\" alt=\"\\delta_1=\\frac{\\partial L}{\\partial h_1}=\\frac{\\partial L}{\\partial h_2}\\frac{\\partial h_2}{\\partial h_1}\" width=\"234.65\" height=\"54.41\" style=\"width:234.65px;height:54.41px;aspect-ratio:234.65/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.53px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/59ca9544049d91dc.svg\"><img class=\"math display-math\" src=\"assets/equations/f49beec63f88f3a8.svg\" alt=\"\\delta_1=\\delta_2v=(-0.5)(0.5)=-0.25\" width=\"334.57\" height=\"24.43\" style=\"width:334.57px;height:24.43px;aspect-ratio:334.57/24.43\" loading=\"lazy\"></picture></div>","<p>There is no separate direct loss at time step 1 to add here. Both deltas use the original recurrent weight.</p>","<h3>Step 4: sum the contributions to each shared parameter</h3>","<p>u appears in both h₁ and h₂, so its gradient receives one contribution from each use:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/94543a0839df0ed3.svg\" alt=\"\\frac{\\partial L}{\\partial u}=\\delta_1x_1+\\delta_2x_2\" width=\"196.00\" height=\"51.29\" style=\"width:196.00px;height:51.29px;aspect-ratio:196.00/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.39px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a96bfa656867b634.svg\"><img class=\"math display-math\" src=\"assets/equations/ef5c8122a0e849c2.svg\" alt=\"\\frac{\\partial L}{\\partial u}=(-0.25)(1)+(-0.5)(2)=-1.25\" width=\"411.88\" height=\"51.29\" style=\"width:411.88px;height:51.29px;aspect-ratio:411.88/51.29\" loading=\"lazy\"></picture></div>","<p>For v, the sending activation is the previous hidden state at the corresponding time:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f377c9f2aefec11.svg\" alt=\"\\frac{\\partial L}{\\partial v}=\\delta_1h_0+\\delta_2h_1\" width=\"196.19\" height=\"51.29\" style=\"width:196.19px;height:51.29px;aspect-ratio:196.19/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.18px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5d9bcac5813d6549.svg\"><img class=\"math display-math\" src=\"assets/equations/bd2ee36e0bc151c4.svg\" alt=\"\\frac{\\partial L}{\\partial v}=(-0.25)(0)+(-0.5)(0.2)=-0.1\" width=\"418.67\" height=\"51.29\" style=\"width:418.67px;height:51.29px;aspect-ratio:418.67/51.29\" loading=\"lazy\"></picture></div>","<p>The same additive bias is used at both steps. Its two local derivatives are 1:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.75px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc0231e316221e07.svg\"><img class=\"math display-math\" src=\"assets/equations/9f8bea284b02b5e1.svg\" alt=\"\\frac{\\partial L}{\\partial b}=\\delta_1+\\delta_2=-0.25-0.5=-0.75\" width=\"397.88\" height=\"51.29\" style=\"width:397.88px;height:51.29px;aspect-ratio:397.88/51.29\" loading=\"lazy\"></picture></div>","<div class=\"table-scroll\"><table><thead><tr><th>Shared parameter</th><th>Contribution at time 1</th><th>Contribution at time 2</th><th>Total gradient</th></tr></thead><tbody><tr><td>u</td><td>−0.25 × 1 = −0.25</td><td>−0.5 × 2 = −1</td><td>−1.25</td></tr><tr><td>v</td><td>−0.25 × 0 = 0</td><td>−0.5 × 0.2 = −0.1</td><td>−0.1</td></tr><tr><td>b</td><td>−0.25</td><td>−0.5</td><td>−0.75</td></tr></tbody></table></div>","<h3>Step 5: update each shared parameter once</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.13px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30e22de1103f6dec.svg\"><img class=\"math display-math\" src=\"assets/equations/7085a94b1a865ca8.svg\" alt=\"u_{\\mathrm{new}}=0.2-0.1(-1.25)=0.325\" width=\"340.37\" height=\"24.43\" style=\"width:340.37px;height:24.43px;aspect-ratio:340.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.78px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4822c14a12ff6b68.svg\"><img class=\"math display-math\" src=\"assets/equations/a9f8b51dd6b5c81d.svg\" alt=\"v_{\\mathrm{new}}=0.5-0.1(-0.1)=0.51\" width=\"313.82\" height=\"24.43\" style=\"width:313.82px;height:24.43px;aspect-ratio:313.82/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.63px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0fa40afe6a0cd296.svg\"><img class=\"math display-math\" src=\"assets/equations/cb22ad4d5122d6cb.svg\" alt=\"b_{\\mathrm{new}}=0-0.1(-0.75)=0.075\" width=\"317.88\" height=\"24.43\" style=\"width:317.88px;height:24.43px;aspect-ratio:317.88/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> gradients are −1.25, −0.1 and −0.75; updated parameters are u = 0.325, v = 0.51 and b = 0.075.</p>","<h3>Evaluate the updated model</h3>","<p>Restart from the same h₀ = 0 and use all updated parameters together:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.89px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/af9ceb62c0e1f59e.svg\"><img class=\"math display-math\" src=\"assets/equations/bac6924667182d4d.svg\" alt=\"h_{1,\\mathrm{new}}=0.325(1)+0.51(0)+0.075=0.4\" width=\"432.66\" height=\"25.35\" style=\"width:432.66px;height:25.35px;aspect-ratio:432.66/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.08px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cef917ae20dca74f.svg\"><img class=\"math display-math\" src=\"assets/equations/43f5d3f6c6303f7b.svg\" alt=\"h_{2,\\mathrm{new}}=0.325(2)+0.51(0.4)+0.075=0.929\" width=\"476.10\" height=\"25.35\" style=\"width:476.10px;height:25.35px;aspect-ratio:476.10/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.40px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8da79c9221b5024a.svg\"><img class=\"math display-math\" src=\"assets/equations/9b3580237637a521.svg\" alt=\"L_{\\mathrm{new}}=\\frac12(0.929-1)^2=0.0025205\" width=\"368.52\" height=\"49.55\" style=\"width:368.52px;height:49.55px;aspect-ratio:368.52/49.55\" loading=\"lazy\"></picture></div>","<p>The loss decreases in this particular update. That is consistent with the computed gradient, but a decrease is not guaranteed for every choice of learning rate.</p>","<h3>Extension to a tanh RNN</h3>","<p>For tanh, the derivative at each state transition also contains 1−hₜ². A trainable output layer contributes its own local derivatives. If losses occur at several time steps, add the direct output-loss contribution and the future-state contribution before applying the local activation derivative. Truncated BPTT limits the number of time steps traversed backward; it does not create separate copies of the recurrent parameters.</p>","<h3>Second worked example: nonlinear tanh BPTT</h3>","<p class=\"inline-question\"><strong>Question.</strong> A scalar RNN uses hₜ = tanh(uxₜ + vhₜ₋₁ + b). Given u = 0.4, v = 0.3, b = 0.1, h₀ = 0 and inputs x₁ = 1, x₂ = −1, its final output is h₂ and target is 0.2. Use only the final-time loss L = ½(h₂ − 0.2)². Calculate both states, all three shared-parameter gradients and one simultaneous update at η = 0.1.</p>","<h3>Given</h3>","<p>Shared input weight u = 0.4; shared recurrent weight v = 0.3; shared bias b = 0.1. Initial state h₀ = 0; x₁ = 1, x₂ = −1. Hidden activation = tanh; final target = 0.2; learning rate η = 0.1. There is no separate output layer and no loss at time 1.</p>","<h3>To find</h3>","<p>Forward states h₁ and h₂, final loss, gradients with respect to u, v and b, and all three updated parameters.</p>","<h3>Formula — which one and why</h3>","<p>Backpropagation must pass through each tanh derivative. Because u, v and b are shared, add their local contributions from both time steps before updating them.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f064c725161475e9.svg\" alt=\"z_t=ux_t+vh_{t-1}+b,\\qquad h_t=\\tanh(z_t)\" width=\"417.11\" height=\"24.43\" style=\"width:417.11px;height:24.43px;aspect-ratio:417.11/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b5081051ef8a38b.svg\" alt=\"\\delta_2=(h_2-y)(1-h_2^2),\\qquad \\delta_1=v\\delta_2(1-h_1^2)\" width=\"458.57\" height=\"27.70\" style=\"width:458.57px;height:27.70px;aspect-ratio:458.57/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/94543a0839df0ed3.svg\" alt=\"\\frac{\\partial L}{\\partial u}=\\delta_1x_1+\\delta_2x_2\" width=\"196.00\" height=\"51.29\" style=\"width:196.00px;height:51.29px;aspect-ratio:196.00/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.99px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e7070aed32f74b9a.svg\"><img class=\"math display-math\" src=\"assets/equations/9e07d1c7fc0741ba.svg\" alt=\"\\frac{\\partial L}{\\partial v}=\\delta_1h_0+\\delta_2h_1,\\qquad \\frac{\\partial L}{\\partial b}=\\delta_1+\\delta_2\" width=\"402.63\" height=\"51.29\" style=\"width:402.63px;height:51.29px;aspect-ratio:402.63/51.29\" loading=\"lazy\"></picture></div>","<p>Here δₜ means ∂L/∂zₜ, not ∂L/∂hₜ. The factor v in δ₁ is the <strong>old recurrent weight 0.3</strong>. The derivative of tanh is 1 − hₜ², using that step&#x27;s activated state.</p>","<h3>Solution — step by step</h3>","<h3>Step 1: calculate the first state</h3>","<p>z₁ = 0.4(1) + 0.3(0) + 0.1 = 0.5.</p>","<p>h₁ = tanh(0.5) = <strong>0.462117157</strong>.</p>","<h3>Step 2: carry that state into time 2</h3>","<p>z₂ = 0.4(−1) + 0.3(0.462117157) + 0.1 = <strong>−0.161364853</strong>.</p>","<p>h₂ = tanh(−0.161364853) = <strong>−0.159978716</strong>.</p>","<h3>Step 3: calculate the final loss and final-time delta</h3>","<p>Prediction error h₂ − y = −0.159978716 − 0.2 = <strong>−0.359978716</strong>.</p>","<p>L = ½(−0.359978716)² = <strong>0.064792338</strong>.</p>","<p>δ₂ = (−0.359978716)[1 − (−0.159978716)²] = <strong>−0.350765712</strong>.</p>","<h3>Step 4: backpropagate through the recurrent connection and first tanh</h3>","<p>There is no direct loss at time 1. Its gradient arrives entirely through time 2:</p>","<p>δ₁ = 0.3(−0.350765712)[1 − (0.462117157)²] = <strong>−0.082757670</strong>.</p>","<h3>Step 5: sum each shared parameter&#x27;s contributions over time</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Parameter</th><th>Time contributions</th><th>Total gradient</th></tr></thead><tbody><tr><td>u</td><td>(−0.082757670)(1) + (−0.350765712)(−1)</td><td>0.268008043</td></tr><tr><td>v</td><td>(−0.082757670)(0) + (−0.350765712)(0.462117157)</td><td>−0.162094854</td></tr><tr><td>b</td><td>−0.082757670 + (−0.350765712)</td><td>−0.433523382</td></tr></tbody></table></div>","<p>For v, the sending state is hₜ₋₁: h₀ for time 1, h₁ for time 2. The negative second input makes its contribution to the u gradient positive.</p>","<h3>Step 6: update all parameters using the same old forward pass</h3>","<p>u_new = 0.4 − 0.1(0.268008043) = <strong>0.373199196</strong>.</p>","<p>v_new = 0.3 − 0.1(−0.162094854) = <strong>0.316209485</strong>.</p>","<p>b_new = 0.1 − 0.1(−0.433523382) = <strong>0.143352338</strong>.</p>","<h3>Step 7: interpret the update with a fresh forward pass</h3>","<p>Using the new parameters from h₀ = 0 gives h₁,new = tanh(0.373199196 + 0.143352338) = <strong>0.475034096</strong>.</p>","<p>h₂,new = tanh(−0.373199196 + 0.316209485(0.475034096) + 0.143352338) = <strong>−0.079468645</strong>.</p>","<p>The new loss is ½(−0.079468645 − 0.2)² = <strong>0.039051362</strong>.</p>","<p><strong>Final answer:</strong> gradients (u,v,b) = <strong>(0.268008043, −0.162094854, −0.433523382)</strong> and updated parameters = <strong>(0.373199196, 0.316209485, 0.143352338)</strong>. This step moves the final prediction toward 0.2 and reduces loss from 0.064792338 to 0.039051362. Both time steps contributed to learning the same parameters.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s7","search":"BPTT with every arithmetic step visible **Question.** A scalar RNN uses the linear state equation hₜ = u xₜ + v hₜ₋₁ + b. Its prediction is ŷ = h₂ and its loss is L = ½(ŷ−1)². Given u = 0.2, v = 0.5, b = 0, h₀ = 0, x₁ = 1 and x₂ = 2, calculate the gradients of u, v and b using BPTT, then update them once using learning rate η = 0.1.\n\n\n\n### Given\n\nhₜ = uxₜ+vhₜ₋₁+b; prediction = h₂.\n\nu = 0.2; v = 0.5; b = 0; h₀ = 0; x₁ = 1; x₂ = 2.\n\nTarget = 1; half squared loss; η = 0.1.\n\n### To find\n\nFind gradients for u,v,b and update each once.\n\n### Formula — which one and why\n\n**Backpropagation through time.** Unroll the recurrence, send the loss derivative backward through its links and add contributions for each shared parameter before updating it once.\n\nFor h_t=ux_t+vh_(t−1)+b with loss only at the last state: δ_t = loss derivative at that state. The linear recurrence has activation slope 1.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Time ke har use ka gradient jodo; shared weight ko ek baar update karo.\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Model and dependency structure\nu is the input weight, v is the recurrent weight and b is the hidden bias. Each is shared by both time steps. The hidden activation is linear in this question, so its derivative is 1. There is a loss only at time step 2; time step 1 influences that loss through h₂.\n\n\n\n### Step 1: complete the forward pass\n\n\n\n\n\n\n### Step 2: differentiate the loss at the final step\nBecause the output is h₂ and the state activation is linear:\n\n\n### Step 3: propagate the derivative to the earlier state\nThe local derivative of h₂ with respect to h₁ is the recurrent weight v = 0.5. Applying the chain rule:\n\n\nThere is no separate direct loss at time step 1 to add here. Both deltas use the original recurrent weight.\n\n### Step 4: sum the contributions to each shared parameter\nu appears in both h₁ and h₂, so its gradient receives one contribution from each use:\n\n\nFor v, the sending activation is the previous hidden state at the corresponding time:\n\n\nThe same additive bias is used at both steps. Its two local derivatives are 1:\n\n\n| Shared parameter | Contribution at time 1 | Contribution at time 2 | Total gradient |\n| u | −0.25 × 1 = −0.25 | −0.5 × 2 = −1 | −1.25 |\n| v | −0.25 × 0 = 0 | −0.5 × 0.2 = −0.1 | −0.1 |\n| b | −0.25 | −0.5 | −0.75 |\n\n### Step 5: update each shared parameter once\n\n\n\n**Final answer:** gradients are −1.25, −0.1 and −0.75; updated parameters are u = 0.325, v = 0.51 and b = 0.075.\n\n### Evaluate the updated model\nRestart from the same h₀ = 0 and use all updated parameters together:\n\n\n\nThe loss decreases in this particular update. That is consistent with the computed gradient, but a decrease is not guaranteed for every choice of learning rate.\n\n### Extension to a tanh RNN\nFor tanh, the derivative at each state transition also contains 1−hₜ². A trainable output layer contributes its own local derivatives. If losses occur at several time steps, add the direct output-loss contribution and the future-state contribution before applying the local activation derivative. Truncated BPTT limits the numbe"},{"title":"Vanishing and exploding gradients","blocks":["<p class=\"definition\"><strong>Definition.</strong> Vanishing and exploding gradients describe the attenuation or amplification of backward derivatives through repeated Jacobian products. In recurrent networks, these products extend across time and affect long-range credit assignment.</p>","<h3>Explanation and working</h3>","<p>In BPTT, the gradient repeatedly multiplies recurrent weights and activation derivatives. Products of many small factors can approach zero; early information then receives very little learning signal. Large repeated factors can make the gradient explode. These are about training signals, not an instruction that every hidden-state value must become zero or infinity.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_vanishing.svg\" aria-label=\"Enlarge diagram: Follow the repeated products. Small factors can weaken the learning signal; large products can destabilize updates.\"><img src=\"assets/figures/v_vanishing.svg\" alt=\"Follow the repeated products. Small factors can weaken the learning signal; large products can destabilize updates.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow the repeated products. Small factors can weaken the learning signal; large products can destabilize updates. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Numerical intuition: </strong> 0.5¹⁰ = 0.0009765625, whereas 2¹⁰ = 1,024. Sigmoid&#x27;s derivative is at most 0.25 and becomes even smaller in saturation. Tanh also saturates for large magnitude inputs.</p>","<p>Useful remedies include LSTM or GRU gates and cell paths, suitable initialization and learning rate, and gradient clipping for explosion. Clipping does not by itself solve vanishing gradients. LSTM makes long-range learning easier; it does not guarantee perfect unlimited memory.</p>","<h3>Why the effect grows with sequence length</h3>","<p>For a vanilla tanh RNN, each hidden-state transition contributes a Jacobian. The derivative through several transitions contains a product of these Jacobians:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78674f482f3097e9.svg\" alt=\"\\frac{\\partial h_t}{\\partial h_{t-1}}=\\operatorname{diag}(1-h_t^2)W_{hh}\" width=\"277.24\" height=\"55.84\" style=\"width:277.24px;height:55.84px;aspect-ratio:277.24/55.84\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/382feba776054adf.svg\" alt=\"\\frac{\\partial h_T}{\\partial h_t}=\\prod_{k=T}^{t+1}\\frac{\\partial h_k}{\\partial h_{k-1}}\" width=\"195.88\" height=\"72.98\" style=\"width:195.88px;height:72.98px;aspect-ratio:195.88/72.98\" loading=\"lazy\"></div>","<p>The product is ordered from the latest transition toward the earliest. Small activation derivatives and recurrent transformations can attenuate the signal; repeated amplification can make it grow. A one-dimensional product illustrates the issue, but a vector RNN depends on the full matrix products, not one weight alone.</p>","<h3>Gradient norm clipping: a complete numerical</h3>","<p>Norm clipping rescales an oversized gradient while retaining its direction. It limits the update size caused by an exploding gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc3f87fdb9a197b4.svg\" alt=\"g_{\\mathrm{clipped}}=g\\min\\left(1,\\frac{\\tau}{\\lVert g\\rVert_2}\\right)\" width=\"277.13\" height=\"58.87\" style=\"width:277.13px;height:58.87px;aspect-ratio:277.13/58.87\" loading=\"lazy\"></div>","<p>If g is the zero vector, leave it unchanged. The threshold τ is positive. This is global norm clipping for the vector being considered; elementwise clipping is a different operation.</p>","<p class=\"inline-question\"><strong>Question. A gradient is g = [6, 8]ᵀ. Clip its Euclidean norm to at most τ = 5, then update w = [1, 1]ᵀ with learning rate η = 0.1.</strong></p>","<h3>Given</h3>","<p>Gradient g = [6,8]ᵀ; norm threshold τ = 5.</p>","<p>Old weights w = [1,1]ᵀ; η = 0.1.</p>","<h3>To find</h3>","<p>Find the clipped gradient and updated weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient norm clipping.</strong> If the vector norm exceeds the allowed threshold, multiply every component by the same scale. This changes magnitude while preserving direction.</p>","<p>g = gradient vector; τ (tau) = maximum norm; ||g||₂ = square root of the sum of squared components; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f0dbe784a7be0b2f.svg\" alt=\"\\lVert g\\rVert_2=\\sqrt{\\sum_i g_i^2}\" width=\"165.94\" height=\"60.11\" style=\"width:165.94px;height:60.11px;aspect-ratio:165.94/60.11\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbdee9367720972d.svg\" alt=\"g_{\\mathrm{clip}}=g\\min\\left(1,\\frac\\tau{\\lVert g\\rVert_2}\\right)\" width=\"250.25\" height=\"58.87\" style=\"width:250.25px;height:58.87px;aspect-ratio:250.25/58.87\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b334e0c9202e5b4.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_{\\mathrm{clip}}\" width=\"181.94\" height=\"21.27\" style=\"width:181.94px;height:21.27px;aspect-ratio:181.94/21.27\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bada gradient? Sab components ko ek hi factor se chhota karo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the original norm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.18px;--narrow-height:77.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5cf7611fc86c5694.svg\"><img class=\"math display-math\" src=\"assets/equations/92ed9c7434bcec37.svg\" alt=\"\\lVert g\\rVert_2=\\sqrt{6^2+8^2}=\\sqrt{36+64}=10\" width=\"369.09\" height=\"33.33\" style=\"width:369.09px;height:33.33px;aspect-ratio:369.09/33.33\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: find the scale.</strong> Since 10 &gt; 5, scale the vector by 5/10 = 0.5.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55639775a78bd93d.svg\" alt=\"g_{\\mathrm{clipped}}=0.5\\begin{bmatrix}6\\\\8\\end{bmatrix}=\\begin{bmatrix}3\\\\4\\end{bmatrix}\" width=\"243.96\" height=\"58.64\" style=\"width:243.96px;height:58.64px;aspect-ratio:243.96/58.64\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: verify the clipped norm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4cd7b08ae98b6682.svg\" alt=\"\\sqrt{3^2+4^2}=\\sqrt{9+16}=5\" width=\"265.31\" height=\"30.79\" style=\"width:265.31px;height:30.79px;aspect-ratio:265.31/30.79\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: update each parameter with the clipped gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/22080c63aaa74ec0.svg\" alt=\"w_{1,\\mathrm{new}}=1-0.1(3)=0.7\" width=\"263.65\" height=\"25.35\" style=\"width:263.65px;height:25.35px;aspect-ratio:263.65/25.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1268aa744d549860.svg\" alt=\"w_{2,\\mathrm{new}}=1-0.1(4)=0.6\" width=\"263.65\" height=\"25.35\" style=\"width:263.65px;height:25.35px;aspect-ratio:263.65/25.35\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> clipped gradient [3, 4]ᵀ and new weights [0.7, 0.6]ᵀ. Clipping does not increase a vanishing gradient and does not replace the need for an appropriate recurrent architecture.</p>","<h3>Gradient norm clipping: [3, 4]</h3>","<p class=\"inline-question\"><strong>Question. Clip gradient g = [3, 4] to maximum L2 norm 10. Use global norm clipping.</strong></p>","<h3>Given</h3>","<p>g = [3, 4]; threshold τ = 10.</p>","<h3>To find</h3>","<p>The norm, scaling factor and clipped gradient.</p>","<h3>Formula — which one and why</h3>","<p>Global norm clipping scales the entire list by one common factor only if its norm exceeds the threshold.</p>","<p>τ is the maximum permitted norm, not a per-entry bound.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c087afaaeb69ebf5.svg\" alt=\"\\|g\\|_2=\\sqrt{\\sum_i g_i^2}\" width=\"165.94\" height=\"60.11\" style=\"width:165.94px;height:60.11px;aspect-ratio:165.94/60.11\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbf72036323a5940.svg\" alt=\"g_{\\mathrm{clip}}=g\\min(1,\\tau/\\|g\\|_2)\" width=\"243.31\" height=\"25.35\" style=\"width:243.31px;height:25.35px;aspect-ratio:243.31/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Norm bada ho tab sab entries ko same ratio se chhota karo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the squared norm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9e1425dca608e703.svg\" alt=\"3^2+4^2=25\" width=\"132.66\" height=\"23.60\" style=\"width:132.66px;height:23.60px;aspect-ratio:132.66/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: take the square root.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31e01f04f62bf975.svg\" alt=\"\\|g\\|_2=\\sqrt{25}=5\" width=\"169.42\" height=\"30.48\" style=\"width:169.42px;height:30.48px;aspect-ratio:169.42/30.48\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: choose the shared scale.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93428ecf1a9721ce.svg\" alt=\"c=\\min(1,10/5)=1\" width=\"219.66\" height=\"24.43\" style=\"width:219.66px;height:24.43px;aspect-ratio:219.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: scale every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/af049506394d9137.svg\" alt=\"g_1^{\\mathrm{clip}}=3(1)=3\" width=\"161.40\" height=\"31.24\" style=\"width:161.40px;height:31.24px;aspect-ratio:161.40/31.24\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c36bcaa7f2c9e3b.svg\" alt=\"g_2^{\\mathrm{clip}}=4(1)=4\" width=\"161.40\" height=\"31.24\" style=\"width:161.40px;height:31.24px;aspect-ratio:161.40/31.24\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Clipped gradient = [3, 4].</p>","<h3>Gradient norm clipping: [0, 12]</h3>","<p class=\"inline-question\"><strong>Question. Clip gradient g = [0, 12] to maximum L2 norm 3. Use global norm clipping.</strong></p>","<h3>Given</h3>","<p>g = [0, 12]; threshold τ = 3.</p>","<h3>To find</h3>","<p>The norm, scaling factor and clipped gradient.</p>","<h3>Formula — which one and why</h3>","<p>Global norm clipping scales the entire list by one common factor only if its norm exceeds the threshold.</p>","<p>τ is the maximum permitted norm, not a per-entry bound.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c087afaaeb69ebf5.svg\" alt=\"\\|g\\|_2=\\sqrt{\\sum_i g_i^2}\" width=\"165.94\" height=\"60.11\" style=\"width:165.94px;height:60.11px;aspect-ratio:165.94/60.11\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbf72036323a5940.svg\" alt=\"g_{\\mathrm{clip}}=g\\min(1,\\tau/\\|g\\|_2)\" width=\"243.31\" height=\"25.35\" style=\"width:243.31px;height:25.35px;aspect-ratio:243.31/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Norm bada ho tab sab entries ko same ratio se chhota karo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the squared norm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d5fe5de098f7a47.svg\" alt=\"0^2+12^2=144\" width=\"157.09\" height=\"23.60\" style=\"width:157.09px;height:23.60px;aspect-ratio:157.09/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: take the square root.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/723310d10d7d6089.svg\" alt=\"\\|g\\|_2=\\sqrt{144}=12\" width=\"193.85\" height=\"30.88\" style=\"width:193.85px;height:30.88px;aspect-ratio:193.85/30.88\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: choose the shared scale.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/185f7122d90f817c.svg\" alt=\"c=\\min(1,3/12)=0.25\" width=\"250.88\" height=\"24.43\" style=\"width:250.88px;height:24.43px;aspect-ratio:250.88/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: scale every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d479ef7213e9c007.svg\" alt=\"g_1^{\\mathrm{clip}}=0(0.25)=0\" width=\"192.63\" height=\"31.24\" style=\"width:192.63px;height:31.24px;aspect-ratio:192.63/31.24\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/451a7aae4fe2ab76.svg\" alt=\"g_2^{\\mathrm{clip}}=12(0.25)=3\" width=\"204.84\" height=\"31.24\" style=\"width:204.84px;height:31.24px;aspect-ratio:204.84/31.24\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Clipped gradient = [0.0, 3.0].</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s8","search":"Vanishing and exploding gradients **Definition.** Vanishing and exploding gradients describe the attenuation or amplification of backward derivatives through repeated Jacobian products. In recurrent networks, these products extend across time and affect long-range credit assignment.\n\n### Explanation and working\nIn BPTT, the gradient repeatedly multiplies recurrent weights and activation derivatives. Products of many small factors can approach zero; early information then receives very little learning signal. Large repeated factors can make the gradient explode. These are about training signals, not an instruction that every hidden-state value must become zero or infinity.\n\n\n\n**Numerical intuition: ** 0.5¹⁰ = 0.0009765625, whereas 2¹⁰ = 1,024. Sigmoid's derivative is at most 0.25 and becomes even smaller in saturation. Tanh also saturates for large magnitude inputs.\nUseful remedies include LSTM or GRU gates and cell paths, suitable initialization and learning rate, and gradient clipping for explosion. Clipping does not by itself solve vanishing gradients. LSTM makes long-range learning easier; it does not guarantee perfect unlimited memory.\n\n### Why the effect grows with sequence length\nFor a vanilla tanh RNN, each hidden-state transition contributes a Jacobian. The derivative through several transitions contains a product of these Jacobians:\n\n\nThe product is ordered from the latest transition toward the earliest. Small activation derivatives and recurrent transformations can attenuate the signal; repeated amplification can make it grow. A one-dimensional product illustrates the issue, but a vector RNN depends on the full matrix products, not one weight alone.\n\n### Gradient norm clipping: a complete numerical\nNorm clipping rescales an oversized gradient while retaining its direction. It limits the update size caused by an exploding gradient.\n\nIf g is the zero vector, leave it unchanged. The threshold τ is positive. This is global norm clipping for the vector being considered; elementwise clipping is a different operation.\n\n**Question. A gradient is g = [6, 8]ᵀ. Clip its Euclidean norm to at most τ = 5, then update w = [1, 1]ᵀ with learning rate η = 0.1.**\n\n\n\n### Given\n\nGradient g = [6,8]ᵀ; norm threshold τ = 5.\n\nOld weights w = [1,1]ᵀ; η = 0.1.\n\n### To find\n\nFind the clipped gradient and updated weights.\n\n### Formula — which one and why\n\n**Gradient norm clipping.** If the vector norm exceeds the allowed threshold, multiply every component by the same scale. This changes magnitude while preserving direction.\n\ng = gradient vector; τ (tau) = maximum norm; ||g||₂ = square root of the sum of squared components; η = learning rate.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Bada gradient? Sab components ko ek hi factor se chhota karo.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: calculate the original norm.**\n\n\n**Step 2: find the scale.** Since 10 > 5, scale the vector by 5/10 = 0.5.\n\n\n**Step 3: verify the clipped norm.**\n\n\n**Step 4: update each parameter with the clipped gradient.**\n\n\n**Final answer:** clipped gradient [3, 4]ᵀ and new weights [0.7, 0.6]ᵀ. Clipping does not increase a vanishing gradient and does not replace the need for an appropriate recurrent architecture.\n\n### Gradient norm clipping: [3, 4]\n\n**Question. Clip gradient g = [3, 4] to maximum L2 norm 10. Use global norm clipping.**\n\n\n\n### Given\n\ng = [3, 4]; threshold τ = 10.\n\n### To find\n\nThe norm, scaling factor and clipped gradient.\n\n### Formula — which one and why\n\nGlobal norm clipping sc"},{"title":"Model answer: backpropagation through time","question":["<p class=\"inline-question\"><strong>Question.</strong> Explain backpropagation through time and the vanishing/exploding gradient problems in a recurrent neural network.</p>"],"answer":["<p>Backpropagation through time, or BPTT, applies backpropagation to an RNN unrolled across a sequence. The forward pass computes the state and any output at each time step. The backward pass follows how later losses depend on earlier states and shared parameters.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bptt.svg\" aria-label=\"Enlarge diagram: The drawn copies reuse one parameter set. Their backward contributions add into one gradient for each shared parameter.\"><img src=\"assets/figures/v_bptt.svg\" alt=\"The drawn copies reuse one parameter set. Their backward contributions add into one gradient for each shared parameter.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>The drawn copies reuse one parameter set. Their backward contributions add into one gradient for each shared parameter. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Working procedure</h3>","<p>1. Start from the supplied initial state and compute h₁, h₂ and all subsequent states in order.</p>","<p>2. Calculate the loss at the output positions specified by the task.</p>","<p>3. Propagate loss derivatives backward through the output computations and recurrent state transitions.</p>","<p>4. Add contributions from all time steps that use the same parameter.</p>","<p>5. Apply the optimizer update to the shared parameter after its gradient contributions have been accumulated.</p>","<h3>Why gradients can vanish or explode</h3>","<p>The chain rule repeatedly multiplies derivatives through time. A simple illustration is multiplying by 0.5 ten times, giving about 0.000977, versus multiplying by 2 ten times, giving 1,024. Real RNNs involve matrices and activation derivatives, so these scalars illustrate the mechanism rather than define a universal threshold.</p>","<p>Vanishing gradients make distant earlier inputs receive very weak learning signals. Exploding gradients can produce extremely large updates and unstable training. Gradient clipping limits gradient magnitude before an optimizer update and is useful for exploding gradients. It does not by itself restore already vanished information.</p>","<p>LSTM/GRU gating, suitable initialization and architecture choices can improve long-range learning. Truncated BPTT limits how far the backward computation runs for computational reasons; it does not mean that each unrolled box has independent parameters.</p>"],"kind":"theory","id":"tee-c9-s9","search":"Model answer: backpropagation through time **Question.** Explain backpropagation through time and the vanishing/exploding gradient problems in a recurrent neural network.\n\n**Model answer.**\nBackpropagation through time, or BPTT, applies backpropagation to an RNN unrolled across a sequence. The forward pass computes the state and any output at each time step. The backward pass follows how later losses depend on earlier states and shared parameters.\n\n\n\n\n### Working procedure\n1. Start from the supplied initial state and compute h₁, h₂ and all subsequent states in order.\n2. Calculate the loss at the output positions specified by the task.\n3. Propagate loss derivatives backward through the output computations and recurrent state transitions.\n4. Add contributions from all time steps that use the same parameter.\n5. Apply the optimizer update to the shared parameter after its gradient contributions have been accumulated.\n\n### Why gradients can vanish or explode\nThe chain rule repeatedly multiplies derivatives through time. A simple illustration is multiplying by 0.5 ten times, giving about 0.000977, versus multiplying by 2 ten times, giving 1,024. Real RNNs involve matrices and activation derivatives, so these scalars illustrate the mechanism rather than define a universal threshold.\n\nVanishing gradients make distant earlier inputs receive very weak learning signals. Exploding gradients can produce extremely large updates and unstable training. Gradient clipping limits gradient magnitude before an optimizer update and is useful for exploding gradients. It does not by itself restore already vanished information.\n\nLSTM/GRU gating, suitable initialization and architecture choices can improve long-range learning. Truncated BPTT limits how far the backward computation runs for computational reasons; it does not mean that each unrolled box has independent parameters.\n"},{"title":"LSTM a memory path with three gates","blocks":["<p class=\"definition\"><strong>Definition.</strong> Long short-term memory (LSTM) is a gated recurrent architecture with a cell state and hidden state. Forget, input and output gates regulate state retention, incorporation of candidate information and exposure of the updated cell.</p>","<h3>Explanation and working</h3>","<p>Long short-term memory, or LSTM, keeps a cell state Cₜ and a hidden state hₜ. A sigmoid gate produces values from 0 to 1: approximately 0 blocks a component, approximately 1 passes it. Intermediate values pass a fraction. Gates are learned from the previous hidden state and current input, not manually assigned by the user during normal inference.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: Follow the cell state from left to right then identify forget input and output gates\"><img src=\"assets/figures/lstm.svg\" alt=\"Follow the cell state from left to right then identify forget input and output gates\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>Follow the cell state from left to right then identify forget input and output gates <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c08c8ddc953628c6.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c)\" width=\"299.78\" height=\"31.40\" style=\"width:299.78px;height:31.40px;aspect-ratio:299.78/31.40\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8751dee634f91753.svg\" alt=\"C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"258.41\" height=\"30.37\" style=\"width:258.41px;height:30.37px;aspect-ratio:258.41/30.37\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/d1817c5fc6ff06c8.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\qquad h_t=o_t\\odot\\tanh(C_t)\" width=\"519.30\" height=\"24.43\" style=\"width:519.30px;height:24.43px;aspect-ratio:519.30/24.43\" loading=\"lazy\"></picture></div>","<p>The brackets [h, x] concatenate two vectors: [a, b] joined with [c, d] gives [a, b, c, d]. Concatenation is not addition. f is the forget gate: how much old cell content remains. i is the input gate: how much new candidate enters. The candidate is proposed content. o is the output gate: how much of the activated cell becomes visible as the hidden state.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s10","search":"LSTM a memory path with three gates **Definition.** Long short-term memory (LSTM) is a gated recurrent architecture with a cell state and hidden state. Forget, input and output gates regulate state retention, incorporation of candidate information and exposure of the updated cell.\n\n### Explanation and working\nLong short-term memory, or LSTM, keeps a cell state Cₜ and a hidden state hₜ. A sigmoid gate produces values from 0 to 1: approximately 0 blocks a component, approximately 1 passes it. Intermediate values pass a fraction. Gates are learned from the previous hidden state and current input, not manually assigned by the user during normal inference.\n\n\n\n\n\nThe brackets [h, x] concatenate two vectors: [a, b] joined with [c, d] gives [a, b, c, d]. Concatenation is not addition. f is the forget gate: how much old cell content remains. i is the input gate: how much new candidate enters. The candidate is proposed content. o is the output gate: how much of the activated cell becomes visible as the hidden state."},{"title":"Reading an LSTM equation one operation at a time","blocks":["<h3>1. Two memories on the page do not mean the same value</h3>","<p>The cell state c carries the recurrent cell memory. The hidden state h is an exposed output computed from that memory. An LSTM passes both to the next step. A question may give the previous cell and hidden states separately; do not substitute one for the other.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_lstm_split.svg\" aria-label=\"Enlarge diagram: Old and new contributions are calculated separately, added to form the cell, and only then transformed into the hidden output.\"><img src=\"assets/figures/v_lstm_split.svg\" alt=\"Old and new contributions are calculated separately, added to form the cell, and only then transformed into the hidden output.\" width=\"1080\" height=\"665\" loading=\"lazy\"></button><figcaption>Old and new contributions are calculated separately, added to form the cell, and only then transformed into the hidden output. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>2. Gate values are multipliers</h3>","<p>For a previous cell value of 0.8, a forget gate of 0.25 keeps 0.25 × 0.8 = 0.2. A gate of 0 keeps none of that contribution; a gate of 1 keeps the whole contribution. Intermediate sigmoid values give partial retention.</p>","<p>An input gate does the same kind of multiplication to the new candidate. If the candidate is −0.4 and the input gate is 0.5, the admitted new contribution is −0.2. The negative sign belongs to the candidate; sigmoid gates themselves are positive.</p>","<h3>3. Add old and new contributions</h3>","<p>With those values, the new cell is 0.2 + (−0.2) = 0. A retained positive contribution and an admitted negative contribution can cancel.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b17315e0dde1dde.svg\" alt=\"c_t=f_tc_{t-1}+i_t\\widetilde c_t\" width=\"178.01\" height=\"23.40\" style=\"width:178.01px;height:23.40px;aspect-ratio:178.01/23.40\" loading=\"lazy\"></div>","<p>This example also explains why “input gate” does not mean simply multiply the raw input x by i. It multiplies the candidate calculated for the cell update.</p>","<h3>4. Calculate the hidden state afterward</h3>","<p>Apply tanh to the updated cell and multiply by the output gate. If o = 0.7 and c = 0, tanh(0) = 0 and h = 0.7 × 0 = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88b1929e93128b1e.svg\" alt=\"h_t=o_t\\tanh(c_t)\" width=\"165.87\" height=\"24.43\" style=\"width:165.87px;height:24.43px;aspect-ratio:165.87/24.43\" loading=\"lazy\"></div>","<p>If c were 1 instead, tanh(1) ≈ 0.761594 and h ≈ 0.533116 for the same output gate. The output gate controls exposure of the transformed cell, not the earlier addition that produced c.</p>","<h3>5. Supplied gates and calculated gates are different numerical types</h3>","<p>When f, i and o are supplied, begin directly with their multiplications. When weights and inputs are supplied, first calculate each gate&#x27;s affine input, apply sigmoid and retain those gate values. Calculate the candidate using tanh. Only then update c and h. The separate solved examples below cover both types and multi-step repetition.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s11","search":"Reading an LSTM equation one operation at a time ### 1. Two memories on the page do not mean the same value\nThe cell state c carries the recurrent cell memory. The hidden state h is an exposed output computed from that memory. An LSTM passes both to the next step. A question may give the previous cell and hidden states separately; do not substitute one for the other.\n\n\n\n\n### 2. Gate values are multipliers\nFor a previous cell value of 0.8, a forget gate of 0.25 keeps 0.25 × 0.8 = 0.2. A gate of 0 keeps none of that contribution; a gate of 1 keeps the whole contribution. Intermediate sigmoid values give partial retention.\nAn input gate does the same kind of multiplication to the new candidate. If the candidate is −0.4 and the input gate is 0.5, the admitted new contribution is −0.2. The negative sign belongs to the candidate; sigmoid gates themselves are positive.\n\n### 3. Add old and new contributions\nWith those values, the new cell is 0.2 + (−0.2) = 0. A retained positive contribution and an admitted negative contribution can cancel.\n\nThis example also explains why “input gate” does not mean simply multiply the raw input x by i. It multiplies the candidate calculated for the cell update.\n\n### 4. Calculate the hidden state afterward\nApply tanh to the updated cell and multiply by the output gate. If o = 0.7 and c = 0, tanh(0) = 0 and h = 0.7 × 0 = 0.\n\nIf c were 1 instead, tanh(1) ≈ 0.761594 and h ≈ 0.533116 for the same output gate. The output gate controls exposure of the transformed cell, not the earlier addition that produced c.\n\n### 5. Supplied gates and calculated gates are different numerical types\nWhen f, i and o are supplied, begin directly with their multiplications. When weights and inputs are supplied, first calculate each gate's affine input, apply sigmoid and retain those gate values. Calculate the candidate using tanh. Only then update c and h. The separate solved examples below cover both types and multi-step repetition.\n"},{"title":"LSTM complete numerical with supplied gates","blocks":["<p class=\"inline-question\"><strong>Question.</strong> An LSTM cell has input gate iₜ = 0.7, forget gate fₜ = 0.4, output gate oₜ = 0.8, candidate cell content C̃ₜ = 0.9 and previous cell state Cₜ₋₁ = 0.5. Calculate the new cell state Cₜ and hidden state hₜ.</p>","<h3>Given</h3>","<p>Activated input gate i = 0.7; forget gate f = 0.4; output gate o = 0.8.</p>","<p>Candidate = 0.9; old cell = 0.5.</p>","<h3>To find</h3>","<p>Find the new cell C and hidden state h.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<h3>Equations and supplied-value convention</h3>","<p>The question supplies <strong>activated gate outputs</strong> and the candidate content. Do not apply sigmoid or tanh to those supplied values again. First update the cell, then calculate the hidden state:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5c31e372051573ef.svg\" alt=\"C_t=f_tC_{t-1}+i_t\\widetilde C_t\" width=\"198.68\" height=\"30.37\" style=\"width:198.68px;height:30.37px;aspect-ratio:198.68/30.37\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/694789d6807a2931.svg\" alt=\"h_t=o_t\\tanh(C_t)\" width=\"172.76\" height=\"24.43\" style=\"width:172.76px;height:24.43px;aspect-ratio:172.76/24.43\" loading=\"lazy\"></div>","<p>The first equation combines retained old content and admitted candidate content. The second equation is a separate transformation of the updated cell.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_lstm_given.svg\" aria-label=\"Enlarge diagram: The diagram uses the supplied gate values. The output gate is applied after the cell has been updated and passed through tanh.\"><img src=\"assets/figures/v_lstm_given.svg\" alt=\"The diagram uses the supplied gate values. The output gate is applied after the cell has been updated and passed through tanh.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The diagram uses the supplied gate values. The output gate is applied after the cell has been updated and passed through tanh. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1: calculate the retained old-cell contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8c446684892171e.svg\" alt=\"f_tC_{t-1}=0.4(0.5)=0.2\" width=\"245.92\" height=\"24.43\" style=\"width:245.92px;height:24.43px;aspect-ratio:245.92/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the admitted candidate contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83577513b17d4dfa.svg\" alt=\"i_t\\widetilde C_t=0.7(0.9)=0.63\" width=\"232.51\" height=\"31.40\" style=\"width:232.51px;height:31.40px;aspect-ratio:232.51/31.40\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two contributions to obtain the new cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f6bfe5d9884a48c2.svg\" alt=\"C_t=0.2+0.63=0.83\" width=\"238.90\" height=\"21.08\" style=\"width:238.90px;height:21.08px;aspect-ratio:238.90/21.08\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: activate the updated cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/01c5de218bff4e7f.svg\"><img class=\"math display-math\" src=\"assets/equations/7d47d77e77a829e1.svg\" alt=\"\\tanh(C_t)=\\tanh(0.83)\\approx0.680476006\" width=\"399.12\" height=\"24.43\" style=\"width:399.12px;height:24.43px;aspect-ratio:399.12/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: multiply by the output gate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cf4e11309aadd94a.svg\"><img class=\"math display-math\" src=\"assets/equations/e0a7ec476bae68f2.svg\" alt=\"h_t=0.8\\tanh(0.83)\\approx0.544380805\" width=\"363.12\" height=\"24.43\" style=\"width:363.12px;height:24.43px;aspect-ratio:363.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Cₜ = 0.83 and hₜ ≈ 0.544381. Multiplying the output gate directly by Cₜ would give 0.664 and omit the required tanh operation.</p>","<h3>Related vector calculation: retention alone</h3>","<p class=\"inline-question\"><strong>Question.</strong> Given forget gate f = [0.1, 0.9] and previous cell C = [2, 1], calculate the retained old-cell contribution.</p>","<h3>Given</h3>","<p>Forget gate = [0.1,0.9]; old cell = [2,1].</p>","<p>Input-gate and candidate values are not supplied.</p>","<h3>To find</h3>","<p>Find only the retained old-cell contribution.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM retained old memory.</strong> Multiply each old cell value by its corresponding forget-gate value. This gives only the old contribution, not the complete new cell.</p>","<p>f = activated forget gate; C_old = previous cell state; ⊙ means multiply matching entries.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35cedc4f6bc20c8a.svg\" alt=\"C_{\\mathrm{retained}}=f\\odot C_{\\mathrm{old}}\" width=\"199.43\" height=\"22.24\" style=\"width:199.43px;height:22.24px;aspect-ratio:199.43/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Forget gate × old cell = bacha hua purana hissa.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: retain the first old-cell component.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/687125898d5f60b7.svg\" alt=\"0.1(2)=0.2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the second old-cell component.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba3003dba6d22d16.svg\" alt=\"0.9(1)=0.9\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: assemble the two retained components.</strong></p>","<p>Keep their original order. This gives the following column:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ece27e6278683163.svg\" alt=\"f\\odot C=\\begin{bmatrix}0.1(2)\\\\0.9(1)\\end{bmatrix}=\\begin{bmatrix}0.2\\\\0.9\\end{bmatrix}\" width=\"272.33\" height=\"58.64\" style=\"width:272.33px;height:58.64px;aspect-ratio:272.33/58.64\" loading=\"lazy\"></div>","<p><strong>Answer:</strong> [0.2, 0.9]. This is the retained contribution, not necessarily the final new cell. The candidate contribution must also be known to calculate the full cell update.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s12","search":"LSTM complete numerical with supplied gates \n**Question.** An LSTM cell has input gate iₜ = 0.7, forget gate fₜ = 0.4, output gate oₜ = 0.8, candidate cell content C̃ₜ = 0.9 and previous cell state Cₜ₋₁ = 0.5. Calculate the new cell state Cₜ and hidden state hₜ.\n\n\n\n### Given\n\nActivated input gate i = 0.7; forget gate f = 0.4; output gate o = 0.8.\n\nCandidate = 0.9; old cell = 0.5.\n\n### To find\n\nFind the new cell C and hidden state h.\n\n### Formula — which one and why\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\n\n### Equations and supplied-value convention\nThe question supplies **activated gate outputs** and the candidate content. Do not apply sigmoid or tanh to those supplied values again. First update the cell, then calculate the hidden state:\n\n\nThe first equation combines retained old content and admitted candidate content. The second equation is a separate transformation of the updated cell.\n\n\n\n**Step 1: calculate the retained old-cell contribution.**\n\n**Step 2: calculate the admitted candidate contribution.**\n\n**Step 3: add the two contributions to obtain the new cell.**\n\n**Step 4: activate the updated cell.**\n\n**Step 5: multiply by the output gate.**\n\n\n**Final answer:** Cₜ = 0.83 and hₜ ≈ 0.544381. Multiplying the output gate directly by Cₜ would give 0.664 and omit the required tanh operation.\n\n### Related vector calculation: retention alone\n**Question.** Given forget gate f = [0.1, 0.9] and previous cell C = [2, 1], calculate the retained old-cell contribution.\n\n\n\n### Given\n\nForget gate = [0.1,0.9]; old cell = [2,1].\n\nInput-gate and candidate values are not supplied.\n\n### To find\n\nFind only the retained old-cell contribution.\n\n### Formula — which one and why\n\n**LSTM retained old memory.** Multiply each old cell value by its corresponding forget-gate value. This gives only the old contribution, not the complete new cell.\n\nf = activated forget gate; C_old = previous cell state; ⊙ means multiply matching entries.\n\n\n\n**Yaad rakhne ka cue:** Forget gate × old cell = bacha hua purana hissa.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: retain the first old-cell component.**\n\n\n\n\n\n\n\n**Step 2: retain the second old-cell component.**\n\n\n\n\n\n\n\n**Step 3: assemble the two retained components.**\n\nKeep their original order. This gives the following column:\n\n\n\n**Answer:** [0.2, 0.9]. This is the retained contribution, not necessarily the final new cell. The candidate contribution must also be known to calculate the full cell update.\n\n"},{"title":"LSTM numerical when gates must first be calculated","blocks":["<p class=\"inline-question\"><strong>Question.</strong> At an LSTM time step, xₜ = 1, hₜ₋₁ = 0 and Cₜ₋₁ = 0.2. The affine preactivations of the forget, input and output gates are all 0. The candidate preactivation is 0.5. Calculate the activated gates, candidate cell content, new cell state and new hidden state.</p>","<h3>Given</h3>","<p>x = 1; old hidden state = 0; old cell = 0.2.</p>","<p>Forget/input/output preactivations are all 0.</p>","<p>Candidate preactivation = 0.5.</p>","<h3>To find</h3>","<p>Activate all gates and candidate, then find C and h.</p>","<h3>Formula — which one and why</h3>","<p><strong>Activate raw gate scores first.</strong> A preactivation is an unprocessed score. Convert forget/input/output scores with sigmoid and candidate scores with tanh before using the cell-update equations.</p>","<p>z_f,z_i,z_o = gate preactivations; z_c = candidate preactivation. An already activated gate must not be passed through sigmoid again.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:108.67px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/82486bbd71caa406.svg\"><img class=\"math display-math\" src=\"assets/equations/cd80ed46001ad4fc.svg\" alt=\"f=\\sigma(z_f),\\quad i=\\sigma(z_i),\\quad o=\\sigma(z_o)\" width=\"364.98\" height=\"25.53\" style=\"width:364.98px;height:25.53px;aspect-ratio:364.98/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b3be31d6f9a03979.svg\" alt=\"\\widetilde C=\\tanh(z_c)\" width=\"139.92\" height=\"31.40\" style=\"width:139.92px;height:31.40px;aspect-ratio:139.92/31.40\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Raw score pehle activate; activated gate ko dobara sigmoid nahi.</p>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<h3>Distinguish preactivations from gate outputs</h3>","<p>The affine transformations have already been evaluated in this question. Their outputs are preactivations, so activation functions are still required. Sigmoid is used for f, i and o; tanh is used for the candidate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d65b06a34ee57b5a.svg\" alt=\"\\sigma(a)=\\frac1{1+e^{-a}}\" width=\"167.30\" height=\"51.56\" style=\"width:167.30px;height:51.56px;aspect-ratio:167.30/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.47px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3aff429544aa57f2.svg\"><img class=\"math display-math\" src=\"assets/equations/cec99860eadf260d.svg\" alt=\"C_t=f_tC_{t-1}+i_t\\widetilde C_t,\\qquad h_t=o_t\\tanh(C_t)\" width=\"431.16\" height=\"31.40\" style=\"width:431.16px;height:31.40px;aspect-ratio:431.16/31.40\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_lstm_gates_first.svg\" aria-label=\"Enlarge diagram: A gate preactivation of zero becomes a sigmoid gate output of 0.5. Use that activated gate value in the cell update.\"><img src=\"assets/figures/v_lstm_gates_first.svg\" alt=\"A gate preactivation of zero becomes a sigmoid gate output of 0.5. Use that activated gate value in the cell update.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>A gate preactivation of zero becomes a sigmoid gate output of 0.5. Use that activated gate value in the cell update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1: activate the three gates.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.98px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b2fa847b2d2be9a.svg\"><img class=\"math display-math\" src=\"assets/equations/7fb3fdabf106eb0d.svg\" alt=\"f_t=i_t=o_t=\\sigma(0)=\\frac1{1+e^0}=0.5\" width=\"371.27\" height=\"52.39\" style=\"width:371.27px;height:52.39px;aspect-ratio:371.27/52.39\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: activate the candidate preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b03e93e6315982fa.svg\"><img class=\"math display-math\" src=\"assets/equations/d7e58ebe85cb8fb2.svg\" alt=\"\\widetilde C_t=\\tanh(0.5)\\approx0.462117157\" width=\"319.00\" height=\"31.40\" style=\"width:319.00px;height:31.40px;aspect-ratio:319.00/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the old and new cell contributions separately.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbc91b31be7f6188.svg\" alt=\"f_tC_{t-1}=0.5(0.2)=0.1\" width=\"245.92\" height=\"24.43\" style=\"width:245.92px;height:24.43px;aspect-ratio:245.92/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.44px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c7c75923a5c216c.svg\"><img class=\"math display-math\" src=\"assets/equations/4c11c7ce4e04ba62.svg\" alt=\"i_t\\widetilde C_t=0.5\\tanh(0.5)\\approx0.231058579\" width=\"370.99\" height=\"31.40\" style=\"width:370.99px;height:31.40px;aspect-ratio:370.99/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: calculate the updated cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.84px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c56ba22ea129ddab.svg\"><img class=\"math display-math\" src=\"assets/equations/4334a43ffdec3984.svg\" alt=\"C_t=0.1+0.5\\tanh(0.5)\\approx0.331058579\" width=\"415.40\" height=\"24.43\" style=\"width:415.40px;height:24.43px;aspect-ratio:415.40/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: calculate the hidden output from the updated cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.86px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/39bac92ae8b9ef62.svg\"><img class=\"math display-math\" src=\"assets/equations/fc38db30848509e4.svg\" alt=\"h_t=0.5\\tanh(C_t)\\approx0.159735818\" width=\"345.42\" height=\"24.43\" style=\"width:345.42px;height:24.43px;aspect-ratio:345.42/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> fₜ = iₜ = oₜ = 0.5; C̃ₜ ≈ 0.462117157; Cₜ ≈ 0.331058579; hₜ ≈ 0.159735818. Retain unrounded calculator values between steps. A gate preactivation of 0 is different from a supplied gate output of 0: the former becomes 0.5 under sigmoid, while the latter would suppress its contribution completely.</p>","<h3>LSTM gates from raw score 0</h3>","<p class=\"inline-question\"><strong>Question. An LSTM has forget, input and output gate raw scores all equal to 0, candidate raw score 0, and old cell 1. Calculate all gates, candidate, new cell and hidden state.</strong></p>","<h3>Given</h3>","<p>Raw scores z_f = z_i = z_o = z_candidate = 0.</p>","<p>Old cell C_old = 1; gate activation sigmoid; candidate activation tanh.</p>","<h3>To find</h3>","<p>f,i,o,candidate,C_new,h_new.</p>","<h3>Formula — which one and why</h3>","<p>Raw gate scores require sigmoid first. The candidate uses tanh; do not apply sigmoid to it.</p>","<p>f retains old memory, i admits candidate, o controls exposed hidden output; C is cell memory.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b53d0d62e0b3dde.svg\" alt=\"f=i=o=\\sigma(z)\" width=\"175.80\" height=\"24.43\" style=\"width:175.80px;height:24.43px;aspect-ratio:175.80/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a911824e1fcf0c02.svg\" alt=\"\\widetilde C=\\tanh(z)\" width=\"130.42\" height=\"31.40\" style=\"width:130.42px;height:31.40px;aspect-ratio:130.42/31.40\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a0929338a45c9e2f.svg\" alt=\"C_{\\mathrm{new}}=fC_{\\mathrm{old}}+i\\widetilde C\" width=\"194.69\" height=\"30.29\" style=\"width:194.69px;height:30.29px;aspect-ratio:194.69/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/56c0f06510c31697.svg\" alt=\"h_{\\mathrm{new}}=o\\tanh(C_{\\mathrm{new}})\" width=\"211.52\" height=\"24.43\" style=\"width:211.52px;height:24.43px;aspect-ratio:211.52/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Gates sigmoid; candidate tanh; cell mein add; hidden pe output gate.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the shared gate value.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.09px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4a59e93b5287041f.svg\"><img class=\"math display-math\" src=\"assets/equations/76974c84c0527257.svg\" alt=\"\\sigma(0)=\\frac1{1+e^{-0}}\\approx0.500000000\" width=\"327.65\" height=\"52.39\" style=\"width:327.65px;height:52.39px;aspect-ratio:327.65/52.39\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/289a06589f8d4dfc.svg\"><img class=\"math display-math\" src=\"assets/equations/7e41db25271d6f77.svg\" alt=\"\\widetilde C=\\tanh(0)\\approx0.000000000\" width=\"292.82\" height=\"31.40\" style=\"width:292.82px;height:31.40px;aspect-ratio:292.82/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: retain the old-cell part.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.79px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65b5c67b809b7ce0.svg\"><img class=\"math display-math\" src=\"assets/equations/89caa918473d927f.svg\" alt=\"fC_{\\mathrm{old}}=(0.500000000)(1)\\approx0.500000000\" width=\"429.32\" height=\"24.43\" style=\"width:429.32px;height:24.43px;aspect-ratio:429.32/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: admit the new content.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:328.54px;--narrow-height:109.59px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9178374ae7a038b8.svg\"><img class=\"math display-math\" src=\"assets/equations/e7c8fe1c4efb3692.svg\" alt=\"i\\widetilde C=(0.500000000)(0.000000000)\\approx0.000000000\" width=\"517.08\" height=\"31.40\" style=\"width:517.08px;height:31.40px;aspect-ratio:517.08/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the memory contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.81px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d66b879a42e6911e.svg\"><img class=\"math display-math\" src=\"assets/equations/3f297224345b33d3.svg\" alt=\"C_{\\mathrm{new}}=0.500000000+(0.000000000)\\approx0.500000000\" width=\"550.20\" height=\"24.43\" style=\"width:550.20px;height:24.43px;aspect-ratio:550.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply tanh to the cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55fd6c15079562c2.svg\" alt=\"\\tanh(C_{\\mathrm{new}})\\approx0.462117157\" width=\"278.70\" height=\"24.43\" style=\"width:278.70px;height:24.43px;aspect-ratio:278.70/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: apply the output gate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:328.54px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9bcf24dd3ef65cfd.svg\"><img class=\"math display-math\" src=\"assets/equations/0d327c238e117d86.svg\" alt=\"h_{\\mathrm{new}}=(0.500000000)(0.462117157)\\approx0.231058579\" width=\"535.94\" height=\"24.43\" style=\"width:535.94px;height:24.43px;aspect-ratio:535.94/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> f=i=o≈0.500000000; candidate≈0.000000000; cell≈0.500000000; hidden≈0.231058579.</p>","<h3>LSTM gates from raw score 1</h3>","<p class=\"inline-question\"><strong>Question. An LSTM has forget, input and output gate raw scores all equal to 1, candidate raw score 1, and old cell -0.5. Calculate all gates, candidate, new cell and hidden state.</strong></p>","<h3>Given</h3>","<p>Raw scores z_f = z_i = z_o = z_candidate = 1.</p>","<p>Old cell C_old = -0.5; gate activation sigmoid; candidate activation tanh.</p>","<h3>To find</h3>","<p>f,i,o,candidate,C_new,h_new.</p>","<h3>Formula — which one and why</h3>","<p>Raw gate scores require sigmoid first. The candidate uses tanh; do not apply sigmoid to it.</p>","<p>f retains old memory, i admits candidate, o controls exposed hidden output; C is cell memory.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b53d0d62e0b3dde.svg\" alt=\"f=i=o=\\sigma(z)\" width=\"175.80\" height=\"24.43\" style=\"width:175.80px;height:24.43px;aspect-ratio:175.80/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a911824e1fcf0c02.svg\" alt=\"\\widetilde C=\\tanh(z)\" width=\"130.42\" height=\"31.40\" style=\"width:130.42px;height:31.40px;aspect-ratio:130.42/31.40\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a0929338a45c9e2f.svg\" alt=\"C_{\\mathrm{new}}=fC_{\\mathrm{old}}+i\\widetilde C\" width=\"194.69\" height=\"30.29\" style=\"width:194.69px;height:30.29px;aspect-ratio:194.69/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/56c0f06510c31697.svg\" alt=\"h_{\\mathrm{new}}=o\\tanh(C_{\\mathrm{new}})\" width=\"211.52\" height=\"24.43\" style=\"width:211.52px;height:24.43px;aspect-ratio:211.52/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Gates sigmoid; candidate tanh; cell mein add; hidden pe output gate.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the shared gate value.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.09px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0ac3af3fea75043b.svg\"><img class=\"math display-math\" src=\"assets/equations/d87096cb2c998d15.svg\" alt=\"\\sigma(1)=\\frac1{1+e^{-1}}\\approx0.731058579\" width=\"327.65\" height=\"52.39\" style=\"width:327.65px;height:52.39px;aspect-ratio:327.65/52.39\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37268273eb5c85e7.svg\"><img class=\"math display-math\" src=\"assets/equations/5b79535c0abe19aa.svg\" alt=\"\\widetilde C=\\tanh(1)\\approx0.761594156\" width=\"292.82\" height=\"31.40\" style=\"width:292.82px;height:31.40px;aspect-ratio:292.82/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: retain the old-cell part.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.80px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c8908718c1a2b52e.svg\"><img class=\"math display-math\" src=\"assets/equations/d526a95c3a3f61ff.svg\" alt=\"fC_{\\mathrm{old}}=(0.731058579)(-0.5)\\approx-0.365529289\" width=\"486.36\" height=\"24.43\" style=\"width:486.36px;height:24.43px;aspect-ratio:486.36/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: admit the new content.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:328.54px;--narrow-height:109.59px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0e17a5e53a3e2bd2.svg\"><img class=\"math display-math\" src=\"assets/equations/f64edf0a473f6a00.svg\" alt=\"i\\widetilde C=(0.731058579)(0.761594156)\\approx0.556769941\" width=\"517.08\" height=\"31.40\" style=\"width:517.08px;height:31.40px;aspect-ratio:517.08/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the memory contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.81px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/62b242322f0e2241.svg\"><img class=\"math display-math\" src=\"assets/equations/a705b1677cd4e456.svg\" alt=\"C_{\\mathrm{new}}=-0.365529289+(0.556769941)\\approx0.191240652\" width=\"569.20\" height=\"24.43\" style=\"width:569.20px;height:24.43px;aspect-ratio:569.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply tanh to the cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/404fb8d8c547f3b7.svg\" alt=\"\\tanh(C_{\\mathrm{new}})\\approx0.188942847\" width=\"278.70\" height=\"24.43\" style=\"width:278.70px;height:24.43px;aspect-ratio:278.70/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: apply the output gate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:328.54px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d1aa738ae9a7c24f.svg\"><img class=\"math display-math\" src=\"assets/equations/a9cc310c7b05f01a.svg\" alt=\"h_{\\mathrm{new}}=(0.731058579)(0.188942847)\\approx0.138128289\" width=\"535.94\" height=\"24.43\" style=\"width:535.94px;height:24.43px;aspect-ratio:535.94/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> f=i=o≈0.731058579; candidate≈0.761594156; cell≈0.191240652; hidden≈0.138128289.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s13","search":"LSTM numerical when gates must first be calculated \n**Question.** At an LSTM time step, xₜ = 1, hₜ₋₁ = 0 and Cₜ₋₁ = 0.2. The affine preactivations of the forget, input and output gates are all 0. The candidate preactivation is 0.5. Calculate the activated gates, candidate cell content, new cell state and new hidden state.\n\n\n\n### Given\n\nx = 1; old hidden state = 0; old cell = 0.2.\n\nForget/input/output preactivations are all 0.\n\nCandidate preactivation = 0.5.\n\n### To find\n\nActivate all gates and candidate, then find C and h.\n\n### Formula — which one and why\n\n**Activate raw gate scores first.** A preactivation is an unprocessed score. Convert forget/input/output scores with sigmoid and candidate scores with tanh before using the cell-update equations.\n\nz_f,z_i,z_o = gate preactivations; z_c = candidate preactivation. An already activated gate must not be passed through sigmoid again.\n\n\n\n\n\n**Yaad rakhne ka cue:** Raw score pehle activate; activated gate ko dobara sigmoid nahi.\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\n\n### Distinguish preactivations from gate outputs\nThe affine transformations have already been evaluated in this question. Their outputs are preactivations, so activation functions are still required. Sigmoid is used for f, i and o; tanh is used for the candidate.\n\n\n\n\n\n**Step 1: activate the three gates.**\n\n**Step 2: activate the candidate preactivation.**\n\n**Step 3: calculate the old and new cell contributions separately.**\n\n\n**Step 4: calculate the updated cell.**\n\n**Step 5: calculate the hidden output from the updated cell.**\n\n\n**Final answer:** fₜ = iₜ = oₜ = 0.5; C̃ₜ ≈ 0.462117157; Cₜ ≈ 0.331058579; hₜ ≈ 0.159735818. Retain unrounded calculator values between steps. A gate preactivation of 0 is different from a supplied gate output of 0: the former becomes 0.5 under sigmoid, while the latter would suppress its contribution completely.\n\n\n\n### LSTM gates from raw score 0\n\n**Question. An LSTM has forget, input and output gate raw scores all equal to 0, candidate raw score 0, and old cell 1. Calculate all gates, candidate, new cell and hidden state.**\n\n\n\n### Given\n\nRaw scores z_f = z_i = z_o = z_candidate = 0.\n\nOld cell C_old = 1; gate activation sigmoid; candidate activation tanh.\n\n### To find\n\nf,i,o,candidate,C_new,h_new.\n\n### Formula — which one and why\n\nRaw gate scores require sigmoid first. The candidate uses tanh; do not apply sigmoid to it.\n\nf retains old memory, i admits candidate, o controls exposed hidden output; C is cell memory.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Gates sigmoid; candidate tanh; cell mein add; hidden pe output gate.\n\n### Solution — step by step\n\n\n\n**Step 1: calculate the shared gate value.**\n\n\n\n\n\n\n\n**Step 2: calculate the candidate.**\n\n\n\n\n\n\n\n**Step 3: retain the old-cell part.**\n\n\n\n\n\n\n\n**Step 4: admit the new content.**\n\n\n\n\n\n\n\n**Step 5: add the memory contributions.**\n\n\n\n\n\n\n\n**Step 6: apply tanh to the cell.**\n\n\n\n\n\n\n\n**Step 7: apply the output gate.**\n\n\n\n\n\n\n\n**Final answer:** f=i=o≈0.500000000; candidate≈0.000000000; cell≈0.500000000; hidden≈0.231058579.\n\n\n"},{"title":"GRU two gates and one state","blocks":["<p class=\"definition\"><strong>Definition.</strong> A gated recurrent unit (GRU) is a recurrent architecture that uses reset and update gates to control its hidden-state transition. Unlike a standard LSTM, it does not carry a separate cell state alongside the hidden state.</p>","<h3>Gate equations and the convention used here</h3>","<p>The reset gate r controls how the previous hidden state enters candidate formation. The update gate z controls the mixture of the old state and the candidate. Both are calculated from the current input and previous hidden state:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/70d5c123a1a8d5b7.svg\" alt=\"r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"290.93\" height=\"24.43\" style=\"width:290.93px;height:24.43px;aspect-ratio:290.93/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/facdae4e8c80fb1f.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z)\" width=\"292.00\" height=\"24.43\" style=\"width:292.00px;height:24.43px;aspect-ratio:292.00/24.43\" loading=\"lazy\"></div>","<p>The candidate equation used in these notes applies reset before the recurrent candidate transformation:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cb42e5f674e4241.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h)\" width=\"403.57\" height=\"31.13\" style=\"width:403.57px;height:31.13px;aspect-ratio:403.57/31.13\" loading=\"lazy\"></div>","<p>These notes define z as the fraction of <strong>new candidate</strong> admitted:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.94px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/949c126edafa8f0a.svg\"><img class=\"math display-math\" src=\"assets/equations/40cc13a7254b2881.svg\" alt=\"h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"311.64\" height=\"31.13\" style=\"width:311.64px;height:31.13px;aspect-ratio:311.64/31.13\" loading=\"lazy\"></picture></div>","<p>Thus z near 0 favors retention of the old hidden state, while z near 1 favors the candidate. The reset gate affects the candidate calculation; it does not directly multiply the retained old-state term in the final mixture.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gru.svg\" aria-label=\"Enlarge diagram: First calculate the reset-dependent candidate. Then combine the old hidden state and the candidate using the stated update-gate convention.\"><img src=\"assets/figures/gru.svg\" alt=\"First calculate the reset-dependent candidate. Then combine the old hidden state and the candidate using the stated update-gate convention.\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>First calculate the reset-dependent candidate. Then combine the old hidden state and the candidate using the stated update-gate convention. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Complete numerical with supplied gate values</h3>","<p class=\"inline-question\"><strong>Question.</strong> A scalar GRU has hₜ₋₁ = 0.4, reset gate rₜ = 0.5, update gate zₜ = 0.25, xₜ = 1, Wₕ = 0.2, Uₕ = 0.5 and bₕ = 0. Calculate the candidate and new hidden state using hₜ = (1−zₜ)hₜ₋₁ + zₜh̃ₜ.</p>","<h3>Given</h3>","<p>Old hidden state = 0.4; r = 0.5; z = 0.25.</p>","<p>x = 1; W = 0.2; U = 0.5; b = 0.</p>","<p>Here z weights the candidate in the final mixture.</p>","<h3>To find</h3>","<p>Find candidate and new hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>GRU reset and state mixture.</strong> The reset gate controls old-state information entering the candidate. The stated update convention then mixes the original old state and the candidate.</p>","<p>r = reset gate; z = update gate; h_old = previous state; h_tilde = candidate. Here z weights the candidate; some questions instead define z to weight the old state.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0823781665f17f77.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(r\\odot h_{\\mathrm{old}})+b)\" width=\"342.15\" height=\"31.13\" style=\"width:342.15px;height:31.13px;aspect-ratio:342.15/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/27ea37a678ab26e6.svg\" alt=\"h=(1-z)\\odot h_{\\mathrm{old}}+z\\odot\\widetilde h\" width=\"273.32\" height=\"31.13\" style=\"width:273.32px;height:31.13px;aspect-ratio:273.32/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Reset candidate ko control; update gate old-new mixture ko control.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: apply the reset gate to the previous hidden state.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4ee6cc7b942d74.svg\" alt=\"r_th_{t-1}=0.5(0.4)=0.2\" width=\"241.56\" height=\"24.43\" style=\"width:241.56px;height:24.43px;aspect-ratio:241.56/24.43\" loading=\"lazy\"></div>","<p>The gates are already supplied as outputs, so no further sigmoid calculation is needed.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.59px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca995973009650d3.svg\"><img class=\"math display-math\" src=\"assets/equations/f549a71ed6a573d3.svg\" alt=\"a_{\\mathrm{candidate}}=W_hx_t+U_h(r_th_{t-1})+b_h\" width=\"371.38\" height=\"24.43\" style=\"width:371.38px;height:24.43px;aspect-ratio:371.38/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.23px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f40a657a883a8d8.svg\"><img class=\"math display-math\" src=\"assets/equations/05a1713a2609d0e7.svg\" alt=\"a_{\\mathrm{candidate}}=0.2(1)+0.5(0.2)+0=0.3\" width=\"400.19\" height=\"24.43\" style=\"width:400.19px;height:24.43px;aspect-ratio:400.19/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: apply tanh to obtain the candidate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e3e84d154de9f24.svg\"><img class=\"math display-math\" src=\"assets/equations/a1e77c483544b002.svg\" alt=\"\\widetilde h_t=\\tanh(0.3)\\approx0.291312612\" width=\"315.61\" height=\"31.13\" style=\"width:315.61px;height:31.13px;aspect-ratio:315.61/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: calculate the two mixture contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/56b9a2466f5d57e7.svg\"><img class=\"math display-math\" src=\"assets/equations/b3f54d1f31eaa225.svg\" alt=\" (1-z_t)h_{t-1}=(1-0.25)(0.4)=0.3\" width=\"376.32\" height=\"24.43\" style=\"width:376.32px;height:24.43px;aspect-ratio:376.32/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.19px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8512106d268f635a.svg\"><img class=\"math display-math\" src=\"assets/equations/4cab7af53e3adf95.svg\" alt=\"z_t\\widetilde h_t=0.25\\tanh(0.3)\\approx0.072828153\" width=\"382.75\" height=\"31.13\" style=\"width:382.75px;height:31.13px;aspect-ratio:382.75/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.52px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/14fb84144802870c.svg\"><img class=\"math display-math\" src=\"assets/equations/99c980a8ec789fec.svg\" alt=\"h_t=0.3+0.25\\tanh(0.3)\\approx0.372828153\" width=\"424.21\" height=\"24.43\" style=\"width:424.21px;height:24.43px;aspect-ratio:424.21/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> candidate ≈ 0.291313 and new hidden state ≈ 0.372828. The new scalar state lies between the old state 0.4 and the candidate 0.291313, as expected for this convex mixture.</p>","<h3>If the question uses the other update-gate convention</h3>","<p>Some texts define z as the fraction of the <strong>old state retained</strong>:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/360ddf17a95ce9ee.svg\" alt=\"h_t=z_th_{t-1}+(1-z_t)\\widetilde h_t\" width=\"251.91\" height=\"31.13\" style=\"width:251.91px;height:31.13px;aspect-ratio:251.91/31.13\" loading=\"lazy\"></div>","<p>Under that explicitly different convention, the same numerical value z = 0.25 gives:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.52px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e8fba95c9469ec76.svg\"><img class=\"math display-math\" src=\"assets/equations/d0cde1d1f4ff9640.svg\" alt=\"h_t=0.25(0.4)+0.75\\tanh(0.3)\\approx0.318484459\" width=\"486.67\" height=\"24.43\" style=\"width:486.67px;height:24.43px;aspect-ratio:486.67/24.43\" loading=\"lazy\"></picture></div>","<p>This is not the answer to the worked question above, which states the first convention. To represent an identical mixture while switching conventions, the gate values must be complemented as well. Always identify the final mixture equation before substituting values.</p>","<h3>Relationship to LSTM</h3>","<p>A basic GRU has three affine transformations: reset, update and candidate. A standard LSTM has four: forget, input, output and candidate. With equal input and hidden dimensions and the same bias convention, GRU therefore has fewer recurrent parameters. This is a parameter-count comparison, not a guarantee of higher accuracy or faster execution for every task.</p>","<h3>Retain-old GRU with gate 0</h3>","<p class=\"inline-question\"><strong>Question. Use h_new = z h_old+(1−z) candidate. Given h_old = 0.4, z = 0, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new state.</strong></p>","<h3>Given</h3>","<p>h_old = 0.4; z = 0; r = 0.5; x = 1.</p>","<p>W = 0.2; U = 0.5; b = 0; z is the retain-old gate.</p>","<h3>To find</h3>","<p>Candidate and final hidden state.</p>","<h3>Formula — which one and why</h3>","<p>The reset gate changes old-state input to the candidate. The update gate separately mixes the original old state and candidate.</p>","<p>The question explicitly makes z multiply the old state. r and z do different jobs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Reset sirf candidate mein; update mix mein original old state.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/298840de1c01f101.svg\" alt=\"rh_{\\mathrm{old}}=0.5(0.4)=0.2\" width=\"228.03\" height=\"24.43\" style=\"width:228.03px;height:24.43px;aspect-ratio:228.03/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate raw sum.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/708a856537eccf89.svg\"><img class=\"math display-math\" src=\"assets/equations/f6b1201a9f34684a.svg\" alt=\"a=0.2(1)+0.5(0.2)+0=0.3\" width=\"325.20\" height=\"24.43\" style=\"width:325.20px;height:24.43px;aspect-ratio:325.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: apply tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5d5bc478f8a3566.svg\"><img class=\"math display-math\" src=\"assets/equations/8ef1fca1e3e9a662.svg\" alt=\"\\widetilde h=\\tanh(0.3)\\approx0.291312612\" width=\"307.34\" height=\"31.13\" style=\"width:307.34px;height:31.13px;aspect-ratio:307.34/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: retain the old-state fraction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/81c714ea0d0f3d30.svg\" alt=\"0(0.4)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the candidate fraction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b85f83251c9025c.svg\"><img class=\"math display-math\" src=\"assets/equations/fb448a828d5eb818.svg\" alt=\"(1-0)(0.291312612)\\approx0.291312612\" width=\"382.84\" height=\"24.43\" style=\"width:382.84px;height:24.43px;aspect-ratio:382.84/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: add the two fractions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb12f65fb3a6f99d.svg\"><img class=\"math display-math\" src=\"assets/equations/05b6b2f57ab16b9a.svg\" alt=\"h_{\\mathrm{new}}=0+(0.291312612)\\approx0.291312612\" width=\"430.05\" height=\"24.43\" style=\"width:430.05px;height:24.43px;aspect-ratio:430.05/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Candidate ≈ 0.291312612; new state ≈ 0.291312612.</p>","<h3>Retain-old GRU with gate 0.8</h3>","<p class=\"inline-question\"><strong>Question. Use h_new = z h_old+(1−z) candidate. Given h_old = -0.2, z = 0.8, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new state.</strong></p>","<h3>Given</h3>","<p>h_old = -0.2; z = 0.8; r = 0.5; x = 1.</p>","<p>W = 0.2; U = 0.5; b = 0; z is the retain-old gate.</p>","<h3>To find</h3>","<p>Candidate and final hidden state.</p>","<h3>Formula — which one and why</h3>","<p>The reset gate changes old-state input to the candidate. The update gate separately mixes the original old state and candidate.</p>","<p>The question explicitly makes z multiply the old state. r and z do different jobs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Reset sirf candidate mein; update mix mein original old state.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c07f11824db74c75.svg\" alt=\"rh_{\\mathrm{old}}=0.5(-0.2)=-0.1\" width=\"266.05\" height=\"24.43\" style=\"width:266.05px;height:24.43px;aspect-ratio:266.05/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate raw sum.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/177d51be8807173f.svg\"><img class=\"math display-math\" src=\"assets/equations/ba304bd37c97d1fe.svg\" alt=\"a=0.2(1)+0.5(-0.1)+0=0.15\" width=\"356.42\" height=\"24.43\" style=\"width:356.42px;height:24.43px;aspect-ratio:356.42/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: apply tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22b0ab9fe31c5dbb.svg\"><img class=\"math display-math\" src=\"assets/equations/89f3eabbc08b8f86.svg\" alt=\"\\widetilde h=\\tanh(0.15)\\approx0.148885034\" width=\"319.55\" height=\"31.13\" style=\"width:319.55px;height:31.13px;aspect-ratio:319.55/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: retain the old-state fraction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d5d62808c22a4a6.svg\" alt=\"0.8(-0.2)=-0.16\" width=\"195.51\" height=\"24.43\" style=\"width:195.51px;height:24.43px;aspect-ratio:195.51/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the candidate fraction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/47661b22efc0daeb.svg\"><img class=\"math display-math\" src=\"assets/equations/349c3a8b18523729.svg\" alt=\"(1-0.8)(0.148885034)\\approx0.029777007\" width=\"401.85\" height=\"24.43\" style=\"width:401.85px;height:24.43px;aspect-ratio:401.85/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: add the two fractions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a559a88735fecf3e.svg\"><img class=\"math display-math\" src=\"assets/equations/78f9973806e42ffa.svg\" alt=\"h_{\\mathrm{new}}=-0.16+(0.029777007)\\approx-0.130222993\" width=\"499.29\" height=\"24.43\" style=\"width:499.29px;height:24.43px;aspect-ratio:499.29/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Candidate ≈ 0.148885034; new state ≈ -0.130222993.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s14","search":"GRU two gates and one state \n**Definition.** A gated recurrent unit (GRU) is a recurrent architecture that uses reset and update gates to control its hidden-state transition. Unlike a standard LSTM, it does not carry a separate cell state alongside the hidden state.\n\n### Gate equations and the convention used here\nThe reset gate r controls how the previous hidden state enters candidate formation. The update gate z controls the mixture of the old state and the candidate. Both are calculated from the current input and previous hidden state:\n\n\nThe candidate equation used in these notes applies reset before the recurrent candidate transformation:\n\nThese notes define z as the fraction of **new candidate** admitted:\n\nThus z near 0 favors retention of the old hidden state, while z near 1 favors the candidate. The reset gate affects the candidate calculation; it does not directly multiply the retained old-state term in the final mixture.\n\n\n\n### Complete numerical with supplied gate values\n**Question.** A scalar GRU has hₜ₋₁ = 0.4, reset gate rₜ = 0.5, update gate zₜ = 0.25, xₜ = 1, Wₕ = 0.2, Uₕ = 0.5 and bₕ = 0. Calculate the candidate and new hidden state using hₜ = (1−zₜ)hₜ₋₁ + zₜh̃ₜ.\n\n\n\n### Given\n\nOld hidden state = 0.4; r = 0.5; z = 0.25.\n\nx = 1; W = 0.2; U = 0.5; b = 0.\n\nHere z weights the candidate in the final mixture.\n\n### To find\n\nFind candidate and new hidden state.\n\n### Formula — which one and why\n\n**GRU reset and state mixture.** The reset gate controls old-state information entering the candidate. The stated update convention then mixes the original old state and the candidate.\n\nr = reset gate; z = update gate; h_old = previous state; h_tilde = candidate. Here z weights the candidate; some questions instead define z to weight the old state.\n\n\n\n\n\n**Yaad rakhne ka cue:** Reset candidate ko control; update gate old-new mixture ko control.\n\n### Solution — step by step\n\n\n\n\n\n**Step 1: apply the reset gate to the previous hidden state.**\n\nThe gates are already supplied as outputs, so no further sigmoid calculation is needed.\n\n**Step 2: calculate the candidate preactivation.**\n\n\n\n**Step 3: apply tanh to obtain the candidate.**\n\n\n**Step 4: calculate the two mixture contributions.**\n\n\n\n**Step 5: add the contributions.**\n\n**Final answer:** candidate ≈ 0.291313 and new hidden state ≈ 0.372828. The new scalar state lies between the old state 0.4 and the candidate 0.291313, as expected for this convex mixture.\n\n### If the question uses the other update-gate convention\nSome texts define z as the fraction of the **old state retained**:\n\nUnder that explicitly different convention, the same numerical value z = 0.25 gives:\n\nThis is not the answer to the worked question above, which states the first convention. To represent an identical mixture while switching conventions, the gate values must be complemented as well. Always identify the final mixture equation before substituting values.\n\n### Relationship to LSTM\nA basic GRU has three affine transformations: reset, update and candidate. A standard LSTM has four: forget, input, output and candidate. With equal input and hidden dimensions and the same bias convention, GRU therefore has fewer recurrent parameters. This is a parameter-count comparison, not a guarantee of higher accuracy or faster execution for every task.\n\n\n\n### Retain-old GRU with gate 0\n\n**Question. Use h_new = z h_old+(1−z) candidate. Given h_old = 0.4, z = 0, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new "},{"title":"Comparing the three recurrent models","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Feature</th><th>Vanilla RNN</th><th>LSTM</th><th>GRU</th></tr></thead><tbody><tr><td>Main state</td><td>h</td><td>h and C</td><td>h</td></tr><tr><td>Gates</td><td>None in vanilla cell</td><td>Forget input output</td><td>Reset update</td></tr><tr><td>Long dependencies</td><td>Often difficult to learn</td><td>Designed to help retain useful long context</td><td>Designed to help retain useful long context</td></tr><tr><td>Parameters at equal dimensions</td><td>Usually fewest</td><td>Usually most of these three</td><td>Usually between vanilla RNN and LSTM</td></tr><tr><td>Typical choice</td><td>Simple short sequences</td><td>Complex long-context sequences</td><td>Efficient gated sequence baseline</td></tr></tbody></table></div>","<p>With input size d and hidden size H, a basic single-bias vanilla recurrent layer has H(d+H+1) parameters; a standard LSTM has 4H(d+H+1); a basic GRU has 3H(d+H+1). These omit output layers; library versions with extra bias vectors differ. The factor four in LSTM counts three gates plus one candidate transform.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_comparison.svg\" aria-label=\"Enlarge diagram: Compare what is carried through time and how many gate or candidate transforms are used.\"><img src=\"assets/figures/v_rnn_comparison.svg\" alt=\"Compare what is carried through time and how many gate or candidate transforms are used.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Compare what is carried through time and how many gate or candidate transforms are used. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s15","search":"Comparing the three recurrent models | Feature | Vanilla RNN | LSTM | GRU |\n| Main state | h | h and C | h |\n| Gates | None in vanilla cell | Forget input output | Reset update |\n| Long dependencies | Often difficult to learn | Designed to help retain useful long context | Designed to help retain useful long context |\n| Parameters at equal dimensions | Usually fewest | Usually most of these three | Usually between vanilla RNN and LSTM |\n| Typical choice | Simple short sequences | Complex long-context sequences | Efficient gated sequence baseline |\nWith input size d and hidden size H, a basic single-bias vanilla recurrent layer has H(d+H+1) parameters; a standard LSTM has 4H(d+H+1); a basic GRU has 3H(d+H+1). These omit output layers; library versions with extra bias vectors differ. The factor four in LSTM counts three gates plus one candidate transform.\n\n\n"},{"title":"Model answer: LSTM and GRU memory","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare a vanilla RNN, an LSTM and a GRU. Explain the roles of the LSTM gates and state the GRU convention used in this course.</p>"],"answer":["<p>A vanilla RNN repeatedly transforms the current input and previous hidden state. LSTMs and GRUs add learned gates that control the retention and replacement of information. Gates usually use sigmoid, so their entries lie between 0 and 1; gate multiplication controls how much of a corresponding value is passed.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_comparison.svg\" aria-label=\"Enlarge diagram: LSTM carries a cell and hidden state; GRU carries a hidden state with two gate roles.\"><img src=\"assets/figures/v_rnn_comparison.svg\" alt=\"LSTM carries a cell and hidden state; GRU carries a hidden state with two gate roles.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>LSTM carries a cell and hidden state; GRU carries a hidden state with two gate roles. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>LSTM</h3>","<p>An LSTM carries a cell state c and a hidden state h. Its forget gate f controls the old cell contribution. Its input gate i controls admission of a new candidate c-tilde. Its output gate o controls the exposed hidden state.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d70555acf8f3a0de.svg\" alt=\"c_t=f_t\\odot c_{t-1}+i_t\\odot\\widetilde c_t\" width=\"237.74\" height=\"23.40\" style=\"width:237.74px;height:23.40px;aspect-ratio:237.74/23.40\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be4b02b5e68c7633.svg\" alt=\"h_t=o_t\\odot\\tanh(c_t)\" width=\"191.66\" height=\"24.43\" style=\"width:191.66px;height:24.43px;aspect-ratio:191.66/24.43\" loading=\"lazy\"></div>","<p>The candidate is commonly formed using tanh, so it can be negative. Gate multiplication is elementwise. The updated cell is not the same as the hidden output; the second equation is another required step.</p>","<h3>GRU</h3>","<p>A GRU carries one hidden state rather than a separate LSTM-style cell state. A reset gate r controls how previous hidden information contributes to candidate formation. An update gate z mixes the old state and candidate. This guide uses:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.94px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/949c126edafa8f0a.svg\"><img class=\"math display-math\" src=\"assets/equations/40cc13a7254b2881.svg\" alt=\"h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"311.64\" height=\"31.13\" style=\"width:311.64px;height:31.13px;aspect-ratio:311.64/31.13\" loading=\"lazy\"></picture></div>","<p>Thus z near 1 favors the new candidate under this convention. Some sources exchange z and 1 − z; always follow the equation printed in the question.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Model</th><th>Carried state</th><th>Main gates</th><th>Typical parameter implication for the same dimensions</th></tr></thead><tbody><tr><td>Vanilla RNN</td><td>Hidden state</td><td>None of these memory gates</td><td>Fewest affine transformations</td></tr><tr><td>LSTM</td><td>Cell and hidden states</td><td>Forget, input and output gates</td><td>Four affine transformations including candidate</td></tr><tr><td>GRU</td><td>Hidden state</td><td>Reset and update gates</td><td>Three affine transformations including candidate</td></tr></tbody></table></div>","<p>Gated models improve control over information flow but do not guarantee perfect indefinite memory. Their benefit must be evaluated for the sequence task.</p>"],"kind":"theory","id":"tee-c9-s16","search":"Model answer: LSTM and GRU memory **Question.** Compare a vanilla RNN, an LSTM and a GRU. Explain the roles of the LSTM gates and state the GRU convention used in this guide.\n\n**Model answer.**\nA vanilla RNN repeatedly transforms the current input and previous hidden state. LSTMs and GRUs add learned gates that control the retention and replacement of information. Gates usually use sigmoid, so their entries lie between 0 and 1; gate multiplication controls how much of a corresponding value is passed.\n\n\n\n\n### LSTM\nAn LSTM carries a cell state c and a hidden state h. Its forget gate f controls the old cell contribution. Its input gate i controls admission of a new candidate c-tilde. Its output gate o controls the exposed hidden state.\n\n\nThe candidate is commonly formed using tanh, so it can be negative. Gate multiplication is elementwise. The updated cell is not the same as the hidden output; the second equation is another required step.\n\n### GRU\nA GRU carries one hidden state rather than a separate LSTM-style cell state. A reset gate r controls how previous hidden information contributes to candidate formation. An update gate z mixes the old state and candidate. This guide uses:\n\nThus z near 1 favors the new candidate under this convention. Some sources exchange z and 1 − z; always follow the equation printed in the question.\n\n| Model | Carried state | Main gates | Typical parameter implication for the same dimensions |\n| Vanilla RNN | Hidden state | None of these memory gates | Fewest affine transformations |\n| LSTM | Cell and hidden states | Forget, input and output gates | Four affine transformations including candidate |\n| GRU | Hidden state | Reset and update gates | Three affine transformations including candidate |\n\nGated models improve control over information flow but do not guarantee perfect indefinite memory. Their benefit must be evaluated for the sequence task.\n"},{"title":"Sequence mappings and applications","blocks":["<p class=\"definition\"><strong>Definition.</strong> A sequence-model configuration specifies how many inputs and outputs are processed and how their time indices relate. One-to-many, many-to-one and many-to-many configurations correspond to different prediction tasks.</p>","<h3>Explanation and working</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: The number and timing of inputs and outputs determine the sequence mapping\"><img src=\"assets/figures/sequences.svg\" alt=\"The number and timing of inputs and outputs determine the sequence mapping\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>The number and timing of inputs and outputs determine the sequence mapping <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"table-scroll\"><table><thead><tr><th>Mapping</th><th>Meaning</th><th>Example and output</th></tr></thead><tbody><tr><td>One to many</td><td>One input conditions several outputs</td><td>Image captioning: image to a word sequence</td></tr><tr><td>Many to one</td><td>Sequence summarized as one output</td><td>Review sentiment: words to positive neutral or negative</td></tr><tr><td>Many to many aligned</td><td>Output associated with each input time</td><td>Video frame labeling or per-word tagging</td></tr><tr><td>Many to many unaligned</td><td>Output sequence length may differ</td><td>Encoder-decoder translation</td></tr></tbody></table></div>","<p>Music generation can use earlier notes to predict the next note repeatedly. Next-word prediction uses the prefix to produce a probability distribution over a vocabulary. A word with the largest predicted probability is a simple choice, but the precise prediction cannot be calculated without the learned model&#x27;s weights.</p>","<p><strong>Sentence explanation: </strong> In “The dogs that bark near my house are loud,” the model should retain the plural subject across the intervening words when choosing “are”. Gates can retain subject information and admit later context. This is an interpretation of what a trained model may learn, not a claim that an individual gate is guaranteed to represent grammar.</p>","<p><strong>Sentiment model answer: </strong> tokenize the review, map tokens to numerical embeddings, process them with an RNN/LSTM/GRU, use a final state or pooled sequence representation, then a dense layer and softmax over three sentiment classes. Train with categorical cross-entropy on labeled reviews; evaluate on held-out data. A bidirectional model is not needed for this answer and is not explicitly listed in the current syllabus.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s17","search":"Sequence mappings and applications **Definition.** A sequence-model configuration specifies how many inputs and outputs are processed and how their time indices relate. One-to-many, many-to-one and many-to-many configurations correspond to different prediction tasks.\n\n### Explanation and working\n\n| Mapping | Meaning | Example and output |\n| One to many | One input conditions several outputs | Image captioning: image to a word sequence |\n| Many to one | Sequence summarized as one output | Review sentiment: words to positive neutral or negative |\n| Many to many aligned | Output associated with each input time | Video frame labeling or per-word tagging |\n| Many to many unaligned | Output sequence length may differ | Encoder-decoder translation |\nMusic generation can use earlier notes to predict the next note repeatedly. Next-word prediction uses the prefix to produce a probability distribution over a vocabulary. A word with the largest predicted probability is a simple choice, but the precise prediction cannot be calculated without the learned model's weights.\n**Sentence explanation: ** In “The dogs that bark near my house are loud,” the model should retain the plural subject across the intervening words when choosing “are”. Gates can retain subject information and admit later context. This is an interpretation of what a trained model may learn, not a claim that an individual gate is guaranteed to represent grammar.\n**Sentiment model answer: ** tokenize the review, map tokens to numerical embeddings, process them with an RNN/LSTM/GRU, use a final state or pooled sequence representation, then a dense layer and softmax over three sentiment classes. Train with categorical cross-entropy on labeled reviews; evaluate on held-out data. A bidirectional model is not needed for this answer and is not explicitly listed in the current syllabus."},{"title":"Recurrent networks: the complete relationship","blocks":["<p>A vanilla RNN repeatedly combines the new input and previous hidden state with shared weights. Backpropagation through time accumulates contributions from every use of those shared weights. LSTM adds an explicit cell state with forget, input and output gates. GRU mixes an old hidden state and a candidate using reset and update gates.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rnn_comparison.svg\" aria-label=\"Enlarge diagram: Read from the ordinary recurrent calculation to the two gated memory designs.\"><img src=\"assets/figures/v_rnn_comparison.svg\" alt=\"Read from the ordinary recurrent calculation to the two gated memory designs.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Read from the ordinary recurrent calculation to the two gated memory designs. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>For every recurrent calculation, compute the gate or hidden preactivation first, apply its stated activation, then combine the resulting values. Elementwise gate multiplication is different from matrix multiplication. The stated GRU update convention determines whether z retains the old state or selects the candidate.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s18","search":"Recurrent networks: the complete relationship A vanilla RNN repeatedly combines the new input and previous hidden state with shared weights. Backpropagation through time accumulates contributions from every use of those shared weights. LSTM adds an explicit cell state with forget, input and output gates. GRU mixes an old hidden state and a candidate using reset and update gates.\n\n\n\nFor every recurrent calculation, compute the gate or hidden preactivation first, apply its stated activation, then combine the resulting values. Elementwise gate multiplication is different from matrix multiplication. The stated GRU update convention determines whether z retains the old state or selects the candidate.\n"},{"title":"Gate logic without memorizing a story","blocks":["<p>In an LSTM, let the previous cell be 2, forget gate 0.5, input gate 0.25, candidate −0.4 and output gate 1. Calculate the retained part, admitted part, new cell and hidden output.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_gate_order.svg\" aria-label=\"Enlarge diagram: The input gate multiplies candidate content. The output gate is applied after updating and activating the cell.\"><img src=\"assets/figures/v_gate_order.svg\" alt=\"The input gate multiplies candidate content. The output gate is applied after updating and activating the cell.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The input gate multiplies candidate content. The output gate is applied after updating and activating the cell. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 retained content:</strong> 0.5 × 2 = 1.</p>","<p class=\"worked-step\"><strong>Step 2 admitted content:</strong> 0.25 × (−0.4) = −0.1. A candidate can be negative even though the gate itself is between zero and one.</p>","<p class=\"worked-step\"><strong>Step 3 cell:</strong> 1 + (−0.1) = 0.9.</p>","<p class=\"worked-step\"><strong>Step 4 hidden:</strong> output gate × tanh(cell) = 1 × tanh(0.9) ≈ 0.716298. The hidden output is not simply 0.9. Explain this distinction once before attempting another LSTM numerical.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c9-s19","search":"Gate logic without memorizing a story In an LSTM, let the previous cell be 2, forget gate 0.5, input gate 0.25, candidate −0.4 and output gate 1. Calculate the retained part, admitted part, new cell and hidden output.\n\n\n\n**Step 1 retained content:** 0.5 × 2 = 1.\n\n**Step 2 admitted content:** 0.25 × (−0.4) = −0.1. A candidate can be negative even though the gate itself is between zero and one.\n**Step 3 cell:** 1 + (−0.1) = 0.9.\n\n**Step 4 hidden:** output gate × tanh(cell) = 1 × tanh(0.9) ≈ 0.716298. The hidden output is not simply 0.9. Explain this distinction once before attempting another LSTM numerical.\n\n"}]},{"n":10,"title":"Current MT1 and the two teacher backprop examples","sections":[{"title":"Start here","blocks":["<p>Sources S03, S01 and the three Teams photographs supplied later. MT1 establishes prerequisites; it does not prove that earlier concepts cannot reappear in MT2.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c10-intro"},{"title":"MT1A Q1a","question":["<p class=\"inline-question\"><strong>Question (2 marks).</strong> Define deep learning and explain its relationship with AI and machine learning.</p>"],"answer":["<p>Artificial intelligence is the broad goal of building systems that perform tasks associated with intelligence. Machine learning is a subset that learns patterns from data. Deep learning is a subset of machine learning using neural networks with multiple processing layers to learn representations. Thus DL ⊂ ML ⊂ AI. Example: a CNN learning image features is deep learning; a decision tree trained on tabular data is machine learning without being deep learning.</p>"],"kind":"practice","id":"tee-c10-s0","search":"MT1A Q1a **Question (2 marks).** Define deep learning and explain its relationship with AI and machine learning.\n\n**Complete worked answer.**\nArtificial intelligence is the broad goal of building systems that perform tasks associated with intelligence. Machine learning is a subset that learns patterns from data. Deep learning is a subset of machine learning using neural networks with multiple processing layers to learn representations. Thus DL ⊂ ML ⊂ AI. Example: a CNN learning image features is deep learning; a decision tree trained on tabular data is machine learning without being deep learning.\n"},{"title":"MT1A Q1b","question":["<p class=\"inline-question\"><strong>Question (2 marks).</strong> List three applications of deep learning and explain any one.</p>"],"answer":["<p>Three applications are image recognition, speech recognition and language translation. In image recognition, a CNN applies filters to learn local edges and textures, combines them into more complex features, and uses an output layer to assign class probabilities. It learns these features from labeled examples instead of requiring every image feature to be manually designed.</p>"],"kind":"practice","id":"tee-c10-s1","search":"MT1A Q1b **Question (2 marks).** List three applications of deep learning and explain any one.\n\n**Complete worked answer.**\nThree applications are image recognition, speech recognition and language translation. In image recognition, a CNN applies filters to learn local edges and textures, combines them into more complex features, and uses an output layer to assign class probabilities. It learns these features from labeled examples instead of requiring every image feature to be manually designed.\n"},{"title":"MT1A Q2","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> A sigmoid neuron has inputs [2,1,3], weights [0.4,−0.2,0.5] and bias 0.1. Compute its output.</p>"],"answer":["<h3>Given</h3>","<p>Inputs x₁ = 2,x₂ = 1,x₃ = 3.</p>","<p>Matching weights w₁ = 0.4,w₂ = −0.2,w₃ = 0.5.</p>","<p>Bias b = 0.1; activation = sigmoid.</p>","<h3>To find</h3>","<p>Calculate net input z and activated output a.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid output.</strong> The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.</p>","<p>z = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Minus-z ki e power, plus one, phir one divided by whole denominator.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/568d8f8a50e883d1.svg\" alt=\"x_1w_1=2(0.4)=0.8\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by weight 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2aecb1c03e00ecf3.svg\" alt=\"x_2w_2=1(-0.2)=-0.2\" width=\"249.67\" height=\"24.43\" style=\"width:249.67px;height:24.43px;aspect-ratio:249.67/24.43\" loading=\"lazy\"></div>","<p>The minus sign belongs to the weight, so the contribution stays negative.</p>","<p class=\"worked-step\"><strong>Step 3: multiply input 3 by weight 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b26c8cde278f5783.svg\" alt=\"x_3w_3=3(0.5)=1.5\" width=\"211.66\" height=\"24.43\" style=\"width:211.66px;height:24.43px;aspect-ratio:211.66/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the three contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.48px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/928ca4d8a84ae46e.svg\"><img class=\"math display-math\" src=\"assets/equations/fa72e2cee0620f1c.svg\" alt=\"s=0.8+(-0.2)+1.5=0.6+1.5=2.1\" width=\"424.20\" height=\"24.43\" style=\"width:424.20px;height:24.43px;aspect-ratio:424.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fc2fbdf24fc7fcdc.svg\" alt=\"z=s+b=2.1+0.1=2.2\" width=\"284.48\" height=\"18.96\" style=\"width:284.48px;height:18.96px;aspect-ratio:284.48/18.96\" loading=\"lazy\"></div>","<p>This is the preactivation. It is not yet the requested sigmoid output.</p>","<p class=\"worked-step\"><strong>Step 6: negate z for the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6ae6042702919060.svg\" alt=\"-z=-2.2\" width=\"113.19\" height=\"18.27\" style=\"width:113.19px;height:18.27px;aspect-ratio:113.19/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3e8120863f30069.svg\" alt=\"e^{-z}=e^{-2.2}\\approx0.110803158\" width=\"277.96\" height=\"23.60\" style=\"width:277.96px;height:23.60px;aspect-ratio:277.96/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:104.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/417b75e5d36172d1.svg\"><img class=\"math display-math\" src=\"assets/equations/72d833375eab0d1c.svg\" alt=\"1+e^{-z}=1+0.110803158=1.110803158\" width=\"442.16\" height=\"22.17\" style=\"width:442.16px;height:22.17px;aspect-ratio:442.16/22.17\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide one by that denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:155.40px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bc1ac01a29b10b0.svg\"><img class=\"math display-math\" src=\"assets/equations/7567a6adfafdbad0.svg\" alt=\"a=\\frac1{1+e^{-z}}=\\frac1{1.110803158}\\approx0.900249511\" width=\"467.09\" height=\"51.56\" style=\"width:467.09px;height:51.56px;aspect-ratio:467.09/51.56\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> sigmoid output ≈ 0.900249511. It lies between 0 and 1. The raw sum was 2.2, whereas the activated output is approximately 0.90025.</p>"],"kind":"practice","id":"tee-c10-s2","search":"MT1A Q2 **Question (3 marks).** A sigmoid neuron has inputs [2,1,3], weights [0.4,−0.2,0.5] and bias 0.1. Compute its output.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInputs x₁ = 2,x₂ = 1,x₃ = 3.\n\nMatching weights w₁ = 0.4,w₂ = −0.2,w₃ = 0.5.\n\nBias b = 0.1; activation = sigmoid.\n\n### To find\n\nCalculate net input z and activated output a.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**Sigmoid output.** The question specifies sigmoid, so turn the complete weighted sum into an output between 0 and 1. Negate z, evaluate the exponential, add 1, then take the reciprocal.\n\nz = sum before activation; a = sigmoid output; e ≈ 2.71828 is the exponential base.\n\n\n\n**Yaad rakhne ka cue:** Minus-z ki e power, plus one, phir one divided by whole denominator.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: multiply input 1 by weight 1.**\n\n\n**Step 2: multiply input 2 by weight 2.**\n\nThe minus sign belongs to the weight, so the contribution stays negative.\n\n**Step 3: multiply input 3 by weight 3.**\n\n\n**Step 4: add the three contributions.**\n\n\n**Step 5: add the bias once.**\n\nThis is the preactivation. It is not yet the requested sigmoid output.\n\n**Step 6: negate z for the exponential.**\n\n\n\n**Step 7: calculate the complete denominator.**\n\n\n**Step 8: divide one by that denominator.**\n\n**Final answer:** sigmoid output ≈ 0.900249511. It lies between 0 and 1. The raw sum was 2.2, whereas the activated output is approximately 0.90025.\n"},{"title":"MT1A Q3","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> For z = [−1,0,1], calculate sigmoid, softmax and Leaky ReLU with α = 0.01 (an explicit assumption because the paper does not give the slope).</p>"],"answer":["<h3>Given</h3>","<p>Scores z = [−1,0,1].</p>","<p>Calculate sigmoid, softmax and Leaky ReLU.</p>","<p>The paper omits the Leaky slope: α = 0.01 is the stated practice assumption.</p>","<h3>To find</h3>","<p>Calculate every component under each of the three activations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<p>Sigmoid is applied separately: σ(−1) = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/983a154bf3030fc0.svg\" alt=\"\\frac{1}{1+e^{1}}\" width=\"58.25\" height=\"40.75\" style=\"width:58.25px;height:40.75px;aspect-ratio:58.25/40.75\" loading=\"lazy\"></span> = 0.268941421; σ(0) = 1/2 = 0.5; σ(1) = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b1ad72f023278d5b.svg\" alt=\"\\frac{1}{1+e^{-1}}\" width=\"68.70\" height=\"40.75\" style=\"width:68.70px;height:40.75px;aspect-ratio:68.70/40.75\" loading=\"lazy\"></span> = 0.731058579.</p>","<p class=\"worked-step\"><strong>Step 1 stabilize: </strong> subtract the largest logit 1 from every value: [-2, -1, 0]. This does not change softmax.</p>","<p class=\"worked-step\"><strong>Step 2 exponentiate: </strong> exp values = [0.135335283, 0.367879441, 1].</p>","<p class=\"worked-step\"><strong>Step 3 denominator: </strong> sum = 1.503214724.</p>","<p class=\"worked-step\"><strong>Step 4 divide each value by this same sum: </strong> probabilities = <strong>[0.090030573, 0.244728471, 0.665240956]</strong>. <strong>Check: </strong> all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.</p>","<p>Leaky ReLU multiplies only negative values by α: [0.01 × (−1),0,1] = <strong>[−0.01,0,1]</strong>. Softmax normalizes the entire vector; independent sigmoid values need not sum to 1.</p>"],"kind":"practice","id":"tee-c10-s3","search":"MT1A Q3 **Question (3 marks).** For z = [−1,0,1], calculate sigmoid, softmax and Leaky ReLU with α = 0.01 (an explicit assumption because the paper does not give the slope).\n\n**Complete worked answer.**\n\n\n\n### Given\n\nScores z = [−1,0,1].\n\nCalculate sigmoid, softmax and Leaky ReLU.\n\nThe paper omits the Leaky slope: α = 0.01 is the stated practice assumption.\n\n### To find\n\nCalculate every component under each of the three activations.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n\nSigmoid is applied separately: σ(−1) = \\(\\frac{1}{1+e^{1}}\\) = 0.268941421; σ(0) = 1/2 = 0.5; σ(1) = \\(\\frac{1}{1+e^{-1}}\\) = 0.731058579.\n**Step 1 stabilize: ** subtract the largest logit 1 from every value: [-2, -1, 0]. This does not change softmax.\n\n**Step 2 exponentiate: ** exp values = [0.135335283, 0.367879441, 1].\n\n**Step 3 denominator: ** sum = 1.503214724.\n\n**Step 4 divide each value by this same sum: ** probabilities = **[0.090030573, 0.244728471, 0.665240956]**. **Check: ** all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.\nLeaky ReLU multiplies only negative values by α: [0.01 × (−1),0,1] = **[−0.01,0,1]**. Softmax normalizes the entire vector; independent sigmoid values need not sum to 1.\n"},{"title":"MT1A Q4","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Input x = [2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1]; W₂ is shown below; b₂ = [0.2]. Hidden and output activations are ReLU. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_bbb5f79ed7.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_bbb5f79ed7.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"210\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [2].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.2].</p>","<p>Hidden and output activations are ReLU.</p>","<p>Target y = [1].</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.90px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/11165a2e9ad9cccb.svg\"><img class=\"math display-math\" src=\"assets/equations/aac90742e2057dd1.svg\" alt=\"z_{h_1} = (0.5 \\times  2) + (0.1) = 1.1\" width=\"299.71\" height=\"24.58\" style=\"width:299.71px;height:24.58px;aspect-ratio:299.71/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51f4d0c29cd3e471.svg\" alt=\"h_{1} = \\max(0,1.1) = 1.1\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.34px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ef13baba40338fd0.svg\"><img class=\"math display-math\" src=\"assets/equations/7f3c69d6493dcb74.svg\" alt=\"z_{o_1} = (0.8 \\times  1.1) + (0.2) = 1.08\" width=\"329.37\" height=\"24.58\" style=\"width:329.37px;height:24.58px;aspect-ratio:329.37/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/965f3f37dce04d5d.svg\" alt=\"o_{1} = \\max(0,1.08) = 1.08\" width=\"262.14\" height=\"24.43\" style=\"width:262.14px;height:24.43px;aspect-ratio:262.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> The question specifies half squared loss. No learning rate is supplied, so report gradients, not invented weight updates.</p>","<p>Prediction minus target = [0.08]. Squared errors = [0.0064]. Half-sum squared loss = 0.0032; mean squared error = 0.0064. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/156b50e8d480457c.svg\"><img class=\"math display-math\" src=\"assets/equations/71054ce9ec8e2e00.svg\" alt=\"\\delta_{o_1} = 1 \\times  (1.08-1) \\times  1 = 0.08\" width=\"326.13\" height=\"24.58\" style=\"width:326.13px;height:24.58px;aspect-ratio:326.13/24.58\" loading=\"lazy\"></picture></div>","<p>The ReLU derivative is 1 here because this preactivation is positive.</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">1.1</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.08</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.088</strong><span class=\"lv-detail\">h1 → o1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.91px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/58dabafbc78878c9.svg\"><img class=\"math display-math\" src=\"assets/equations/4f9573bd5025e29a.svg\" alt=\"g_{1,1}^{(2)}=(0.08)\\times(1.1)\\approx 0.088\" width=\"299.16\" height=\"36.54\" style=\"width:299.16px;height:36.54px;aspect-ratio:299.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.08</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.8</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.064</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.064</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:203.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/234bc238f68f3454.svg\"><img class=\"math display-math\" src=\"assets/equations/8d62e6bfc12bb1ba.svg\" alt=\"C_1=(0.8)\\times(0.08)\\approx 0.064\" width=\"291.52\" height=\"24.43\" style=\"width:291.52px;height:24.43px;aspect-ratio:291.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/37af0a1e41171eca.svg\" alt=\"\\text{Sum}=C_1\\approx 0.064\" width=\"196.50\" height=\"20.89\" style=\"width:196.50px;height:20.89px;aspect-ratio:196.50/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b10ee7f796aaf918.svg\" alt=\"\\delta_{h_1} = 0.064 \\times  1 = 0.064\" width=\"248.95\" height=\"23.78\" style=\"width:248.95px;height:23.78px;aspect-ratio:248.95/23.78\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.064</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.128</strong><span class=\"lv-detail\">x1 → h1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.12px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/12beed29e7a45da4.svg\"><img class=\"math display-math\" src=\"assets/equations/a8c9a6cdcee54a64.svg\" alt=\"g_{1,1}^{(1)}=(0.064)\\times(2)\\approx 0.128\" width=\"292.37\" height=\"36.54\" style=\"width:292.37px;height:36.54px;aspect-ratio:292.37/36.54\" loading=\"lazy\"></picture></div>","<p><strong>Requested answers: </strong> dL/dw₂ = <strong>0.088</strong> and dL/db₂ = <strong>0.08</strong>. Hidden gradients above explain the dependency and are additional practice.</p>"],"kind":"practice","id":"tee-c10-s4","search":"MT1A Q4 **Question (3 marks).** Input x = [2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1]; W₂ is shown below; b₂ = [0.2]. Hidden and output activations are ReLU. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [2].\n\nW₁ is printed with the question.\n\nb₁ = [0.1].\n\nW₂ is printed with the question.\n\nb₂ = [0.2].\n\nHidden and output activations are ReLU.\n\nTarget y = [1].\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** The question specifies half squared loss. No learning rate is supplied, so report gradients, not invented weight updates.\nPrediction minus target = [0.08]. Squared errors = [0.0064]. Half-sum squared loss = 0.0032; mean squared error = 0.0064. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe ReLU derivative is 1 here because this preactivation is positive.\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (0.08) × 1.1 = 0.088.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n**Hidden 1 downstream contribution:**\n\n\n**Step 5 input weights.** Multiply the hidden delta by the corresponding raw input, not by the hidden output.\nx1 → h1: gradient = (0.064) × (2) = 0.128.\n**Requested answers: ** dL/dw₂ = **0.088** and dL/db₂ = **0.08**. Hidden gradients above explain the dependency and are additional practice.\n"},{"title":"MT1B Q1a","question":["<p class=\"inline-question\"><strong>Question (2 marks).</strong> State two motivations for using deep learning.</p>"],"answer":["<p>First, deep networks can learn useful representations directly from complex data such as images and speech, reducing dependence on manually engineered features. Second, multiple nonlinear layers can model complicated patterns and relationships when suitable data, computation and training are available. Example: a CNN can learn edges, parts and object features at successive levels.</p>"],"kind":"practice","id":"tee-c10-s5","search":"MT1B Q1a **Question (2 marks).** State two motivations for using deep learning.\n\n**Complete worked answer.**\nFirst, deep networks can learn useful representations directly from complex data such as images and speech, reducing dependence on manually engineered features. Second, multiple nonlinear layers can model complicated patterns and relationships when suitable data, computation and training are available. Example: a CNN can learn edges, parts and object features at successive levels.\n"},{"title":"MT1B Q1b","question":["<p class=\"inline-question\"><strong>Question (2 marks).</strong> Differentiate machine learning and deep learning with respect to feature extraction and data requirements.</p>"],"answer":["<p>Traditional machine-learning pipelines often rely on manually selected or engineered features; deep networks often learn feature representations jointly with the task. Training a large deep network from scratch commonly needs more data than simpler models. However, pretrained deep features can be useful even with a small target dataset. These are practical tendencies, not absolute definitions.</p>"],"kind":"practice","id":"tee-c10-s6","search":"MT1B Q1b **Question (2 marks).** Differentiate machine learning and deep learning with respect to feature extraction and data requirements.\n\n**Complete worked answer.**\nTraditional machine-learning pipelines often rely on manually selected or engineered features; deep networks often learn feature representations jointly with the task. Training a large deep network from scratch commonly needs more data than simpler models. However, pretrained deep features can be useful even with a small target dataset. These are practical tendencies, not absolute definitions.\n"},{"title":"MT1B Q2","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Show how a perceptron with w₁ = w₂ = 0.6 and bias −0.8 implements AND.</p>"],"answer":["<h3>Given</h3>","<p>Binary inputs 00,01,10,11.</p>","<p>w₁ = w₂ = 0.6; b = −0.8; output 1 when net ≥ 0.</p>","<h3>To find</h3>","<p>Calculate all four net values and outputs to show AND.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<h3>Input (0, 0)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e725afda84fc9ed3.svg\" alt=\"s=0+0=0\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d15ca461c07dd695.svg\" alt=\"z=0+(-0.8)=-0.8\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.8; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (0, 1)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8544b9e49d354ea3.svg\" alt=\"s=0+0.6=0.6\" width=\"181.17\" height=\"18.27\" style=\"width:181.17px;height:18.27px;aspect-ratio:181.17/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f10c0127832440d1.svg\" alt=\"z=0.6+(-0.8)=-0.2\" width=\"257.12\" height=\"24.43\" style=\"width:257.12px;height:24.43px;aspect-ratio:257.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.2; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (1, 0)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4145d1d293ebdf3.svg\" alt=\"0.6(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5398d7a271c52472.svg\" alt=\"s=0.6+0=0.6\" width=\"181.17\" height=\"18.27\" style=\"width:181.17px;height:18.27px;aspect-ratio:181.17/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f10c0127832440d1.svg\" alt=\"z=0.6+(-0.8)=-0.2\" width=\"257.12\" height=\"24.43\" style=\"width:257.12px;height:24.43px;aspect-ratio:257.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.2; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (1, 1)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6eb084da38b1ada3.svg\" alt=\"0.6(1)=0.6\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/379a82d19e479abf.svg\" alt=\"s=0.6+0.6=1.2\" width=\"200.18\" height=\"18.27\" style=\"width:200.18px;height:18.27px;aspect-ratio:200.18/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/63a2763d058f9aec.svg\" alt=\"z=1.2+(-0.8)=0.4\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = 0.4; output = 1 because output is 1 exactly when z ≥ 0.</p>","<p><strong>Final answer:</strong> outputs are [0, 0, 0, 1] for inputs 00, 01, 10, 11: exactly AND.</p>"],"kind":"practice","id":"tee-c10-s7","search":"MT1B Q2 **Question (3 marks).** Show how a perceptron with w₁ = w₂ = 0.6 and bias −0.8 implements AND.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nBinary inputs 00,01,10,11.\n\nw₁ = w₂ = 0.6; b = −0.8; output 1 when net ≥ 0.\n\n### To find\n\nCalculate all four net values and outputs to show AND.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\n### Input (0, 0)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.8; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (0, 1)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.2; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (1, 0)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.2; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (1, 1)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = 0.4; output = 1 because output is 1 exactly when z ≥ 0.\n\n**Final answer:** outputs are [0, 0, 0, 1] for inputs 00, 01, 10, 11: exactly AND.\n\n\n"},{"title":"MT1B Q3","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Calculate sigmoid, ReLU and tanh for z = [−2,0,2].</p>"],"answer":["<h3>Given</h3>","<p>Input scores = [−2,0,2].</p>","<p>Required activations: sigmoid, ReLU and tanh.</p>","<h3>To find</h3>","<p>Calculate all three activation outputs for each score.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<p><strong>Tanh and its slope.</strong> Tanh preserves a signed output between −1 and 1. Once its output a is known, the local slope is 1−a².</p>","<p>z = value entering tanh; a = its output. A prime means derivative, or local rate of change.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11b2c40e39b0ee66.svg\" alt=\"a=\\tanh z=\\frac{e^z-e^{-z}}{e^z+e^{-z}}\" width=\"239.38\" height=\"54.23\" style=\"width:239.38px;height:54.23px;aspect-ratio:239.38/54.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b6ac5e0c1df9b26.svg\" alt=\"\\frac{da}{dz}=1-a^2\" width=\"134.64\" height=\"50.50\" style=\"width:134.64px;height:50.50px;aspect-ratio:134.64/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh signed output deta hai; slope = 1 minus output ka square.</p>","<h3>Solution — step by step</h3>","<h3>Preactivation z = -2</h3>","<p class=\"worked-step\"><strong>Step 1: negate z for sigmoid.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baed17557936141e.svg\" alt=\"-z=2\" width=\"75.18\" height=\"18.27\" style=\"width:75.18px;height:18.27px;aspect-ratio:75.18/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ee2ca92f60ab98c1.svg\" alt=\"e^{-z}\\approx7.389056099\" width=\"196.44\" height=\"20.70\" style=\"width:196.44px;height:20.70px;aspect-ratio:196.44/20.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one to form the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c833999cba87b62d.svg\"><img class=\"math display-math\" src=\"assets/equations/16b7ac365fcbbf5e.svg\" alt=\"1+7.389056099=8.389056099\" width=\"332.60\" height=\"18.52\" style=\"width:332.60px;height:18.52px;aspect-ratio:332.60/18.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: take the reciprocal for sigmoid.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.49px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c492fd878121169c.svg\"><img class=\"math display-math\" src=\"assets/equations/610916657193c755.svg\" alt=\"\\sigma(-2)=\\frac1{8.389056099}\\approx0.119202922\" width=\"398.03\" height=\"50.09\" style=\"width:398.03px;height:50.09px;aspect-ratio:398.03/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: compare z with zero for ReLU.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eb663510f8ab435b.svg\"><img class=\"math display-math\" src=\"assets/equations/31ec7384f72f0b9e.svg\" alt=\"\\mathrm{ReLU}(-2)=\\max(0,-2)=0\" width=\"308.85\" height=\"24.43\" style=\"width:308.85px;height:24.43px;aspect-ratio:308.85/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: calculate the tanh numerator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d6baa3ddebec66e.svg\"><img class=\"math display-math\" src=\"assets/equations/efa746faa7f9257e.svg\" alt=\"e^{-2}-e^{2}\\approx0.135335283-7.389056099=-7.253720816\" width=\"588.36\" height=\"23.60\" style=\"width:588.36px;height:23.60px;aspect-ratio:588.36/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: calculate the tanh denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee253631806c17e2.svg\"><img class=\"math display-math\" src=\"assets/equations/8e33913f50550c4f.svg\" alt=\"e^{-2}+e^{2}\\approx0.135335283+7.389056099=7.524391382\" width=\"569.35\" height=\"23.60\" style=\"width:569.35px;height:23.60px;aspect-ratio:569.35/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide for tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.31px;--narrow-height:128.52px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4bb67612e76e38e6.svg\"><img class=\"math display-math\" src=\"assets/equations/5a3af3ace5989f73.svg\" alt=\"\\tanh(-2)\\approx\\frac{-7.253720816}{7.524391382}\\approx-0.964027580\" width=\"471.00\" height=\"50.34\" style=\"width:471.00px;height:50.34px;aspect-ratio:471.00/50.34\" loading=\"lazy\"></picture></div>","<h3>Preactivation z = 0</h3>","<p class=\"worked-step\"><strong>Step 1: negate z for sigmoid.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3aebd020c0eccec6.svg\" alt=\"-z=0\" width=\"75.18\" height=\"18.27\" style=\"width:75.18px;height:18.27px;aspect-ratio:75.18/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f5ab9de96f693147.svg\" alt=\"e^{-z}\\approx1.000000000\" width=\"196.44\" height=\"20.70\" style=\"width:196.44px;height:20.70px;aspect-ratio:196.44/20.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one to form the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29756201dd5e46c6.svg\"><img class=\"math display-math\" src=\"assets/equations/aa21aa600ebc8e6e.svg\" alt=\"1+1.000000000=2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: take the reciprocal for sigmoid.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.48px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc3feba9268d5c6f.svg\"><img class=\"math display-math\" src=\"assets/equations/e2631bc2ce7ebc9e.svg\" alt=\"\\sigma(0)=\\frac1{2.000000000}\\approx0.500000000\" width=\"379.03\" height=\"50.09\" style=\"width:379.03px;height:50.09px;aspect-ratio:379.03/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: compare z with zero for ReLU.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8512edeebdecaad0.svg\" alt=\"\\mathrm{ReLU}(0)=\\max(0,0)=0\" width=\"270.82\" height=\"24.43\" style=\"width:270.82px;height:24.43px;aspect-ratio:270.82/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: calculate the tanh numerator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2df025bea6def52b.svg\"><img class=\"math display-math\" src=\"assets/equations/d9a65f4b4641a1c1.svg\" alt=\"e^{0}-e^{0}\\approx1.000000000-1.000000000=0.000000000\" width=\"555.91\" height=\"23.60\" style=\"width:555.91px;height:23.60px;aspect-ratio:555.91/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: calculate the tanh denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c3fb9efcb35a389.svg\"><img class=\"math display-math\" src=\"assets/equations/f1f2e3760e822d0f.svg\" alt=\"e^{0}+e^{0}\\approx1.000000000+1.000000000=2.000000000\" width=\"555.91\" height=\"23.60\" style=\"width:555.91px;height:23.60px;aspect-ratio:555.91/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide for tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.42px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3179ee482059cbdd.svg\"><img class=\"math display-math\" src=\"assets/equations/6b66e253736ed179.svg\" alt=\"\\tanh(0)\\approx\\frac{0.000000000}{2.000000000}\\approx0.000000000\" width=\"413.97\" height=\"50.09\" style=\"width:413.97px;height:50.09px;aspect-ratio:413.97/50.09\" loading=\"lazy\"></picture></div>","<h3>Preactivation z = 2</h3>","<p class=\"worked-step\"><strong>Step 1: negate z for sigmoid.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e116d9c93aba3d51.svg\" alt=\"-z=-2\" width=\"94.19\" height=\"18.27\" style=\"width:94.19px;height:18.27px;aspect-ratio:94.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/63363cd12105c12d.svg\" alt=\"e^{-z}\\approx0.135335283\" width=\"196.44\" height=\"20.70\" style=\"width:196.44px;height:20.70px;aspect-ratio:196.44/20.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one to form the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4e918224e5cd8eaa.svg\"><img class=\"math display-math\" src=\"assets/equations/cec6cfa7eb635dc5.svg\" alt=\"1+0.135335283=1.135335283\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: take the reciprocal for sigmoid.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.48px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b29d72f7254a4877.svg\"><img class=\"math display-math\" src=\"assets/equations/398e028b924c49e3.svg\" alt=\"\\sigma(2)=\\frac1{1.135335283}\\approx0.880797078\" width=\"379.03\" height=\"50.09\" style=\"width:379.03px;height:50.09px;aspect-ratio:379.03/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: compare z with zero for ReLU.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c454b416d112784d.svg\" alt=\"\\mathrm{ReLU}(2)=\\max(0,2)=2\" width=\"270.82\" height=\"24.43\" style=\"width:270.82px;height:24.43px;aspect-ratio:270.82/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: calculate the tanh numerator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/beea5fae2dfeb83f.svg\"><img class=\"math display-math\" src=\"assets/equations/03ff82884c1feede.svg\" alt=\"e^{2}-e^{-2}\\approx7.389056099-0.135335283=7.253720816\" width=\"569.35\" height=\"23.60\" style=\"width:569.35px;height:23.60px;aspect-ratio:569.35/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: calculate the tanh denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.97px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/597fbd34bf357417.svg\"><img class=\"math display-math\" src=\"assets/equations/54c21815de76e465.svg\" alt=\"e^{2}+e^{-2}\\approx7.389056099+0.135335283=7.524391382\" width=\"569.35\" height=\"23.60\" style=\"width:569.35px;height:23.60px;aspect-ratio:569.35/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide for tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.42px;--narrow-height:89.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c415e8a033259d4.svg\"><img class=\"math display-math\" src=\"assets/equations/99823d0144ee439b.svg\" alt=\"\\tanh(2)\\approx\\frac{7.253720816}{7.524391382}\\approx0.964027580\" width=\"413.97\" height=\"50.34\" style=\"width:413.97px;height:50.34px;aspect-ratio:413.97/50.34\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> sigmoid = [0.119202922, 0.5, 0.880797078]; ReLU = [0, 0, 2]; tanh = [−0.964027580, 0, 0.964027580].</p>"],"kind":"practice","id":"tee-c10-s8","search":"MT1B Q3 **Question (3 marks).** Calculate sigmoid, ReLU and tanh for z = [−2,0,2].\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput scores = [−2,0,2].\n\nRequired activations: sigmoid, ReLU and tanh.\n\n### To find\n\nCalculate all three activation outputs for each score.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n**Tanh and its slope.** Tanh preserves a signed output between −1 and 1. Once its output a is known, the local slope is 1−a².\n\nz = value entering tanh; a = its output. A prime means derivative, or local rate of change.\n\n\n\n\n\n**Yaad rakhne ka cue:** Tanh signed output deta hai; slope = 1 minus output ka square.\n\n### Solution — step by step\n\n\n\n\n\n\n### Preactivation z = -2\n\n**Step 1: negate z for sigmoid.**\n\n\n\n\n\n\n\n**Step 2: evaluate the exponential.**\n\n\n\n\n\n\n\n**Step 3: add one to form the denominator.**\n\n\n\n\n\n\n\n**Step 4: take the reciprocal for sigmoid.**\n\n\n\n\n\n\n\n**Step 5: compare z with zero for ReLU.**\n\n\n\n\n\n\n\n**Step 6: calculate the tanh numerator.**\n\n\n\n\n\n\n\n**Step 7: calculate the tanh denominator.**\n\n\n\n\n\n\n\n**Step 8: divide for tanh.**\n\n\n\n\n\n\n\n\n### Preactivation z = 0\n\n**Step 1: negate z for sigmoid.**\n\n\n\n\n\n\n\n**Step 2: evaluate the exponential.**\n\n\n\n\n\n\n\n**Step 3: add one to form the denominator.**\n\n\n\n\n\n\n\n**Step 4: take the reciprocal for sigmoid.**\n\n\n\n\n\n\n\n**Step 5: compare z with zero for ReLU.**\n\n\n\n\n\n\n\n**Step 6: calculate the tanh numerator.**\n\n\n\n\n\n\n\n**Step 7: calculate the tanh denominator.**\n\n\n\n\n\n\n\n**Step 8: divide for tanh.**\n\n\n\n\n\n\n\n\n### Preactivation z = 2\n\n**Step 1: negate z for sigmoid.**\n\n\n\n\n\n\n\n**Step 2: evaluate the exponential.**\n\n\n\n\n\n\n\n**Step 3: add one to form the denominator.**\n\n\n\n\n\n\n\n**Step 4: take the reciprocal for sigmoid.**\n\n\n\n\n\n\n\n**Step 5: compare z with zero for ReLU.**\n\n\n\n\n\n\n\n**Step 6: calculate the tanh numerator.**\n\n\n\n\n\n\n\n**Step 7: calculate the tanh denominator.**\n\n\n\n\n\n\n\n**Step 8: divide for tanh.**\n\n\n\n\n\n\n\n**Final answer:** sigmoid = [0.119202922, 0.5, 0.880797078]; ReLU = [0, 0, 2]; tanh = [−0.964027580, 0, 0.964027580].\n"},{"title":"MT1B Q4","question":["<p class=\"inline-question\"><strong>Question (3 marks).</strong> Input x = [3]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are sigmoid. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_ec03263237.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_ec03263237.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"210\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [3].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.1].</p>","<p>Hidden and output activations are sigmoid.</p>","<p>Target y = [1].</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.90px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/624d0aa704cb40ed.svg\"><img class=\"math display-math\" src=\"assets/equations/8d4aa9c483de249e.svg\" alt=\"z_{h_1} = (0.4 \\times  3) + (0.2) = 1.4\" width=\"299.71\" height=\"24.58\" style=\"width:299.71px;height:24.58px;aspect-ratio:299.71/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c20e39027aee1353.svg\"><img class=\"math display-math\" src=\"assets/equations/eddfa3ffedc7ea27.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(1.4)}}=0.802183889\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f73d73bef40a3e53.svg\"><img class=\"math display-math\" src=\"assets/equations/6ee49ebab88ca242.svg\" alt=\"z_{o_1} = (0.6 \\times  0.802183889) + (0.1) = 0.581310333\" width=\"512.62\" height=\"24.58\" style=\"width:512.62px;height:24.58px;aspect-ratio:512.62/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72c83495e26a383d.svg\"><img class=\"math display-math\" src=\"assets/equations/909595bd0fd39ab1.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.581310333)}}=0.641368858\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> Use the half squared loss stated in this question. No learning rate is supplied.</p>","<p>Prediction minus target = [-0.358631142]. Squared errors = [0.128616296]. Half-sum squared loss = 0.064308148; mean squared error = 0.128616296. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4b919c902c0118b6.svg\"><img class=\"math display-math\" src=\"assets/equations/cee1321a8d736f56.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.641368858-1) \\times  0.230014846 = -0.082490487\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.802183889</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.082490487</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.066172539</strong><span class=\"lv-detail\">h1 → o1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/275f10a4f3768fee.svg\"><img class=\"math display-math\" src=\"assets/equations/79c1b8202fcf991a.svg\" alt=\"g_{1,1}^{(2)}=(-0.082490487)\\times(0.802183889)\\approx -0.066172539\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.082490487</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.6</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.049494292</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.049494292</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d8c0fdc1c33b51f1.svg\"><img class=\"math display-math\" src=\"assets/equations/8e21ad6a02297b75.svg\" alt=\"C_1=(0.6)\\times(-0.082490487)\\approx -0.049494292\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8e5ced5b8d72aefa.svg\"><img class=\"math display-math\" src=\"assets/equations/569b8ebcbf1272c9.svg\" alt=\"\\text{Sum}=C_1\\approx -0.049494292\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d94f5a36d64f33c1.svg\"><img class=\"math display-math\" src=\"assets/equations/059d2cfd4db853f1.svg\" alt=\"\\delta_{h_1} = -0.049494292 \\times  0.158684897 = -0.007853997\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">3</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.007853997</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.02356199</strong><span class=\"lv-detail\">x1 → h1</span></div></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8fbb5c252349f4b6.svg\"><img class=\"math display-math\" src=\"assets/equations/d7d37c7aaeaeb2f8.svg\" alt=\"g_{1,1}^{(1)}=(-0.007853997)\\times(3)\\approx -0.02356199\" width=\"464.77\" height=\"36.54\" style=\"width:464.77px;height:36.54px;aspect-ratio:464.77/36.54\" loading=\"lazy\"></picture></div>","<p><strong>Requested answers: </strong> dL/dw₂ = <strong>−0.066172539</strong>; dL/db₂ = <strong>−0.082490487</strong>. Negative gradients mean ordinary gradient descent would increase those parameters.</p>"],"kind":"practice","id":"tee-c10-s9","search":"MT1B Q4 **Question (3 marks).** Input x = [3]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are sigmoid. Target y = [1]. Use L = ½(o−y)². Calculate the gradients of the output weight and output bias.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [3].\n\nW₁ is printed with the question.\n\nb₁ = [0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.1].\n\nHidden and output activations are sigmoid.\n\nTarget y = [1].\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** Use the half squared loss stated in this question. No learning rate is supplied.\nPrediction minus target = [-0.358631142]. Squared errors = [0.128616296]. Half-sum squared loss = 0.064308148; mean squared error = 0.128616296. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe derivative is o(1−o).\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (-0.082490487) × 0.802183889 = -0.066172539.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n**Hidden 1 downstream contribution:**\n\n\n**Step 5 input weights.** Multiply the hidden delta by the corresponding raw input, not by the hidden output.\nx1 → h1: gradient = (-0.007853997) × (3) = -0.02356199.\n**Requested answers: ** dL/dw₂ = **−0.066172539**; dL/db₂ = **−0.082490487**. Negative gradients mean ordinary gradient descent would increase those parameters.\n"},{"title":"Teacher vectorized ReLU example","blocks":["<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_handwritten.svg\" aria-label=\"Enlarge diagram: The teacher vectorized example with its exact connections\"><img src=\"assets/figures/net_handwritten.svg\" alt=\"The teacher vectorized example with its exact connections\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>The teacher vectorized example with its exact connections <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"inline-question\"><strong>Question.</strong> Input x = [2, 3]. Each row below lists the incoming weights of one receiving neuron. W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/386eee5b3bdd13ab.svg\" alt=\"\\begin{bmatrix}0.11 &amp; 0.21\\\\0.12 &amp; 0.08\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>; b₁ = [0, 0]; W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/d33649adcaa2e9c5.svg\" alt=\"\\begin{bmatrix}0.14 &amp; 0.15\\end{bmatrix}\" width=\"97.15\" height=\"19.00\" style=\"width:97.15px;height:19.00px;aspect-ratio:97.15/19.00\" loading=\"lazy\"></span>; b₂ = [0]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.05. Use half squared loss and perform forward and backward passes.</p>","<h3>Given</h3>","<p>Input x = [2, 3].</p>","<p>W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/386eee5b3bdd13ab.svg\" alt=\"\\begin{bmatrix}0.11 &amp; 0.21\\\\0.12 &amp; 0.08\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>.</p>","<p>b₁ = [0, 0].</p>","<p>W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/d33649adcaa2e9c5.svg\" alt=\"\\begin{bmatrix}0.14 &amp; 0.15\\end{bmatrix}\" width=\"97.15\" height=\"19.00\" style=\"width:97.15px;height:19.00px;aspect-ratio:97.15/19.00\" loading=\"lazy\"></span>.</p>","<p>b₂ = [0].</p>","<p>Hidden and output activations are ReLU.</p>","<p>Target y = [1].</p>","<p>Learning rate η = 0.05.</p>","<p>Use half squared loss and perform forward and backward passes.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.51px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/89d0bf0bfbd0eee8.svg\"><img class=\"math display-math\" src=\"assets/equations/977db4dfa37a6afe.svg\" alt=\"z_{h_1} = (0.11 \\times  2) + (0.21 \\times  3) + (0) = 0.85\" width=\"439.55\" height=\"24.58\" style=\"width:439.55px;height:24.58px;aspect-ratio:439.55/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86a3de78168e02c1.svg\" alt=\"h_{1} = \\max(0,0.85) = 0.85\" width=\"264.36\" height=\"24.43\" style=\"width:264.36px;height:24.43px;aspect-ratio:264.36/24.43\" loading=\"lazy\"></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.51px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/71f2cfea44a277ff.svg\"><img class=\"math display-math\" src=\"assets/equations/ae9a1b94e41b8118.svg\" alt=\"z_{h_2} = (0.12 \\times  2) + (0.08 \\times  3) + (0) = 0.48\" width=\"439.55\" height=\"24.58\" style=\"width:439.55px;height:24.58px;aspect-ratio:439.55/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5c17f7904703c18.svg\" alt=\"h_{2} = \\max(0,0.48) = 0.48\" width=\"264.36\" height=\"24.43\" style=\"width:264.36px;height:24.43px;aspect-ratio:264.36/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.74px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30c6287eca7be224.svg\"><img class=\"math display-math\" src=\"assets/equations/c5d0ce28abb02731.svg\" alt=\"z_{o_1} = (0.14 \\times  0.85) + (0.15 \\times  0.48) + (0) = 0.191\" width=\"512.64\" height=\"24.58\" style=\"width:512.64px;height:24.58px;aspect-ratio:512.64/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0510bc5bdad8a8b2.svg\" alt=\"o_{1} = \\max(0,0.191) = 0.191\" width=\"286.58\" height=\"24.43\" style=\"width:286.58px;height:24.43px;aspect-ratio:286.58/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.809]. Squared errors = [0.654481]. Half-sum squared loss = 0.3272405; mean squared error = 0.654481. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.23px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0231cff1e5d205d.svg\"><img class=\"math display-math\" src=\"assets/equations/24763fc6860afd3e.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.191-1) \\times  1 = -0.809\" width=\"369.58\" height=\"24.58\" style=\"width:369.58px;height:24.58px;aspect-ratio:369.58/24.58\" loading=\"lazy\"></picture></div>","<p>The ReLU derivative is 1 here because this preactivation is positive.</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.85</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.809</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.68765</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.14</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.1743825</strong></div></div><p>Subtract η × gradient = <b>−0.0343825</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.35px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7b158dc1aab8c85.svg\"><img class=\"math display-math\" src=\"assets/equations/e7ee971a6dfd8bcc.svg\" alt=\"g_{1,1}^{(2)}=(-0.809)\\times(0.85)\\approx -0.68765\" width=\"386.05\" height=\"36.54\" style=\"width:386.05px;height:36.54px;aspect-ratio:386.05/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5a6b892831ec0aa5.svg\"><img class=\"math display-math\" src=\"assets/equations/a1a6aafaa6af94cf.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.14-0.05(-0.68765)\\approx 0.1743825\" width=\"486.30\" height=\"36.54\" style=\"width:486.30px;height:36.54px;aspect-ratio:486.30/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.48</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.809</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.38832</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.169416</strong></div></div><p>Subtract η × gradient = <b>−0.019416</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.35px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d09d2ce4b3621339.svg\"><img class=\"math display-math\" src=\"assets/equations/289592bf5d88c4d2.svg\" alt=\"g_{1,2}^{(2)}=(-0.809)\\times(0.48)\\approx -0.38832\" width=\"386.05\" height=\"36.54\" style=\"width:386.05px;height:36.54px;aspect-ratio:386.05/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/780b675c44e8ec0a.svg\"><img class=\"math display-math\" src=\"assets/equations/ae18879446b6ea9d.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.15-0.05(-0.38832)\\approx 0.169416\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.809</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.14</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.11326</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.11326</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9be822c811879a17.svg\"><img class=\"math display-math\" src=\"assets/equations/53405206a97657fd.svg\" alt=\"C_1=(0.14)\\times(-0.809)\\approx -0.11326\" width=\"378.42\" height=\"24.43\" style=\"width:378.42px;height:24.43px;aspect-ratio:378.42/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e31db28d376c594d.svg\" alt=\"\\text{Sum}=C_1\\approx -0.11326\" width=\"239.93\" height=\"20.89\" style=\"width:239.93px;height:20.89px;aspect-ratio:239.93/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.15px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0406bf395ccea595.svg\"><img class=\"math display-math\" src=\"assets/equations/ce1e6b90f6c99a43.svg\" alt=\"\\delta_{h_1} = -0.11326 \\times  1 = -0.11326\" width=\"335.84\" height=\"23.78\" style=\"width:335.84px;height:23.78px;aspect-ratio:335.84/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.809</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.12135</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.12135</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/628dab575705c1e4.svg\"><img class=\"math display-math\" src=\"assets/equations/1763bcb69a11b8d9.svg\" alt=\"C_1=(0.15)\\times(-0.809)\\approx -0.12135\" width=\"378.42\" height=\"24.43\" style=\"width:378.42px;height:24.43px;aspect-ratio:378.42/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f74169ed59976f22.svg\" alt=\"\\text{Sum}=C_1\\approx -0.12135\" width=\"239.93\" height=\"20.89\" style=\"width:239.93px;height:20.89px;aspect-ratio:239.93/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.15px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/73149a9e0e57e742.svg\"><img class=\"math display-math\" src=\"assets/equations/bff8528433d7519f.svg\" alt=\"\\delta_{h_2} = -0.12135 \\times  1 = -0.12135\" width=\"335.84\" height=\"23.78\" style=\"width:335.84px;height:23.78px;aspect-ratio:335.84/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.11326</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.22652</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.11</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.121326</strong></div></div><p>Subtract η × gradient = <b>−0.011326</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6540c5b7941f90d3.svg\"><img class=\"math display-math\" src=\"assets/equations/d4fe1c7bccab7769.svg\" alt=\"g_{1,1}^{(1)}=(-0.11326)\\times(2)\\approx -0.22652\" width=\"379.25\" height=\"36.54\" style=\"width:379.25px;height:36.54px;aspect-ratio:379.25/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/857c0ad228d64fc5.svg\"><img class=\"math display-math\" src=\"assets/equations/f709770d92b5a6d7.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.11-0.05(-0.22652)\\approx 0.121326\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.11326</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.33978</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.21</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.226989</strong></div></div><p>Subtract η × gradient = <b>−0.016989</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93e0a3007b972754.svg\"><img class=\"math display-math\" src=\"assets/equations/851d3df89190bcd1.svg\" alt=\"g_{1,2}^{(1)}=(-0.11326)\\times(3)\\approx -0.33978\" width=\"379.25\" height=\"36.54\" style=\"width:379.25px;height:36.54px;aspect-ratio:379.25/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3e18578432e574df.svg\"><img class=\"math display-math\" src=\"assets/equations/5a3350f101c32e1b.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.21-0.05(-0.33978)\\approx 0.226989\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.12135</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.2427</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.12</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.132135</strong></div></div><p>Subtract η × gradient = <b>−0.012135</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5d0a80d06a8382c.svg\"><img class=\"math display-math\" src=\"assets/equations/80079b2d3df7b0fb.svg\" alt=\"g_{2,1}^{(1)}=(-0.12135)\\times(2)\\approx -0.2427\" width=\"367.04\" height=\"36.54\" style=\"width:367.04px;height:36.54px;aspect-ratio:367.04/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:179.22px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f91b7787569a2882.svg\"><img class=\"math display-math\" src=\"assets/equations/ce1785dad16e9ba5.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.12-0.05(-0.2427)\\approx 0.132135\" width=\"461.87\" height=\"36.54\" style=\"width:461.87px;height:36.54px;aspect-ratio:461.87/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.12135</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.36405</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.08</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.0982025</strong></div></div><p>Subtract η × gradient = <b>−0.0182025</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.56px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f8d27aa1e3f5627.svg\"><img class=\"math display-math\" src=\"assets/equations/a1b23a6eb1610029.svg\" alt=\"g_{2,2}^{(1)}=(-0.12135)\\times(3)\\approx -0.36405\" width=\"379.25\" height=\"36.54\" style=\"width:379.25px;height:36.54px;aspect-ratio:379.25/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6cd428530ca786f9.svg\"><img class=\"math display-math\" src=\"assets/equations/5d899a39e45c0338.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.08-0.05(-0.36405)\\approx 0.0982025\" width=\"486.30\" height=\"36.54\" style=\"width:486.30px;height:36.54px;aspect-ratio:486.30/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2bb2563809fc624e.svg\"><img class=\"math display-math\" src=\"assets/equations/6a689b75bd65601f.svg\" alt=\"b_{h_1,\\mathrm{new}}=0-0.05(-0.113260000)=0.005663000\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2db77709ff0c80b8.svg\"><img class=\"math display-math\" src=\"assets/equations/1a16f67956817315.svg\" alt=\"b_{h_2,\\mathrm{new}}=0-0.05(-0.121350000)=0.006067500\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a95d59624552356.svg\"><img class=\"math display-math\" src=\"assets/equations/f01c357a6fdbd536.svg\" alt=\"b_{o_1,\\mathrm{new}}=0-0.05(-0.809000000)=0.040450000\" width=\"509.64\" height=\"25.35\" style=\"width:509.64px;height:25.35px;aspect-ratio:509.64/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Correction to the handwritten working: </strong> the hidden deltas are negative (−0.11326 and −0.12135). A positive value at that step is a sign error. Keep output error as prediction minus target throughout.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c10-s10","search":"Teacher vectorized ReLU example \n**Question.** Input x = [2, 3]. Each row below lists the incoming weights of one receiving neuron. W₁ = ; b₁ = [0, 0]; W₂ = ; b₂ = [0]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.05. Use half squared loss and perform forward and backward passes.\n\n\n\n### Given\n\nInput x = [2, 3].\n\nW₁ = .\n\nb₁ = [0, 0].\n\nW₂ = .\n\nb₂ = [0].\n\nHidden and output activations are ReLU.\n\nTarget y = [1].\n\nLearning rate η = 0.05.\n\nUse half squared loss and perform forward and backward passes.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.809]. Squared errors = [0.654481]. Half-sum squared loss = 0.3272405; mean squared error = 0.654481. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe ReLU derivative is 1 here because this preactivation is positive.\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (-0.809) × 0.85 = -0.68765. New weight = 0.14−0.05 × (-0.68765) = **0.1743825**.\nh2 → o1: gradient = (-0.809) × 0.48 = -0.38832. New weight = 0.15−0.05 × (-0.38832) = **0.169416**.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n*"},{"title":"Teams photos full sigmoid example","blocks":["<p>The three photographs show this 2 → 2 → 2 network and its chain rule. The photo label for w₃ is read as 0.25, consistent with the visible output/error values and the matching worked example in S05. Learning rate is not legible/specified in these photos; η = 0.5 below is an explicit practice assumption.</p>","<p class=\"inline-question\"><strong>Question.</strong> Input x = [0.05, 0.1]. Each row below lists the incoming weights of one receiving neuron. W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/82d4501fc485058b.svg\" alt=\"\\begin{bmatrix}0.15 &amp; 0.2\\\\0.25 &amp; 0.3\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>; b₁ = [0.35, 0.35]; W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6699cc1064bfaf3.svg\" alt=\"\\begin{bmatrix}0.4 &amp; 0.45\\\\0.5 &amp; 0.55\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>; b₂ = [0.6, 0.6]. Hidden and output activations are sigmoid. Target y = [0.01, 0.99]. Learning rate η = 0.5. Compute all outputs, total half squared loss, all eight weight gradients and one simultaneous weight update. Map weights in order: w₁ = x₁ → h₁, w₂ = x₂ → h₁, w₃ = x₁ → h₂, w₄ = x₂ → h₂; w₅ = h₁ → o₁, w₆ = h₂ → o₁, w₇ = h₁ → o₂, w₈ = h₂ → o₂.</p>","<h3>Given</h3>","<p>Input x = [0.05, 0.1].</p>","<p>W₁ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/82d4501fc485058b.svg\" alt=\"\\begin{bmatrix}0.15 &amp; 0.2\\\\0.25 &amp; 0.3\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>.</p>","<p>b₁ = [0.35, 0.35].</p>","<p>W₂ = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6699cc1064bfaf3.svg\" alt=\"\\begin{bmatrix}0.4 &amp; 0.45\\\\0.5 &amp; 0.55\\end{bmatrix}\" width=\"97.15\" height=\"45.61\" style=\"width:97.15px;height:45.61px;aspect-ratio:97.15/45.61\" loading=\"lazy\"></span>.</p>","<p>b₂ = [0.6, 0.6].</p>","<p>Hidden and output activations are sigmoid.</p>","<p>Target y = [0.01, 0.99].</p>","<p>Learning rate η = 0.5.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/teams.svg\" aria-label=\"Enlarge diagram: Every arrow in the teacher example is labeled so the two backward paths can be traced\"><img src=\"assets/figures/teams.svg\" alt=\"Every arrow in the teacher example is labeled so the two backward paths can be traced\" width=\"960\" height=\"490\" loading=\"lazy\"></button><figcaption>Every arrow in the teacher example is labeled so the two backward paths can be traced <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.53px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/feca30d72e6cdb12.svg\"><img class=\"math display-math\" src=\"assets/equations/1be2ce6f8e5a6ae7.svg\" alt=\"z_{h_1} = (0.15 \\times  0.05) + (0.2 \\times  0.1) + (0.35) = 0.3775\" width=\"533.23\" height=\"24.58\" style=\"width:533.23px;height:24.58px;aspect-ratio:533.23/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.46px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e586b2530e4f9cf0.svg\"><img class=\"math display-math\" src=\"assets/equations/2196ffb4d15fecbe.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(0.3775)}}=0.593269992\" width=\"360.01\" height=\"53.84\" style=\"width:360.01px;height:53.84px;aspect-ratio:360.01/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.53px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0d0fc7f16047fdb4.svg\"><img class=\"math display-math\" src=\"assets/equations/3ec93d9dd746e448.svg\" alt=\"z_{h_2} = (0.25 \\times  0.05) + (0.3 \\times  0.1) + (0.35) = 0.3925\" width=\"533.23\" height=\"24.58\" style=\"width:533.23px;height:24.58px;aspect-ratio:533.23/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.46px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/78d6d0a3e42830ce.svg\"><img class=\"math display-math\" src=\"assets/equations/8275f180adb30096.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.3925)}}=0.596884378\" width=\"360.01\" height=\"53.84\" style=\"width:360.01px;height:53.84px;aspect-ratio:360.01/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/587365feb9b3026e.svg\"><img class=\"math display-math\" src=\"assets/equations/a499c079904c4335.svg\" alt=\"z_{o_1} = (0.4 \\times  0.593269992) + (0.45 \\times  0.596884378) + (0.6) = 1.105905967\" width=\"763.79\" height=\"24.58\" style=\"width:763.79px;height:24.58px;aspect-ratio:763.79/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a028b62b987f7076.svg\"><img class=\"math display-math\" src=\"assets/equations/3a8725cabdafc869.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(1.105905967)}}=0.75136507\" width=\"388.77\" height=\"53.84\" style=\"width:388.77px;height:53.84px;aspect-ratio:388.77/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a3d7358ccdf52d31.svg\"><img class=\"math display-math\" src=\"assets/equations/8f06ed5dcff2563f.svg\" alt=\"z_{o_2} = (0.5 \\times  0.593269992) + (0.55 \\times  0.596884378) + (0.6) = 1.224921404\" width=\"763.79\" height=\"24.58\" style=\"width:763.79px;height:24.58px;aspect-ratio:763.79/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/378ac86a046b16fc.svg\"><img class=\"math display-math\" src=\"assets/equations/624e9e7741da0cb6.svg\" alt=\"o_{2}=\\frac{1}{1+e^{-(1.224921404)}}=0.772928465\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> The photos explicitly use ½(t₁−o₁)² + ½(t₂−o₂)². With exactly two output components, this equals their mean squared error, 0.298371109. The unhalved sum is 0.596742218.</p>","<p>Prediction minus target = [0.74136507, -0.217071535]. Squared errors = [0.549622166, 0.047120051]. Half-sum squared loss = 0.298371109; mean squared error = 0.298371109. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.94px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ffde7979414e34c0.svg\"><img class=\"math display-math\" src=\"assets/equations/071d20abad3f9df8.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.75136507-0.01) \\times  0.186815602 = 0.138498562\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p><strong>Output delta 2:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e7235b42f1e0b22.svg\"><img class=\"math display-math\" src=\"assets/equations/65a80e7107d22398.svg\" alt=\"\\delta_{o_2} = 1 \\times  (0.772928465-0.99) \\times  0.175510053 = -0.038098237\" width=\"664.16\" height=\"24.58\" style=\"width:664.16px;height:24.58px;aspect-ratio:664.16/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.593269992</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.138498562</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.082167041</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.35891648</strong></div></div><p>Subtract η × gradient = <b>0.04108352</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8d844a8676791dfd.svg\"><img class=\"math display-math\" src=\"assets/equations/a9b1122ca44cd5cd.svg\" alt=\"g_{1,1}^{(2)}=(0.138498562)\\times(0.593269992)\\approx 0.082167041\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3afaa45378006799.svg\"><img class=\"math display-math\" src=\"assets/equations/89c2c818c7a2e7dd.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.4-0.5(0.082167041)\\approx 0.35891648\" width=\"503.95\" height=\"36.54\" style=\"width:503.95px;height:36.54px;aspect-ratio:503.95/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.596884378</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.138498562</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.082667628</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.45</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.408666186</strong></div></div><p>Subtract η × gradient = <b>0.041333814</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/df479afdae4fe00d.svg\"><img class=\"math display-math\" src=\"assets/equations/c40f5279cb6e8a57.svg\" alt=\"g_{1,2}^{(2)}=(0.138498562)\\times(0.596884378)\\approx 0.082667628\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ad573638df0109c.svg\"><img class=\"math display-math\" src=\"assets/equations/4aaec1199c9864bb.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.45-0.5(0.082667628)\\approx 0.408666186\" width=\"528.38\" height=\"36.54\" style=\"width:528.38px;height:36.54px;aspect-ratio:528.38/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h1 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.593269992</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.038098237</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.02260254</strong><span class=\"lv-detail\">h1 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.51130127</strong></div></div><p>Subtract η × gradient = <b>−0.01130127</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dde4ee7e9e8f997c.svg\" alt=\"g_{2,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,1}}=\\delta_{o_2}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f032d0a14a103c60.svg\"><img class=\"math display-math\" src=\"assets/equations/35e5314b87f154a8.svg\" alt=\"g_{2,1}^{(2)}=(-0.038098237)\\times(0.593269992)\\approx -0.02260254\" width=\"581.52\" height=\"36.54\" style=\"width:581.52px;height:36.54px;aspect-ratio:581.52/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.86px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/62292012970cdab4.svg\"><img class=\"math display-math\" src=\"assets/equations/80442c4c79c12529.svg\" alt=\"W^{(2)}_{2,1,\\mathrm{new}}=0.5-0.5(-0.02260254)\\approx 0.51130127\" width=\"510.74\" height=\"36.54\" style=\"width:510.74px;height:36.54px;aspect-ratio:510.74/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.596884378</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.038098237</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.022740242</strong><span class=\"lv-detail\">h2 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.561370121</strong></div></div><p>Subtract η × gradient = <b>−0.011370121</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57d7e754e94fe533.svg\" alt=\"g_{2,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,2}}=\\delta_{o_2}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/02d5efeb8dafde38.svg\"><img class=\"math display-math\" src=\"assets/equations/890a2f895bb237f9.svg\" alt=\"g_{2,2}^{(2)}=(-0.038098237)\\times(0.596884378)\\approx -0.022740242\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/af1284429e824dd6.svg\"><img class=\"math display-math\" src=\"assets/equations/f2313d50d5e6909b.svg\" alt=\"W^{(2)}_{2,2,\\mathrm{new}}=0.55-0.5(-0.022740242)\\approx 0.561370121\" width=\"547.39\" height=\"36.54\" style=\"width:547.39px;height:36.54px;aspect-ratio:547.39/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.138498562</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.055399425</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.038098237</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.019049118</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.036350306</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7ba541a2ae61050.svg\"><img class=\"math display-math\" src=\"assets/equations/4e8c5af2cd60942b.svg\" alt=\"C_1=(0.4)\\times(0.138498562)\\approx 0.055399425\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/899ef2a84df9b3cd.svg\"><img class=\"math display-math\" src=\"assets/equations/fb089b7c1d8f6873.svg\" alt=\"C_2=(0.5)\\times(-0.038098237)\\approx -0.019049118\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/167389750e490b23.svg\"><img class=\"math display-math\" src=\"assets/equations/2537e0a69ea64761.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.036350306\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3d990b0c410497e3.svg\"><img class=\"math display-math\" src=\"assets/equations/2792e998f36b387c.svg\" alt=\"\\delta_{h_1} = 0.036350306 \\times  0.241300709 = 0.008771355\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.138498562</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.45</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.062324353</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.038098237</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.02095403</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.041370323</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/78866731f335909d.svg\"><img class=\"math display-math\" src=\"assets/equations/88812c8e2d3784df.svg\" alt=\"C_1=(0.45)\\times(0.138498562)\\approx 0.062324353\" width=\"462.57\" height=\"24.43\" style=\"width:462.57px;height:24.43px;aspect-ratio:462.57/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2b032a83e37967d3.svg\"><img class=\"math display-math\" src=\"assets/equations/fea577940f5fb0f2.svg\" alt=\"C_2=(0.55)\\times(-0.038098237)\\approx -0.02095403\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5c3c002092c7eca9.svg\"><img class=\"math display-math\" src=\"assets/equations/e59e8769f280fbd2.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.041370323\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bdbc44ac317050d2.svg\"><img class=\"math display-math\" src=\"assets/equations/31d2f2dbdaea47ab.svg\" alt=\"\\delta_{h_2} = 0.041370323 \\times  0.240613417 = 0.009954255\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.05</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008771355</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000438568</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.149780716</strong></div></div><p>Subtract η × gradient = <b>0.000219284</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2525430dc0c2af1f.svg\"><img class=\"math display-math\" src=\"assets/equations/9d2ed0236b62ab2a.svg\" alt=\"g_{1,1}^{(1)}=(0.008771355)\\times(0.05)\\approx 0.000438568\" width=\"470.20\" height=\"36.54\" style=\"width:470.20px;height:36.54px;aspect-ratio:470.20/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/db7d742025f4d68e.svg\"><img class=\"math display-math\" src=\"assets/equations/4f7a0b344b0cf201.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.15-0.5(0.000438568)\\approx 0.149780716\" width=\"528.38\" height=\"36.54\" style=\"width:528.38px;height:36.54px;aspect-ratio:528.38/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008771355</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000877135</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.199561432</strong></div></div><p>Subtract η × gradient = <b>0.000438568</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/753fcf33c45e8537.svg\"><img class=\"math display-math\" src=\"assets/equations/1850aa156783fa4e.svg\" alt=\"g_{1,2}^{(1)}=(0.008771355)\\times(0.1)\\approx 0.000877135\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/738f6089731cd94e.svg\"><img class=\"math display-math\" src=\"assets/equations/0bf05631c8b81136.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.2-0.5(0.000877135)\\approx 0.199561432\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.05</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.009954255</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000497713</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.249751144</strong></div></div><p>Subtract η × gradient = <b>0.000248856</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/76611b6fffb6eae0.svg\"><img class=\"math display-math\" src=\"assets/equations/12dc3d7596ccb7c2.svg\" alt=\"g_{2,1}^{(1)}=(0.009954255)\\times(0.05)\\approx 0.000497713\" width=\"470.20\" height=\"36.54\" style=\"width:470.20px;height:36.54px;aspect-ratio:470.20/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8c4ebc4a08766591.svg\"><img class=\"math display-math\" src=\"assets/equations/46b3c1d000945dc9.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.25-0.5(0.000497713)\\approx 0.249751144\" width=\"528.38\" height=\"36.54\" style=\"width:528.38px;height:36.54px;aspect-ratio:528.38/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.009954255</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000995425</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.299502287</strong></div></div><p>Subtract η × gradient = <b>0.000497712</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3534da4dd6514b21.svg\"><img class=\"math display-math\" src=\"assets/equations/28799f80ac592874.svg\" alt=\"g_{2,2}^{(1)}=(0.009954255)\\times(0.1)\\approx 0.000995425\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/770fd618f5ab4f7d.svg\"><img class=\"math display-math\" src=\"assets/equations/f0ef9e4142c40173.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.3-0.5(0.000995425)\\approx 0.299502287\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0caa37a084caf21.svg\"><img class=\"math display-math\" src=\"assets/equations/2c688c2612d04439.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.35-0.5(0.008771355)=0.345614322\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b81e2513786c90a9.svg\"><img class=\"math display-math\" src=\"assets/equations/ef67240d0fdef037.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.35-0.5(0.009954255)=0.345022872\" width=\"511.21\" height=\"25.35\" style=\"width:511.21px;height:25.35px;aspect-ratio:511.21/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37ec194c9837cd70.svg\"><img class=\"math display-math\" src=\"assets/equations/59d69997bb013f94.svg\" alt=\"b_{o_1,\\mathrm{new}}=0.6-0.5(0.138498562)=0.530750719\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2267211e36f3ce48.svg\"><img class=\"math display-math\" src=\"assets/equations/f8b71ed80001f62a.svg\" alt=\"b_{o_2,\\mathrm{new}}=0.6-0.5(-0.038098237)=0.619049118\" width=\"516.43\" height=\"25.35\" style=\"width:516.43px;height:25.35px;aspect-ratio:516.43/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Why the photos add two terms for h₁: </strong> dL/dh₁ = δo₁w₅ + δo₂w₇ = 0.138498562 × 0.4 + (−0.038098237) × 0.5 = 0.055399425−0.019049118 = 0.036350306. Now multiply by h₁(1−h₁) = 0.241300709 to obtain δh₁ = 0.008771355; multiply by x₁ = 0.05 to obtain dL/dw₁ = 0.000438568. Adding the two output paths is essential.</p>","<p><strong>Memory sequence: </strong> error → output slope → outgoing weight → add paths → hidden slope → input. If you can explain why each factor appears, changed numbers or extra output neurons are much less confusing.</p>","<p><strong>Bias convention: </strong> the photo draws one bias value per layer. If these are literally tied scalars rather than equal initial per-neuron biases, sum the relevant deltas: hidden shared b becomes 0.35−0.5(0.008771355+0.009954255) = 0.340637195; output shared b becomes 0.6−0.5(0.138498562−0.038098237) = 0.549799837. If only weights are requested, do not invent a bias update requirement.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c10-s11","search":"Teams photos full sigmoid example The three photographs show this 2 → 2 → 2 network and its chain rule. The photo label for w₃ is read as 0.25, consistent with the visible output/error values and the matching worked example in S05. Learning rate is not legible/specified in these photos; η = 0.5 below is an explicit practice assumption.\n**Question.** Input x = [0.05, 0.1]. Each row below lists the incoming weights of one receiving neuron. W₁ = ; b₁ = [0.35, 0.35]; W₂ = ; b₂ = [0.6, 0.6]. Hidden and output activations are sigmoid. Target y = [0.01, 0.99]. Learning rate η = 0.5. Compute all outputs, total half squared loss, all eight weight gradients and one simultaneous weight update. Map weights in order: w₁ = x₁ → h₁, w₂ = x₂ → h₁, w₃ = x₁ → h₂, w₄ = x₂ → h₂; w₅ = h₁ → o₁, w₆ = h₂ → o₁, w₇ = h₁ → o₂, w₈ = h₂ → o₂.\n\n\n\n### Given\n\nInput x = [0.05, 0.1].\n\nW₁ = .\n\nb₁ = [0.35, 0.35].\n\nW₂ = .\n\nb₂ = [0.6, 0.6].\n\nHidden and output activations are sigmoid.\n\nTarget y = [0.01, 0.99].\n\nLearning rate η = 0.5.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Output neuron 2: **\n\n\n**Step 2 loss convention.** The photos explicitly use "}]},{"n":11,"title":"Final examination December 2025 fully solved","sections":[{"title":"Start here","blocks":["<p>F25 = S12, 3 December 2025, with S13 as a comparison answer key. S18 is another copy of this same paper. All questions are included; its historical choice rule does not remove questions from this practice bank.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c11-intro"},{"title":"F25 Q1a","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Give four ML versus DL differences with examples. Choose and justify ML or DL for (1) 2,000 short product reviews, (2) labeled financial fraud records, (3) captions for 100,000 labeled natural-scene images.</p>"],"answer":["<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>","<p><strong>Choices: </strong> (1) Start with traditional ML using text features because the labeled dataset is small; pretrained text models are a viable extension. (2) Start with a tabular ML classifier such as a tree ensemble; labeled structured features do not automatically require DL. (3) DL is appropriate for learning visual features and generating a word sequence; a CNN encoder with a sequence decoder is a syllabus-aligned design. Compare held-out metrics rather than claiming one method must always win.</p>"],"kind":"practice","id":"tee-c11-s0","search":"F25 Q1a **Question (5 marks).** Give four ML versus DL differences with examples. Choose and justify ML or DL for (1) 2,000 short product reviews, (2) labeled financial fraud records, (3) captions for 100,000 labeled natural-scene images.\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n**Choices: ** (1) Start with traditional ML using text features because the labeled dataset is small; pretrained text models are a viable extension. (2) Start with a tabular ML classifier such as a tree ensemble; labeled structured features do not automatically require DL. (3) DL is appropriate for learning visual features and generating a word sequence; a CNN encoder with a sequence decoder is a syllabus-aligned design. Compare held-out metrics rather than claiming one method must always win.\n"},{"title":"F25 Q1b","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> For automated leaf-disease image classification, discuss factors affecting loss selection. For classes Normal, Mild, Severe with target [0,1,0] and predicted probabilities [0.1,0.8,0.1], compute and interpret categorical cross-entropy.</p>"],"answer":["<h3>Given</h3>","<p>Classes = Normal,Mild,Severe; target = [0,1,0].</p>","<p>Predicted probabilities = [0.1,0.8,0.1]; use natural logarithms.</p>","<h3>To find</h3>","<p>Calculate categorical cross-entropy and interpret the result.</p>","<h3>Formula — which one and why</h3>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<p>Select a loss according to the task and output meaning: real-valued regression often uses MSE/MAE, binary classification uses binary cross-entropy, and one-of-K classification uses categorical cross-entropy. Consider class imbalance, noisy labels/outliers, whether outputs are calibrated probabilities, and differentiability for optimization.</p>","<p class=\"worked-step\"><strong>Step 1: expand the categorical cross-entropy sum.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6cc766252350138b.svg\" alt=\"L=-[0\\ln(0.1)+1\\ln(0.8)+0\\ln(0.1)]\" width=\"402.28\" height=\"24.43\" style=\"width:402.28px;height:24.43px;aspect-ratio:402.28/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: keep the term for the true class.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17a83c5bb645a7c5.svg\" alt=\"L=-\\ln(0.8)\" width=\"142.93\" height=\"24.43\" style=\"width:142.93px;height:24.43px;aspect-ratio:142.93/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: negate the logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/178c3708a55e1ab7.svg\" alt=\"L\\approx0.223143551\" width=\"178.19\" height=\"17.23\" style=\"width:178.19px;height:17.23px;aspect-ratio:178.19/17.23\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> loss ≈ 0.223144 nats. The true class received probability 0.8, so the loss is relatively small; probability 1 would give loss zero.</p>"],"kind":"practice","id":"tee-c11-s1","search":"F25 Q1b **Question (5 marks).** For automated leaf-disease image classification, discuss factors affecting loss selection. For classes Normal, Mild, Severe with target [0,1,0] and predicted probabilities [0.1,0.8,0.1], compute and interpret categorical cross-entropy.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nClasses = Normal,Mild,Severe; target = [0,1,0].\n\nPredicted probabilities = [0.1,0.8,0.1]; use natural logarithms.\n\n### To find\n\nCalculate categorical cross-entropy and interpret the result.\n\n### Formula — which one and why\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n\n\nSelect a loss according to the task and output meaning: real-valued regression often uses MSE/MAE, binary classification uses binary cross-entropy, and one-of-K classification uses categorical cross-entropy. Consider class imbalance, noisy labels/outliers, whether outputs are calibrated probabilities, and differentiability for optimization.\n**Step 1: expand the categorical cross-entropy sum.**\n\n\n\n\n\n\n\n**Step 2: keep the term for the true class.**\n\n\n\n\n\n\n\n**Step 3: calculate its natural logarithm.**\n\n\n\n\n\n\n\n**Step 4: negate the logarithm.**\n\n\n\n\n\n\n\n**Final answer:** loss ≈ 0.223144 nats. The true class received probability 0.8, so the loss is relatively small; probability 1 would give loss zero.\n"},{"title":"F25 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Which regularizer leads to sparsity and why? For an MNIST CNN with high training accuracy and lower validation accuracy, explain how dropout works during training and how it can improve generalization.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>"],"kind":"practice","id":"tee-c11-s2","search":"F25 Q1c **Question (5 marks).** Which regularizer leads to sparsity and why? For an MNIST CNN with high training accuracy and lower validation accuracy, explain how dropout works during training and how it can improve generalization.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n"},{"title":"F25 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Describe sequence processing, context and variable-length sentences in RNNs. Explain their use in language translation, as illustrated by the historical reference to Google Translate.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>"],"kind":"practice","id":"tee-c11-s3","search":"F25 Q1d **Question (5 marks).** Describe sequence processing, context and variable-length sentences in RNNs. Explain their use in language translation, as illustrated by the historical reference to Google Translate.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n"},{"title":"F25 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A 2 → 2 → 1 sigmoid network has all four input-to-hidden weights 0.5, both hidden-to-output weights 0.25, hidden and output biases 0, and target 1. Perform forward and backward passes to update the x₁ → h₁ weight, h₁ → output weight and output bias at η = 0.5. The paper does not state the numerical inputs or loss.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_f25.svg\" aria-label=\"Enlarge diagram: F25 Q2a connections with explicitly assumed inputs\"><img src=\"assets/figures/net_f25.svg\" alt=\"F25 Q2a connections with explicitly assumed inputs\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>F25 Q2a connections with explicitly assumed inputs <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Architecture 2 → 2 → 1; every neuron uses sigmoid.</p>","<p>All four input-to-hidden weights = 0.5; both hidden-to-output weights = 0.25.</p>","<p>All biases = 0; target = 1; η = 0.5.</p>","<p>The paper omits inputs and loss: this worked solution explicitly assumes x = [1,1] and half squared loss.</p>","<h3>To find</h3>","<p>Calculate the forward pass, then gradients and updates for x₁→h₁, h₁→output and the output bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p><strong>Assumptions: </strong> use x = [1,1] and half squared loss. The paper permits suitable assumptions and its key also introduces assumed inputs. There is no unique numerical result without them.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ebc8dda9737caeb3.svg\"><img class=\"math display-math\" src=\"assets/equations/a57d08e71109e92c.svg\" alt=\"z_{h_1} = (0.5 \\times  1) + (0.5 \\times  1) + (0) = 1\" width=\"383.89\" height=\"24.58\" style=\"width:383.89px;height:24.58px;aspect-ratio:383.89/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9d9a8c14314f06ad.svg\"><img class=\"math display-math\" src=\"assets/equations/68fa3eedfd721c67.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(1)}}=0.731058579\" width=\"320.65\" height=\"53.84\" style=\"width:320.65px;height:53.84px;aspect-ratio:320.65/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9d50f49ceec1f464.svg\"><img class=\"math display-math\" src=\"assets/equations/74149e3e776dce9d.svg\" alt=\"z_{h_2} = (0.5 \\times  1) + (0.5 \\times  1) + (0) = 1\" width=\"383.89\" height=\"24.58\" style=\"width:383.89px;height:24.58px;aspect-ratio:383.89/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5f1426f29e3d87e6.svg\"><img class=\"math display-math\" src=\"assets/equations/8276b57ee8bf3bfd.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(1)}}=0.731058579\" width=\"320.65\" height=\"53.84\" style=\"width:320.65px;height:53.84px;aspect-ratio:320.65/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c44792db3abbdcd0.svg\"><img class=\"math display-math\" src=\"assets/equations/28292662ef4f2232.svg\" alt=\"z_{o_1} = (0.25 \\times  0.731058579) + (0.25 \\times  0.731058579) + (0) = 0.365529289\" width=\"756.99\" height=\"24.58\" style=\"width:756.99px;height:24.58px;aspect-ratio:756.99/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/07b12d14b1f2a0ff.svg\"><img class=\"math display-math\" src=\"assets/equations/a199e77a25ea274a.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.365529289)}}=0.590378257\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.409621743]. Squared errors = [0.167789972]. Half-sum squared loss = 0.083894986; mean squared error = 0.167789972. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b7b0310d2c3be2ab.svg\"><img class=\"math display-math\" src=\"assets/equations/cfa9f3b565ded315.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.590378257-1) \\times  0.241831771 = -0.099059551\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.731058579</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.099059551</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.072418335</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.286209167</strong></div></div><p>Subtract η × gradient = <b>−0.036209168</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30f7bf8aa04d2bf2.svg\"><img class=\"math display-math\" src=\"assets/equations/0995183f490671de.svg\" alt=\"g_{1,1}^{(2)}=(-0.099059551)\\times(0.731058579)\\approx -0.072418335\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/82203dea1f21db8c.svg\"><img class=\"math display-math\" src=\"assets/equations/7a3beb590205510e.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.25-0.5(-0.072418335)\\approx 0.286209167\" width=\"547.39\" height=\"36.54\" style=\"width:547.39px;height:36.54px;aspect-ratio:547.39/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.731058579</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.099059551</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.072418335</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.286209167</strong></div></div><p>Subtract η × gradient = <b>−0.036209168</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fd02f5bab6bb789a.svg\"><img class=\"math display-math\" src=\"assets/equations/06ed406edd749bf9.svg\" alt=\"g_{1,2}^{(2)}=(-0.099059551)\\times(0.731058579)\\approx -0.072418335\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/66e7552de1ba0f15.svg\"><img class=\"math display-math\" src=\"assets/equations/fd5e1c3ecdebae0c.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.25-0.5(-0.072418335)\\approx 0.286209167\" width=\"547.39\" height=\"36.54\" style=\"width:547.39px;height:36.54px;aspect-ratio:547.39/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.099059551</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.024764888</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.024764888</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/486b61a3d9f85a8a.svg\"><img class=\"math display-math\" src=\"assets/equations/b990515cad5dba89.svg\" alt=\"C_1=(0.25)\\times(-0.099059551)\\approx -0.024764888\" width=\"500.59\" height=\"24.43\" style=\"width:500.59px;height:24.43px;aspect-ratio:500.59/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d708f3df447c37c4.svg\"><img class=\"math display-math\" src=\"assets/equations/786870ca2f319d3c.svg\" alt=\"\\text{Sum}=C_1\\approx -0.024764888\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/faa954804a7ac56f.svg\"><img class=\"math display-math\" src=\"assets/equations/efc565ce467804a9.svg\" alt=\"\\delta_{h_1} = -0.024764888 \\times  0.196611933 = -0.004869072\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.099059551</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.024764888</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.024764888</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/486b61a3d9f85a8a.svg\"><img class=\"math display-math\" src=\"assets/equations/b990515cad5dba89.svg\" alt=\"C_1=(0.25)\\times(-0.099059551)\\approx -0.024764888\" width=\"500.59\" height=\"24.43\" style=\"width:500.59px;height:24.43px;aspect-ratio:500.59/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d708f3df447c37c4.svg\"><img class=\"math display-math\" src=\"assets/equations/786870ca2f319d3c.svg\" alt=\"\\text{Sum}=C_1\\approx -0.024764888\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c9f11eb5cc7cb0d3.svg\"><img class=\"math display-math\" src=\"assets/equations/569e06b7bb3c113c.svg\" alt=\"\\delta_{h_2} = -0.024764888 \\times  0.196611933 = -0.004869072\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9759c3655229ab0e.svg\"><img class=\"math display-math\" src=\"assets/equations/e290def3a1c4ea90.svg\" alt=\"g_{1,1}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c3d90c909dab8209.svg\"><img class=\"math display-math\" src=\"assets/equations/a169e16b705d6d2b.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a5cd9a960e8e0d8.svg\"><img class=\"math display-math\" src=\"assets/equations/ebfca408333d760d.svg\" alt=\"g_{1,2}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/057d087cc10bb2a8.svg\"><img class=\"math display-math\" src=\"assets/equations/da0b9b9064b8dcd6.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd47a26ddf1d4480.svg\"><img class=\"math display-math\" src=\"assets/equations/e99b8cf0ca1131d6.svg\" alt=\"g_{2,1}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5614079c42cc22b4.svg\"><img class=\"math display-math\" src=\"assets/equations/8fd73e44677515a6.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d63a8ff35a6906b2.svg\"><img class=\"math display-math\" src=\"assets/equations/4d0ac3ffd181b903.svg\" alt=\"g_{2,2}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bfabbdcd726cbd9c.svg\"><img class=\"math display-math\" src=\"assets/equations/9733a71bb8ca6e2e.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c94badc259c5a62b.svg\"><img class=\"math display-math\" src=\"assets/equations/0aa5e626ccf3c903.svg\" alt=\"b_{h_1,\\mathrm{new}}=0-0.5(-0.004869072)=0.002434536\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2b6bc6b29544f77.svg\"><img class=\"math display-math\" src=\"assets/equations/594dcb090f7d4418.svg\" alt=\"b_{h_2,\\mathrm{new}}=0-0.5(-0.004869072)=0.002434536\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55595ef27eaeb48f.svg\"><img class=\"math display-math\" src=\"assets/equations/8a047fabd725efcd.svg\" alt=\"b_{o_1,\\mathrm{new}}=0-0.5(-0.099059551)=0.049529775\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Requested values: </strong> input weight <strong>0.502434536</strong>, output weight <strong>0.286209167</strong>, output bias <strong>0.049529775</strong>. Other supplied inputs produce different correct conditional results.</p>"],"kind":"practice","id":"tee-c11-s4","search":"F25 Q2a **Question (10 marks).** A 2 → 2 → 1 sigmoid network has all four input-to-hidden weights 0.5, both hidden-to-output weights 0.25, hidden and output biases 0, and target 1. Perform forward and backward passes to update the x₁ → h₁ weight, h₁ → output weight and output bias at η = 0.5. The paper does not state the numerical inputs or loss.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nArchitecture 2 → 2 → 1; every neuron uses sigmoid.\n\nAll four input-to-hidden weights = 0.5; both hidden-to-output weights = 0.25.\n\nAll biases = 0; target = 1; η = 0.5.\n\nThe paper omits inputs and loss: this worked solution explicitly assumes x = [1,1] and half squared loss.\n\n### To find\n\nCalculate the forward pass, then gradients and updates for x₁→h₁, h₁→output and the output bias.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**Assumptions: ** use x = [1,1] and half squared loss. The paper permits suitable assumptions and its key also introduces assumed inputs. There is no unique numerical result without them.\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.409621743]. Squared errors = [0.167789972]. Half-sum squared loss = 0.083894986; mean squared error = 0.167789972. These are different unless the number of output components makes the scale"},{"title":"F25 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain how ResNet skip connections influence gradient flow, feature reuse and vanishing gradients. Compare InceptionNet and AlexNet learning and feature extraction.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>","<p>AlexNet learns features along a mainly sequential stack of convolutional layers. Inception learns several spatial scales in parallel within a module and combines their channels. Both learn filter weights through backpropagation; their structural organization differs.</p>"],"kind":"practice","id":"tee-c11-s5","search":"F25 Q2b **Question (10 marks).** Explain how ResNet skip connections influence gradient flow, feature reuse and vanishing gradients. Compare InceptionNet and AlexNet learning and feature extraction.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\nAlexNet learns features along a mainly sequential stack of convolutional layers. Inception learns several spatial scales in parallel within a module and combines their channels. Both learn filter weights through backpropagation; their structural organization differs.\n"},{"title":"F25 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Train one epoch of a single perceptron with η = 1, initial weights and bias 0, threshold 0, on [−1,1,−1] → 0, [−1,1,1] → 1, [1,−1,1] → 1, [−1,1,1] → 1. Then map biological-neuron components to artificial-neuron components.</p>"],"answer":["<h3>Given</h3>","<p>Initial weights and bias = 0; η = 1; threshold = 0.</p>","<p>Samples in order: [−1,1,−1]→0; [−1,1,1]→1; [1,−1,1]→1; [−1,1,1]→1.</p>","<p>Use output 1 when net &gt; 0 and 0 otherwise, matching the supplied key; one epoch.</p>","<h3>To find</h3>","<p>Process each sample in order, carrying updated weights forward, and report final weights/bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Perceptron learning rule.</strong> Evaluate the stated threshold, compare the predicted class with its target, then correct weights and bias. The next sample uses the newly updated parameters.</p>","<p>t = target; o = thresholded output; η = learning rate; xᵢ = input i. Binary and bipolar output conventions must follow the question.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fccc40e029a1d4e.svg\" alt=\"w_i^{\\mathrm{new}}=w_i+\\eta(t-o)x_i\" width=\"240.87\" height=\"24.55\" style=\"width:240.87px;height:24.55px;aspect-ratio:240.87/24.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/58dd8fcb5fcd562f.svg\" alt=\"b^{\\mathrm{new}}=b+\\eta(t-o)\" width=\"196.89\" height=\"24.43\" style=\"width:196.89px;height:24.43px;aspect-ratio:196.89/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Prediction nikalo; target−prediction se correction nikalo.</p>","<h3>Solution — step by step</h3>","<p><strong>State the threshold rule.</strong> Use binary output 1 if z&gt;0 and 0 otherwise, matching the associated key. Update Δw = η(t−o)x and Δb = η(t−o), with η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.</p>","<h3>Epoch 1, sample 1</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, -1], target = 0.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (0 × -1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [-1, 1, -1] = [0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 0, 0], new b = 0.</p>","<h3>Epoch 1, sample 2</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (0 × 1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [-1, 1, 1] = [-1, 1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-1, 1, 1], new b = 1.</p>","<h3>Epoch 1, sample 3</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, -1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-1 × 1) + (1 × -1) + (1 × 1) + (1) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [1, -1, 1] = [1, -1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 0, 2], new b = 2.</p>","<h3>Epoch 1, sample 4</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (2 × 1) + (2) = 4</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [-1, 1, 1] = [0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 0, 2], new b = 2.</p>","<p><strong>Final after exactly the requested epochs: </strong> w = <strong>[0, 0, 2]</strong>, b = <strong>2</strong>. A finite number of requested epochs does not itself prove convergence or correct classification of every sample.</p>","<p>Biological dendrites receive signals, synapses influence connection strength, the cell body integrates information, and an axon carries an output signal. In the artificial analogy, inputs represent received signals, weights represent connection strengths, the weighted sum plus bias performs aggregation, and an activation function produces an output. The bias shifts the firing threshold. This is a simplified computational analogy, not a complete biological model.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: The artificial neuron multiplies each input by a weight then adds bias and activates\"><img src=\"assets/figures/neuron.svg\" alt=\"The artificial neuron multiplies each input by a weight then adds bias and activates\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>The artificial neuron multiplies each input by a weight then adds bias and activates <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c11-s6","search":"F25 Q3a **Question (10 marks).** Train one epoch of a single perceptron with η = 1, initial weights and bias 0, threshold 0, on [−1,1,−1] → 0, [−1,1,1] → 1, [1,−1,1] → 1, [−1,1,1] → 1. Then map biological-neuron components to artificial-neuron components.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInitial weights and bias = 0; η = 1; threshold = 0.\n\nSamples in order: [−1,1,−1]→0; [−1,1,1]→1; [1,−1,1]→1; [−1,1,1]→1.\n\nUse output 1 when net > 0 and 0 otherwise, matching the supplied key; one epoch.\n\n### To find\n\nProcess each sample in order, carrying updated weights forward, and report final weights/bias.\n\n### Formula — which one and why\n\n**Perceptron learning rule.** Evaluate the stated threshold, compare the predicted class with its target, then correct weights and bias. The next sample uses the newly updated parameters.\n\nt = target; o = thresholded output; η = learning rate; xᵢ = input i. Binary and bipolar output conventions must follow the question.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Prediction nikalo; target−prediction se correction nikalo.\n\n### Solution — step by step\n\n\n\n\n**State the threshold rule.** Use binary output 1 if z>0 and 0 otherwise, matching the associated key. Update Δw = η(t−o)x and Δb = η(t−o), with η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.\n### Epoch 1, sample 1\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, -1], target = 0.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (0 × -1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 0\n\n**Step 5: calculate all weight changes.**\n\nΔw = 0 × [-1, 1, -1] = [0, 0, 0]\n\n**Step 6: calculate the bias change.**\n\nΔb = 0.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 0, 0], new b = 0.\n\n\n### Epoch 1, sample 2\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (0 × 1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [-1, 1, 1] = [-1, 1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [-1, 1, 1], new b = 1.\n\n\n### Epoch 1, sample 3\n\n**Step 1: copy this sample and target.**\n\nx = [1, -1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (-1 × 1) + (1 × -1) + (1 × 1) + (1) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [1, -1, 1] = [1, -1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 0, 2], new b = 2.\n\n\n### Epoch 1, sample 4\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (2 × 1) + (2) = 4\n\n**Step 3: apply the threshold.**\n\noutput = 1.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 0\n\n**Step 5: calculate all weight changes.**\n\nΔw = 0 × [-1, 1, 1] = [0, 0, 0]\n\n**Step 6: calculate the bias change.**\n\nΔb = 0.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 0, 2], new b = 2.\n\n\n**Final after exactly the requested epochs: ** w = **[0, 0, 2]**, b = **2**. A finite number of requested epochs does not itself prove convergence or"},{"title":"F25 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design face-recognition attendance using a CNN when the supplied dataset is very small. Discuss ways to address the issue and explain transfer learning.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>"],"kind":"practice","id":"tee-c11-s7","search":"F25 Q3b **Question (10 marks).** Design face-recognition attendance using a CNN when the supplied dataset is very small. Discuss ways to address the issue and explain transfer learning.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n"},{"title":"F25 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For N = 1,000 samples and batch size 100, count weight updates per epoch for batch GD, SGD and mini-batch GD. For J(θ) = 0.5 θ², η = 0.1, momentum 0.9, v₀ = 0, θ₀ = 1, compute two momentum iterations. List the required momentum-training hyperparameters.</p>"],"answer":["<h3>Given</h3>","<p>N = 1,000; mini-batch size = 100.</p>","<p>J(θ) = 0.5θ²; θ₀ = 1; v₀ = 0; η = 0.1; β = 0.9.</p>","<p>Use signed velocity.</p>","<h3>To find</h3>","<p>Count updates per epoch for batch, stochastic and mini-batch GD; then perform two momentum iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count full-batch updates.</strong></p>","<p>All 1,000 samples contribute to one update: 1 per epoch.</p>","<p class=\"worked-step\"><strong>Step 2: count stochastic updates.</strong></p>","<p>One update per sample: 1,000 per epoch.</p>","<p class=\"worked-step\"><strong>Step 3: count mini-batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eee877d70ea14115.svg\" alt=\"1000/100=10\" width=\"154.75\" height=\"24.43\" style=\"width:154.75px;height:24.43px;aspect-ratio:154.75/24.43\" loading=\"lazy\"></div>","<p>Use signed velocity vₜ = βvₜ₋₁−ηgₜ and θₜ = θₜ₋₁+vₜ; g(θ) = θ.</p>","<h3>Momentum iteration 1</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the gradient at the current parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/228fc3b3267b30c9.svg\" alt=\"g_1=1\" width=\"67.12\" height=\"21.29\" style=\"width:67.12px;height:21.29px;aspect-ratio:67.12/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the previous displacement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4351a4e3442a023e.svg\" alt=\"0.9(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the current gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cde65d80bbbce53.svg\" alt=\"0.1(1)=0.1\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: combine to obtain the new signed velocity.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2c6e04e58352c2ce.svg\" alt=\"v_1=0-0.1=-0.1\" width=\"211.24\" height=\"19.94\" style=\"width:211.24px;height:19.94px;aspect-ratio:211.24/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add new velocity to the actual old parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<h3>Momentum iteration 2</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the gradient at the current parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc4532aff9a9a2da.svg\" alt=\"g_2=0.9\" width=\"86.13\" height=\"21.29\" style=\"width:86.13px;height:21.29px;aspect-ratio:86.13/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the previous displacement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8fd30bce103b617.svg\" alt=\"0.9(-0.1)=-0.09\" width=\"195.51\" height=\"24.43\" style=\"width:195.51px;height:24.43px;aspect-ratio:195.51/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the current gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf93339d0945c688.svg\" alt=\"0.1(0.9)=0.09\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: combine to obtain the new signed velocity.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f18fc7f5dc715d05.svg\" alt=\"v_2=-0.09-0.09=-0.18\" width=\"285.91\" height=\"19.94\" style=\"width:285.91px;height:19.94px;aspect-ratio:285.91/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add new velocity to the actual old parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Hyperparameters: </strong> the basic momentum update has two main tunable coefficients, learning rate η and momentum β. A full training run also requires choices such as epochs and batch size (one for literal SGD), and may include a learning-rate schedule. There is no universal single count for all training configurations; state what is counted. Initial θ and v are initialization values, not learned outputs of the first update.</p>"],"kind":"practice","id":"tee-c11-s8","search":"F25 Q4a **Question (10 marks).** For N = 1,000 samples and batch size 100, count weight updates per epoch for batch GD, SGD and mini-batch GD. For J(θ) = 0.5 θ², η = 0.1, momentum 0.9, v₀ = 0, θ₀ = 1, compute two momentum iterations. List the required momentum-training hyperparameters.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nN = 1,000; mini-batch size = 100.\n\nJ(θ) = 0.5θ²; θ₀ = 1; v₀ = 0; η = 0.1; β = 0.9.\n\nUse signed velocity.\n\n### To find\n\nCount updates per epoch for batch, stochastic and mini-batch GD; then perform two momentum iterations.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: count full-batch updates.**\n\nAll 1,000 samples contribute to one update: 1 per epoch.\n\n**Step 2: count stochastic updates.**\n\nOne update per sample: 1,000 per epoch.\n\n**Step 3: count mini-batches.**\n\n\n\n\n\n\n\n\nUse signed velocity vₜ = βvₜ₋₁−ηgₜ and θₜ = θₜ₋₁+vₜ; g(θ) = θ.\n### Momentum iteration 1\n\n**Step 1: evaluate the gradient at the current parameter.**\n\n\n\n\n\n\n\n**Step 2: retain the previous displacement.**\n\n\n\n\n\n\n\n**Step 3: scale the current gradient.**\n\n\n\n\n\n\n\n**Step 4: combine to obtain the new signed velocity.**\n\n\n\n\n\n\n\n**Step 5: add new velocity to the actual old parameter.**\n\n\n\n\n\n\n\n\n### Momentum iteration 2\n\n**Step 1: evaluate the gradient at the current parameter.**\n\n\n\n\n\n\n\n**Step 2: retain the previous displacement.**\n\n\n\n\n\n\n\n**Step 3: scale the current gradient.**\n\n\n\n\n\n\n\n**Step 4: combine to obtain the new signed velocity.**\n\n\n\n\n\n\n\n**Step 5: add new velocity to the actual old parameter.**\n\n\n\n\n\n\n\n\n**Hyperparameters: ** the basic momentum update has two main tunable coefficients, learning rate η and momentum β. A full training run also requires choices such as epochs and batch size (one for literal SGD), and may include a learning-rate schedule. There is no universal single count for all training configurations; state what is counted. Initial θ and v are initialization values, not learned outputs of the first update.\n"},{"title":"F25 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Define vanishing gradients in RNNs and explain why they occur. Use “The dogs barked at the thief and … were appreciated” to discuss long context. Explain LSTM forgetting/retention, then compute the retained contribution for f = [0.1,0.9], Cprevious = [2,1].</p>"],"answer":["<h3>Given</h3>","<p>Forget-gate outputs f = [0.1,0.9]; old cell = [2,1].</p>","<p>No input gate or candidate is supplied.</p>","<h3>To find</h3>","<p>Explain forgetting/retention and calculate the retained old-cell part only.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM retained old memory.</strong> Multiply each old cell value by its corresponding forget-gate value. This gives only the old contribution, not the complete new cell.</p>","<p>f = activated forget gate; C_old = previous cell state; ⊙ means multiply matching entries.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35cedc4f6bc20c8a.svg\" alt=\"C_{\\mathrm{retained}}=f\\odot C_{\\mathrm{old}}\" width=\"199.43\" height=\"22.24\" style=\"width:199.43px;height:22.24px;aspect-ratio:199.43/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Forget gate × old cell = bacha hua purana hissa.</p>","<h3>Solution — step by step</h3>","<p>Backpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.</p>","<p>1. Initialize the hidden state and run the forward recurrence from the first input to the last.</p>","<p>2. Compute the specified output loss, at the final step or across several steps.</p>","<p>3. Start from the last loss and propagate derivatives backwards through output and hidden operations.</p>","<p>4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.</p>","<p>5. Sum all uses of each shared weight before applying the optimizer update.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:371.04px;--narrow-height:147.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fdf1ee48fdcfd79f.svg\"><img class=\"math display-math\" src=\"assets/equations/43466db031266f9c.svg\" alt=\"\\delta_t=(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1})\\odot(1-h_t^2),\\quad \\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T}\" width=\"623.72\" height=\"62.51\" style=\"width:623.72px;height:62.51px;aspect-ratio:623.72/62.51\" loading=\"lazy\"></picture></div>","<p>The tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: BPTT follows this unrolled network backwards and sums gradients of shared weights\"><img src=\"assets/figures/rnn.svg\" alt=\"BPTT follows this unrolled network backwards and sums gradients of shared weights\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>BPTT follows this unrolled network backwards and sums gradients of shared weights <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The plural subject “dogs” must remain represented across intervening words. A vanilla RNN may fail to learn that dependency when early gradients are weak; it is not guaranteed to fail on every such sentence. In an LSTM, forget components close to 1 retain relevant subject information along the cell path.</p>","<p class=\"worked-step\"><strong>Step 1: retain the first old-cell component.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/687125898d5f60b7.svg\" alt=\"0.1(2)=0.2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the second old-cell component.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba3003dba6d22d16.svg\" alt=\"0.9(1)=0.9\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: assemble the retained old-cell contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/813a6e1d025fa14c.svg\" alt=\"f\\odot C_{\\mathrm{old}}=[0.2,0.9]\" width=\"205.34\" height=\"24.43\" style=\"width:205.34px;height:24.43px;aspect-ratio:205.34/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> [0.2,0.9] is only retained old content. The input gate and candidate are missing, so the complete updated cell cannot be calculated.</p>"],"kind":"practice","id":"tee-c11-s9","search":"F25 Q4b **Question (10 marks).** Define vanishing gradients in RNNs and explain why they occur. Use “The dogs barked at the thief and … were appreciated” to discuss long context. Explain LSTM forgetting/retention, then compute the retained contribution for f = [0.1,0.9], Cprevious = [2,1].\n\n**Complete worked answer.**\n\n\n\n### Given\n\nForget-gate outputs f = [0.1,0.9]; old cell = [2,1].\n\nNo input gate or candidate is supplied.\n\n### To find\n\nExplain forgetting/retention and calculate the retained old-cell part only.\n\n### Formula — which one and why\n\n**LSTM retained old memory.** Multiply each old cell value by its corresponding forget-gate value. This gives only the old contribution, not the complete new cell.\n\nf = activated forget gate; C_old = previous cell state; ⊙ means multiply matching entries.\n\n\n\n**Yaad rakhne ka cue:** Forget gate × old cell = bacha hua purana hissa.\n\n### Solution — step by step\n\n\n\n\nBackpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.\n1. Initialize the hidden state and run the forward recurrence from the first input to the last.\n2. Compute the specified output loss, at the final step or across several steps.\n3. Start from the last loss and propagate derivatives backwards through output and hidden operations.\n4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.\n5. Sum all uses of each shared weight before applying the optimizer update.\n\nThe tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.\n\nThe plural subject “dogs” must remain represented across intervening words. A vanilla RNN may fail to learn that dependency when early gradients are weak; it is not guaranteed to fail on every such sentence. In an LSTM, forget components close to 1 retain relevant subject information along the cell path.\n**Step 1: retain the first old-cell component.**\n\n\n\n\n\n\n\n**Step 2: retain the second old-cell component.**\n\n\n\n\n\n\n\n**Step 3: assemble the retained old-cell contribution.**\n\n\n\n\n\n\n\n**Final answer:** [0.2,0.9] is only retained old content. The input gate and candidate are missing, so the complete updated cell cannot be calculated.\n"},{"title":"F25 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> State the purpose of each LSTM gate. For “Artificial Intelligence has revolutionized every domain. The work force will have to update themselves to remain relevant,” explain a context change. Calculate C and h given i = 0.7, f = 0.4, o = 0.8, candidate = 0.9, Cprevious = 0.5. Why is LSTM more effective than a simple RNN for language modeling?</p>"],"answer":["<h3>Given</h3>","<p>Activated gate values: i = 0.7,f = 0.4,o = 0.8.</p>","<p>Candidate = 0.9; old cell = 0.5.</p>","<h3>To find</h3>","<p>Explain the context change in the question; calculate the new cell and hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>","<p>The second sentence shifts attention toward the workforce while retaining useful prior AI context. Input gates can admit the new subject; forget gates can reduce obsolete details.</p>","<p class=\"worked-step\"><strong>Step 1: retain old memory.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8f3bf24a2e1d90a0.svg\" alt=\"fC_{old}=0.4(0.5)=0.2\" width=\"233.31\" height=\"24.43\" style=\"width:233.31px;height:24.43px;aspect-ratio:233.31/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: admit candidate content.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a48bf51c7d9b9c7.svg\" alt=\"i\\widetilde C=0.7(0.9)=0.63\" width=\"217.08\" height=\"31.40\" style=\"width:217.08px;height:31.40px;aspect-ratio:217.08/31.40\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b89883a392a4e3ec.svg\" alt=\"C=0.2+0.63=0.83\" width=\"231.72\" height=\"19.23\" style=\"width:231.72px;height:19.23px;aspect-ratio:231.72/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply tanh to the updated cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6aee7e26a8e96885.svg\" alt=\"\\tanh(0.83)\\approx0.680476006\" width=\"272.89\" height=\"24.43\" style=\"width:272.89px;height:24.43px;aspect-ratio:272.89/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: multiply by the output gate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.86px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c85eca49bc37b1e7.svg\"><img class=\"math display-math\" src=\"assets/equations/6ea5c9d366d636a3.svg\" alt=\"h=0.8(0.680476006)\\approx0.544380805\" width=\"387.41\" height=\"24.43\" style=\"width:387.41px;height:24.43px;aspect-ratio:387.41/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> C = 0.83 and h ≈ 0.544380805. The supplied gates are already activated; do not apply sigmoid again.</p>"],"kind":"practice","id":"tee-c11-s10","search":"F25 Q5a **Question (10 marks).** State the purpose of each LSTM gate. For “Artificial Intelligence has revolutionized every domain. The work force will have to update themselves to remain relevant,” explain a context change. Calculate C and h given i = 0.7, f = 0.4, o = 0.8, candidate = 0.9, Cprevious = 0.5. Why is LSTM more effective than a simple RNN for language modeling?\n\n**Complete worked answer.**\n\n\n\n### Given\n\nActivated gate values: i = 0.7,f = 0.4,o = 0.8.\n\nCandidate = 0.9; old cell = 0.5.\n\n### To find\n\nExplain the context change in the question; calculate the new cell and hidden state.\n\n### Formula — which one and why\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\nThe second sentence shifts attention toward the workforce while retaining useful prior AI context. Input gates can admit the new subject; forget gates can reduce obsolete details.\n**Step 1: retain old memory.**\n\n\n\n\n\n\n\n**Step 2: admit candidate content.**\n\n\n\n\n\n\n\n**Step 3: add the two contributions.**\n\n\n\n\n\n\n\n**Step 4: apply tanh to the updated cell.**\n\n\n\n\n\n\n\n**Step 5: multiply by the output gate.**\n\n\n\n\n\n\n\n**Final answer:** C = 0.83 and h ≈ 0.544380805. The supplied gates are already activated; do not apply sigmoid again.\n"},{"title":"F25 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain AdaGrad, give its update rule and discuss advantages and disadvantages compared with standard SGD.</p>"],"answer":["<p>AdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p>Frequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.</p>","<p>Example with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.</p>","<p>Advantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.</p>"],"kind":"practice","id":"tee-c11-s11","search":"F25 Q5b **Question (10 marks).** Explain AdaGrad, give its update rule and discuss advantages and disadvantages compared with standard SGD.\n\n**Complete worked answer.**\nAdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:\n\nFrequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.\nExample with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.\nAdvantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.\n"},{"title":"F25 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Calculate every activation shape and trainable-parameter count for: Input 128 × 128 × 3. → Conv K = 3, filters = 16, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 3, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 240 units. → Dense 120 units. → Dense 5 units. Also convolve the input A with the kernel K shown below, valid padding and stride 2.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 2; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Input 128 × 128 × 3.</p>","<p>Conv K = 3, filters = 16, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 240 units.</p>","<p>Dense 120 units.</p>","<p>Dense 5 units.</p>","<p>Also convolve the input A with the kernel K shown below, valid padding and stride 2.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total. Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">128 × 128 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">16 filters · 3 × 3 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">126 × 126 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">432</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">16</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">448</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>128 × 128 × 3</strong>. Use 16 filters of spatial size 3 × 3, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60bad070a07deb57.svg\"><img class=\"math display-math\" src=\"assets/equations/32d2786097210b6e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{128+2(0)-3}{1}\\right\\rfloor+1=126\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>126 × 126 × 16</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd36df36d5f6f027.svg\"><img class=\"math display-math\" src=\"assets/equations/2eb50e4698b8f7ed.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times3\\times16=432\" width=\"330.89\" height=\"23.91\" style=\"width:330.89px;height:23.91px;aspect-ratio:330.89/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc0c940eb69b41c0.svg\" alt=\"N_{\\mathrm{biases}}=16\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe2e71f3a8efffa4.svg\" alt=\"P_1=432+16=448\" width=\"219.13\" height=\"20.36\" style=\"width:219.13px;height:20.36px;aspect-ratio:219.13/20.36\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">126 × 126 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">63 × 63 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>126 × 126 × 16</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31d9e5cfd413812f.svg\"><img class=\"math display-math\" src=\"assets/equations/3c15021631c4c384.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1=63\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>63 × 63 × 16</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">63 × 63 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 3 × 3 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">61 × 61 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,608</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,640</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>63 × 63 × 16</strong>. Use 32 filters of spatial size 3 × 3, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d1b1c42ec3b8b44b.svg\"><img class=\"math display-math\" src=\"assets/equations/a0caa4135f45ed9c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{63+2(0)-3}{1}\\right\\rfloor+1=61\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>61 × 61 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 16 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcf6aecafd4a3651.svg\"><img class=\"math display-math\" src=\"assets/equations/767ba18d56e40888.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times16\\times32=4{,}608\" width=\"362.11\" height=\"23.91\" style=\"width:362.11px;height:23.91px;aspect-ratio:362.11/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebc484850d4827e3.svg\" alt=\"P_3=4{,}608+32=4{,}640\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">61 × 61 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">30 × 30 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>61 × 61 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2fa03284017c373e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1=30\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>30 × 30 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 29.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 5 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">30 × 30 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">28,800</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>30 × 30 × 32</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f8d6a23f5595005e.svg\"><img class=\"math display-math\" src=\"assets/equations/9fedbcb21e866a38.svg\" alt=\"n_{\\mathrm{flat}}=30\\times30\\times32=28{,}800\" width=\"308.23\" height=\"21.02\" style=\"width:308.23px;height:21.02px;aspect-ratio:308.23/21.02\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>28,800 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 6 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">28,800</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">240 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">240</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">6,912,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">240</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">6,912,240</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>28,800 features</strong>. Output: <strong>240 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e815f655162e42b.svg\"><img class=\"math display-math\" src=\"assets/equations/24e6116ce6d82f93.svg\" alt=\"N_{\\mathrm{weights}}=28{,}800\\times240=6{,}912{,}000\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/237f8d226a0fb66a.svg\" alt=\"N_{\\mathrm{biases}}=240\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a36eb80ee2f332fd.svg\"><img class=\"math display-math\" src=\"assets/equations/a4474a3c31a68206.svg\" alt=\"P_6=6{,}912{,}000+240=6{,}912{,}240\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">240</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">28,800</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">28,920</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>240 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.13px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55419bb786cbe655.svg\"><img class=\"math display-math\" src=\"assets/equations/67cf05b2fc828555.svg\" alt=\"N_{\\mathrm{weights}}=240\\times120=28{,}800\" width=\"314.59\" height=\"23.91\" style=\"width:314.59px;height:23.91px;aspect-ratio:314.59/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/780340973d3c0ce4.svg\"><img class=\"math display-math\" src=\"assets/equations/056fc82ce0b81134.svg\" alt=\"P_7=28{,}800+120=28{,}920\" width=\"293.80\" height=\"21.43\" style=\"width:293.80px;height:21.43px;aspect-ratio:293.80/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">5 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">5</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">600</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">605</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>5 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26857a3f5e70fd9d.svg\" alt=\"N_{\\mathrm{weights}}=120\\times5=600\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8917be67939f2d89.svg\" alt=\"N_{\\mathrm{biases}}=5\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4289ff8bd02992b.svg\" alt=\"P_8=600+5=605\" width=\"206.92\" height=\"20.74\" style=\"width:206.92px;height:20.74px;aspect-ratio:206.92/20.74\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/dbb0832b53a96b49.svg\" alt=\"\\left\\lfloor\\frac{128+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>126 x 126 x 16</td><td>432</td><td>16</td><td>448</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6979fd0d1f6b483.svg\" alt=\"\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>63 x 63 x 16</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f9e5ee2c7c7e1bbb.svg\" alt=\"\\left\\lfloor\\frac{63+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>61 x 61 x 32</td><td>4,608</td><td>32</td><td>4,640</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/1ac02853de1445dd.svg\" alt=\"\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>30 x 30 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 flat</td><td>30 × 30 × 32</td><td>28800</td><td>0</td><td>0</td><td>0</td></tr><tr><td>6 dense</td><td>28800 → 240</td><td>240</td><td>6,912,000</td><td>240</td><td>6,912,240</td></tr><tr><td>7 dense</td><td>240 → 120</td><td>120</td><td>28,800</td><td>120</td><td>28,920</td></tr><tr><td>8 dense</td><td>120 → 5</td><td>5</td><td>600</td><td>5</td><td>605</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (3 x 3 x 3 + 1) x 16 = 448.</p>","<p>Layer 3: (3 x 3 x 16 + 1) x 32 = 4,640.</p>","<p>Layer 6: (28800 + 1) x 240 = 6,912,240.</p>","<p>Layer 7: (240 + 1) x 120 = 28,920.</p>","<p>Layer 8: (120 + 1) x 5 = 605.</p>","<p><strong>Total: </strong> 448 + 4,640 + 6,912,240 + 28,920 + 605 = <strong>6,946,853 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p><strong>Separate convolution calculation: </strong></p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/966c8fb493880239.svg\" alt=\"\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −4\">−4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 + (−2) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>4 + 0 + (−4) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 0 + (−1) = 2</b></div></div><p class=\"lv-combine\"><b>1 + 0 + 2 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7b5121489bd31f6.svg\"><img class=\"math display-math\" src=\"assets/equations/a9fce55fa8f0fbec.svg\" alt=\"R_1=(3)\\times(1)+(1)\\times(0)+(2)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2be91abc57b10ecb.svg\"><img class=\"math display-math\" src=\"assets/equations/b71bdd3aed98c346.svg\" alt=\"R_2=(2)\\times(2)+(1)\\times(0)+(2)\\times(-2)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e404b4617ef0e7d0.svg\"><img class=\"math display-math\" src=\"assets/equations/19fc18a5d8a877eb.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(0)+(1)\\times(-1)=2\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b108d091066c8f7c.svg\" alt=\"Y_{1,1}=(1)+(0)+(2)=3\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0\">0</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 + (−1) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>4 + 0 + 0 = 4</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>1 + 0 + (−1) = 0</b></div></div><p class=\"lv-combine\"><b>1 + 4 + 0 = 5</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa4766cd874d5e7f.svg\"><img class=\"math display-math\" src=\"assets/equations/eaf8c509090f51f1.svg\" alt=\"R_1=(2)\\times(1)+(2)\\times(0)+(1)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93a6f5b5b20f2f23.svg\"><img class=\"math display-math\" src=\"assets/equations/47348f4aaa64e235.svg\" alt=\"R_2=(2)\\times(2)+(1)\\times(0)+(0)\\times(-2)=4\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5f03457a49dcba68.svg\"><img class=\"math display-math\" src=\"assets/equations/91d68511c5df7991.svg\" alt=\"R_3=(1)\\times(1)+(0)\\times(0)+(1)\\times(-1)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd6e5a7547d2ee64.svg\" alt=\"Y_{1,2}=(1)+(4)+(0)=5\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0\">0</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 + (−1) = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>1 + 0 + 0 = 1</b></div></div><p class=\"lv-combine\"><b>2 + 0 + 1 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3a3d0394f9567ec.svg\"><img class=\"math display-math\" src=\"assets/equations/1f506dd6c963dbdb.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(0)+(1)\\times(-1)=2\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ab2e486b72e8236.svg\"><img class=\"math display-math\" src=\"assets/equations/7737415f7a101340.svg\" alt=\"R_2=(0)\\times(2)+(3)\\times(0)+(0)\\times(-2)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2dca2b82f9aac21.svg\"><img class=\"math display-math\" src=\"assets/equations/dbc9736155e0a1ec.svg\" alt=\"R_3=(1)\\times(1)+(1)\\times(0)+(0)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f077b3678b0e1f35.svg\" alt=\"Y_{2,1}=(2)+(0)+(1)=3\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −4\">−4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 + (−1) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 + (−4) = −4</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0 + 0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>0 + (−4) + (−3) = −7</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8247d99177a36658.svg\"><img class=\"math display-math\" src=\"assets/equations/bbe676b3e02a351a.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(0)+(1)\\times(-1)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/959c04625a9a0df4.svg\"><img class=\"math display-math\" src=\"assets/equations/b50d1e82d7e6e8b7.svg\" alt=\"R_2=(0)\\times(2)+(1)\\times(0)+(2)\\times(-2)=-4\" width=\"481.33\" height=\"24.43\" style=\"width:481.33px;height:24.43px;aspect-ratio:481.33/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/20986846d13e4484.svg\"><img class=\"math display-math\" src=\"assets/equations/369116c3da370aea.svg\" alt=\"R_3=(0)\\times(1)+(2)\\times(0)+(3)\\times(-1)=-3\" width=\"481.33\" height=\"24.43\" style=\"width:481.33px;height:24.43px;aspect-ratio:481.33/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:182.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec0342788a9224e.svg\"><img class=\"math display-math\" src=\"assets/equations/0984e17e87f9bbc9.svg\" alt=\"Y_{2,2}=(0)+(-4)+(-3)=-7\" width=\"326.14\" height=\"25.35\" style=\"width:326.14px;height:25.35px;aspect-ratio:326.14/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/3797d8870cefe33e.svg\" alt=\"\\begin{bmatrix}3 &amp; 5\\\\3 &amp; -7\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"kind":"practice","id":"tee-c11-s12","search":"F25 Q6a **Question (10 marks).** Calculate every activation shape and trainable-parameter count for: Input 128 × 128 × 3. → Conv K = 3, filters = 16, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 3, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 240 units. → Dense 120 units. → Dense 5 units. Also convolve the input A with the kernel K shown below, valid padding and stride 2.\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 128 × 128 × 3.\n\nConv K = 3, filters = 16, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 3, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 240 units.\n\nDense 120 units.\n\nDense 5 units.\n\nAlso convolve the input A with the kernel K shown below, valid padding and stride 2.\n\n### To find\n\nFind every layer shape, its parameter count and the network total. Find every convolution output cell.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{128+2 \\times  0-3}{1}\\right\\rfloor+1\\) | 126 x 126 x 16 | 432 | 16 | 448 |\n| 2 pool | \\(\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1\\) | 63 x 63 x 16 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{63+2 \\times  0-3}{1}\\right\\rfloor+1\\) | 61 x 61 x 32 | 4,608 | 32 | 4,640 |\n| 4 pool | \\(\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1\\) | 30 x 30 x 32 | 0 | 0 | 0 |\n| 5 flat | 30 × 30 × 32 | 28800 | 0 | 0 | 0 |\n| 6 dense | 28800 → 240 | 240 | 6,912,000 | 240 | 6,912,240 |\n| 7 dense | 240 → 120 | 120 | 28,800 | 120 | 28,920 |\n| 8 dense | 120 → 5 | 5 | 600 | 5 | 605 |\n**Parameter substitutions, in layer order: **\nLayer 1: (3 x 3 x 3 + 1) x 16 = 448.\nLayer 3: (3 x 3 x 16 + 1) x 32 = 4,640.\nLayer 6: (28800 + 1) x 240 = 6,912,240.\nLayer 7: (240 + 1) x 120 = 28,920.\nLayer 8: (120 + 1) x 5 = 605.\n**Total: ** 448 + 4,640 + 6,912,240 + 28,920 + 605 = **6,946,853 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n**Separate convolution calculation: **\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{5+2 \\times  0"},{"title":"F25 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain activations and the role of nonlinearity. Compare sigmoid, tanh, ReLU and Leaky ReLU including advantages and disadvantages.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>"],"kind":"practice","id":"tee-c11-s13","search":"F25 Q6b **Question (10 marks).** Explain activations and the role of nonlinearity. Compare sigmoid, tanh, ReLU and Leaky ReLU including advantages and disadvantages.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n"},{"title":"F25 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain feedforward information flow, weights, biases and activations, then calculate the output. Input x = [1, 0]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_412d332265.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_412d332265.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [1, 0].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.1].</p>","<p>Hidden and output activations are ReLU.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and the final output. Explain the role of weights, biases and activations in this forward pass.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<p>A feedforward network transforms inputs layer by layer with no recurrent feedback. Weights scale contributions; bias shifts the preactivation; activation supplies the nonlinear transformation.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> Each row of W₁ receives all inputs; each row of W₂ receives all hidden outputs. Bias is added once per receiving neuron.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd4f127dab262e74.svg\"><img class=\"math display-math\" src=\"assets/equations/dc2c7898e4942415.svg\" alt=\"z_{h_1} = (0.2 \\times  1) + (0.4 \\times  0) + (0.1) = 0.3\" width=\"421.90\" height=\"24.58\" style=\"width:421.90px;height:24.58px;aspect-ratio:421.90/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b99f7dd17297569.svg\" alt=\"h_{1} = \\max(0,0.3) = 0.3\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6bf10ef9c5abf8e9.svg\"><img class=\"math display-math\" src=\"assets/equations/f8a809dfb5349555.svg\" alt=\"z_{h_2} = (0.3 \\times  1) + (0.7 \\times  0) + (0.2) = 0.5\" width=\"421.90\" height=\"24.58\" style=\"width:421.90px;height:24.58px;aspect-ratio:421.90/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ac1a985150f1b35b.svg\" alt=\"h_{2} = \\max(0,0.5) = 0.5\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/725a43999780ebd1.svg\"><img class=\"math display-math\" src=\"assets/equations/e22a0b62445991e6.svg\" alt=\"z_{o_1} = (0.5 \\times  0.3) + (0.6 \\times  0.5) + (0.1) = 0.55\" width=\"470.57\" height=\"24.58\" style=\"width:470.57px;height:24.58px;aspect-ratio:470.57/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d22e4c171ba2abbb.svg\" alt=\"o_{1} = \\max(0,0.55) = 0.55\" width=\"262.14\" height=\"24.43\" style=\"width:262.14px;height:24.43px;aspect-ratio:262.14/24.43\" loading=\"lazy\"></div>","<p><strong>Matrix-orientation note: </strong> this solution uses column input and rows as receiving neurons, giving <strong>0.55</strong>. The historical key uses the transpose interpretation for W₁ and obtains 0.61. If the problem does not define its orientation, state your convention; do not silently swap it during calculation. Under the alternative: hidden values = [0.3,0.6], output = 0.5 × 0.3+0.6 × 0.6+0.1 = 0.61.</p>"],"kind":"practice","id":"tee-c11-s14","search":"F25 Q7a **Question (10 marks).** Explain feedforward information flow, weights, biases and activations, then calculate the output. Input x = [1, 0]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [1, 0].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.1].\n\nHidden and output activations are ReLU.\n\n### To find\n\nFind all preactivations, hidden activations and the final output. Explain the role of weights, biases and activations in this forward pass.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\nA feedforward network transforms inputs layer by layer with no recurrent feedback. Weights scale contributions; bias shifts the preactivation; activation supplies the nonlinear transformation.\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Matrix-orientation note: ** this solution uses column input and rows as receiving neurons, giving **0.55**. The historical key uses the transpose interpretation for W₁ and obtains 0.61. If the problem does not define its orientation, state your convention; do not silently swap it during calculation. Under the alternative: hidden values = [0.3,0.6], output = 0.5 × 0.3+0.6 × 0.6+0.1 = 0.61.\n"},{"title":"F25 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain hierarchical CNN feature extraction and the roles of convolution, pooling and fully connected layers. Why prefer CNNs over fully connected ANNs for images? Give medical-image and autonomous-vehicle applications and advantages.</p>"],"answer":["<p>A convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/convolution.svg\" aria-label=\"Enlarge diagram: One filter is reused at successive spatial positions\"><img src=\"assets/figures/convolution.svg\" alt=\"One filter is reused at successive spatial positions\" width=\"960\" height=\"630\" loading=\"lazy\"></button><figcaption>One filter is reused at successive spatial positions <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Convolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.</p>","<p>Compared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.</p>","<p>For medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.</p>"],"kind":"practice","id":"tee-c11-s15","search":"F25 Q7b **Question (10 marks).** Explain hierarchical CNN feature extraction and the roles of convolution, pooling and fully connected layers. Why prefer CNNs over fully connected ANNs for images? Give medical-image and autonomous-vehicle applications and advantages.\n\n**Complete worked answer.**\nA convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.\n\nConvolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.\nCompared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.\nFor medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.\n\n\n"}]},{"n":12,"title":"Re examination February 2026 fully solved","sections":[{"title":"Start here","blocks":["<p>R26 = S09, 10 February 2026. S08 is the associated answer key; S10/S11 are duplicate-content copies in another program folder. One subpart asks a topic not explicitly listed in the current syllabus and is flagged below.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c12-intro"},{"title":"R26 Q1a","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Describe two situations favoring DL over traditional ML. Choose ML or DL for house prices from 1,000 numerical records, real-time facial-emotion video recognition, and translation from millions of sentence pairs.</p>"],"answer":["<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>","<p><strong>Choices: </strong> house prices: start with tabular ML because the features are structured and data are limited. Video emotion: DL can learn visual spatial features and temporal patterns. Large parallel-text translation: DL can learn representations and sequence dependencies. Two situations particularly suited to learned deep representations are complex image recognition and large-scale speech/language tasks; compare validation results instead of assuming an unconditional advantage.</p>"],"kind":"practice","id":"tee-c12-s0","search":"R26 Q1a **Question (5 marks).** Describe two situations favoring DL over traditional ML. Choose ML or DL for house prices from 1,000 numerical records, real-time facial-emotion video recognition, and translation from millions of sentence pairs.\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n**Choices: ** house prices: start with tabular ML because the features are structured and data are limited. Video emotion: DL can learn visual spatial features and temporal patterns. Large parallel-text translation: DL can learn representations and sequence dependencies. Two situations particularly suited to learned deep representations are complex image recognition and large-scale speech/language tasks; compare validation results instead of assuming an unconditional advantage.\n"},{"title":"R26 Q1b","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Explain how activations affect gradients, convergence and performance. State preferred contexts for sigmoid, tanh, ReLU and Leaky ReLU.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>"],"kind":"practice","id":"tee-c12-s1","search":"R26 Q1b **Question (5 marks).** Explain how activations affect gradients, convergence and performance. State preferred contexts for sigmoid, tanh, ReLU and Leaky ReLU.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n"},{"title":"R26 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Explain L1 and L2 regularization. Apply 50% dropout to outputs [0.8,−0.4,0.6,0.2] using an explicitly assumed mask.</p>"],"answer":["<h3>Given</h3>","<p>Activations = [0.8,−0.4,0.6,0.2]; dropout rate = 50%.</p>","<p>The worked example assumes mask [1,0,1,0] and uses inverted dropout.</p>","<p>No numerical weights or λ are supplied for the regularization explanation.</p>","<h3>To find</h3>","<p>Explain L1/L2 and calculate post-dropout activations under the stated mask.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>L2 penalty with a factor of one-half.</strong> This answer uses λ/2 times the sum of squared weights. Differentiating a square supplies a factor of 2, which cancels the one-half, so the added gradient is λw. Use this same convention in the explanation below.</p>","<p>λ = penalty strength; J_data = original data loss; wᵢ = weight i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e906f5f903db890.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac{\\lambda}{2}\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/919b9b7755f3c860.svg\" alt=\"\\frac{\\partial J}{\\partial w_i}=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"210.30\" height=\"54.60\" style=\"width:210.30px;height:54.60px;aspect-ratio:210.30/54.60\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L2 mein half diya hai: square ka 2 cancel, gradient mein lambda × weight.</p>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<h3>Solution — step by step</h3>","<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<h3>Numerical with one explicitly chosen mask</h3>","<p class=\"worked-step\"><strong>Step 1: convert dropout probability to keep probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39070c1933e29986.svg\" alt=\"q=1-0.5=0.5\" width=\"180.95\" height=\"21.02\" style=\"width:180.95px;height:21.02px;aspect-ratio:180.95/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: state a possible mask.</strong></p>","<p>Choose [1,0,1,0]; 1 means keep and 0 means drop. The question allows an assumed mask; others give different realizations.</p>","<p class=\"worked-step\"><strong>Step 3: multiply each activation by its mask entry.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:334.02px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ccd5e8324645240.svg\"><img class=\"math display-math\" src=\"assets/equations/11f3e40a403e55d3.svg\" alt=\"[0.8(1),(-0.4)(0),0.6(1),0.2(0)]=[0.8,0,0.6,0]\" width=\"499.67\" height=\"24.43\" style=\"width:499.67px;height:24.43px;aspect-ratio:499.67/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide the kept values by q for inverted dropout.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/552d192c8691910e.svg\" alt=\"0.8/0.5=1.6\" width=\"138.49\" height=\"24.43\" style=\"width:138.49px;height:24.43px;aspect-ratio:138.49/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2dc3409b6b4b5c.svg\" alt=\"0.6/0.5=1.2\" width=\"138.49\" height=\"24.43\" style=\"width:138.49px;height:24.43px;aspect-ratio:138.49/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: assemble the training output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e92cb4c6084d0ae8.svg\" alt=\"a_{\\mathrm{train}}=[1.6,0,1.2,0]\" width=\"217.16\" height=\"24.43\" style=\"width:217.16px;height:24.43px;aspect-ratio:217.16/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> simple masking gives [0.8,0,0.6,0]; inverted training dropout gives [1.6,0,1.2,0]. At inference inverted dropout is disabled.</p>"],"kind":"practice","id":"tee-c12-s2","search":"R26 Q1c **Question (5 marks).** Explain L1 and L2 regularization. Apply 50% dropout to outputs [0.8,−0.4,0.6,0.2] using an explicitly assumed mask.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nActivations = [0.8,−0.4,0.6,0.2]; dropout rate = 50%.\n\nThe worked example assumes mask [1,0,1,0] and uses inverted dropout.\n\nNo numerical weights or λ are supplied for the regularization explanation.\n\n### To find\n\nExplain L1/L2 and calculate post-dropout activations under the stated mask.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**L2 penalty with a factor of one-half.** This answer uses λ/2 times the sum of squared weights. Differentiating a square supplies a factor of 2, which cancels the one-half, so the added gradient is λw. Use this same convention in the explanation below.\n\nλ = penalty strength; J_data = original data loss; wᵢ = weight i.\n\n\n\n\n\n**Yaad rakhne ka cue:** L2 mein half diya hai: square ka 2 cancel, gradient mein lambda × weight.\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n### Solution — step by step\n\n\n\n\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n### Numerical with one explicitly chosen mask\n\n**Step 1: convert dropout probability to keep probability.**\n\n\n\n\n\n\n\n**Step 2: state a possible mask.**\n\nChoose [1,0,1,0]; 1 means keep and 0 means drop. The question allows an assumed mask; others give different realizations.\n\n**Step 3: multiply each activation by its mask entry.**\n\n\n\n\n\n\n\n**Step 4: divide the kept values by q for inverted dropout.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 5: assemble the training output.**\n\n\n\n\n\n\n\n**Final answer:** simpl"},{"title":"R26 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Explain an RNN for positive, negative or neutral e-commerce review sentiment. Why are recurrence and word order relevant?</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p>For this task select a many-to-one output: tokenize and embed the full review, update the recurrent state across its words, and classify the final sequence representation with a three-unit softmax. Train using one-hot sentiment labels and categorical cross-entropy. “Not worth buying” and “worth buying” illustrate why negation and order matter.</p>"],"kind":"practice","id":"tee-c12-s3","search":"R26 Q1d **Question (5 marks).** Explain an RNN for positive, negative or neutral e-commerce review sentiment. Why are recurrence and word order relevant?\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\nFor this task select a many-to-one output: tokenize and embed the full review, update the recurrent state across its words, and classify the final sequence representation with a three-unit softmax. Train using one-hot sentiment labels and categorical cross-entropy. “Not worth buying” and “worth buying” illustrate why negation and order matter.\n"},{"title":"R26 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Use the sigmoid network Input x = [0.25, 0.7]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [1, 1]; W₂ is shown below; b₂ = [1, 1]. Hidden and output activations are sigmoid. Target y = [0.7, 0.3]. Learning rate η = 1. Here w₁ = x₁ → h₁, w₅ = h₁ → o₁ and w₇ = h₁ → o₂. Run forward and backward passes and update w₁, w₅, w₇. The paper gives no explicit loss formula.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_23b4df4e5b.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_23b4df4e5b.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_r26.svg\" aria-label=\"Enlarge diagram: R26 Q2a weights and both target outputs\"><img src=\"assets/figures/net_r26.svg\" alt=\"R26 Q2a weights and both target outputs\" width=\"960\" height=\"638\" loading=\"lazy\"></button><figcaption>R26 Q2a weights and both target outputs <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [0.25,0.7]; W₁ and W₂ are printed with the question.</p>","<p>Hidden biases = [1,1]; output biases = [1,1]; all activations sigmoid.</p>","<p>Target = [0.7,0.3]; η = 1.</p>","<p>The paper omits the loss; this solution explicitly assumes half summed squared loss.</p>","<h3>To find</h3>","<p>Calculate forward values and update only w₁ = x₁→h₁, w₅ = h₁→o₁ and w₇ = h₁→o₂.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.52px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c1e1a5f6adaaf15c.svg\"><img class=\"math display-math\" src=\"assets/equations/b2652e077761f90d.svg\" alt=\"z_{h_1} = (0.2 \\times  0.25) + (0.15 \\times  0.7) + (1) = 1.155\" width=\"489.78\" height=\"24.58\" style=\"width:489.78px;height:24.58px;aspect-ratio:489.78/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.82px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46c27da6983edf63.svg\"><img class=\"math display-math\" src=\"assets/equations/7c8842866c444dfb.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(1.155)}}=0.760423002\" width=\"351.37\" height=\"53.84\" style=\"width:351.37px;height:53.84px;aspect-ratio:351.37/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/474f99259d04d172.svg\"><img class=\"math display-math\" src=\"assets/equations/47dad759cc7cca83.svg\" alt=\"z_{h_2} = (0.28 \\times  0.25) + (0.3 \\times  0.7) + (1) = 1.28\" width=\"477.57\" height=\"24.58\" style=\"width:477.57px;height:24.58px;aspect-ratio:477.57/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.18px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c014b8bfa585b6d4.svg\"><img class=\"math display-math\" src=\"assets/equations/70222d9bfd6af500.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(1.28)}}=0.782449776\" width=\"342.73\" height=\"53.84\" style=\"width:342.73px;height:53.84px;aspect-ratio:342.73/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ffac566fd3026595.svg\"><img class=\"math display-math\" src=\"assets/equations/6bdace1303796a35.svg\" alt=\"z_{o_1} = (0.1 \\times  0.760423002) + (0.24 \\times  0.782449776) + (1) = 1.263830247\" width=\"744.77\" height=\"24.58\" style=\"width:744.77px;height:24.58px;aspect-ratio:744.77/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee7303ec679c99fc.svg\"><img class=\"math display-math\" src=\"assets/equations/96a03b52510301b3.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(1.263830247)}}=0.779684759\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/32b3910a4ac203c7.svg\"><img class=\"math display-math\" src=\"assets/equations/10506f88ee297ee7.svg\" alt=\"z_{o_2} = (0.12 \\times  0.760423002) + (0.21 \\times  0.782449776) + (1) = 1.255565213\" width=\"756.99\" height=\"24.58\" style=\"width:756.99px;height:24.58px;aspect-ratio:756.99/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/86e75776a23fe7d0.svg\"><img class=\"math display-math\" src=\"assets/equations/de94c544219f4fc9.svg\" alt=\"o_{2}=\\frac{1}{1+e^{-(1.255565213)}}=0.778261739\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [0.079684759, 0.478261739]. Squared errors = [0.006349661, 0.228734291]. Half-sum squared loss = 0.117541976; mean squared error = 0.117541976. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.94px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8de071d3c6435068.svg\"><img class=\"math display-math\" src=\"assets/equations/22b99147ed30be36.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.779684759-0.7) \\times  0.171776436 = 0.013687964\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p><strong>Output delta 2:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.94px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60c2dd77da13f6a8.svg\"><img class=\"math display-math\" src=\"assets/equations/288db260700d28bd.svg\" alt=\"\\delta_{o_2} = 1 \\times  (0.778261739-0.3) \\times  0.172570404 = 0.082533822\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.760423002</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.013687964</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.010408643</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.089591357</strong></div></div><p>Subtract η × gradient = <b>0.010408643</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/084609daa967b1e5.svg\"><img class=\"math display-math\" src=\"assets/equations/b41423f571bf9199.svg\" alt=\"g_{1,1}^{(2)}=(0.013687964)\\times(0.760423002)\\approx 0.010408643\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/642d828dd8261846.svg\"><img class=\"math display-math\" src=\"assets/equations/f48683b41d55c168.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.1-1(0.010408643)\\approx 0.089591357\" width=\"497.16\" height=\"36.54\" style=\"width:497.16px;height:36.54px;aspect-ratio:497.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.782449776</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.013687964</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.010710144</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.24</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.229289856</strong></div></div><p>Subtract η × gradient = <b>0.010710144</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/64e131d9d2fc4b37.svg\"><img class=\"math display-math\" src=\"assets/equations/2d59dee332a4bda3.svg\" alt=\"g_{1,2}^{(2)}=(0.013687964)\\times(0.782449776)\\approx 0.010710144\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7790608d36a6c436.svg\"><img class=\"math display-math\" src=\"assets/equations/db1d78d9cd004855.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.24-1(0.010710144)\\approx 0.229289856\" width=\"509.37\" height=\"36.54\" style=\"width:509.37px;height:36.54px;aspect-ratio:509.37/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h1 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.760423002</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.082533822</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.062760617</strong><span class=\"lv-detail\">h1 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.12</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.057239383</strong></div></div><p>Subtract η × gradient = <b>0.062760617</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dde4ee7e9e8f997c.svg\" alt=\"g_{2,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,1}}=\\delta_{o_2}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7a7372df9b0b6f47.svg\"><img class=\"math display-math\" src=\"assets/equations/393cb494838a4f33.svg\" alt=\"g_{2,1}^{(2)}=(0.082533822)\\times(0.760423002)\\approx 0.062760617\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c6ebfdbda545915.svg\"><img class=\"math display-math\" src=\"assets/equations/28cd106ebaec1141.svg\" alt=\"W^{(2)}_{2,1,\\mathrm{new}}=0.12-1(0.062760617)\\approx 0.057239383\" width=\"509.37\" height=\"36.54\" style=\"width:509.37px;height:36.54px;aspect-ratio:509.37/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.782449776</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.082533822</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.06457857</strong><span class=\"lv-detail\">h2 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.21</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.14542143</strong></div></div><p>Subtract η × gradient = <b>0.06457857</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57d7e754e94fe533.svg\" alt=\"g_{2,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,2}}=\\delta_{o_2}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2264f32e74104528.svg\"><img class=\"math display-math\" src=\"assets/equations/fa16e98e65914abf.svg\" alt=\"g_{2,2}^{(2)}=(0.082533822)\\times(0.782449776)\\approx 0.06457857\" width=\"543.50\" height=\"36.54\" style=\"width:543.50px;height:36.54px;aspect-ratio:543.50/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/334d93272bd11b36.svg\"><img class=\"math display-math\" src=\"assets/equations/9edb4302c3d8076f.svg\" alt=\"W^{(2)}_{2,2,\\mathrm{new}}=0.21-1(0.06457857)\\approx 0.14542143\" width=\"484.93\" height=\"36.54\" style=\"width:484.93px;height:36.54px;aspect-ratio:484.93/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.013687964</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.001368796</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.082533822</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.12</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.009904059</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.011272855</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/02eca34bc6cd23b0.svg\"><img class=\"math display-math\" src=\"assets/equations/0831b555d8416461.svg\" alt=\"C_1=(0.1)\\times(0.013687964)\\approx 0.001368796\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aad6a8cccacf85e0.svg\"><img class=\"math display-math\" src=\"assets/equations/dc757bbb5573b8af.svg\" alt=\"C_2=(0.12)\\times(0.082533822)\\approx 0.009904059\" width=\"462.57\" height=\"24.43\" style=\"width:462.57px;height:24.43px;aspect-ratio:462.57/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/53b10cae0b234be6.svg\"><img class=\"math display-math\" src=\"assets/equations/8c5cd57b66d241cf.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.011272855\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8f0662ebcf4e93d4.svg\"><img class=\"math display-math\" src=\"assets/equations/40cdf85c2c162114.svg\" alt=\"\\delta_{h_1} = 0.011272855 \\times  0.18217986 = 0.002053687\" width=\"500.08\" height=\"23.78\" style=\"width:500.08px;height:23.78px;aspect-ratio:500.08/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.013687964</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.24</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.003285111</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.082533822</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.21</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.017332103</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.020617214</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/276b2a8c520bda99.svg\"><img class=\"math display-math\" src=\"assets/equations/b9be444cf3dd3958.svg\" alt=\"C_1=(0.24)\\times(0.013687964)\\approx 0.003285111\" width=\"462.57\" height=\"24.43\" style=\"width:462.57px;height:24.43px;aspect-ratio:462.57/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5de7487aca6930f.svg\"><img class=\"math display-math\" src=\"assets/equations/0d410407b9e64f3c.svg\" alt=\"C_2=(0.21)\\times(0.082533822)\\approx 0.017332103\" width=\"462.57\" height=\"24.43\" style=\"width:462.57px;height:24.43px;aspect-ratio:462.57/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22192ace89a11d90.svg\"><img class=\"math display-math\" src=\"assets/equations/4564965b0a02c263.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.020617214\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60a157af571eaf0a.svg\"><img class=\"math display-math\" src=\"assets/equations/adbef55caefb8d30.svg\" alt=\"\\delta_{h_2} = 0.020617214 \\times  0.170222124 = 0.003509506\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.25</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.002053687</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000513422</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.199486578</strong></div></div><p>Subtract η × gradient = <b>0.000513422</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c850e9fc715149c.svg\"><img class=\"math display-math\" src=\"assets/equations/fc19919c700c68af.svg\" alt=\"g_{1,1}^{(1)}=(0.002053687)\\times(0.25)\\approx 0.000513422\" width=\"470.20\" height=\"36.54\" style=\"width:470.20px;height:36.54px;aspect-ratio:470.20/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b64d0783616b88f9.svg\"><img class=\"math display-math\" src=\"assets/equations/c0273447c0bc7aba.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.2-1(0.000513422)\\approx 0.199486578\" width=\"497.16\" height=\"36.54\" style=\"width:497.16px;height:36.54px;aspect-ratio:497.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.7</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.002053687</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.001437581</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.15</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.148562419</strong></div></div><p>Subtract η × gradient = <b>0.001437581</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/acf691feadca0305.svg\"><img class=\"math display-math\" src=\"assets/equations/4a66a34e7f770bc0.svg\" alt=\"g_{1,2}^{(1)}=(0.002053687)\\times(0.7)\\approx 0.001437581\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dcaf6fc9df70c8e9.svg\"><img class=\"math display-math\" src=\"assets/equations/1b9c2ae970f21b09.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.15-1(0.001437581)\\approx 0.148562419\" width=\"509.37\" height=\"36.54\" style=\"width:509.37px;height:36.54px;aspect-ratio:509.37/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.25</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.003509506</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000877376</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.28</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.279122624</strong></div></div><p>Subtract η × gradient = <b>0.000877376</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f5370d39d2a07d5.svg\"><img class=\"math display-math\" src=\"assets/equations/a274b0a4de386476.svg\" alt=\"g_{2,1}^{(1)}=(0.003509506)\\times(0.25)\\approx 0.000877376\" width=\"470.20\" height=\"36.54\" style=\"width:470.20px;height:36.54px;aspect-ratio:470.20/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a8f3aa782e00c9f2.svg\"><img class=\"math display-math\" src=\"assets/equations/31e044948722082e.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.28-1(0.000877376)\\approx 0.279122624\" width=\"509.37\" height=\"36.54\" style=\"width:509.37px;height:36.54px;aspect-ratio:509.37/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.7</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.003509506</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.002456654</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.297543346</strong></div></div><p>Subtract η × gradient = <b>0.002456654</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a4233a0dbb4825a8.svg\"><img class=\"math display-math\" src=\"assets/equations/00759f830d2e59b2.svg\" alt=\"g_{2,2}^{(1)}=(0.003509506)\\times(0.7)\\approx 0.002456654\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5c8769134fc1a5f1.svg\"><img class=\"math display-math\" src=\"assets/equations/300691e5cdc3e69a.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.3-1(0.002456654)\\approx 0.297543346\" width=\"497.16\" height=\"36.54\" style=\"width:497.16px;height:36.54px;aspect-ratio:497.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/08fecfb5b65de142.svg\"><img class=\"math display-math\" src=\"assets/equations/94f695ae06ea20c8.svg\" alt=\"b_{h_1,\\mathrm{new}}=1-1(0.002053687)=0.997946313\" width=\"460.98\" height=\"25.35\" style=\"width:460.98px;height:25.35px;aspect-ratio:460.98/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e12e4a571f964fad.svg\"><img class=\"math display-math\" src=\"assets/equations/f5d3af77f03c0547.svg\" alt=\"b_{h_2,\\mathrm{new}}=1-1(0.003509506)=0.996490494\" width=\"460.98\" height=\"25.35\" style=\"width:460.98px;height:25.35px;aspect-ratio:460.98/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/001388bc6f2ce55e.svg\"><img class=\"math display-math\" src=\"assets/equations/7c1e6deff768e7e1.svg\" alt=\"b_{o_1,\\mathrm{new}}=1-1(0.013687964)=0.986312036\" width=\"459.40\" height=\"25.35\" style=\"width:459.40px;height:25.35px;aspect-ratio:459.40/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.06px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7e14e96554640753.svg\"><img class=\"math display-math\" src=\"assets/equations/44e91760f0bb8195.svg\" alt=\"b_{o_2,\\mathrm{new}}=1-1(0.082533822)=0.917466178\" width=\"459.40\" height=\"25.35\" style=\"width:459.40px;height:25.35px;aspect-ratio:459.40/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Requested updates: </strong> w₁ = <strong>0.199486578</strong>, w₅ = <strong>0.089591357</strong>, w₇ = <strong>0.057239383</strong>. For two outputs, this chosen half-sum equals their MSE; an unaveraged unhalved sum would double the gradients.</p>"],"kind":"practice","id":"tee-c12-s4","search":"R26 Q2a **Question (10 marks).** Use the sigmoid network Input x = [0.25, 0.7]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [1, 1]; W₂ is shown below; b₂ = [1, 1]. Hidden and output activations are sigmoid. Target y = [0.7, 0.3]. Learning rate η = 1. Here w₁ = x₁ → h₁, w₅ = h₁ → o₁ and w₇ = h₁ → o₂. Run forward and backward passes and update w₁, w₅, w₇. The paper gives no explicit loss formula.\n\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [0.25,0.7]; W₁ and W₂ are printed with the question.\n\nHidden biases = [1,1]; output biases = [1,1]; all activations sigmoid.\n\nTarget = [0.7,0.3]; η = 1.\n\nThe paper omits the loss; this solution explicitly assumes half summed squared loss.\n\n### To find\n\nCalculate forward values and update only w₁ = x₁→h₁, w₅ = h₁→o₁ and w₇ = h₁→o₂.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Output neuron 2: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [0.079684759, 0.478261739]. Squared errors = [0.006349661, 0.228734291]. Half-sum squared loss = 0.117541976; mean squared error = 0.117541976. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe derivative is o(1−o).\n**Output delta 2:**\n\nThe d"},{"title":"R26 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain AlexNet regularization and training improvements; explain Inception multiscale features and 1 × 1 convolutions; recommend an architecture for large-scale image classification with justification.</p>"],"answer":["<p>AlexNet uses a sequence of convolutional layers followed by fully connected classification layers. Its influential design used ReLU activations, max pooling, dropout in the fully connected part, data augmentation and GPU training. ReLU&#x27;s positive derivative supports learning compared with heavily saturated sigmoid hidden units. Augmentation supplies varied training views; dropout reduces co-adaptation; GPU computation makes a large network practical to train.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/alexnet.svg\" aria-label=\"Enlarge diagram: The common classroom AlexNet layout contains five convolutions and three dense layers\"><img src=\"assets/figures/alexnet.svg\" alt=\"The common classroom AlexNet layout contains five convolutions and three dense layers\" width=\"960\" height=\"480\" loading=\"lazy\"></button><figcaption>The common classroom AlexNet layout contains five convolutions and three dense layers <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The common 227-pixel classroom layout is: Conv 11 stride 4 with 96 filters; pool 3 stride 2; Conv 5 padding 2 with 256 filters; pool 3 stride 2; three Conv 3 padding 1 layers with 384,384,256 filters; pool 3 stride 2; dense 4096; dense 4096; output 1000. Nonlinearities are applied between learned layers. Exact padding, grouping and input conventions must follow the question: the original model used channel groups in some layers, so parameter counts differ from a fully connected-channel simplification.</p>","<p>AlexNet follows a mainly sequential feature-extraction path. An Inception module processes several spatial scales in parallel and concatenates them, often using 1 × 1 bottlenecks to reduce cost. Neither architecture is universally best; the task, resource budget and validation performance determine the choice.</p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>","<p><strong>Recommendation: </strong> an Inception-family model is a defensible choice when varied object scales and computation efficiency matter, because parallel scales with bottlenecks provide diverse features at controlled cost. Compare held-out accuracy, latency and memory with available alternatives. This is a justified choice, not a claim that Inception always beats AlexNet on every dataset.</p>"],"kind":"practice","id":"tee-c12-s5","search":"R26 Q2b **Question (10 marks).** Explain AlexNet regularization and training improvements; explain Inception multiscale features and 1 × 1 convolutions; recommend an architecture for large-scale image classification with justification.\n\n**Complete worked answer.**\nAlexNet uses a sequence of convolutional layers followed by fully connected classification layers. Its influential design used ReLU activations, max pooling, dropout in the fully connected part, data augmentation and GPU training. ReLU's positive derivative supports learning compared with heavily saturated sigmoid hidden units. Augmentation supplies varied training views; dropout reduces co-adaptation; GPU computation makes a large network practical to train.\n\nThe common 227-pixel classroom layout is: Conv 11 stride 4 with 96 filters; pool 3 stride 2; Conv 5 padding 2 with 256 filters; pool 3 stride 2; three Conv 3 padding 1 layers with 384,384,256 filters; pool 3 stride 2; dense 4096; dense 4096; output 1000. Nonlinearities are applied between learned layers. Exact padding, grouping and input conventions must follow the question: the original model used channel groups in some layers, so parameter counts differ from a fully connected-channel simplification.\nAlexNet follows a mainly sequential feature-extraction path. An Inception module processes several spatial scales in parallel and concatenates them, often using 1 × 1 bottlenecks to reduce cost. Neither architecture is universally best; the task, resource budget and validation performance determine the choice.\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\n**Recommendation: ** an Inception-family model is a defensible choice when varied object scales and computation efficiency matter, because parallel scales with bottlenecks provide diverse features at controlled cost. Compare held-out accuracy, latency and memory with available alternatives. This is a justified choice, not a claim that Inception always beats AlexNet on every dataset.\n"},{"title":"R26 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Train a perceptron for one epoch, η = 1, initial weights and bias 0, threshold 0. Samples: [−1,1,−1] → −1; [1,1,1] → 1; [−1,−1,1] → −1; [−1,1,1] → −1. Discuss limitations with examples.</p>"],"answer":["<h3>Given</h3>","<p>Train a perceptron for one epoch, η = 1, initial weights and bias 0, threshold 0.</p>","<p>Samples: [−1,1,−1] → −1.</p>","<p>[1,1,1] → 1.</p>","<p>[−1,−1,1] → −1.</p>","<p>[−1,1,1] → −1.</p>","<h3>To find</h3>","<p>Process samples in order for the stated epochs and report the final weights and bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Target-based perceptron correction.</strong> This worked convention changes parameters only on a wrong prediction. Use the target itself as the signed multiplier; it differs from the binary error rule.</p>","<p>t is the bipolar target; η is the learning rate. Output is +1 above zero, −1 below zero and 0 at exactly zero.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:153.52px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aae3c82602ee4336.svg\"><img class=\"math display-math\" src=\"assets/equations/9f96d47c421b72ff.svg\" alt=\"\\Delta w=\\eta t x,\\quad\\Delta b=\\eta t\\quad\\text{on a mismatch}\" width=\"403.01\" height=\"22.78\" style=\"width:403.01px;height:22.78px;aspect-ratio:403.01/22.78\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Is convention mein galat hua toh target × input se correction.</p>","<h3>Solution — step by step</h3>","<p><strong>State the threshold rule.</strong> Use output +1 if z&gt;0, −1 if z&lt;0, and 0 at z = 0. On a mismatch use Δw = η tx and Δb = ηt; on a match make no update. η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.</p>","<h3>Epoch 1, sample 1</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, -1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (0 × -1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = -1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = -1 × [-1, 1, -1] = [1, -1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = -1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [1, -1, 1], new b = -1.</p>","<h3>Epoch 1, sample 2</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (1 × 1) + (-1 × 1) + (1 × 1) + (-1) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [1, 1, 1] = [1, 1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [2, 0, 2], new b = 0.</p>","<h3>Epoch 1, sample 3</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, -1, 1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (2 × -1) + (0 × -1) + (2 × 1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = -1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = -1 × [-1, -1, 1] = [1, 1, -1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = -1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [3, 1, 1], new b = -1.</p>","<h3>Epoch 1, sample 4</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, 1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (3 × -1) + (1 × 1) + (1 × 1) + (-1) = -2</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = -1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [-1, 1, 1] = [0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [3, 1, 1], new b = -1.</p>","<p><strong>Final after exactly the requested epochs: </strong> w = <strong>[3, 1, 1]</strong>, b = <strong>-1</strong>. A finite number of requested epochs does not itself prove convergence or correct classification of every sample.</p>","<p>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.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/xor.svg\" aria-label=\"Enlarge diagram: Opposite corners for XOR cannot be split by one straight line\"><img src=\"assets/figures/xor.svg\" alt=\"Opposite corners for XOR cannot be split by one straight line\" width=\"960\" height=\"430\" loading=\"lazy\"></button><figcaption>Opposite corners for XOR cannot be split by one straight line <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>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.</p>","<p>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.</p>","<p>A multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.</p>","<p><strong>Key correction: </strong> recomputing each net with the latest weights gives net values 0,0,0,−2 and final w = [3,1,1], b = −1 under the stated bipolar rule. The supplied answer-key table contains inconsistent intermediate arithmetic.</p>"],"kind":"practice","id":"tee-c12-s6","search":"R26 Q3a **Question (10 marks).** Train a perceptron for one epoch, η = 1, initial weights and bias 0, threshold 0. Samples: [−1,1,−1] → −1; [1,1,1] → 1; [−1,−1,1] → −1; [−1,1,1] → −1. Discuss limitations with examples.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nTrain a perceptron for one epoch, η = 1, initial weights and bias 0, threshold 0.\n\nSamples: [−1,1,−1] → −1.\n\n[1,1,1] → 1.\n\n[−1,−1,1] → −1.\n\n[−1,1,1] → −1.\n\n### To find\n\nProcess samples in order for the stated epochs and report the final weights and bias.\n\n### Formula — which one and why\n\n**Target-based perceptron correction.** This worked convention changes parameters only on a wrong prediction. Use the target itself as the signed multiplier; it differs from the binary error rule.\n\nt is the bipolar target; η is the learning rate. Output is +1 above zero, −1 below zero and 0 at exactly zero.\n\n\n\n**Yaad rakhne ka cue:** Is convention mein galat hua toh target × input se correction.\n\n### Solution — step by step\n\n\n\n\n**State the threshold rule.** Use output +1 if z>0, −1 if z<0, and 0 at z = 0. On a mismatch use Δw = η tx and Δb = ηt; on a match make no update. η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.\n### Epoch 1, sample 1\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, -1], target = -1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (0 × -1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = -1\n\n**Step 5: calculate all weight changes.**\n\nΔw = -1 × [-1, 1, -1] = [1, -1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = -1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [1, -1, 1], new b = -1.\n\n\n### Epoch 1, sample 2\n\n**Step 1: copy this sample and target.**\n\nx = [1, 1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (1 × 1) + (-1 × 1) + (1 × 1) + (-1) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [1, 1, 1] = [1, 1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [2, 0, 2], new b = 0.\n\n\n### Epoch 1, sample 3\n\n**Step 1: copy this sample and target.**\n\nx = [-1, -1, 1], target = -1.\n\n**Step 2: calculate the current net.**\n\nz = (2 × -1) + (0 × -1) + (2 × 1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = -1\n\n**Step 5: calculate all weight changes.**\n\nΔw = -1 × [-1, -1, 1] = [1, 1, -1]\n\n**Step 6: calculate the bias change.**\n\nΔb = -1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [3, 1, 1], new b = -1.\n\n\n### Epoch 1, sample 4\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, 1], target = -1.\n\n**Step 2: calculate the current net.**\n\nz = (3 × -1) + (1 × 1) + (1 × 1) + (-1) = -2\n\n**Step 3: apply the threshold.**\n\noutput = -1.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 0\n\n**Step 5: calculate all weight changes.**\n\nΔw = 0 × [-1, 1, 1] = [0, 0, 0]\n\n**Step 6: calculate the bias change.**\n\nΔb = 0.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [3, 1, 1], new b = -1.\n\n\n**Final after exactly the requested epochs: ** w = **[3, 1, 1]**, b = **-1**. A finite number of requested epochs does not itself prove convergence or correct classification of every sample.\nA single perceptron forms a weighted sum and a"},{"title":"R26 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> How should CNN filter counts be selected? Explain effects on feature extraction, dimensionality, computation/memory, overfitting and hierarchical learning.</p>"],"answer":["<p>Choose filter counts as architecture hyperparameters using task complexity, available data, validation performance and resource limits. There is no universal correct count.</p>","<p>1. More filters can represent a wider variety of learned features at a layer; redundant filters do not automatically improve accuracy.</p>","<p>2. Cout filters produce Cout output channels; spatial height/width still follow kernel, padding and stride.</p>","<p>3. A K × K layer uses K²CinCout weights plus Cout biases. More output channels increase current activations and the input-channel cost of the next convolution.</p>","<p>4. Extra capacity can overfit limited data, so use validation, augmentation, transfer learning or regularization. Too few channels may underfit.</p>","<p>5. Later layers often use more channels after spatial downsampling, allowing complex feature combinations at a smaller spatial size. This is a common design choice, not a compulsory rule.</p>","<p>Example: a 3 × 3 layer with 16 input channels has (9 × 16+1) × 32 = 4,640 parameters for 32 filters, versus 9,280 for 64 filters. Output-channel count doubles while the same spatial-size formula applies.</p>"],"kind":"practice","id":"tee-c12-s7","search":"R26 Q3b **Question (10 marks).** How should CNN filter counts be selected? Explain effects on feature extraction, dimensionality, computation/memory, overfitting and hierarchical learning.\n\n**Complete worked answer.**\nChoose filter counts as architecture hyperparameters using task complexity, available data, validation performance and resource limits. There is no universal correct count.\n1. More filters can represent a wider variety of learned features at a layer; redundant filters do not automatically improve accuracy.\n2. Cout filters produce Cout output channels; spatial height/width still follow kernel, padding and stride.\n3. A K × K layer uses K²CinCout weights plus Cout biases. More output channels increase current activations and the input-channel cost of the next convolution.\n4. Extra capacity can overfit limited data, so use validation, augmentation, transfer learning or regularization. Too few channels may underfit.\n5. Later layers often use more channels after spatial downsampling, allowing complex feature combinations at a smaller spatial size. This is a common design choice, not a compulsory rule.\nExample: a 3 × 3 layer with 16 input channels has (9 × 16+1) × 32 = 4,640 parameters for 32 filters, versus 9,280 for 64 filters. Output-channel count doubles while the same spatial-size formula applies.\n"},{"title":"R26 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Compare batch GD and SGD for loss oscillations with a graph, memory and large datasets. Discuss learning rate extremes. For J(θ) = 0.7 θ³, θ₀ = 1, η = 0.1, perform two iterations.</p>"],"answer":["<h3>Given</h3>","<p>J(θ) = 0.7θ³; θ₀ = 1; η = 0.1.</p>","<h3>To find</h3>","<p>Calculate the derivative and perform two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<p>The learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative full batch and stochastic traces distinguish smoothness from progress\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative full batch and stochastic traces distinguish smoothness from progress\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative full batch and stochastic traces distinguish smoothness from progress <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Batch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.</p>","<p>Momentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.</p>","<p>Diagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.</p>","<p class=\"worked-step\"><strong>Step 1: differentiate the objective before substituting.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaad5a7869c46a71.svg\" alt=\"J(\\theta)=0.7\\theta^3\" width=\"131.88\" height=\"27.69\" style=\"width:131.88px;height:27.69px;aspect-ratio:131.88/27.69\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2aadd5dc4445f1ba.svg\" alt=\"g(\\theta)=0.7(3)\\theta^2=2.1\\theta^2\" width=\"245.22\" height=\"27.70\" style=\"width:245.22px;height:27.70px;aspect-ratio:245.22/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate gradient at the original parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6e21de54ead2d325.svg\" alt=\"g_1=2.1(1)^2=2.1\" width=\"191.84\" height=\"27.70\" style=\"width:191.84px;height:27.70px;aspect-ratio:191.84/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the first gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3ed37be87afc8239.svg\" alt=\"0.1(2.1)=0.21\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: subtract to obtain the first update.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e9423903ada8f563.svg\" alt=\"\\theta_1=1-0.21=0.79\" width=\"216.27\" height=\"20.89\" style=\"width:216.27px;height:20.89px;aspect-ratio:216.27/20.89\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: square the changed parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c5b6ff4c2963f39a.svg\" alt=\"0.79^2=0.6241\" width=\"154.57\" height=\"23.60\" style=\"width:154.57px;height:23.60px;aspect-ratio:154.57/23.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: recalculate the gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c986b4d77e3de9d0.svg\" alt=\"g_2=2.1(0.6241)=1.31061\" width=\"285.70\" height=\"24.43\" style=\"width:285.70px;height:24.43px;aspect-ratio:285.70/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: scale the second gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f5b4b6bf69894db.svg\" alt=\"0.1(1.31061)=0.131061\" width=\"255.23\" height=\"24.43\" style=\"width:255.23px;height:24.43px;aspect-ratio:255.23/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 8: subtract from the first updated parameter.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/11da355fe098969f.svg\"><img class=\"math display-math\" src=\"assets/equations/0d180bfeaebc1926.svg\" alt=\"\\theta_2=0.79-0.131061=0.658939\" width=\"345.23\" height=\"20.89\" style=\"width:345.23px;height:20.89px;aspect-ratio:345.23/20.89\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> θ₁ = 0.79; θ₂ = 0.658939. No individual samples are supplied, so these are the stated scalar gradient updates. The cubic is unbounded below; two steps are not a convergence proof.</p>"],"kind":"practice","id":"tee-c12-s8","search":"R26 Q4a **Question (10 marks).** Compare batch GD and SGD for loss oscillations with a graph, memory and large datasets. Discuss learning rate extremes. For J(θ) = 0.7 θ³, θ₀ = 1, η = 0.1, perform two iterations.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nJ(θ) = 0.7θ³; θ₀ = 1; η = 0.1.\n\n### To find\n\nCalculate the derivative and perform two updates.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\nThe learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.\n\nBatch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.\nMomentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.\nDiagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.\n**Step 1: differentiate the objective before substituting.**\n\n\n\n\n\n\n\n\n\n\n\n**Step 2: evaluate gradient at the original parameter.**\n\n\n\n\n\n\n\n**Step 3: scale the first gradient.**\n\n\n\n\n\n\n\n**Step 4: subtract to obtain the first update.**\n\n\n\n\n\n\n\n**Step 5: square the changed parameter.**\n\n\n\n\n\n\n\n**Step 6: recalculate the gradient.**\n\n\n\n\n\n\n\n**Step 7: scale the second gradient.**\n\n\n\n\n\n\n\n**Step 8: subtract from the first updated parameter.**\n\n\n\n\n\n\n\n**Final answer:** θ₁ = 0.79; θ₂ = 0.658939. No individual samples are supplied, so these are the stated scalar gradient updates. The cubic is unbounded below; two steps are not a convergence proof.\n"},{"title":"R26 Q4b","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare LSTM and GRU gates and architecture. Explain the potential computational efficiency of GRU and how its gates can reduce the effect of irrelevant tokens.</p>","<p><strong>Syllabus-aligned extract:</strong> source R26 Q4b, parts i–iii. Marks for these retained parts are not separately stated.</p>"],"answer":["<p>A GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:279.17px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/552178cdb39642a9.svg\"><img class=\"math display-math\" src=\"assets/equations/4c9f5914ab749b31.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z),\\quad r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"618.24\" height=\"24.43\" style=\"width:618.24px;height:24.43px;aspect-ratio:618.24/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:388.02px;--narrow-height:155.11px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/24dba2ef5a8c9844.svg\"><img class=\"math display-math\" src=\"assets/equations/e0ad3b2f8e3f246b.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h),\\quad h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"750.51\" height=\"31.13\" style=\"width:750.51px;height:31.13px;aspect-ratio:750.51/31.13\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gru.svg\" aria-label=\"Enlarge diagram: Reset controls candidate context and update controls the old new mixture\"><img src=\"assets/figures/gru.svg\" alt=\"Reset controls candidate context and update controls the old new mixture\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Reset controls candidate context and update controls the old new mixture <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.</p>","<p>Compared with an LSTM&#x27;s input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.</p>"],"kind":"practice","id":"tee-c12-s9","search":"R26 Q4b **Question.** Compare LSTM and GRU gates and architecture. Explain the potential computational efficiency of GRU and how its gates can reduce the effect of irrelevant tokens.\n\n**Syllabus-aligned extract:** source R26 Q4b, parts i–iii. Marks for these retained parts are not separately stated.\n\n**Complete worked answer.**\nA GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:\n\n\n\nThe reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.\nCompared with an LSTM's input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.\n"},{"title":"R26 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain feedforward limitations for sequential context and how recurrence helps. Calculate h using tanh for Wxh is shown below, Whh is shown below, x = [0,1], hprevious = [0,1], zero bias. Explain next-word probabilities.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_deac39f14c.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_deac39f14c.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Wxh and Whh are printed in the question; use their receiving-neuron rows.</p>","<p>Current input = [0,1]; previous hidden state = [0,1]; bias = 0.</p>","<p>Activation = tanh.</p>","<h3>To find</h3>","<p>Calculate both entries of the new hidden state. Output-layer weights are not supplied.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p class=\"worked-step\"><strong>Step 1: multiply the input vector into row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10e199f12bbe9b83.svg\"><img class=\"math display-math\" src=\"assets/equations/ae37ee7dd9298b47.svg\" alt=\"0.6(0)+0.4(1)=0+0.4=0.4\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: multiply the input vector into row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/360d1cebae87086f.svg\"><img class=\"math display-math\" src=\"assets/equations/0824814bcead44c1.svg\" alt=\"0.3(0)+0.7(1)=0+0.7=0.7\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: multiply previous state into recurrent row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7c5775eea93e5ad0.svg\"><img class=\"math display-math\" src=\"assets/equations/1ae989326f224964.svg\" alt=\"0.5(0)+0.3(1)=0+0.3=0.3\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: multiply previous state into recurrent row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.58px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/818979c823c2927e.svg\"><img class=\"math display-math\" src=\"assets/equations/cd403f4588367553.svg\" alt=\"0.2(0)+0.4(1)=0+0.4=0.4\" width=\"324.49\" height=\"24.43\" style=\"width:324.49px;height:24.43px;aspect-ratio:324.49/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: combine contributions for hidden unit 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/01f98e63892e2cf5.svg\" alt=\"a_1=0.4+0.3+0=0.7\" width=\"254.40\" height=\"20.21\" style=\"width:254.40px;height:20.21px;aspect-ratio:254.40/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: combine contributions for hidden unit 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d5abcbc4ff3b8b0f.svg\" alt=\"a_2=0.7+0.4+0=1.1\" width=\"254.40\" height=\"20.21\" style=\"width:254.40px;height:20.21px;aspect-ratio:254.40/20.21\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: apply tanh separately to each complete sum.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc5f2bb1f8425e2b.svg\"><img class=\"math display-math\" src=\"assets/equations/644bf14870d92481.svg\" alt=\"h_1=\\tanh(0.7)\\approx0.604367777\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ceaf167b0d164375.svg\"><img class=\"math display-math\" src=\"assets/equations/f19c8c78d2c06e2b.svg\" alt=\"h_2=\\tanh(1.1)\\approx0.800499022\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> h ≈ [0.604367777,0.800499022]. The absent vocabulary output weights prevent calculating a numerical next-word probability list.</p>"],"kind":"practice","id":"tee-c12-s10","search":"R26 Q5a **Question (10 marks).** Explain feedforward limitations for sequential context and how recurrence helps. Calculate h using tanh for Wxh is shown below, Whh is shown below, x = [0,1], hprevious = [0,1], zero bias. Explain next-word probabilities.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nWxh and Whh are printed in the question; use their receiving-neuron rows.\n\nCurrent input = [0,1]; previous hidden state = [0,1]; bias = 0.\n\nActivation = tanh.\n\n### To find\n\nCalculate both entries of the new hidden state. Output-layer weights are not supplied.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n**Step 1: multiply the input vector into row 1.**\n\n\n\n\n\n\n\n**Step 2: multiply the input vector into row 2.**\n\n\n\n\n\n\n\n**Step 3: multiply previous state into recurrent row 1.**\n\n\n\n\n\n\n\n**Step 4: multiply previous state into recurrent row 2.**\n\n\n\n\n\n\n\n**Step 5: combine contributions for hidden unit 1.**\n\n\n\n\n\n\n\n**Step 6: combine contributions for hidden unit 2.**\n\n\n\n\n\n\n\n**Step 7: apply tanh separately to each complete sum.**\n\n\n\n\n\n\n\n\n\n\n\n**Final answer:** h ≈ [0.604367777,0.800499022]. The absent vocabulary output weights prevent calculating a numerical next-word probability list.\n"},{"title":"R26 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain RMSProp, its update rule and accumulated squared gradients. Give advantages and disadvantages relative to SGD.</p>"],"answer":["<p>RMSProp keeps an exponentially weighted average of squared gradients, instead of AdaGrad&#x27;s ever-growing sum. For each parameter, initialize s₀ = 0 and use:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.46px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/459c86785f7d6c4f.svg\"><img class=\"math display-math\" src=\"assets/equations/914e44e2b8e8e8f9.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"483.06\" height=\"52.24\" style=\"width:483.06px;height:52.24px;aspect-ratio:483.06/52.24\" loading=\"lazy\"></picture></div>","<p>ρ controls how strongly earlier squared gradients are retained. A large average magnitude produces a larger denominator and a smaller step. A small average magnitude produces a relatively larger step. Squaring happens before averaging; averaging signed gradients instead would allow cancellation and would not be RMSProp.</p>","<p>Example: θ₀ = 1, η = 0.1, ρ = 0.9, s₀ = 0, g₁ = 2. Then s₁ = 0.9 × 0+0.1 × 4 = 0.4. θ₁ = 1−0.2/√0.4 = 0.683772234 when ε is negligible. If g₂ = 1, s₂ = 0.9 × 0.4+0.1 × 1 = 0.46 and θ₂ = 0.683772234−0.1/√0.46 = 0.536330278.</p>","<p>Benefits include adapting to different coordinate scales and avoiding AdaGrad&#x27;s permanent accumulation of all past squared gradients. Costs include extra state memory and tuning η, ρ and ε; noisy or badly chosen settings can still produce poor training. Unlike standard SGD it rescales each coordinate; unlike Adam it does not include a separate first-moment estimate in this basic form.</p>"],"kind":"practice","id":"tee-c12-s11","search":"R26 Q5b **Question (10 marks).** Explain RMSProp, its update rule and accumulated squared gradients. Give advantages and disadvantages relative to SGD.\n\n**Complete worked answer.**\nRMSProp keeps an exponentially weighted average of squared gradients, instead of AdaGrad's ever-growing sum. For each parameter, initialize s₀ = 0 and use:\n\nρ controls how strongly earlier squared gradients are retained. A large average magnitude produces a larger denominator and a smaller step. A small average magnitude produces a relatively larger step. Squaring happens before averaging; averaging signed gradients instead would allow cancellation and would not be RMSProp.\nExample: θ₀ = 1, η = 0.1, ρ = 0.9, s₀ = 0, g₁ = 2. Then s₁ = 0.9 × 0+0.1 × 4 = 0.4. θ₁ = 1−0.2/√0.4 = 0.683772234 when ε is negligible. If g₂ = 1, s₂ = 0.9 × 0.4+0.1 × 1 = 0.46 and θ₂ = 0.683772234−0.1/√0.46 = 0.536330278.\nBenefits include adapting to different coordinate scales and avoiding AdaGrad's permanent accumulation of all past squared gradients. Costs include extra state memory and tuning η, ρ and ε; noisy or badly chosen settings can still produce poor training. Unlike standard SGD it rescales each coordinate; unlike Adam it does not include a separate first-moment estimate in this basic form.\n"},{"title":"R26 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For the binary CNN below, calculate output dimensions and trainable parameters after every layer. Input 256 × 256 × 3. → Conv K = 5, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 128, stride = 1, padding = 1. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 84 units. → Dense 32 units. → Dense 1 units. The printed output size is unspecified; assume one sigmoid output. Unspecified convolution padding is taken as valid.</p>"],"answer":["<h3>Given</h3>","<p>Input 256 × 256 × 3.</p>","<p>Conv K = 5, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 64, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 128, stride = 1, padding = 1.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 84 units.</p>","<p>Dense 32 units.</p>","<p>Dense 1 units.</p>","<p>assume one sigmoid output.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">256 × 256 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">252 × 252 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">2,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">2,432</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>256 × 256 × 3</strong>. Use 32 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f4b85116af3d067a.svg\"><img class=\"math display-math\" src=\"assets/equations/fd4c812f057cfbdc.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{256+2(0)-5}{1}\\right\\rfloor+1=252\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>252 × 252 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/963130ef1e615735.svg\"><img class=\"math display-math\" src=\"assets/equations/ab73b23ba038b015.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times3\\times32=2{,}400\" width=\"349.90\" height=\"23.91\" style=\"width:349.90px;height:23.91px;aspect-ratio:349.90/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/113b757e4d085763.svg\" alt=\"P_1=2{,}400+32=2{,}432\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">252 × 252 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">126 × 126 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>252 × 252 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3083aa89c3311d57.svg\"><img class=\"math display-math\" src=\"assets/equations/ea4835a0c4e1225d.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{252-2}{2}\\right\\rfloor+1=126\" width=\"308.50\" height=\"58.62\" style=\"width:308.50px;height:58.62px;aspect-ratio:308.50/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>126 × 126 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">126 × 126 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">64 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">122 × 122 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">51,200</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">64</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">51,264</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>126 × 126 × 32</strong>. Use 64 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/991cd2a9cf06a3a0.svg\"><img class=\"math display-math\" src=\"assets/equations/8f94d1b01f536cf3.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{126+2(0)-5}{1}\\right\\rfloor+1=122\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>122 × 122 × 64</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 32 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a22447ce668f8dbf.svg\"><img class=\"math display-math\" src=\"assets/equations/5b861b3fc768032c.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times32\\times64=51{,}200\" width=\"374.33\" height=\"23.91\" style=\"width:374.33px;height:23.91px;aspect-ratio:374.33/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc3a74202b89cbd8.svg\" alt=\"N_{\\mathrm{biases}}=64\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/101c0d0d89af6010.svg\" alt=\"P_3=51{,}200+64=51{,}264\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">122 × 122 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">61 × 61 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>122 × 122 × 64</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5f058816466e626.svg\"><img class=\"math display-math\" src=\"assets/equations/61527941fb172a39.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{122-2}{2}\\right\\rfloor+1=61\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>61 × 61 × 64</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">61 × 61 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">128 filters · 5 × 5 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">59 × 59 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">204,800</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">128</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">204,928</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>61 × 61 × 64</strong>. Use 128 filters of spatial size 5 × 5, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8321e7609e3b2886.svg\"><img class=\"math display-math\" src=\"assets/equations/b9ff7e28d1cec2ae.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{61+2(1)-5}{1}\\right\\rfloor+1=59\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>59 × 59 × 128</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 64 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c52ed6d2bdad242d.svg\"><img class=\"math display-math\" src=\"assets/equations/2b0e3ca2da50e61a.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times64\\times128=204{,}800\" width=\"398.77\" height=\"23.91\" style=\"width:398.77px;height:23.91px;aspect-ratio:398.77/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf36568f06144792.svg\" alt=\"N_{\\mathrm{biases}}=128\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f00380ddc73ffc90.svg\"><img class=\"math display-math\" src=\"assets/equations/81ad3f9ee9d3ccc2.svg\" alt=\"P_5=204{,}800+128=204{,}928\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">59 × 59 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">29 × 29 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>59 × 59 × 128</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c7e04e5a610fd348.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{59-2}{2}\\right\\rfloor+1=29\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>29 × 29 × 128</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 28.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 7 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">29 × 29 × 128</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">107,648</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>29 × 29 × 128</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.99px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4f51a385169358d4.svg\"><img class=\"math display-math\" src=\"assets/equations/d04e40df15cb4a0b.svg\" alt=\"n_{\\mathrm{flat}}=29\\times29\\times128=107{,}648\" width=\"332.66\" height=\"21.29\" style=\"width:332.66px;height:21.29px;aspect-ratio:332.66/21.29\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>107,648 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">107,648</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">84 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">9,042,432</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">84</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">9,042,516</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>107,648 features</strong>. Output: <strong>84 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3496f06ddb91fc91.svg\"><img class=\"math display-math\" src=\"assets/equations/63fdb30c55665f91.svg\" alt=\"N_{\\mathrm{weights}}=107{,}648\\times84=9{,}042{,}432\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec58135349b68114.svg\" alt=\"N_{\\mathrm{biases}}=84\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.35px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a73b69ea184fcd0.svg\"><img class=\"math display-math\" src=\"assets/equations/868b3136771d3432.svg\" alt=\"P_8=9{,}042{,}432+84=9{,}042{,}516\" width=\"344.03\" height=\"21.43\" style=\"width:344.03px;height:21.43px;aspect-ratio:344.03/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 9 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">32 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">32</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">2,688</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">2,720</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>84 features</strong>. Output: <strong>32 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6439e320bc2235fb.svg\" alt=\"N_{\\mathrm{weights}}=84\\times32=2{,}688\" width=\"277.94\" height=\"23.91\" style=\"width:277.94px;height:23.91px;aspect-ratio:277.94/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737742757d7487f8.svg\" alt=\"P_9=2{,}688+32=2{,}720\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">32</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">1 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">33</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>32 features</strong>. Output: <strong>1 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/63bcab1d4c5ad97d.svg\" alt=\"N_{\\mathrm{weights}}=32\\times1=32\" width=\"234.50\" height=\"23.91\" style=\"width:234.50px;height:23.91px;aspect-ratio:234.50/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9172e32c44e88eec.svg\" alt=\"N_{\\mathrm{biases}}=1\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6095954f97f48924.svg\" alt=\"P_10=32+1=33\" width=\"194.69\" height=\"20.36\" style=\"width:194.69px;height:20.36px;aspect-ratio:194.69/20.36\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/6723e51cb832856a.svg\" alt=\"\\left\\lfloor\\frac{256+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>252 x 252 x 32</td><td>2,400</td><td>32</td><td>2,432</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/88e7931306349767.svg\" alt=\"\\left\\lfloor\\frac{252-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>126 x 126 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5b79f5df9ff78236.svg\" alt=\"\\left\\lfloor\\frac{126+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>122 x 122 x 64</td><td>51,200</td><td>64</td><td>51,264</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/8713b9890edc970c.svg\" alt=\"\\left\\lfloor\\frac{122-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>61 x 61 x 64</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/54ee85e0468271d4.svg\" alt=\"\\left\\lfloor\\frac{61+2 \\times  1-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>59 x 59 x 128</td><td>204,800</td><td>128</td><td>204,928</td></tr><tr><td>6 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e80bd4fe22509760.svg\" alt=\"\\left\\lfloor\\frac{59-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>29 x 29 x 128</td><td>0</td><td>0</td><td>0</td></tr><tr><td>7 flat</td><td>29 × 29 × 128</td><td>107648</td><td>0</td><td>0</td><td>0</td></tr><tr><td>8 dense</td><td>107648 → 84</td><td>84</td><td>9,042,432</td><td>84</td><td>9,042,516</td></tr><tr><td>9 dense</td><td>84 → 32</td><td>32</td><td>2,688</td><td>32</td><td>2,720</td></tr><tr><td>10 dense</td><td>32 → 1</td><td>1</td><td>32</td><td>1</td><td>33</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (5 x 5 x 3 + 1) x 32 = 2,432.</p>","<p>Layer 3: (5 x 5 x 32 + 1) x 64 = 51,264.</p>","<p>Layer 5: (5 x 5 x 64 + 1) x 128 = 204,928.</p>","<p>Layer 8: (107648 + 1) x 84 = 9,042,516.</p>","<p>Layer 9: (84 + 1) x 32 = 2,720.</p>","<p>Layer 10: (32 + 1) x 1 = 33.</p>","<p><strong>Total: </strong> 2,432 + 51,264 + 204,928 + 9,042,516 + 2,720 + 33 = <strong>9,303,893 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p><strong>Correction: </strong> Conv 3 has (5 × 5 × 64+1) × 128 = <strong>204,928</strong> parameters, not 73,856 as printed in the key. Correct total is <strong>9,303,893</strong>. If binary classification is instead implemented with two softmax outputs, the last dense layer has(32+1) × 2 = 66 parameters and the total becomes 9,303,926; explicitly state the output convention.</p>"],"kind":"practice","id":"tee-c12-s12","search":"R26 Q6a **Question (10 marks).** For the binary CNN below, calculate output dimensions and trainable parameters after every layer. Input 256 × 256 × 3. → Conv K = 5, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 128, stride = 1, padding = 1. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 84 units. → Dense 32 units. → Dense 1 units. The printed output size is unspecified; assume one sigmoid output. Unspecified convolution padding is taken as valid.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 256 × 256 × 3.\n\nConv K = 5, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 64, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 128, stride = 1, padding = 1.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 84 units.\n\nDense 32 units.\n\nDense 1 units.\n\nassume one sigmoid output.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{256+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 252 x 252 x 32 | 2,400 | 32 | 2,432 |\n| 2 pool | \\(\\left\\lfloor\\frac{252-2}{2}\\right\\rfloor+1\\) | 126 x 126 x 32 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{126+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 122 x 122 x 64 | 51,200 | 64 | 51,264 |\n| 4 pool | \\(\\left\\lfloor\\frac{122-2}{2}\\right\\rfloor+1\\) | 61 x 61 x 64 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{61+2 \\times  1-5}{1}\\right\\rfloor+1\\) | 59 x 59 x 128 | 204,800 | 128 | 204,928 |\n| 6 pool | \\(\\left\\lfloor\\frac{59-2}{2}\\right\\rfloor+1\\) | 29 x 29 x 128 | 0 | 0 | 0 |\n| 7 flat | 29 × 29 × 128 | 107648 | 0 | 0 | 0 |\n| 8 dense | 107648 → 84 | 84 | 9,042,432 | 84 | 9,042,516 |\n| 9 dense | 84 → 32 | 32 | 2,688 | 32 | 2,720 |\n| 10 dense | 32 → 1 | 1 | 32 | 1 | 33 |\n**Parameter substitutions, in layer order: **\nLayer 1: (5 x 5 x 3 + 1) x 32 = 2,432.\nLayer 3: (5 x 5 x 32 + 1) x 64 = 51,264.\nLayer 5: (5 x 5 x 64 + 1) x 128 = 204,928.\nLayer 8: (107648 + 1) x 84 = 9,042,516.\nLayer 9: (84 + 1) x 32 = 2,720.\nLayer 10: (32 + 1) x 1 = 33.\n**Total: ** 2,432 + 51,264 + 204,928 + 9,042,516 + 2,720 + 33 = **9,303,893 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n**Correction: ** Conv 3 has (5 × 5 × 64+1) × 128 = **204,928** parameters, not 73,856 as printed in the key. Correct total is "},{"title":"R26 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For a 10-layer network using sigmoid: compute f(6), compute its derivative at 6, explain its effect on backpropagation, and calculate softmax for [2.3,4.5,3.2].</p>"],"answer":["<h3>Given</h3>","<p>Sigmoid is evaluated at z = 6 in a ten-layer network.</p>","<p>Softmax scores = [2.3,4.5,3.2].</p>","<h3>To find</h3>","<p>Calculate sigmoid and its derivative at 6, explain the gradient effect and calculate all three softmax probabilities.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<h3>Solution — step by step</h3>","<p>f(6) = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ac8062a4bfd609d2.svg\" alt=\"\\frac{1}{1+e^{-6}}\" width=\"68.70\" height=\"40.75\" style=\"width:68.70px;height:40.75px;aspect-ratio:68.70/40.75\" loading=\"lazy\"></span> = <strong>0.997527377</strong>. Derivative = f(6)[1−f(6)] = 0.997527377 × 0.002472623 = <strong>0.002466509</strong>. This is a saturated sigmoid with a very small slope. Repeatedly multiplying small activation derivatives and weight factors can weaken earlier-layer gradients; the exact gradient also depends on weights and all preactivations, so it is not simply this derivative raised to 10 unless those conditions are assumed.</p>","<p class=\"worked-step\"><strong>Step 1 stabilize: </strong> subtract the largest logit 4.5 from every value: [-2.2, 0, -1.3]. This does not change softmax.</p>","<p class=\"worked-step\"><strong>Step 2 exponentiate: </strong> exp values = [0.110803158, 1, 0.272531793].</p>","<p class=\"worked-step\"><strong>Step 3 denominator: </strong> sum = 1.383334951.</p>","<p class=\"worked-step\"><strong>Step 4 divide each value by this same sum: </strong> probabilities = <strong>[0.080098575, 0.722890721, 0.197010704]</strong>. <strong>Check: </strong> all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.</p>"],"kind":"practice","id":"tee-c12-s13","search":"R26 Q6b **Question (10 marks).** For a 10-layer network using sigmoid: compute f(6), compute its derivative at 6, explain its effect on backpropagation, and calculate softmax for [2.3,4.5,3.2].\n\n**Complete worked answer.**\n\n\n\n### Given\n\nSigmoid is evaluated at z = 6 in a ten-layer network.\n\nSoftmax scores = [2.3,4.5,3.2].\n\n### To find\n\nCalculate sigmoid and its derivative at 6, explain the gradient effect and calculate all three softmax probabilities.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n### Solution — step by step\n\n\n\n\n\n\nf(6) = \\(\\frac{1}{1+e^{-6}}\\) = **0.997527377**. Derivative = f(6)[1−f(6)] = 0.997527377 × 0.002472623 = **0.002466509**. This is a saturated sigmoid with a very small slope. Repeatedly multiplying small activation derivatives and weight factors can weaken earlier-layer gradients; the exact gradient also depends on weights and all preactivations, so it is not simply this derivative raised to 10 unless those conditions are assumed.\n**Step 1 stabilize: ** subtract the largest logit 4.5 from every value: [-2.2, 0, -1.3]. This does not change softmax.\n\n**Step 2 exponentiate: ** exp values = [0.110803158, 1, 0.272531793].\n\n**Step 3 denominator: ** sum = 1.383334951.\n\n**Step 4 divide each value by this same sum: ** probabilities = **[0.080098575, 0.722890721, 0.197010704]**. **Check: ** all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.\n"},{"title":"R26 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Compare single-layer and multilayer feedforward networks and explain hidden nonlinearity. Compute the output for Input x = [0.5, 0.2, 0.1]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.5]. Hidden and output activations are sigmoid.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_2fad289da9.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_2fad289da9.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [0.5, 0.2, 0.1].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.5].</p>","<p>Hidden and output activations are sigmoid.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<h3>Solution — step by step</h3>","<p>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.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/xor.svg\" aria-label=\"Enlarge diagram: Opposite corners for XOR cannot be split by one straight line\"><img src=\"assets/figures/xor.svg\" alt=\"Opposite corners for XOR cannot be split by one straight line\" width=\"960\" height=\"430\" loading=\"lazy\"></button><figcaption>Opposite corners for XOR cannot be split by one straight line <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>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.</p>","<p>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.</p>","<p>A multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> Each row of W₁ receives all inputs; each row of W₂ receives all hidden outputs. Bias is added once per receiving neuron.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eecbe3a4008b0943.svg\"><img class=\"math display-math\" src=\"assets/equations/ce1c6f120d2c62ed.svg\" alt=\"z_{h_1} = (0.1 \\times  0.5) + (0.4 \\times  0.2) + (0.2 \\times  0.1) + (0.1) = 0.25\" width=\"613.34\" height=\"24.58\" style=\"width:613.34px;height:24.58px;aspect-ratio:613.34/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.18px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/00585fcf1de8913d.svg\"><img class=\"math display-math\" src=\"assets/equations/49beb90377a79a2a.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(0.25)}}=0.562176501\" width=\"342.73\" height=\"53.84\" style=\"width:342.73px;height:53.84px;aspect-ratio:342.73/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b2e10076eac3269f.svg\"><img class=\"math display-math\" src=\"assets/equations/805e34a1908652d7.svg\" alt=\"z_{h_2} = (0.3 \\times  0.5) + (0.5 \\times  0.2) + (0.7 \\times  0.1) + (0.2) = 0.52\" width=\"613.34\" height=\"24.58\" style=\"width:613.34px;height:24.58px;aspect-ratio:613.34/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.18px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e33e2e29f7e69ace.svg\"><img class=\"math display-math\" src=\"assets/equations/ee84a1f5182572dc.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.52)}}=0.627147766\" width=\"342.73\" height=\"53.84\" style=\"width:342.73px;height:53.84px;aspect-ratio:342.73/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8b8732deca8578d9.svg\"><img class=\"math display-math\" src=\"assets/equations/221339217d406589.svg\" alt=\"z_{o_1} = (0.6 \\times  0.562176501) + (0.9 \\times  0.627147766) + (0.5) = 1.40173889\" width=\"739.35\" height=\"24.58\" style=\"width:739.35px;height:24.58px;aspect-ratio:739.35/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.80px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/728269faf184ac73.svg\"><img class=\"math display-math\" src=\"assets/equations/69ae9d8fc60db8fd.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(1.40173889)}}=0.802459679\" width=\"392.34\" height=\"53.84\" style=\"width:392.34px;height:53.84px;aspect-ratio:392.34/53.84\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c12-s14","search":"R26 Q7a **Question (10 marks).** Compare single-layer and multilayer feedforward networks and explain hidden nonlinearity. Compute the output for Input x = [0.5, 0.2, 0.1]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.5]. Hidden and output activations are sigmoid.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [0.5, 0.2, 0.1].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.5].\n\nHidden and output activations are sigmoid.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n### Solution — step by step\n\n\n\n\nA 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.\n\nFor 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.\nFor 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.\nA multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n"},{"title":"R26 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain transfer learning with CNNs and how to adapt a pretrained model to a new image classification task, including an example model.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>","<p><strong>Concrete example: </strong> replace the 1000-class head of a pretrained ResNet with a 10-class vegetable head. Train the new head with the base frozen, then optionally fine-tune late residual blocks at a smaller rate. Input preprocessing must match the pretrained model. The 10 output probabilities sum to 1 for mutually exclusive classes.</p>"],"kind":"practice","id":"tee-c12-s15","search":"R26 Q7b **Question (10 marks).** Explain transfer learning with CNNs and how to adapt a pretrained model to a new image classification task, including an example model.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n**Concrete example: ** replace the 1000-class head of a pretrained ResNet with a 10-class vegetable head. Train the new head with the base frozen, then optionally fine-tune late residual blocks at a smaller rate. Input preprocessing must match the pretrained model. The 10 output probabilities sum to 1 for mutually exclusive classes.\n\n\n"}]},{"n":13,"title":"Final examination December 2023 fully solved","sections":[{"title":"Start here","blocks":["<p>F23 = S17, 2 December 2023. Scanned formulas and diagrams were checked visually rather than trusting OCR alone.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c13-intro"},{"title":"F23 Q1a","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> State the features and limitations of deep learning.</p>"],"answer":["<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>"],"kind":"practice","id":"tee-c13-s0","search":"F23 Q1a **Question (5 marks).** State the features and limitations of deep learning.\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n"},{"title":"F23 Q1b","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Identify the hyperparameters to tune when training an ANN and explain their significance.</p>"],"answer":["<p>Hyperparameters are chosen outside the ordinary weight-gradient updates. Learning rate controls step size; number of layers and units controls capacity; activation determines nonlinear behavior; batch size controls the data used per update and memory demand; epochs control training duration. Regularization strength, dropout rate and early-stopping patience affect generalization. Optimizer-specific choices include momentum β or Adam β₁, β₂,ε. Tune using validation data while keeping the final test set separate. Weights and biases are learned parameters; they are not hyperparameters merely because their initial values must be selected.</p>"],"kind":"practice","id":"tee-c13-s1","search":"F23 Q1b **Question (5 marks).** Identify the hyperparameters to tune when training an ANN and explain their significance.\n\n**Complete worked answer.**\nHyperparameters are chosen outside the ordinary weight-gradient updates. Learning rate controls step size; number of layers and units controls capacity; activation determines nonlinear behavior; batch size controls the data used per update and memory demand; epochs control training duration. Regularization strength, dropout rate and early-stopping patience affect generalization. Optimizer-specific choices include momentum β or Adam β₁, β₂,ε. Tune using validation data while keeping the final test set separate. Weights and biases are learned parameters; they are not hyperparameters merely because their initial values must be selected.\n"},{"title":"F23 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Draw a time-unrolled RNN and briefly explain training by backpropagation through time.</p>"],"answer":["<p>Backpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.</p>","<p>1. Initialize the hidden state and run the forward recurrence from the first input to the last.</p>","<p>2. Compute the specified output loss, at the final step or across several steps.</p>","<p>3. Start from the last loss and propagate derivatives backwards through output and hidden operations.</p>","<p>4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.</p>","<p>5. Sum all uses of each shared weight before applying the optimizer update.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:371.04px;--narrow-height:147.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fdf1ee48fdcfd79f.svg\"><img class=\"math display-math\" src=\"assets/equations/43466db031266f9c.svg\" alt=\"\\delta_t=(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1})\\odot(1-h_t^2),\\quad \\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T}\" width=\"623.72\" height=\"62.51\" style=\"width:623.72px;height:62.51px;aspect-ratio:623.72/62.51\" loading=\"lazy\"></picture></div>","<p>The tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: BPTT follows this unrolled network backwards and sums gradients of shared weights\"><img src=\"assets/figures/rnn.svg\" alt=\"BPTT follows this unrolled network backwards and sums gradients of shared weights\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>BPTT follows this unrolled network backwards and sums gradients of shared weights <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c13-s2","search":"F23 Q1c **Question (5 marks).** Draw a time-unrolled RNN and briefly explain training by backpropagation through time.\n\n**Complete worked answer.**\nBackpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.\n1. Initialize the hidden state and run the forward recurrence from the first input to the last.\n2. Compute the specified output loss, at the final step or across several steps.\n3. Start from the last loss and propagate derivatives backwards through output and hidden operations.\n4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.\n5. Sum all uses of each shared weight before applying the optimizer update.\n\nThe tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.\n\n"},{"title":"F23 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 1; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.</p>","<h3>To find</h3>","<p>Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/451621c0173b1850.svg\" alt=\"\\left\\lfloor\\frac{4+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 14\">14</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>10 + 9 + 5 = 24</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>5 + 14 + 6 = 25</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 3 + 2 = 8</b></div></div><p class=\"lv-combine\"><b>24 + 25 + 8 = 57</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fe1b0c406527aa8.svg\"><img class=\"math display-math\" src=\"assets/equations/17e6fe356ebb57a3.svg\" alt=\"R_1=(10)\\times(1)+(9)\\times(1)+(5)\\times(1)=24\" width=\"467.75\" height=\"24.43\" style=\"width:467.75px;height:24.43px;aspect-ratio:467.75/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dec76766281c84de.svg\"><img class=\"math display-math\" src=\"assets/equations/4ae5e24b45a652e7.svg\" alt=\"R_2=(5)\\times(1)+(7)\\times(2)+(6)\\times(1)=25\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/612c6e731f469d2a.svg\"><img class=\"math display-math\" src=\"assets/equations/640dbb668111d247.svg\" alt=\"R_3=(3)\\times(1)+(3)\\times(1)+(2)\\times(1)=8\" width=\"443.31\" height=\"24.43\" style=\"width:443.31px;height:24.43px;aspect-ratio:443.31/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.75px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b718b308893f322.svg\"><img class=\"math display-math\" src=\"assets/equations/572c32730d6fe617.svg\" alt=\"Y_{1,1}=(24)+(25)+(8)=57\" width=\"305.76\" height=\"25.35\" style=\"width:305.76px;height:25.35px;aspect-ratio:305.76/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>2–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 9\">9</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 6\">6</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 7\">7</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 12\">12</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 7\">7</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 8\">8</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>9 + 5 + 6 = 20</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>7 + 12 + 7 = 26</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 2 + 8 = 13</b></div></div><p class=\"lv-combine\"><b>20 + 26 + 13 = 59</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c760b3950eb840ed.svg\"><img class=\"math display-math\" src=\"assets/equations/227f73214fffc2b3.svg\" alt=\"R_1=(9)\\times(1)+(5)\\times(1)+(6)\\times(1)=20\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/16eb873463fe23bb.svg\"><img class=\"math display-math\" src=\"assets/equations/5e2ed47a500a084d.svg\" alt=\"R_2=(7)\\times(1)+(6)\\times(2)+(7)\\times(1)=26\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/17c18e38643140f3.svg\"><img class=\"math display-math\" src=\"assets/equations/adea8f6e7cdc7e9c.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(1)+(8)\\times(1)=13\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.65px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f077bed2b9d89eff.svg\"><img class=\"math display-math\" src=\"assets/equations/b674e79df8f34858.svg\" alt=\"Y_{1,2}=(20)+(26)+(13)=59\" width=\"317.98\" height=\"25.35\" style=\"width:317.98px;height:25.35px;aspect-ratio:317.98/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–4</b>, columns <b>1–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 5\">5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 7\">7</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 6\">6</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 6\">6</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 6\">6</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>5 + 7 + 6 = 18</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>3 + 6 + 2 = 11</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 2 + 6 = 11</b></div></div><p class=\"lv-combine\"><b>18 + 11 + 11 = 40</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ba28bdc7c806323.svg\"><img class=\"math display-math\" src=\"assets/equations/a148f40de653ff23.svg\" alt=\"R_1=(5)\\times(1)+(7)\\times(1)+(6)\\times(1)=18\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5861059147729994.svg\"><img class=\"math display-math\" src=\"assets/equations/0bf1f6754ed5f9c0.svg\" alt=\"R_2=(3)\\times(1)+(3)\\times(2)+(2)\\times(1)=11\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c85bf61f7da39979.svg\"><img class=\"math display-math\" src=\"assets/equations/849173dcb9ca1a0f.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(1)+(6)\\times(1)=11\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.65px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ba895c690daff56.svg\"><img class=\"math display-math\" src=\"assets/equations/867dfee50107ebc8.svg\" alt=\"Y_{2,1}=(18)+(11)+(11)=40\" width=\"317.98\" height=\"25.35\" style=\"width:317.98px;height:25.35px;aspect-ratio:317.98/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–4</b>, columns <b>2–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 10\">10</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 9\">9</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 6\">6</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 5\">5</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 7\">7</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 6\">6</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 7\">7</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 8\">8</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 6\">6</td><td class=\"lv-row-2 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 1\">1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 7\">7</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 6\">6</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 7\">7</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 8\">8</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 6\">6</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 7\">7</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>7 + 6 + 7 = 20</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>3 + 4 + 8 = 15</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>2 + 6 + 7 = 15</b></div></div><p class=\"lv-combine\"><b>20 + 15 + 15 = 50</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 57\">57</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 59\">59</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 40\">40</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 50\">50</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/05ae17650121d076.svg\"><img class=\"math display-math\" src=\"assets/equations/9f8fed3c271dceb7.svg\" alt=\"R_1=(7)\\times(1)+(6)\\times(1)+(7)\\times(1)=20\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9dcb85c5c6766eb3.svg\"><img class=\"math display-math\" src=\"assets/equations/7daf395d533e53c4.svg\" alt=\"R_2=(3)\\times(1)+(2)\\times(2)+(8)\\times(1)=15\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2745b26251055027.svg\"><img class=\"math display-math\" src=\"assets/equations/0136802d6b00a2fe.svg\" alt=\"R_3=(2)\\times(1)+(6)\\times(1)+(7)\\times(1)=15\" width=\"455.52\" height=\"24.43\" style=\"width:455.52px;height:24.43px;aspect-ratio:455.52/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:187.65px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90b52e79a3bf1954.svg\"><img class=\"math display-math\" src=\"assets/equations/9333688e57e199f1.svg\" alt=\"Y_{2,2}=(20)+(15)+(15)=50\" width=\"317.98\" height=\"25.35\" style=\"width:317.98px;height:25.35px;aspect-ratio:317.98/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/3c78c4fdcdcef59f.svg\" alt=\"\\begin{bmatrix}57 &amp; 59\\\\40 &amp; 50\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"kind":"practice","id":"tee-c13-s3","search":"F23 Q1d **Question (5 marks).** Compute the convolution using the input A and kernel K shown below using padding 0 and stride 1.\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nCompute the convolution using the input A and kernel K shown below using padding 0 and stride 1.\n\n### To find\n\nFind every convolution output cell.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{4+2 \\times  0-3}{1}\\right\\rfloor+1\\) = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.\n**Output (1,1): ** (10 × (1)) + (9 × (1)) + (5 × (1)) + (5 × (1)) + (7 × (2)) + (6 × (1)) + (3 × (1)) + (3 × (1)) + (2 × (1)) = **57**.\n**Output (1,2): ** (9 × (1)) + (5 × (1)) + (6 × (1)) + (7 × (1)) + (6 × (2)) + (7 × (1)) + (3 × (1)) + (2 × (1)) + (8 × (1)) = **59**.\n**Output (2,1): ** (5 × (1)) + (7 × (1)) + (6 × (1)) + (3 × (1)) + (3 × (2)) + (2 × (1)) + (3 × (1)) + (2 × (1)) + (6 × (1)) = **40**.\n**Output (2,2): ** (7 × (1)) + (6 × (1)) + (7 × (1)) + (3 × (1)) + (2 × (2)) + (8 × (1)) + (2 × (1)) + (6 × (1)) + (7 × (1)) = **50**.\n**Final output: ** . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.\n"},{"title":"F23 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A feedforward network has inputs 1,2; hidden nodes 3,4; outputs 5,6. Weights: w13 = −2, w23 = 3, w14 = 4, w24 = −1, w35 = 1, w45 = −1, w36 = −1, w46 = 1; all biases 0. All nodes 3–6 use step(z) = 1 if z≥0 else 0. Find(y5, y6) for inputs(0,0), (1,0), (0,1), (1,1).</p>"],"answer":["<h3>Given</h3>","<p>A feedforward network has inputs 1,2.</p>","<p>hidden nodes 3,4.</p>","<p>outputs 5,6.</p>","<p>Weights: w13 = −2, w23 = 3, w14 = 4, w24 = −1, w35 = 1, w45 = −1, w36 = −1, w46 = 1.</p>","<p>all biases 0.</p>","<p>All nodes 3–6 use step(z) = 1 if z≥0 else 0.</p>","<p>Find(y5, y6) for inputs(0,0), (1,0), (0,1), (1,1).</p>","<h3>To find</h3>","<p>Write every row of the truth table and the requested network output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<p>Use exactly the printed step: output 1 if z≥0, otherwise 0. In particular, step(0) = 1. The equations are z₃ = −2x₁+3x₂, z₄ = 4x₁−x₂, z₅ = h₃−h₄, z₆ = −h₃+h₄.</p>","<p class=\"worked-step\"><strong>Step 1: Input(0,0).</strong> z₃ = −2 × 0+3 × 0 = 0; h₃ = 1. z₄ = 4 × 0−0 = 0; h₄ = 1. z₅ = 1−1 = 0; y₅ = 1. z₆ = −1+1 = 0; y₆ = 1. Final pair = <strong>(1,1)</strong>.</p>","<p class=\"worked-step\"><strong>Step 2: Input(1,0).</strong> z₃ = −2 × 1+3 × 0 = -2; h₃ = 0. z₄ = 4 × 1−0 = 4; h₄ = 1. z₅ = 0−1 = -1; y₅ = 0. z₆ = −0+1 = 1; y₆ = 1. Final pair = <strong>(0,1)</strong>.</p>","<p class=\"worked-step\"><strong>Step 3: Input(0,1).</strong> z₃ = −2 × 0+3 × 1 = 3; h₃ = 1. z₄ = 4 × 0−1 = -1; h₄ = 0. z₅ = 1−0 = 1; y₅ = 1. z₆ = −1+0 = -1; y₆ = 0. Final pair = <strong>(1,0)</strong>.</p>","<p class=\"worked-step\"><strong>Step 4: Input(1,1).</strong> z₃ = −2 × 1+3 × 1 = 1; h₃ = 1. z₄ = 4 × 1−1 = 3; h₄ = 1. z₅ = 1−1 = 0; y₅ = 1. z₆ = −1+1 = 0; y₆ = 1. Final pair = <strong>(1,1)</strong>.</p>"],"kind":"practice","id":"tee-c13-s4","search":"F23 Q2a **Question (10 marks).** A feedforward network has inputs 1,2; hidden nodes 3,4; outputs 5,6. Weights: w13 = −2, w23 = 3, w14 = 4, w24 = −1, w35 = 1, w45 = −1, w36 = −1, w46 = 1; all biases 0. All nodes 3–6 use step(z) = 1 if z≥0 else 0. Find(y5, y6) for inputs(0,0), (1,0), (0,1), (1,1).\n\n**Complete worked answer.**\n\n\n\n### Given\n\nA feedforward network has inputs 1,2.\n\nhidden nodes 3,4.\n\noutputs 5,6.\n\nWeights: w13 = −2, w23 = 3, w14 = 4, w24 = −1, w35 = 1, w45 = −1, w36 = −1, w46 = 1.\n\nall biases 0.\n\nAll nodes 3–6 use step(z) = 1 if z≥0 else 0.\n\nFind(y5, y6) for inputs(0,0), (1,0), (0,1), (1,1).\n\n### To find\n\nWrite every row of the truth table and the requested network output.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\n\n\nUse exactly the printed step: output 1 if z≥0, otherwise 0. In particular, step(0) = 1. The equations are z₃ = −2x₁+3x₂, z₄ = 4x₁−x₂, z₅ = h₃−h₄, z₆ = −h₃+h₄.\n**Step 1: Input(0,0).** z₃ = −2 × 0+3 × 0 = 0; h₃ = 1. z₄ = 4 × 0−0 = 0; h₄ = 1. z₅ = 1−1 = 0; y₅ = 1. z₆ = −1+1 = 0; y₆ = 1. Final pair = **(1,1)**.\n**Step 2: Input(1,0).** z₃ = −2 × 1+3 × 0 = -2; h₃ = 0. z₄ = 4 × 1−0 = 4; h₄ = 1. z₅ = 0−1 = -1; y₅ = 0. z₆ = −0+1 = 1; y₆ = 1. Final pair = **(0,1)**.\n**Step 3: Input(0,1).** z₃ = −2 × 0+3 × 1 = 3; h₃ = 1. z₄ = 4 × 0−1 = -1; h₄ = 0. z₅ = 1−0 = 1; y₅ = 1. z₆ = −1+0 = -1; y₆ = 0. Final pair = **(1,0)**.\n**Step 4: Input(1,1).** z₃ = −2 × 1+3 × 1 = 1; h₃ = 1. z₄ = 4 × 1−1 = 3; h₄ = 1. z₅ = 1−1 = 0; y₅ = 1. z₆ = −1+1 = 0; y₆ = 1. Final pair = **(1,1)**.\n"},{"title":"F23 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> (i) Justify the need for activations and explain any two. (ii) Choose ML or DL for facial recognition using 227 × 227 × 1 images and state the advantages.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>","<p><strong>Facial recognition: </strong> a CNN is a suitable DL choice because the input contains spatial visual patterns. It learns local and hierarchical features with shared filters, reducing dependence on manually selected face descriptors. One channel means grayscale. With limited target data, pretrained features and carefully chosen augmentation are preferable starting points; the image dimensions alone do not guarantee enough data for training from scratch.</p>"],"kind":"practice","id":"tee-c13-s5","search":"F23 Q2b **Question (10 marks).** (i) Justify the need for activations and explain any two. (ii) Choose ML or DL for facial recognition using 227 × 227 × 1 images and state the advantages.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n**Facial recognition: ** a CNN is a suitable DL choice because the input contains spatial visual patterns. It learns local and hierarchical features with shared filters, reducing dependence on manually selected face descriptors. One channel means grayscale. With limited target data, pretrained features and carefully chosen augmentation are preferable starting points; the image dimensions alone do not guarantee enough data for training from scratch.\n"},{"title":"F23 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For x = [1,0,1], target 1, η = 0.9, use sigmoid at hidden and output layers. Weights w14 = .2, w15 = −.3, w24 = .4, w25 = .1, w34 = −.5, w35 = .2, w46 = −.3, w56 = −.2, biases at 4,5,6 are−.4,.2,.1. Update w46 and w56 using backpropagation.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_f23.svg\" aria-label=\"Enlarge diagram: F23 Q3a connections with the supplied biases\"><img src=\"assets/figures/net_f23.svg\" alt=\"F23 Q3a connections with the supplied biases\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>F23 Q3a connections with the supplied biases <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>For x = [1,0,1], target 1, η = 0.9, use sigmoid at hidden and output layers.</p>","<p>Weights w14 = .2, w15 = −.3, w24 = .4, w25 = .1, w34 = −.5, w35 = .2, w46 = −.3, w56 = −.2, biases at 4,5,6 are−.4,.2,.1.</p>","<p>Update w46 and w56 using backpropagation.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:263.40px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/743c8cd16a50ddc1.svg\"><img class=\"math display-math\" src=\"assets/equations/2f70d876265d1c94.svg\" alt=\"z_{h_1} = (0.2 \\times  1) + (0.4 \\times  0) + (-0.5 \\times  1) + (-0.4) = -0.7\" width=\"601.13\" height=\"24.58\" style=\"width:601.13px;height:24.58px;aspect-ratio:601.13/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.99px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a03d842e36f6059c.svg\"><img class=\"math display-math\" src=\"assets/equations/d8bf113d37695d28.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(-0.7)}}=0.331812228\" width=\"347.53\" height=\"53.84\" style=\"width:347.53px;height:53.84px;aspect-ratio:347.53/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.38px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/16f057ecfbad99c5.svg\"><img class=\"math display-math\" src=\"assets/equations/18df325704d974aa.svg\" alt=\"z_{h_2} = (-0.3 \\times  1) + (0.1 \\times  0) + (0.2 \\times  1) + (0.2) = 0.1\" width=\"563.11\" height=\"24.58\" style=\"width:563.11px;height:24.58px;aspect-ratio:563.11/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7b09cff87f366114.svg\"><img class=\"math display-math\" src=\"assets/equations/708107445814199b.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.1)}}=0.524979187\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c16074919b105b06.svg\"><img class=\"math display-math\" src=\"assets/equations/e1f248930dc68c45.svg\" alt=\"z_{o_1} = (-0.3 \\times  0.331812228) + (-0.2 \\times  0.524979187) + (0.1) = -0.104539506\" width=\"808.60\" height=\"24.58\" style=\"width:808.60px;height:24.58px;aspect-ratio:808.60/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.87px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/942e59b171acdc83.svg\"><img class=\"math display-math\" src=\"assets/equations/8d4f0a07993ddded.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(-0.104539506)}}=0.473888899\" width=\"414.42\" height=\"53.84\" style=\"width:414.42px;height:53.84px;aspect-ratio:414.42/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.526111101]. Squared errors = [0.276792891]. Half-sum squared loss = 0.138396445; mean squared error = 0.276792891. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fa2e026fc3449bb0.svg\"><img class=\"math display-math\" src=\"assets/equations/06f4e7ac9debce46.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.473888899-1) \\times  0.24931821 = -0.131169078\" width=\"620.71\" height=\"24.58\" style=\"width:620.71px;height:24.58px;aspect-ratio:620.71/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.331812228</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.131169078</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.043523504</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.260828846</strong></div></div><p>Subtract η × gradient = <b>−0.039171154</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4a6b58e5f34c0b65.svg\"><img class=\"math display-math\" src=\"assets/equations/0cc7b6d9a9598b69.svg\" alt=\"g_{1,1}^{(2)}=(-0.131169078)\\times(0.331812228)\\approx -0.043523504\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/08c4c4ecc81b818b.svg\"><img class=\"math display-math\" src=\"assets/equations/e28a7e27c4f74611.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=-0.3-0.9(-0.043523504)\\approx -0.260828846\" width=\"573.19\" height=\"36.54\" style=\"width:573.19px;height:36.54px;aspect-ratio:573.19/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.524979187</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.131169078</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.068861036</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.138025068</strong></div></div><p>Subtract η × gradient = <b>−0.061974932</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a93072cdabc372b8.svg\"><img class=\"math display-math\" src=\"assets/equations/61ef33f1a6d1ba26.svg\" alt=\"g_{1,2}^{(2)}=(-0.131169078)\\times(0.524979187)\\approx -0.068861036\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f20144355441ad1.svg\"><img class=\"math display-math\" src=\"assets/equations/54531eae8fb17595.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=-0.2-0.9(-0.068861036)\\approx -0.138025068\" width=\"573.19\" height=\"36.54\" style=\"width:573.19px;height:36.54px;aspect-ratio:573.19/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.131169078</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">−0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.039350723</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.039350723</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0153f0b9bcb4caa4.svg\"><img class=\"math display-math\" src=\"assets/equations/c0b7949b10b38e6f.svg\" alt=\"C_1=(-0.3)\\times(-0.131169078)\\approx 0.039350723\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c677dcae787d564f.svg\" alt=\"\\text{Sum}=C_1\\approx 0.039350723\" width=\"269.79\" height=\"20.89\" style=\"width:269.79px;height:20.89px;aspect-ratio:269.79/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/890b9a76a0888667.svg\"><img class=\"math display-math\" src=\"assets/equations/464805fe24d02ce3.svg\" alt=\"\\delta_{h_1} = 0.039350723 \\times  0.221712873 = 0.008724562\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.131169078</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.026233816</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.026233816</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b7f5cea4501981c5.svg\"><img class=\"math display-math\" src=\"assets/equations/8b80255c0daf41f8.svg\" alt=\"C_1=(-0.2)\\times(-0.131169078)\\approx 0.026233816\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cea4b9d0baabf5b5.svg\" alt=\"\\text{Sum}=C_1\\approx 0.026233816\" width=\"269.79\" height=\"20.89\" style=\"width:269.79px;height:20.89px;aspect-ratio:269.79/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc3edfca69eaeef5.svg\"><img class=\"math display-math\" src=\"assets/equations/c52b54d99a7b69d0.svg\" alt=\"\\delta_{h_2} = 0.026233816 \\times  0.24937604 = 0.006542085\" width=\"500.08\" height=\"23.78\" style=\"width:500.08px;height:23.78px;aspect-ratio:500.08/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008724562</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.008724562</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.192147894</strong></div></div><p>Subtract η × gradient = <b>0.007852106</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/548224ebc74d73ba.svg\"><img class=\"math display-math\" src=\"assets/equations/527d49eeeec9b622.svg\" alt=\"g_{1,1}^{(1)}=(0.008724562)\\times(1)\\approx 0.008724562\" width=\"438.97\" height=\"36.54\" style=\"width:438.97px;height:36.54px;aspect-ratio:438.97/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b50d4b76d5185b7.svg\"><img class=\"math display-math\" src=\"assets/equations/0149f12f0acd3c01.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.2-0.9(0.008724562)\\approx 0.192147894\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008724562</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.4</strong></div></div><p>Subtract η × gradient = <b>0</b>. This weight <b>stays unchanged</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5c9199d39ef465bf.svg\"><img class=\"math display-math\" src=\"assets/equations/579a2b920b0ef6cb.svg\" alt=\"g_{1,2}^{(1)}=(0.008724562)\\times(0)\\approx 0\" width=\"322.22\" height=\"36.54\" style=\"width:322.22px;height:36.54px;aspect-ratio:322.22/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.87px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10496bc73c8c3b85.svg\"><img class=\"math display-math\" src=\"assets/equations/3e63507e62c558f8.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.4-0.9(0)\\approx 0.4\" width=\"301.68\" height=\"36.54\" style=\"width:301.68px;height:36.54px;aspect-ratio:301.68/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x3 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x3 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.008724562</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.008724562</strong><span class=\"lv-detail\">x3 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.507852106</strong></div></div><p>Subtract η × gradient = <b>0.007852106</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/75cb25a10b4d1d19.svg\" alt=\"g_{1,3}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,3}}=\\delta_{h_1}x_3\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/27c65cc6a73f6ef7.svg\"><img class=\"math display-math\" src=\"assets/equations/79371253b0a7529c.svg\" alt=\"g_{1,3}^{(1)}=(0.008724562)\\times(1)\\approx 0.008724562\" width=\"438.97\" height=\"36.54\" style=\"width:438.97px;height:36.54px;aspect-ratio:438.97/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b5e18accd983b7d3.svg\"><img class=\"math display-math\" src=\"assets/equations/1a852512507633c5.svg\" alt=\"W^{(1)}_{1,3,\\mathrm{new}}=-0.5-0.9(0.008724562)\\approx -0.507852106\" width=\"554.18\" height=\"36.54\" style=\"width:554.18px;height:36.54px;aspect-ratio:554.18/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.006542085</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.006542085</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.305887877</strong></div></div><p>Subtract η × gradient = <b>0.005887876</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e657c5ac09391365.svg\"><img class=\"math display-math\" src=\"assets/equations/5846229bdca31634.svg\" alt=\"g_{2,1}^{(1)}=(0.006542085)\\times(1)\\approx 0.006542085\" width=\"438.97\" height=\"36.54\" style=\"width:438.97px;height:36.54px;aspect-ratio:438.97/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5c15a33a77f594c0.svg\"><img class=\"math display-math\" src=\"assets/equations/a32b4e1a94dcddab.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=-0.3-0.9(0.006542085)\\approx -0.305887877\" width=\"554.18\" height=\"36.54\" style=\"width:554.18px;height:36.54px;aspect-ratio:554.18/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.006542085</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.1</strong></div></div><p>Subtract η × gradient = <b>0</b>. This weight <b>stays unchanged</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e95a4cf560314569.svg\"><img class=\"math display-math\" src=\"assets/equations/64d7fdc83e81a56d.svg\" alt=\"g_{2,2}^{(1)}=(0.006542085)\\times(0)\\approx 0\" width=\"322.22\" height=\"36.54\" style=\"width:322.22px;height:36.54px;aspect-ratio:322.22/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.87px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c531dfb193e72d45.svg\"><img class=\"math display-math\" src=\"assets/equations/3ce2a12d83343b99.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.1-0.9(0)\\approx 0.1\" width=\"301.68\" height=\"36.54\" style=\"width:301.68px;height:36.54px;aspect-ratio:301.68/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x3 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x3 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.006542085</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.006542085</strong><span class=\"lv-detail\">x3 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.194112123</strong></div></div><p>Subtract η × gradient = <b>0.005887876</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48d08524866113b9.svg\" alt=\"g_{2,3}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,3}}=\\delta_{h_2}x_3\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2728e830590acf7.svg\"><img class=\"math display-math\" src=\"assets/equations/0a817131e93ad648.svg\" alt=\"g_{2,3}^{(1)}=(0.006542085)\\times(1)\\approx 0.006542085\" width=\"438.97\" height=\"36.54\" style=\"width:438.97px;height:36.54px;aspect-ratio:438.97/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d92699928835e1d2.svg\"><img class=\"math display-math\" src=\"assets/equations/5f93f3b16b7e9a42.svg\" alt=\"W^{(1)}_{2,3,\\mathrm{new}}=0.2-0.9(0.006542085)\\approx 0.194112123\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/96118c608a159aef.svg\"><img class=\"math display-math\" src=\"assets/equations/f8478e0f34b4c2ea.svg\" alt=\"b_{h_1,\\mathrm{new}}=-0.4-0.9(0.008724562)=-0.407852106\" width=\"537.01\" height=\"25.35\" style=\"width:537.01px;height:25.35px;aspect-ratio:537.01/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/85c1ef6621c6cf83.svg\"><img class=\"math display-math\" src=\"assets/equations/4826d8c0344d9683.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.2-0.9(0.006542085)=0.194112124\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/172a74d19c4bbc33.svg\"><img class=\"math display-math\" src=\"assets/equations/4993d13feab65d1f.svg\" alt=\"b_{o_1,\\mathrm{new}}=0.1-0.9(-0.131169078)=0.218052170\" width=\"516.43\" height=\"25.35\" style=\"width:516.43px;height:25.35px;aspect-ratio:516.43/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Required: </strong> w46 = <strong>−0.260828846</strong>, w56 = <strong>−0.138025068</strong> under half squared loss. If a one-output unhalved MSE is explicitly required, double the shown gradients before updating; the paper itself does not state that scaling.</p>"],"kind":"practice","id":"tee-c13-s6","search":"F23 Q3a **Question (10 marks).** For x = [1,0,1], target 1, η = 0.9, use sigmoid at hidden and output layers. Weights w14 = .2, w15 = −.3, w24 = .4, w25 = .1, w34 = −.5, w35 = .2, w46 = −.3, w56 = −.2, biases at 4,5,6 are−.4,.2,.1. Update w46 and w56 using backpropagation.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nFor x = [1,0,1], target 1, η = 0.9, use sigmoid at hidden and output layers.\n\nWeights w14 = .2, w15 = −.3, w24 = .4, w25 = .1, w34 = −.5, w35 = .2, w46 = −.3, w56 = −.2, biases at 4,5,6 are−.4,.2,.1.\n\nUpdate w46 and w56 using backpropagation.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the sigmoid output and, if requested, its derivative. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.526111101]. Squared errors = [0.276792891]. Half-sum squared loss = 0.138396445; mean squared error = 0.276792891. These are different unless the number of output components makes the scale coincide.\n**Output delta 1:**\n\nThe derivative is o(1−o).\n**Step 3 output weights.** Gradient = receiving delta × sending activation. An output bias gradient equals its delta.\nh1 → o1: gradient = (-0.131169078) × 0.331812228 = -0.043523504. New weight = -0.3−0.9 × (-0.043523504) = **-0.260828846**.\nh2 → o1: gradient = (-0.131169078) × 0.524979187 = -0.068861036. New weight = -0.2−0.9 × (-0.068861036) = **-0.138025068**.\n**Step 4 hidden deltas.** A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.\n**Hidden 1 downstream contribution:**\n\n\n**Hidden 2 downstream contribution:**\n\n\n**Step 5 input weights.** M"},{"title":"F23 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain key advantages of Adam for ANN training and how it differs from SGD.</p>"],"answer":["<p>Adam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.71px;--narrow-height:202.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92678247acd594b0.svg\"><img class=\"math display-math\" src=\"assets/equations/c443fc0367c152b1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\widehat v_t=\\frac{v_t}{1-\\beta_2^t},\\quad\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"571.98\" height=\"66.85\" style=\"width:571.98px;height:66.85px;aspect-ratio:571.98/66.85\" loading=\"lazy\"></picture></div>","<p>Use update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.</p>","<p>For g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.</p>","<p>Compared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.</p>"],"kind":"practice","id":"tee-c13-s7","search":"F23 Q3b **Question (10 marks).** Explain key advantages of Adam for ANN training and how it differs from SGD.\n\n**Complete worked answer.**\nAdam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.\n\n\nUse update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.\nFor g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.\nCompared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.\n"},{"title":"F23 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Determine feature-map dimensions and parameters at every layer of the pictured AlexNet-style CNN. The normalized architecture is Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.</p>"],"answer":["<h3>Given</h3>","<p>The normalized architecture is Input 227 × 227 × 3.</p>","<p>Conv K = 11, filters = 96, stride = 4, padding = 0.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 256, stride = 1, padding = 2.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 256, stride = 1, padding = 1.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Dense 4096 units.</p>","<p>Dense 4096 units.</p>","<p>Dense 1000 units.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">227 × 227 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">96 filters · 11 × 11 · S = 4 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">34,848</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">96</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">34,944</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>227 × 227 × 3</strong>. Use 96 filters of spatial size 11 × 11, stride 4, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.10px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/441a061296efda7a.svg\"><img class=\"math display-math\" src=\"assets/equations/1ca643e3f874dc98.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{227+2(0)-11}{4}\\right\\rfloor+1=55\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>55 × 55 × 96</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9a11e5db4a09d338.svg\"><img class=\"math display-math\" src=\"assets/equations/e8a26a7b03e38af6.svg\" alt=\"N_{\\mathrm{weights}}=11\\times11\\times3\\times96=34{,}848\" width=\"386.55\" height=\"23.91\" style=\"width:386.55px;height:23.91px;aspect-ratio:386.55/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3b19ed994769f54.svg\" alt=\"N_{\\mathrm{biases}}=96\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ae51bc20750a112f.svg\" alt=\"P_1=34{,}848+96=34{,}944\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>55 × 55 × 96</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d42806d80c07005c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1=27\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>27 × 27 × 96</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 5 × 5 · S = 1 · P = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">614,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">614,656</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>27 × 27 × 96</strong>. Use 256 filters of spatial size 5 × 5, stride 1, and padding 2 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f4e102905e6bf9f.svg\"><img class=\"math display-math\" src=\"assets/equations/da9a62eaf99ea1e8.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27+2(2)-5}{1}\\right\\rfloor+1=27\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>27 × 27 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 96 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b720c78ffc948913.svg\"><img class=\"math display-math\" src=\"assets/equations/05edf5328cb35876.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times96\\times256=614{,}400\" width=\"398.77\" height=\"23.91\" style=\"width:398.77px;height:23.91px;aspect-ratio:398.77/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29c935e56c01ee26.svg\"><img class=\"math display-math\" src=\"assets/equations/67ebf4d50d295918.svg\" alt=\"P_3=614{,}400+256=614{,}656\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>27 × 27 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ca522f15a3632877.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1=13\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">885,120</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 256 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/492d70515e0406f9.svg\"><img class=\"math display-math\" src=\"assets/equations/0f457ff5f3c6b74f.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times256\\times384=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e9338e40808aff5.svg\"><img class=\"math display-math\" src=\"assets/equations/0cca75bb5a08cdeb.svg\" alt=\"P_5=884{,}736+384=885{,}120\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">1,327,104</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">1,327,488</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3729f79bf2b69fab.svg\"><img class=\"math display-math\" src=\"assets/equations/a2fb560ecf5f18c3.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times384=1{,}327{,}104\" width=\"429.99\" height=\"23.91\" style=\"width:429.99px;height:23.91px;aspect-ratio:429.99/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4565bf3714918ad3.svg\"><img class=\"math display-math\" src=\"assets/equations/8d8b08cc6480d083.svg\" alt=\"P_6=1{,}327{,}104+384=1{,}327{,}488\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">884,992</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 256 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/be0b63ec1f7ffb8c.svg\"><img class=\"math display-math\" src=\"assets/equations/42a81620f94360dd.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times256=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c304d00633ff2322.svg\"><img class=\"math display-math\" src=\"assets/equations/a803766772104e69.svg\" alt=\"P_7=884{,}736+256=884{,}992\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/117abcc38db86957.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1=6\" width=\"271.85\" height=\"58.62\" style=\"width:271.85px;height:58.62px;aspect-ratio:271.85/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>6 × 6 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 9 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>6 × 6 × 256</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d9921c92554e599.svg\" alt=\"n_{\\mathrm{flat}}=6\\times6\\times256=9{,}216\" width=\"283.79\" height=\"21.02\" style=\"width:283.79px;height:21.02px;aspect-ratio:283.79/21.02\" loading=\"lazy\"></div>","<p>Output: a vector with <strong>9,216 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">37,748,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">37,752,832</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>9,216 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/253a54d671a02309.svg\"><img class=\"math display-math\" src=\"assets/equations/864d5792c1506a4b.svg\" alt=\"N_{\\mathrm{weights}}=9{,}216\\times4{,}096=37{,}748{,}736\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a6d14bbf5757207.svg\"><img class=\"math display-math\" src=\"assets/equations/42e41d5d625e4b33.svg\" alt=\"P_10=37{,}748{,}736+4{,}096=37{,}752{,}832\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 11 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 11: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">16,777,216</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">16,781,312</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe4cfd667cc7b7ce.svg\"><img class=\"math display-math\" src=\"assets/equations/37f33b938916c485.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times4{,}096=16{,}777{,}216\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3652163d527344ad.svg\"><img class=\"math display-math\" src=\"assets/equations/ca42e0122e881f05.svg\" alt=\"P_11=16{,}777{,}216+4{,}096=16{,}781{,}312\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 12 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 12: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">1,000 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">1,000</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,096,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">1,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,097,000</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>1,000 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3d7876f0d5fdb4fa.svg\"><img class=\"math display-math\" src=\"assets/equations/a47853490ec706c7.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times1{,}000=4{,}096{,}000\" width=\"383.84\" height=\"23.91\" style=\"width:383.84px;height:23.91px;aspect-ratio:383.84/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d0008f88a44995b2.svg\" alt=\"N_{\\mathrm{biases}}=1{,}000\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3adeefbc3dbe4d6b.svg\"><img class=\"math display-math\" src=\"assets/equations/91b7bd4147e4b8d6.svg\" alt=\"P_12=4{,}096{,}000+1{,}000=4{,}097{,}000\" width=\"387.48\" height=\"21.43\" style=\"width:387.48px;height:21.43px;aspect-ratio:387.48/21.43\" loading=\"lazy\"></picture></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/74235148b2b7312a.svg\" alt=\"\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\" width=\"199.47\" height=\"45.60\" style=\"width:199.47px;height:45.60px;aspect-ratio:199.47/45.60\" loading=\"lazy\"></span></td><td>55 x 55 x 96</td><td>34,848</td><td>96</td><td>34,944</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cdac8f1c682bc40a.svg\" alt=\"\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 96</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/71046f85d0cc0ca5.svg\" alt=\"\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 256</td><td>614,400</td><td>256</td><td>614,656</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/55802f10aac3668d.svg\" alt=\"\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>884,736</td><td>384</td><td>885,120</td></tr><tr><td>6 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>1,327,104</td><td>384</td><td>1,327,488</td></tr><tr><td>7 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>884,736</td><td>256</td><td>884,992</td></tr><tr><td>8 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/73ab07c24eb836b2.svg\" alt=\"\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>6 x 6 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>9 flat</td><td>6 × 6 × 256</td><td>9216</td><td>0</td><td>0</td><td>0</td></tr><tr><td>10 dense</td><td>9216 → 4096</td><td>4096</td><td>37,748,736</td><td>4,096</td><td>37,752,832</td></tr><tr><td>11 dense</td><td>4096 → 4096</td><td>4096</td><td>16,777,216</td><td>4,096</td><td>16,781,312</td></tr><tr><td>12 dense</td><td>4096 → 1000</td><td>1000</td><td>4,096,000</td><td>1,000</td><td>4,097,000</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (11 x 11 x 3 + 1) x 96 = 34,944.</p>","<p>Layer 3: (5 x 5 x 96 + 1) x 256 = 614,656.</p>","<p>Layer 5: (3 x 3 x 256 + 1) x 384 = 885,120.</p>","<p>Layer 6: (3 x 3 x 384 + 1) x 384 = 1,327,488.</p>","<p>Layer 7: (3 x 3 x 384 + 1) x 256 = 884,992.</p>","<p>Layer 10: (9216 + 1) x 4096 = 37,752,832.</p>","<p>Layer 11: (4096 + 1) x 4096 = 16,781,312.</p>","<p>Layer 12: (4096 + 1) x 1000 = 4,097,000.</p>","<p><strong>Total: </strong> 34,944 + 614,656 + 885,120 + 1,327,488 + 884,992 + 37,752,832 + 16,781,312 + 4,097,000 = <strong>62,378,344 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p>The count treats every listed convolution as connected to all input channels. Original grouped AlexNet implementations have different counts; do not insert grouping that is not shown in the question.</p>"],"kind":"practice","id":"tee-c13-s8","search":"F23 Q4a **Question (10 marks).** Determine feature-map dimensions and parameters at every layer of the pictured AlexNet-style CNN. The normalized architecture is Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nThe normalized architecture is Input 227 × 227 × 3.\n\nConv K = 11, filters = 96, stride = 4, padding = 0.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 5, filters = 256, stride = 1, padding = 2.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 256, stride = 1, padding = 1.\n\nPool K = 3, stride = 2, padding = 0.\n\nDense 4096 units.\n\nDense 4096 units.\n\nDense 1000 units.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\\) | 55 x 55 x 96 | 34,848 | 96 | 34,944 |\n| 2 pool | \\(\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\\) | 27 x 27 x 96 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\\) | 27 x 27 x 256 | 614,400 | 256 | 614,656 |\n| 4 pool | \\(\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\\) | 13 x 13 x 256 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 884,736 | 384 | 885,120 |\n| 6 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 1,327,104 | 384 | 1,327,488 |\n| 7 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 256 | 884,736 | 256 | 884,992 |\n| 8 pool | \\(\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\\) | 6 x 6 x 256 | 0 | 0 | 0 |\n| 9 flat | 6 × 6 × 256 | 9216 | 0 | 0 | 0 |\n| 10 dense | 9216 → 4096 | 4096 | 37,748,736 | 4,096 | 37,752,832 |\n| 11 dense | 4096 → 4096 | 4096 | 16,777,216 | 4,096 | 16,781,312 |\n| 12 dense | 4096 → 1000 | 1000 | 4,096,000 | 1,000 | 4,097,000 |\n**Parameter substitutions, in layer order: **\nLayer 1: (11 x 11 x 3 + 1) x 96 = 34,944.\nLayer 3: (5 x 5 x 96 + 1) x 256 = 614,656.\nLayer 5: (3 x 3 x 256 + 1) x 384 = 885,120.\nLayer 6: (3 x"},{"title":"F23 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design an LSTM autocomplete model for “Maharashtra is a state in the western part of India. The capital of Maharashtra is ___.” Draw the model and write conditional probabilities at each time step.</p>"],"answer":["<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>","<p>Architecture: token → embedding → LSTM state → vocabulary softmax → next-token distribution. During training use the actual prefix and its next-word labels with cross-entropy. At inference, feed the available prefix and choose/sample the next token. “Mumbai” is the intended factual completion in this example; a model only predicts it if learned probabilities support it.</p>","<p><strong>One explicit tokenization ignoring punctuation: </strong></p>","<p>1. P(Maharashtra | START).</p>","<p>2. P(is | Maharashtra).</p>","<p>3. P(a | Maharashtra is).</p>","<p>4. P(state | Maharashtra is a).</p>","<p>5. P(in | Maharashtra is a state).</p>","<p>6. P(the | Maharashtra is a state in).</p>","<p>7. P(western | Maharashtra is a state in the).</p>","<p>8. P(part | Maharashtra is a state in the western).</p>","<p>9. P(of | Maharashtra is a state in the western part).</p>","<p>10. P(India | Maharashtra is a state in the western part of).</p>","<p>11. P(The | Maharashtra is a state in the western part of India).</p>","<p>12. P(capital | Maharashtra is a state in the western part of India The).</p>","<p>13. P(of | Maharashtra is a state in the western part of India The capital).</p>","<p>14. P(Maharashtra | Maharashtra is a state in the western part of India The capital of).</p>","<p>15. P(is | Maharashtra is a state in the western part of India The capital of Maharashtra).</p>","<p>16. P(Mumbai | Maharashtra is a state in the western part of India The capital of Maharashtra is).</p>","<p>The joint sequence probability is the product of these conditionals. Numerical probability values cannot be computed from the sentence alone because weights are not supplied.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Replace the repeated recurrent cell with an LSTM and attach a vocabulary softmax at each step\"><img src=\"assets/figures/rnn.svg\" alt=\"Replace the repeated recurrent cell with an LSTM and attach a vocabulary softmax at each step\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Replace the repeated recurrent cell with an LSTM and attach a vocabulary softmax at each step <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c13-s9","search":"F23 Q4b **Question (10 marks).** Design an LSTM autocomplete model for “Maharashtra is a state in the western part of India. The capital of Maharashtra is ___.” Draw the model and write conditional probabilities at each time step.\n\n**Complete worked answer.**\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\nArchitecture: token → embedding → LSTM state → vocabulary softmax → next-token distribution. During training use the actual prefix and its next-word labels with cross-entropy. At inference, feed the available prefix and choose/sample the next token. “Mumbai” is the intended factual completion in this example; a model only predicts it if learned probabilities support it.\n**One explicit tokenization ignoring punctuation: **\n1. P(Maharashtra | START).\n2. P(is | Maharashtra).\n3. P(a | Maharashtra is).\n4. P(state | Maharashtra is a).\n5. P(in | Maharashtra is a state).\n6. P(the | Maharashtra is a state in).\n7. P(western | Maharashtra is a state in the).\n8. P(part | Maharashtra is a state in the western).\n9. P(of | Maharashtra is a state in the western part).\n10. P(India | Maharashtra is a state in the western part of).\n11. P(The | Maharashtra is a state in the western part of India).\n12. P(capital | Maharashtra is a state in the western part of India The).\n13. P(of | Maharashtra is a state in the western part of India The capital).\n14. P(Maharashtra | Maharashtra is a state in the western part of India The capital of).\n15. P(is | Maharashtra is a state in the western part of India The capital of Maharashtra).\n16. P(Mumbai | Maharashtra is a state in the western part of India The capital of Maharashtra is).\nThe joint sequence probability is the product of these conditionals. Numerical probability values cannot be computed from the sentence alone because weights are not supplied.\n\n"},{"title":"F23 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For Inception V 1, justify different kernel sizes in one block, explain 1 × 1 convolutions and sketch one block.</p>"],"answer":["<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>"],"kind":"practice","id":"tee-c13-s10","search":"F23 Q5a **Question (10 marks).** For Inception V 1, justify different kernel sizes in one block, explain 1 × 1 convolutions and sketch one block.\n\n**Complete worked answer.**\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\n"},{"title":"F23 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain why a single perceptron cannot classify nonlinearly separable data. Implement XOR and XNOR using suitable perceptrons.</p>"],"answer":["<h3>Given</h3>","<p>Required logic functions = XOR and XNOR on two binary inputs.</p>","<p>Weights and biases are design choices, not given constants.</p>","<h3>To find</h3>","<p>Explain the failure of a single linear separator, choose suitable hidden/output perceptrons and show all four truth-table rows.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<p>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.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/xor.svg\" aria-label=\"Enlarge diagram: Opposite corners for XOR cannot be split by one straight line\"><img src=\"assets/figures/xor.svg\" alt=\"Opposite corners for XOR cannot be split by one straight line\" width=\"960\" height=\"430\" loading=\"lazy\"></button><figcaption>Opposite corners for XOR cannot be split by one straight line <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>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.</p>","<p>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.</p>","<p>A multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.</p>","<h3>Verify input (0,0)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aac6904086092425.svg\" alt=\"z_1=0+0-0.5=-0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/738e2d766424863e.svg\" alt=\"h_1=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad20a476f045fd25.svg\" alt=\"z_2=0+0-1.5=-1.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1de867d02667e910.svg\" alt=\"h_2=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65c6f2e86202561b.svg\"><img class=\"math display-math\" src=\"assets/equations/d3b2998fcd8ceee6.svg\" alt=\"z_{XOR}=0-2(0)-0.5=-0.5\" width=\"316.44\" height=\"24.43\" style=\"width:316.44px;height:24.43px;aspect-ratio:316.44/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3624761b5a00605.svg\" alt=\"y_{XOR}=0\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/458da5139ca95df2.svg\"><img class=\"math display-math\" src=\"assets/equations/824ad51bf0e571df.svg\" alt=\"z_{XNOR}=-0+2(0)+0.5=0.5\" width=\"331.79\" height=\"24.43\" style=\"width:331.79px;height:24.43px;aspect-ratio:331.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/016b62d9d7436c82.svg\" alt=\"y_{XNOR}=1\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<h3>Verify input (0,1)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90f88a492c8d4d66.svg\" alt=\"z_1=0+1-0.5=0.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6025713e0c4b56ee.svg\" alt=\"h_1=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60ef65c2ea0ecf5f.svg\" alt=\"z_2=0+1-1.5=-0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1de867d02667e910.svg\" alt=\"h_2=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ee6edf14f171730.svg\"><img class=\"math display-math\" src=\"assets/equations/2d91f383d484e960.svg\" alt=\"z_{XOR}=1-2(0)-0.5=0.5\" width=\"297.43\" height=\"24.43\" style=\"width:297.43px;height:24.43px;aspect-ratio:297.43/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/43f7e4fce3fb5771.svg\" alt=\"y_{XOR}=1\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fbcbb7c54a55ba6f.svg\"><img class=\"math display-math\" src=\"assets/equations/573087efcdde0646.svg\" alt=\"z_{XNOR}=-1+2(0)+0.5=-0.5\" width=\"350.79\" height=\"24.43\" style=\"width:350.79px;height:24.43px;aspect-ratio:350.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51f578d6708881af.svg\" alt=\"y_{XNOR}=0\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<h3>Verify input (1,0)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/318ee2a6640d10f0.svg\" alt=\"z_1=1+0-0.5=0.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6025713e0c4b56ee.svg\" alt=\"h_1=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6d1cd15a27d9572e.svg\" alt=\"z_2=1+0-1.5=-0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1de867d02667e910.svg\" alt=\"h_2=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ee6edf14f171730.svg\"><img class=\"math display-math\" src=\"assets/equations/2d91f383d484e960.svg\" alt=\"z_{XOR}=1-2(0)-0.5=0.5\" width=\"297.43\" height=\"24.43\" style=\"width:297.43px;height:24.43px;aspect-ratio:297.43/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/43f7e4fce3fb5771.svg\" alt=\"y_{XOR}=1\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fbcbb7c54a55ba6f.svg\"><img class=\"math display-math\" src=\"assets/equations/573087efcdde0646.svg\" alt=\"z_{XNOR}=-1+2(0)+0.5=-0.5\" width=\"350.79\" height=\"24.43\" style=\"width:350.79px;height:24.43px;aspect-ratio:350.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51f578d6708881af.svg\" alt=\"y_{XNOR}=0\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<h3>Verify input (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/285947e47dfebe51.svg\" alt=\"z_1=1+1-0.5=1.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6025713e0c4b56ee.svg\" alt=\"h_1=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86c5a45ae836809c.svg\" alt=\"z_2=1+1-1.5=0.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/397f5515899ffae5.svg\" alt=\"h_2=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd1914e888d3b3fb.svg\"><img class=\"math display-math\" src=\"assets/equations/eac20b8fec07829f.svg\" alt=\"z_{XOR}=1-2(1)-0.5=-1.5\" width=\"316.44\" height=\"24.43\" style=\"width:316.44px;height:24.43px;aspect-ratio:316.44/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3624761b5a00605.svg\" alt=\"y_{XOR}=0\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ce164dbb1fd1549.svg\"><img class=\"math display-math\" src=\"assets/equations/7d050e174f67d846.svg\" alt=\"z_{XNOR}=-1+2(1)+0.5=1.5\" width=\"331.79\" height=\"24.43\" style=\"width:331.79px;height:24.43px;aspect-ratio:331.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/016b62d9d7436c82.svg\" alt=\"y_{XNOR}=1\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> XOR = [0,1,1,0]; XNOR = [1,0,0,1] for 00,01,10,11. The hidden nonlinear units make this possible.</p>"],"kind":"practice","id":"tee-c13-s11","search":"F23 Q5b **Question (10 marks).** Explain why a single perceptron cannot classify nonlinearly separable data. Implement XOR and XNOR using suitable perceptrons.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nRequired logic functions = XOR and XNOR on two binary inputs.\n\nWeights and biases are design choices, not given constants.\n\n### To find\n\nExplain the failure of a single linear separator, choose suitable hidden/output perceptrons and show all four truth-table rows.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\nA 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.\n\nFor 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.\nFor 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.\nA multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.\n\n\n### Verify input (0,0)\n\n**Step 1: calculate hidden OR preactivation.**\n\n\n\n\n\n\n\n**Step 2: apply its threshold.**\n\n\n\n\n\n\n\n**Step 3: calculate hidden AND preactivation.**\n\n\n\n\n\n\n\n**Step 4: apply its threshold.**\n\n\n\n\n\n\n\n**Step 5: calculate XOR output preactivation.**\n\n\n\n\n\n\n\n**Step 6: apply the XOR threshold.**\n\n\n\n\n\n\n\n**Step 7: calculate XNOR output preactivation.**\n\n\n\n\n\n\n\n**Step 8: apply the XNOR threshold.**\n\n\n\n\n\n\n\n\n### Verify input (0,1)\n\n**Step 1: calculate hidden OR preactivation.**\n\n\n\n\n\n\n\n**Step 2: apply its threshold.**\n\n\n\n\n\n\n\n**Step 3: calculate hidden AND preactivation.**\n\n\n\n\n\n\n\n**Step 4: apply its threshold.**\n\n\n\n\n\n\n\n**Step 5: calculate XOR output preactivation.**\n\n\n\n\n\n\n\n**Step 6: apply the XOR threshold.**\n\n\n\n\n\n\n\n**Step 7: calculate XNOR output preactivation.**\n\n\n\n\n\n\n\n**Step 8: apply the XNOR threshold.**\n\n\n\n\n\n\n\n\n### Verify input (1,0)\n\n**Step 1: calculate hidden OR preactivation.**\n\n\n\n\n\n\n\n**Step 2: apply its threshold.**\n\n\n\n\n\n\n\n**Step 3: calculate hidden AND preactivation.**\n\n\n\n\n\n\n\n**Step 4: apply its threshold.**\n\n\n\n\n\n\n\n**Step 5: calculate XOR output preactivation.**\n\n\n\n\n\n\n\n**Step 6: apply the XOR threshold.**\n\n\n\n\n\n\n\n**Step 7: calculate XNOR output preactivation.**\n\n\n\n\n\n\n\n**Step 8: apply the XNOR threshold.**\n\n\n\n\n\n\n\n\n### Verify input (1,1)\n\n**Step 1: calculate hidden OR preactivation.**\n\n\n\n\n\n\n\n**Step 2: apply its threshold.**\n\n\n\n\n\n\n\n**Step 3: calculate hidden AND preactivation.**\n\n\n\n\n\n\n\n**Step 4: apply its threshold.**\n\n\n\n\n\n\n\n**Step 5: calculate XOR output preactivation.**\n\n\n\n\n\n\n\n**Step 6: apply the XOR threshold.**\n\n\n\n\n\n\n\n**Step 7: calculate XNOR output preactivation.**\n\n\n\n\n\n\n\n**Step 8: apply the XNOR "},{"title":"F23 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For the pictured LSTM time step, explain the forget, “update” and output gates, develop “update and reset” equations, and discuss long sequence lengths. The source mixes LSTM and GRU terminology.</p>"],"answer":["<p><strong>Terminology correction: </strong> the pictured LSTM uses forget, input and output gates plus a candidate. Its input/candidate path updates the cell. A reset gate belongs to GRU, so no genuine LSTM reset-gate equation exists. The complete consistent LSTM answer is:</p>","<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>","<p><strong>For the explicitly named GRU terms in the question: </strong></p>","<p>A GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:279.17px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/552178cdb39642a9.svg\"><img class=\"math display-math\" src=\"assets/equations/4c9f5914ab749b31.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z),\\quad r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"618.24\" height=\"24.43\" style=\"width:618.24px;height:24.43px;aspect-ratio:618.24/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:388.02px;--narrow-height:155.11px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/24dba2ef5a8c9844.svg\"><img class=\"math display-math\" src=\"assets/equations/e0ad3b2f8e3f246b.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h),\\quad h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"750.51\" height=\"31.13\" style=\"width:750.51px;height:31.13px;aspect-ratio:750.51/31.13\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gru.svg\" aria-label=\"Enlarge diagram: Reset controls candidate context and update controls the old new mixture\"><img src=\"assets/figures/gru.svg\" alt=\"Reset controls candidate context and update controls the old new mixture\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Reset controls candidate context and update controls the old new mixture <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.</p>","<p>Compared with an LSTM&#x27;s input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.</p>","<p>In an exam, state the mismatch in one sentence, label each architecture clearly and then give its correct equations. Do not memorize a fictitious reset gate for LSTM.</p>"],"kind":"practice","id":"tee-c13-s12","search":"F23 Q6a **Question (10 marks).** For the pictured LSTM time step, explain the forget, “update” and output gates, develop “update and reset” equations, and discuss long sequence lengths. The source mixes LSTM and GRU terminology.\n\n**Complete worked answer.**\n**Terminology correction: ** the pictured LSTM uses forget, input and output gates plus a candidate. Its input/candidate path updates the cell. A reset gate belongs to GRU, so no genuine LSTM reset-gate equation exists. The complete consistent LSTM answer is:\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\n**For the explicitly named GRU terms in the question: **\nA GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:\n\n\n\nThe reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.\nCompared with an LSTM's input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.\nIn an exam, state the mismatch in one sentence, label each architecture clearly and then give its correct equations. Do not memorize a fictitious reset gate for LSTM.\n"},{"title":"F23 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain how ResNet addresses vanishing gradients. Compare a block output with and without a residual connection.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>"],"kind":"practice","id":"tee-c13-s13","search":"F23 Q6b **Question (10 marks).** Explain how ResNet addresses vanishing gradients. Compare a block output with and without a residual connection.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\n"},{"title":"F23 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design and sketch a sentiment-analysis model whose input is a small paragraph. Explain how its output is generated.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p><strong>Concrete many-to-one design: </strong> tokenize paragraph → embeddings → LSTM sequence processor → final hidden state → dense 3 → softmax for positive/neutral/negative. If the task specifies only two labels, use one sigmoid or two softmax outputs instead. Train with the matching cross-entropy. Keep token order, handle padding/masks consistently and evaluate held-out reviews.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: Sentiment uses the many-to-one pattern\"><img src=\"assets/figures/sequences.svg\" alt=\"Sentiment uses the many-to-one pattern\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>Sentiment uses the many-to-one pattern <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c13-s14","search":"F23 Q7a **Question (10 marks).** Design and sketch a sentiment-analysis model whose input is a small paragraph. Explain how its output is generated.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n**Concrete many-to-one design: ** tokenize paragraph → embeddings → LSTM sequence processor → final hidden state → dense 3 → softmax for positive/neutral/negative. If the task specifies only two labels, use one sigmoid or two softmax outputs instead. Train with the matching cross-entropy. Keep token order, handle padding/masks consistently and evaluate held-out reviews.\n\n"},{"title":"F23 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain the bias-variance tradeoff. Fill effects on bias and variance for weight regularization, more hidden units, dropout and more training data from the same distribution.</p>"],"answer":["<p>Bias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/overfitting.svg\" aria-label=\"Enlarge diagram: Validation behavior distinguishes useful fitting from prolonged fitting to training details\"><img src=\"assets/figures/overfitting.svg\" alt=\"Validation behavior distinguishes useful fitting from prolonged fitting to training details\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Validation behavior distinguishes useful fitting from prolonged fitting to training details <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Increasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model&#x27;s approximation bias much. These are typical trends, not unconditional numerical laws.</p>","<p>Underfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.</p>","<p>Training and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Change</th><th>Typical bias</th><th>Typical variance</th></tr></thead><tbody><tr><td>Stronger weight regularization</td><td>Increases</td><td>Decreases</td></tr><tr><td>More hidden units</td><td>Decreases</td><td>Increases</td></tr><tr><td>Dropout during training</td><td>Increases</td><td>Decreases</td></tr><tr><td>More same-distribution training data</td><td>Approximately no change</td><td>Decreases</td></tr></tbody></table></div>","<p>These are the conventional exam trends, assuming other conditions are comparable. They are not guarantees for every training run.</p>"],"kind":"practice","id":"tee-c13-s15","search":"F23 Q7b **Question (10 marks).** Explain the bias-variance tradeoff. Fill effects on bias and variance for weight regularization, more hidden units, dropout and more training data from the same distribution.\n\n**Complete worked answer.**\nBias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.\n\nIncreasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model's approximation bias much. These are typical trends, not unconditional numerical laws.\nUnderfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.\nTraining and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.\n| Change | Typical bias | Typical variance |\n| Stronger weight regularization | Increases | Decreases |\n| More hidden units | Decreases | Increases |\n| Dropout during training | Increases | Decreases |\n| More same-distribution training data | Approximately no change | Decreases |\nThese are the conventional exam trends, assuming other conditions are comparable. They are not guarantees for every training run.\n\n\n"}]},{"n":14,"title":"Re examination February 2024 fully solved","sections":[{"title":"Start here","blocks":["<p>R24 = S14, 13 February 2024. Its source matrix uses an input-to-hidden indexing convention, explicitly handled below.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c14-intro"},{"title":"R24 Q1a","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> What factors drive widespread adoption of deep learning?</p>"],"answer":["<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>"],"kind":"practice","id":"tee-c14-s0","search":"R24 Q1a **Question (5 marks).** What factors drive widespread adoption of deep learning?\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n"},{"title":"R24 Q1b","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Draw an animal-classification network with 10 inputs, three hidden layers of 5 neurons each and 4 output classes. Every hidden/output neuron has a bias. Count all trainable parameters.</p>"],"answer":["<h3>Given</h3>","<p>10 input features → 5 hidden → 5 hidden → 5 hidden → 4 output classes.</p>","<p>One bias per hidden/output neuron.</p>","<h3>To find</h3>","<p>Draw the layer structure and count weights and biases.</p>","<h3>Formula — which one and why</h3>","<p><strong>Dense-layer parameters.</strong> Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.</p>","<p>n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/494312d0893d20d2.svg\" alt=\"P=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"184.79\" height=\"24.43\" style=\"width:184.79px;height:24.43px;aspect-ratio:184.79/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output ke liye saare inputs plus ek bias.</p>","<h3>Solution — step by step</h3>","<p>Architecture: 10 → 5 → 5 → 5 → 4. Each non-input neuron has one bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/dense_10_5_5_5_4.svg\" aria-label=\"Enlarge diagram: R24 Q1b every layer contains the stated number of neurons\"><img src=\"assets/figures/dense_10_5_5_5_4.svg\" alt=\"R24 Q1b every layer contains the stated number of neurons\" width=\"960\" height=\"495\" loading=\"lazy\"></button><figcaption>R24 Q1b every layer contains the stated number of neurons <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Layer 10 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6bd3c4c12c1c454b.svg\" alt=\"10(5)=50\" width=\"112.68\" height=\"24.43\" style=\"width:112.68px;height:24.43px;aspect-ratio:112.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cacbd65e2c06f4f4.svg\" alt=\"50+5=55\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d16b109d87f9088b.svg\" alt=\"5(5)=25\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/862c71dcbfedc68d.svg\" alt=\"25+5=30\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d16b109d87f9088b.svg\" alt=\"5(5)=25\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/862c71dcbfedc68d.svg\" alt=\"25+5=30\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 4</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b06f6eedc0b0c61f.svg\" alt=\"5(4)=20\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 4 receiving neurons, so 4 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/92df7685dd83d921.svg\" alt=\"20+4=24\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<p><strong>Total = 139</strong>. Input values and activations are not trainable parameters.</p>","<p>Use hidden nonlinearities such as ReLU and a 4-class softmax. Learned parameters are the connections and biases; the number of layers and units are design choices.</p>"],"kind":"practice","id":"tee-c14-s1","search":"R24 Q1b **Question (5 marks).** Draw an animal-classification network with 10 inputs, three hidden layers of 5 neurons each and 4 output classes. Every hidden/output neuron has a bias. Count all trainable parameters.\n\n**Complete worked answer.**\n\n\n\n### Given\n\n10 input features → 5 hidden → 5 hidden → 5 hidden → 4 output classes.\n\nOne bias per hidden/output neuron.\n\n### To find\n\nDraw the layer structure and count weights and biases.\n\n### Formula — which one and why\n\n**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\nn_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.\n\n\n\n**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.\n\n### Solution — step by step\n\n\n\n\n\n\nArchitecture: 10 → 5 → 5 → 5 → 4. Each non-input neuron has one bias.\n\n### Layer 10 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 4\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 4 receiving neurons, so 4 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n**Total = 139**. Input values and activations are not trainable parameters.\nUse hidden nonlinearities such as ReLU and a 4-class softmax. Learned parameters are the connections and biases; the number of layers and units are design choices.\n"},{"title":"R24 Q1c","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> A deep network strongly overfits its training set and performs poorly on unseen data. Explain remedies.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<p>Use a representative validation set to choose the remedy. Also inspect leakage, label quality and distribution mismatch. If the final test set was repeatedly used to tune changes, reserve a fresh untouched set for final reporting.</p>"],"kind":"practice","id":"tee-c14-s2","search":"R24 Q1c **Question (5 marks).** A deep network strongly overfits its training set and performs poorly on unseen data. Explain remedies.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\nUse a representative validation set to choose the remedy. Also inspect leakage, label quality and distribution mismatch. If the final test set was repeatedly used to tune changes, reserve a fresh untouched set for final reporting.\n"},{"title":"R24 Q1d","question":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> For feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_915e1db14b.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_915e1db14b.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"405\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>For feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.</p>","<h3>To find</h3>","<p>Find the requested pooled output(s).</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ad46d0c1b3646c71.svg\" alt=\"\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[21, 11, 12, 9]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>21 + 11 + 12 + 9 = 53</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>53/4 = <strong>13.25</strong>. Maximum = <strong>21</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[15, 10, 10, 11]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>15 + 10 + 10 + 11 = 46</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>46/4 = <strong>11.5</strong>. Maximum = <strong>15</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[11, 13, 7, 4]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>11 + 13 + 7 + 4 = 35</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>35/4 = <strong>8.75</strong>. Maximum = <strong>13</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[18, 12, 15, 12]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>18 + 12 + 15 + 12 = 57</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>57/4 = <strong>14.25</strong>. Maximum = <strong>18</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/94682b0fab3f0b97.svg\" alt=\"\\begin{bmatrix}13.25 &amp; 11.5\\\\8.75 &amp; 14.25\\end{bmatrix}\" width=\"125.66\" height=\"45.61\" style=\"width:125.66px;height:45.61px;aspect-ratio:125.66/45.61\" loading=\"lazy\"></span>. <strong>Max output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/89ec596cf1c6ec68.svg\" alt=\"\\begin{bmatrix}21 &amp; 15\\\\13 &amp; 18\\end{bmatrix}\" width=\"77.08\" height=\"45.61\" style=\"width:77.08px;height:45.61px;aspect-ratio:77.08/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>"],"kind":"practice","id":"tee-c14-s3","search":"R24 Q1d **Question (5 marks).** For feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nFor feature map Matrix 1 shown below, find max and average pooling with 2 × 2 windows, stride 2.\n\n### To find\n\nFind the requested pooled output(s).\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n\n\n**Shape: ** \\(\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\\) = 2 on each axis; channels stay unchanged.\n### Pooling window (1,1)\n\n**Step 1: select the entries.**\n\n[21, 11, 12, 9]\n\n**Step 2: add all selected entries.**\n\n21 + 11 + 12 + 9 = 53\n\n**Step 3: divide by the 4 entries in this window.**\n\n53/4 = **13.25**. Maximum = **21**\n\n\n### Pooling window (1,2)\n\n**Step 1: select the entries.**\n\n[15, 10, 10, 11]\n\n**Step 2: add all selected entries.**\n\n15 + 10 + 10 + 11 = 46\n\n**Step 3: divide by the 4 entries in this window.**\n\n46/4 = **11.5**. Maximum = **15**\n\n\n### Pooling window (2,1)\n\n**Step 1: select the entries.**\n\n[11, 13, 7, 4]\n\n**Step 2: add all selected entries.**\n\n11 + 13 + 7 + 4 = 35\n\n**Step 3: divide by the 4 entries in this window.**\n\n35/4 = **8.75**. Maximum = **13**\n\n\n### Pooling window (2,2)\n\n**Step 1: select the entries.**\n\n[18, 12, 15, 12]\n\n**Step 2: add all selected entries.**\n\n18 + 12 + 15 + 12 = 57\n\n**Step 3: divide by the 4 entries in this window.**\n\n57/4 = **14.25**. Maximum = **18**\n\n\n**Average output: ** . **Max output: ** . Pooling normally has zero trainable parameters and reduces spatial dimensions.\n"},{"title":"R24 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> 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.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_28edc44005.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_28edc44005.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"405\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_r24.svg\" aria-label=\"Enlarge diagram: R24 Q2a receiving-neuron rows after transposing the source convention\"><img src=\"assets/figures/net_r24.svg\" alt=\"R24 Q2a receiving-neuron rows after transposing the source convention\" width=\"960\" height=\"675\" loading=\"lazy\"></button><figcaption>R24 Q2a receiving-neuron rows after transposing the source convention <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>A 4 → 4 → 1 sigmoid network has input [.4,.3,.5,−.4].</p>","<p>The printed W₁ is printed with the question, W₂ = [.5,.7,−.6,.2].</p>","<p>hidden bias 0.6, output bias 0.2, target 0.9, η = .5.</p>","<h3>To find</h3>","<p>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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Mean squared loss.</strong> Average the squared scalar prediction errors. The derivative retains the factor 2/n; n must count the outputs included in this mean.</p>","<p>n = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f5544f3d0af79c26.svg\" alt=\"L=\\frac1n\\sum_j(o_j-y_j)^2\" width=\"215.65\" height=\"65.25\" style=\"width:215.65px;height:65.25px;aspect-ratio:215.65/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b0ae494a9901408.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=\\frac2n(o_j-y_j)\" width=\"194.57\" height=\"57.94\" style=\"width:194.57px;height:57.94px;aspect-ratio:194.57/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p><strong>Orientation: </strong> 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.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:259.33px;--narrow-height:180.96px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee9cf86ec848950c.svg\"><img class=\"math display-math\" src=\"assets/equations/d580103bada11b64.svg\" alt=\"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.9\" width=\"799.36\" height=\"24.58\" style=\"width:799.36px;height:24.58px;aspect-ratio:799.36/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f76f739a80a9361b.svg\"><img class=\"math display-math\" src=\"assets/equations/8df07c79c171fe96.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(0.9)}}=0.710949503\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.32px;--narrow-height:180.96px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/13efea50d945325a.svg\"><img class=\"math display-math\" src=\"assets/equations/f62211e96d9d3780.svg\" alt=\"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.7\" width=\"761.35\" height=\"24.58\" style=\"width:761.35px;height:24.58px;aspect-ratio:761.35/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d9473d1a5522dcc7.svg\"><img class=\"math display-math\" src=\"assets/equations/1e4c0a3ecd05bfd3.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.7)}}=0.668187772\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 3: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.32px;--narrow-height:181.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cbf6b0463b666856.svg\"><img class=\"math display-math\" src=\"assets/equations/6fe54eb13873171d.svg\" alt=\"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.56\" width=\"792.57\" height=\"24.85\" style=\"width:792.57px;height:24.85px;aspect-ratio:792.57/24.85\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.18px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b006fd2ae332459.svg\"><img class=\"math display-math\" src=\"assets/equations/ab920f7e27d63556.svg\" alt=\"h_{3}=\\frac{1}{1+e^{-(0.56)}}=0.63645254\" width=\"330.51\" height=\"53.84\" style=\"width:330.51px;height:53.84px;aspect-ratio:330.51/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 4: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.32px;--narrow-height:180.96px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7e4d728bbba36941.svg\"><img class=\"math display-math\" src=\"assets/equations/ed52dc7ef4c0c34d.svg\" alt=\"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.6\" width=\"761.35\" height=\"24.58\" style=\"width:761.35px;height:24.58px;aspect-ratio:761.35/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3e375a5e30dabd6f.svg\"><img class=\"math display-math\" src=\"assets/equations/4f0e84b4e9fe0752.svg\" alt=\"h_{4}=\\frac{1}{1+e^{-(0.6)}}=0.645656306\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b82d291c09c8255f.svg\" alt=\"\\begin{aligned}z_{o_1}={}&amp;0.5(0.710949503)+0.7(0.668187772)\\\\&amp;-0.6(0.63645254)+0.2(0.645656306)+0.2\\\\={}&amp;0.770465929\\end{aligned}\" width=\"528.92\" height=\"88.12\" style=\"width:528.92px;height:88.12px;aspect-ratio:528.92/88.12\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5ce3c8d47df25f40.svg\"><img class=\"math display-math\" src=\"assets/equations/928c85e2f67a9c66.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.770465929)}}=0.683621675\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> Use the explicitly requested one-output MSE, not half squared loss.</p>","<p>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.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.94px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7665056831c42066.svg\"><img class=\"math display-math\" src=\"assets/equations/d17a9957b64c0cce.svg\" alt=\"\\delta_{o_1} = 2 \\times  (0.683621675-0.9) \\times  0.216283081 = -0.093597941\" width=\"651.93\" height=\"24.58\" style=\"width:651.93px;height:24.58px;aspect-ratio:651.93/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.710949503</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.093597941</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.06654341</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.533271705</strong></div></div><p>Subtract η × gradient = <b>−0.033271705</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a4c5e0af98c4e800.svg\"><img class=\"math display-math\" src=\"assets/equations/08e2708ce0eb567a.svg\" alt=\"g_{1,1}^{(2)}=(-0.093597941)\\times(0.710949503)\\approx -0.06654341\" width=\"581.52\" height=\"36.54\" style=\"width:581.52px;height:36.54px;aspect-ratio:581.52/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.86px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d5193daabf661dea.svg\"><img class=\"math display-math\" src=\"assets/equations/db770dae3f630bdc.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.5-0.5(-0.06654341)\\approx 0.533271705\" width=\"522.96\" height=\"36.54\" style=\"width:522.96px;height:36.54px;aspect-ratio:522.96/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.668187772</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.093597941</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.062541</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.7</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.7312705</strong></div></div><p>Subtract η × gradient = <b>−0.0312705</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc6c904cdf89e2ca.svg\"><img class=\"math display-math\" src=\"assets/equations/9a4ef8c75729d56e.svg\" alt=\"g_{1,2}^{(2)}=(-0.093597941)\\times(0.668187772)\\approx -0.062541\" width=\"557.09\" height=\"36.54\" style=\"width:557.09px;height:36.54px;aspect-ratio:557.09/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.43px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a56876d47ec41774.svg\"><img class=\"math display-math\" src=\"assets/equations/988e1d1b7e014f5c.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.7-0.5(-0.062541)\\approx 0.7312705\" width=\"474.09\" height=\"36.54\" style=\"width:474.09px;height:36.54px;aspect-ratio:474.09/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h3 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h3 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.63645254</strong><span class=\"lv-detail\">h3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.093597941</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.059570648</strong><span class=\"lv-detail\">h3 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.6</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.570214676</strong></div></div><p>Subtract η × gradient = <b>−0.029785324</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/85e8a967a0a12f92.svg\" alt=\"g_{1,3}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,3}}=\\delta_{o_1}h_3\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc44ca9541b76f51.svg\"><img class=\"math display-math\" src=\"assets/equations/b7d94cc71bc1bf29.svg\" alt=\"g_{1,3}^{(2)}=(-0.093597941)\\times(0.63645254)\\approx -0.059570648\" width=\"581.52\" height=\"36.54\" style=\"width:581.52px;height:36.54px;aspect-ratio:581.52/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30d92749f17fd5d6.svg\"><img class=\"math display-math\" src=\"assets/equations/6c5ddaf1b80c1d4b.svg\" alt=\"W^{(2)}_{1,3,\\mathrm{new}}=-0.6-0.5(-0.059570648)\\approx -0.570214676\" width=\"573.19\" height=\"36.54\" style=\"width:573.19px;height:36.54px;aspect-ratio:573.19/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h4 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h4 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.645656306</strong><span class=\"lv-detail\">h4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.093597941</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.060432101</strong><span class=\"lv-detail\">h4 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.230216051</strong></div></div><p>Subtract η × gradient = <b>−0.03021605</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/62648b24044cc2ea.svg\" alt=\"g_{1,4}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,4}}=\\delta_{o_1}h_4\" width=\"230.12\" height=\"69.74\" style=\"width:230.12px;height:69.74px;aspect-ratio:230.12/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/95d6468f8fc70889.svg\"><img class=\"math display-math\" src=\"assets/equations/5bd5e9e2c424a3de.svg\" alt=\"g_{1,4}^{(2)}=(-0.093597941)\\times(0.645656306)\\approx -0.060432101\" width=\"593.74\" height=\"36.72\" style=\"width:593.74px;height:36.72px;aspect-ratio:593.74/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/09adce4276bdd712.svg\"><img class=\"math display-math\" src=\"assets/equations/d362d593396fe5bf.svg\" alt=\"W^{(2)}_{1,4,\\mathrm{new}}=0.2-0.5(-0.060432101)\\approx 0.230216051\" width=\"535.17\" height=\"36.72\" style=\"width:535.17px;height:36.72px;aspect-ratio:535.17/36.72\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.093597941</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.04679897</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.046798971</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e1dda3f8681ba484.svg\"><img class=\"math display-math\" src=\"assets/equations/aabc39607d847229.svg\" alt=\"C_1=(0.5)\\times(-0.093597941)\\approx -0.04679897\" width=\"476.15\" height=\"24.43\" style=\"width:476.15px;height:24.43px;aspect-ratio:476.15/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f1f4d5705234aba2.svg\"><img class=\"math display-math\" src=\"assets/equations/457a7a6b8a317393.svg\" alt=\"\\text{Sum}=C_1\\approx -0.046798971\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81cfb49d2e12d4ca.svg\"><img class=\"math display-math\" src=\"assets/equations/88603ee1250e709b.svg\" alt=\"\\delta_{h_1} = -0.046798971 \\times  0.205500307 = -0.009617203\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.093597941</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.7</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.065518559</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.065518559</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d3e0ecf8502df13.svg\"><img class=\"math display-math\" src=\"assets/equations/00d532669e6f8902.svg\" alt=\"C_1=(0.7)\\times(-0.093597941)\\approx -0.065518559\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/893a1456a543073d.svg\"><img class=\"math display-math\" src=\"assets/equations/bed646f2d5a5b17a.svg\" alt=\"\\text{Sum}=C_1\\approx -0.065518559\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/26b1106bf05e76a6.svg\"><img class=\"math display-math\" src=\"assets/equations/e65ba09e76cd6492.svg\" alt=\"\\delta_{h_2} = -0.065518559 \\times  0.221712873 = -0.014526308\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 3 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.093597941</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">−0.6</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.056158765</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.056158765</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/44316b3d49dde0a3.svg\"><img class=\"math display-math\" src=\"assets/equations/47a1c511453df266.svg\" alt=\"C_1=(-0.6)\\times(-0.093597941)\\approx 0.056158765\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b369b4600b5c9b60.svg\" alt=\"\\text{Sum}=C_1\\approx 0.056158765\" width=\"269.79\" height=\"20.89\" style=\"width:269.79px;height:20.89px;aspect-ratio:269.79/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:103.04px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/43d6f061bf15172b.svg\"><img class=\"math display-math\" src=\"assets/equations/ded30217d8f2c313.svg\" alt=\"\\delta_{h_3} = 0.056158765 \\times  0.231380704 = 0.012994055\" width=\"512.31\" height=\"24.04\" style=\"width:512.31px;height:24.04px;aspect-ratio:512.31/24.04\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 4 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.093597941</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.018719588</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.018719588</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0303b36ec5b8423b.svg\"><img class=\"math display-math\" src=\"assets/equations/5b437d314c196916.svg\" alt=\"C_1=(0.2)\\times(-0.093597941)\\approx -0.018719588\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4daca8885b8234c0.svg\"><img class=\"math display-math\" src=\"assets/equations/0ab4749810e2fc16.svg\" alt=\"\\text{Sum}=C_1\\approx -0.018719588\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b8fde02c1bff3e4f.svg\"><img class=\"math display-math\" src=\"assets/equations/432e3ebd056288aa.svg\" alt=\"\\delta_{h_4} = -0.018719588 \\times  0.22878424 = -0.004282747\" width=\"538.11\" height=\"23.78\" style=\"width:538.11px;height:23.78px;aspect-ratio:538.11/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.009617203</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.003846881</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.8</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.801923441</strong></div></div><p>Subtract η × gradient = <b>−0.00192344</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1ec98954f2916f01.svg\"><img class=\"math display-math\" src=\"assets/equations/568ab83eab81feec.svg\" alt=\"g_{1,1}^{(1)}=(-0.009617203)\\times(0.4)\\approx -0.003846881\" width=\"496.00\" height=\"36.54\" style=\"width:496.00px;height:36.54px;aspect-ratio:496.00/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c75e592a0b5226d2.svg\"><img class=\"math display-math\" src=\"assets/equations/681392cf40c3207a.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.8-0.5(-0.003846881)\\approx 0.801923441\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.009617203</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.002885161</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.49855742</strong></div></div><p>Subtract η × gradient = <b>−0.00144258</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3ad09496c853dfe2.svg\"><img class=\"math display-math\" src=\"assets/equations/42a98609ebae9895.svg\" alt=\"g_{1,2}^{(1)}=(-0.009617203)\\times(0.3)\\approx -0.002885161\" width=\"496.00\" height=\"36.54\" style=\"width:496.00px;height:36.54px;aspect-ratio:496.00/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8044a6006ab0ca77.svg\"><img class=\"math display-math\" src=\"assets/equations/9076174f0a478139.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=-0.5-0.5(-0.002885161)\\approx -0.49855742\" width=\"560.97\" height=\"36.54\" style=\"width:560.97px;height:36.54px;aspect-ratio:560.97/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x3 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x3 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.5</strong><span class=\"lv-detail\">x3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.009617203</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004808601</strong><span class=\"lv-detail\">x3 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.102404301</strong></div></div><p>Subtract η × gradient = <b>−0.0024043</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/75cb25a10b4d1d19.svg\" alt=\"g_{1,3}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,3}}=\\delta_{h_1}x_3\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/053d52dc796832a9.svg\"><img class=\"math display-math\" src=\"assets/equations/efb4f1bd62923583.svg\" alt=\"g_{1,3}^{(1)}=(-0.009617203)\\times(0.5)\\approx -0.004808601\" width=\"496.00\" height=\"36.54\" style=\"width:496.00px;height:36.54px;aspect-ratio:496.00/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/86d9f58aa097fd71.svg\"><img class=\"math display-math\" src=\"assets/equations/239fd2aae5bb89b7.svg\" alt=\"W^{(1)}_{1,3,\\mathrm{new}}=0.1-0.5(-0.004808601)\\approx 0.102404301\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x4 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x4 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">−0.4</strong><span class=\"lv-detail\">x4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.009617203</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.003846881</strong><span class=\"lv-detail\">x4 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.201923441</strong></div></div><p>Subtract η × gradient = <b>0.00192344</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51881657a5cb91ef.svg\" alt=\"g_{1,4}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,4}}=\\delta_{h_1}x_4\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a4af21673941e601.svg\"><img class=\"math display-math\" src=\"assets/equations/576777ca605fe30f.svg\" alt=\"g_{1,4}^{(1)}=(-0.009617203)\\times(-0.4)\\approx 0.003846881\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bdc8b7088a5ab57a.svg\"><img class=\"math display-math\" src=\"assets/equations/80909f1382fb6dde.svg\" alt=\"W^{(1)}_{1,4,\\mathrm{new}}=-0.2-0.5(0.003846881)\\approx -0.201923441\" width=\"554.18\" height=\"36.72\" style=\"width:554.18px;height:36.72px;aspect-ratio:554.18/36.72\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.014526308</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.005810523</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.202905262</strong></div></div><p>Subtract η × gradient = <b>−0.002905262</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/afb5bb784d05f461.svg\"><img class=\"math display-math\" src=\"assets/equations/c99ccbe66229f64d.svg\" alt=\"g_{2,1}^{(1)}=(-0.014526308)\\times(0.4)\\approx -0.005810523\" width=\"496.00\" height=\"36.54\" style=\"width:496.00px;height:36.54px;aspect-ratio:496.00/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d7bc835c6d4c639d.svg\"><img class=\"math display-math\" src=\"assets/equations/dc852cb894d5794e.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.2-0.5(-0.005810523)\\approx 0.202905262\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.014526308</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004357892</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.402178946</strong></div></div><p>Subtract η × gradient = <b>−0.002178946</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7674dd635ddd9ccc.svg\"><img class=\"math display-math\" src=\"assets/equations/f974f6695dcb0ab0.svg\" alt=\"g_{2,2}^{(1)}=(-0.014526308)\\times(0.3)\\approx -0.004357892\" width=\"496.00\" height=\"36.54\" style=\"width:496.00px;height:36.54px;aspect-ratio:496.00/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3acb31488ce3b963.svg\"><img class=\"math display-math\" src=\"assets/equations/ec08f8a3c878658a.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.4-0.5(-0.004357892)\\approx 0.402178946\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x3 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x3 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.5</strong><span class=\"lv-detail\">x3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.014526308</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.007263154</strong><span class=\"lv-detail\">x3 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.203631577</strong></div></div><p>Subtract η × gradient = <b>−0.003631577</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48d08524866113b9.svg\" alt=\"g_{2,3}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,3}}=\\delta_{h_2}x_3\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5d328fe04a37cfc6.svg\"><img class=\"math display-math\" src=\"assets/equations/42b60f11f5e3cb58.svg\" alt=\"g_{2,3}^{(1)}=(-0.014526308)\\times(0.5)\\approx -0.007263154\" width=\"496.00\" height=\"36.54\" style=\"width:496.00px;height:36.54px;aspect-ratio:496.00/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5eeed9f16670c55b.svg\"><img class=\"math display-math\" src=\"assets/equations/83ac46e79dd0ac76.svg\" alt=\"W^{(1)}_{2,3,\\mathrm{new}}=0.2-0.5(-0.007263154)\\approx 0.203631577\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x4 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x4 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">−0.4</strong><span class=\"lv-detail\">x4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.014526308</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.005810523</strong><span class=\"lv-detail\">x4 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.497094738</strong></div></div><p>Subtract η × gradient = <b>0.002905262</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c111f40d015517f1.svg\" alt=\"g_{2,4}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,4}}=\\delta_{h_2}x_4\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e120af498da6af3d.svg\"><img class=\"math display-math\" src=\"assets/equations/c06fd2203e85c0d9.svg\" alt=\"g_{2,4}^{(1)}=(-0.014526308)\\times(-0.4)\\approx 0.005810523\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/901765ceedbe9376.svg\"><img class=\"math display-math\" src=\"assets/equations/ec111f9ae9bb85b7.svg\" alt=\"W^{(1)}_{2,4,\\mathrm{new}}=0.5-0.5(0.005810523)\\approx 0.497094738\" width=\"516.16\" height=\"36.72\" style=\"width:516.16px;height:36.72px;aspect-ratio:516.16/36.72\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h3:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h3</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.012994055</strong><span class=\"lv-detail\">δ at h3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.005197622</strong><span class=\"lv-detail\">x1 → h3</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.297401189</strong></div></div><p>Subtract η × gradient = <b>0.002598811</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c647740724db2342.svg\" alt=\"g_{3,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{3,1}}=\\delta_{h_3}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/618f330eb0013565.svg\"><img class=\"math display-math\" src=\"assets/equations/3982bafceb3d1f9a.svg\" alt=\"g_{3,1}^{(1)}=(0.012994055)\\times(0.4)\\approx 0.005197622\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f7218a8971ce6230.svg\"><img class=\"math display-math\" src=\"assets/equations/b709fa905c40f2d3.svg\" alt=\"W^{(1)}_{3,1,\\mathrm{new}}=0.3-0.5(0.005197622)\\approx 0.297401189\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h3:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h3</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.012994055</strong><span class=\"lv-detail\">δ at h3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.003898216</strong><span class=\"lv-detail\">x2 → h3</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.298050892</strong></div></div><p>Subtract η × gradient = <b>0.001949108</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11a3a8fd1c29457a.svg\" alt=\"g_{3,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{3,2}}=\\delta_{h_3}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/96944db9c899fc7e.svg\"><img class=\"math display-math\" src=\"assets/equations/6b2e81bef7a212bd.svg\" alt=\"g_{3,2}^{(1)}=(0.012994055)\\times(0.3)\\approx 0.003898216\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/87125a5db71e09ef.svg\"><img class=\"math display-math\" src=\"assets/equations/671d11febf8e19cd.svg\" alt=\"W^{(1)}_{3,2,\\mathrm{new}}=0.3-0.5(0.003898216)\\approx 0.298050892\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x3 → h3:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x3 → h3</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.5</strong><span class=\"lv-detail\">x3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.012994055</strong><span class=\"lv-detail\">δ at h3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.006497027</strong><span class=\"lv-detail\">x3 → h3</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.103248514</strong></div></div><p>Subtract η × gradient = <b>0.003248514</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec47dc9f5403d781.svg\" alt=\"g_{3,3}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{3,3}}=\\delta_{h_3}x_3\" width=\"231.60\" height=\"69.53\" style=\"width:231.60px;height:69.53px;aspect-ratio:231.60/69.53\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9d6717c29bdbe2b4.svg\"><img class=\"math display-math\" src=\"assets/equations/682fcf2989244bd9.svg\" alt=\"g_{3,3}^{(1)}=(0.012994055)\\times(0.5)\\approx 0.006497027\" width=\"457.98\" height=\"36.51\" style=\"width:457.98px;height:36.51px;aspect-ratio:457.98/36.51\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/80c1a9c61f216679.svg\"><img class=\"math display-math\" src=\"assets/equations/9712a05089c95dbd.svg\" alt=\"W^{(1)}_{3,3,\\mathrm{new}}=-0.1-0.5(0.006497027)\\approx -0.103248514\" width=\"554.18\" height=\"36.51\" style=\"width:554.18px;height:36.51px;aspect-ratio:554.18/36.51\" loading=\"lazy\"></picture></div>","<p><strong>x4 → h3:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x4 → h3</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">−0.4</strong><span class=\"lv-detail\">x4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.012994055</strong><span class=\"lv-detail\">δ at h3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.005197622</strong><span class=\"lv-detail\">x4 → h3</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502598811</strong></div></div><p>Subtract η × gradient = <b>−0.002598811</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4791ee899924c031.svg\" alt=\"g_{3,4}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{3,4}}=\\delta_{h_3}x_4\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/406ff2da076d59bc.svg\"><img class=\"math display-math\" src=\"assets/equations/0ce21e721ab1dd63.svg\" alt=\"g_{3,4}^{(1)}=(0.012994055)\\times(-0.4)\\approx -0.005197622\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/85589f5b6f5c0202.svg\"><img class=\"math display-math\" src=\"assets/equations/facfaa0bc7aa72e7.svg\" alt=\"W^{(1)}_{3,4,\\mathrm{new}}=0.5-0.5(-0.005197622)\\approx 0.502598811\" width=\"535.17\" height=\"36.72\" style=\"width:535.17px;height:36.72px;aspect-ratio:535.17/36.72\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h4:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h4</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004282747</strong><span class=\"lv-detail\">δ at h4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.001713099</strong><span class=\"lv-detail\">x1 → h4</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.400856549</strong></div></div><p>Subtract η × gradient = <b>−0.00085655</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e5b6b4e6329ece21.svg\" alt=\"g_{4,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{4,1}}=\\delta_{h_4}x_1\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/313f27074af89747.svg\"><img class=\"math display-math\" src=\"assets/equations/fed96721b701f460.svg\" alt=\"g_{4,1}^{(1)}=(-0.004282747)\\times(0.4)\\approx -0.001713099\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/15f2ab91f5697a46.svg\"><img class=\"math display-math\" src=\"assets/equations/ef6569978fef20ab.svg\" alt=\"W^{(1)}_{4,1,\\mathrm{new}}=0.4-0.5(-0.001713099)\\approx 0.400856549\" width=\"535.17\" height=\"36.72\" style=\"width:535.17px;height:36.72px;aspect-ratio:535.17/36.72\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h4:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h4</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.3</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004282747</strong><span class=\"lv-detail\">δ at h4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.001284824</strong><span class=\"lv-detail\">x2 → h4</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.200642412</strong></div></div><p>Subtract η × gradient = <b>−0.000642412</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e7cc212944346db.svg\" alt=\"g_{4,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{4,2}}=\\delta_{h_4}x_2\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b3de47e4aca426e5.svg\"><img class=\"math display-math\" src=\"assets/equations/f46fd9e254c79580.svg\" alt=\"g_{4,2}^{(1)}=(-0.004282747)\\times(0.3)\\approx -0.001284824\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e488fc21bed8f11.svg\"><img class=\"math display-math\" src=\"assets/equations/03e07f52a47c5589.svg\" alt=\"W^{(1)}_{4,2,\\mathrm{new}}=0.2-0.5(-0.001284824)\\approx 0.200642412\" width=\"535.17\" height=\"36.72\" style=\"width:535.17px;height:36.72px;aspect-ratio:535.17/36.72\" loading=\"lazy\"></picture></div>","<p><strong>x3 → h4:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x3 → h4</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.5</strong><span class=\"lv-detail\">x3</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004282747</strong><span class=\"lv-detail\">δ at h4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.002141373</strong><span class=\"lv-detail\">x3 → h4</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.201070687</strong></div></div><p>Subtract η × gradient = <b>−0.001070686</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f10479c14422cd43.svg\" alt=\"g_{4,3}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{4,3}}=\\delta_{h_4}x_3\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2192ca5fcdf60ef8.svg\"><img class=\"math display-math\" src=\"assets/equations/1b83f252b55ba36d.svg\" alt=\"g_{4,3}^{(1)}=(-0.004282747)\\times(0.5)\\approx -0.002141373\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5bb6f3c8fa38e377.svg\"><img class=\"math display-math\" src=\"assets/equations/7947b1af682a8c01.svg\" alt=\"W^{(1)}_{4,3,\\mathrm{new}}=0.2-0.5(-0.002141373)\\approx 0.201070687\" width=\"535.17\" height=\"36.72\" style=\"width:535.17px;height:36.72px;aspect-ratio:535.17/36.72\" loading=\"lazy\"></picture></div>","<p><strong>x4 → h4:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x4 → h4</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">−0.4</strong><span class=\"lv-detail\">x4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004282747</strong><span class=\"lv-detail\">δ at h4</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.001713099</strong><span class=\"lv-detail\">x4 → h4</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.8</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.799143451</strong></div></div><p>Subtract η × gradient = <b>0.00085655</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/54a191df99677201.svg\" alt=\"g_{4,4}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{4,4}}=\\delta_{h_4}x_4\" width=\"231.60\" height=\"69.74\" style=\"width:231.60px;height:69.74px;aspect-ratio:231.60/69.74\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:260.67px;--narrow-height:75.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f326d58085d05315.svg\"><img class=\"math display-math\" src=\"assets/equations/39b46eb4072b2e58.svg\" alt=\"g_{4,4}^{(1)}=(-0.004282747)\\times(-0.4)\\approx 0.001713099\" width=\"496.00\" height=\"36.72\" style=\"width:496.00px;height:36.72px;aspect-ratio:496.00/36.72\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b007fcf05f829e6c.svg\"><img class=\"math display-math\" src=\"assets/equations/13c9d7893d4ecaff.svg\" alt=\"W^{(1)}_{4,4,\\mathrm{new}}=0.8-0.5(0.001713099)\\approx 0.799143451\" width=\"516.16\" height=\"36.72\" style=\"width:516.16px;height:36.72px;aspect-ratio:516.16/36.72\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5d88aea5b1073764.svg\"><img class=\"math display-math\" src=\"assets/equations/8b40f970f91aece5.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.6-0.5(-0.009617203)=0.604808601\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/758b03c4be06d181.svg\"><img class=\"math display-math\" src=\"assets/equations/cb4635077c8c6a0a.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.6-0.5(-0.014526308)=0.607263154\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/01910665e2cb2391.svg\"><img class=\"math display-math\" src=\"assets/equations/1f4b70cb7e5f9e49.svg\" alt=\"b_{h_3,\\mathrm{new}}=0.6-0.5(0.012994055)=0.593502972\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f3f5c6e854f64acf.svg\"><img class=\"math display-math\" src=\"assets/equations/2d5702d767818373.svg\" alt=\"b_{h_4,\\mathrm{new}}=0.6-0.5(-0.004282747)=0.602141373\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75d8de25e1127fac.svg\"><img class=\"math display-math\" src=\"assets/equations/e9c198f623dedcbc.svg\" alt=\"b_{o_1,\\mathrm{new}}=0.2-0.5(-0.093597941)=0.246798971\" width=\"516.43\" height=\"25.35\" style=\"width:516.43px;height:25.35px;aspect-ratio:516.43/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Required result: </strong> output <strong>0.683621675</strong>, MSE <strong>0.046819580</strong>, h₁ → output new weight <strong>0.533271705</strong>. 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.</p>"],"kind":"practice","id":"tee-c14-s4","search":"R24 Q2a **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.\n\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nA 4 → 4 → 1 sigmoid network has input [.4,.3,.5,−.4].\n\nThe printed W₁ is printed with the question, W₂ = [.5,.7,−.6,.2].\n\nhidden bias 0.6, output bias 0.2, target 0.9, η = .5.\n\n### To find\n\nFind 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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\nn = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.\n\n\n\n\n\n**Yaad rakhne ka cue:** MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**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.\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Hidden neuron 3: **\n\n\n**Hidden neuron 4: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** Use the explicitly requested one-output MSE, not half squared loss.\nPrediction 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.\n**Output delta 1:**\n\nThe derivative is o(1−o).\n**Step 3 output weights.** Gradient = receiving delta × send"},{"title":"R24 Q2b","question":["<p class=\"inline-question\"><strong>Question.</strong> Compare standard momentum and Nesterov accelerated gradient using their gradient-evaluation points and update equations. Explain what may happen when momentum is extremely close to 1, for example 0.9999.</p>","<p><strong>Syllabus-aligned extract:</strong> source R24 Q2b. The current-syllabus optimizer comparison and high-momentum discussion are retained; marks for this extract are not separately stated.</p>"],"answer":["<p>Use signed velocity. Standard momentum evaluates g at current θ: vnew = βv−ηg(θ), θ new = θ+vnew. Nesterov evaluates at a look-ahead point: θ look = θ+βv; vnew = βv−ηg(θ look); θ new = θ+vnew. Thus the gradient can correct a direction after anticipating part of the momentum move. Nesterov often reduces overshoot in suitable settings, but it is not universally faster for every neural network.</p>","<p>With β = 0.9999, old velocity decays very slowly. The method can respond sluggishly to direction changes, overshoot or oscillate, particularly with a large learning rate. An approximate memory scale 1/(1−β) = 10,000 steps illustrates the long persistence; it is not an exact convergence time.</p>"],"kind":"practice","id":"tee-c14-s5","search":"R24 Q2b **Question.** Compare standard momentum and Nesterov accelerated gradient using their gradient-evaluation points and update equations. Explain what may happen when momentum is extremely close to 1, for example 0.9999.\n\n**Syllabus-aligned extract:** source R24 Q2b. The current-syllabus optimizer comparison and high-momentum discussion are retained; marks for this extract are not separately stated.\n\n**Complete worked answer.**\nUse signed velocity. Standard momentum evaluates g at current θ: vnew = βv−ηg(θ), θ new = θ+vnew. Nesterov evaluates at a look-ahead point: θ look = θ+βv; vnew = βv−ηg(θ look); θ new = θ+vnew. Thus the gradient can correct a direction after anticipating part of the momentum move. Nesterov often reduces overshoot in suitable settings, but it is not universally faster for every neural network.\nWith β = 0.9999, old velocity decays very slowly. The method can respond sluggishly to direction changes, overshoot or oscillate, particularly with a large learning rate. An approximate memory scale 1/(1−β) = 10,000 steps illustrates the long persistence; it is not an exact convergence time.\n"},{"title":"R24 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Differentiate sigmoid and ReLU(4). Explain why sigmoid/tanh are often avoided in deep hidden layers(3). Compute softmax of [2.1,4.8,3.5](3).</p>"],"answer":["<h3>Given</h3>","<p>Softmax scores = [2.1,4.8,3.5].</p>","<p>The numerals (4),(3),(3) in the prompt are marks allocations, not activation inputs.</p>","<h3>To find</h3>","<p>Differentiate sigmoid/ReLU, explain hidden-layer saturation and calculate softmax.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>","<p class=\"worked-step\"><strong>Step 1 stabilize: </strong> subtract the largest logit 4.8 from every value: [-2.7, 0, -1.3]. This does not change softmax.</p>","<p class=\"worked-step\"><strong>Step 2 exponentiate: </strong> exp values = [0.067205513, 1, 0.272531793].</p>","<p class=\"worked-step\"><strong>Step 3 denominator: </strong> sum = 1.339737306.</p>","<p class=\"worked-step\"><strong>Step 4 divide each value by this same sum: </strong> probabilities = <strong>[0.050163202, 0.746414984, 0.203421814]</strong>. <strong>Check: </strong> all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.</p>"],"kind":"practice","id":"tee-c14-s6","search":"R24 Q3a **Question (10 marks).** Differentiate sigmoid and ReLU(4). Explain why sigmoid/tanh are often avoided in deep hidden layers(3). Compute softmax of [2.1,4.8,3.5](3).\n\n**Complete worked answer.**\n\n\n\n### Given\n\nSoftmax scores = [2.1,4.8,3.5].\n\nThe numerals (4),(3),(3) in the prompt are marks allocations, not activation inputs.\n\n### To find\n\nDifferentiate sigmoid/ReLU, explain hidden-layer saturation and calculate softmax.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n**Step 1 stabilize: ** subtract the largest logit 4.8 from every value: [-2.7, 0, -1"},{"title":"R24 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain why regularization matters, list techniques and elaborate one.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<p><strong>Elaborating L2: </strong> add(λ/2)Σw² to the data loss. For weight w = .5, data gradient.2, λ = .1, η = .1, total gradient = .2+.1 × .5 = .25, so wnew = .5−.1 × .25 = .475. Relative to the data-only update.48, the penalty pulls the weight further toward 0. Too large λ can remove useful signal, so tune on validation data.</p>"],"kind":"practice","id":"tee-c14-s7","search":"R24 Q3b **Question (10 marks).** Explain why regularization matters, list techniques and elaborate one.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n**Elaborating L2: ** add(λ/2)Σw² to the data loss. For weight w = .5, data gradient.2, λ = .1, η = .1, total gradient = .2+.1 × .5 = .25, so wnew = .5−.1 × .25 = .475. Relative to the data-only update.48, the penalty pulls the weight further toward 0. Too large λ can remove useful signal, so tune on validation data.\n"},{"title":"R24 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Train a perceptron for 2 epochs with η = 1, initial weights and bias 0, threshold 0. Samples in order: [1,1,1,1] → 1; [−1,1,−1,−1] → 1; [1,1,1,−1] → −1; [1,−1,−1,1] → −1. Bias input is 1.</p>"],"answer":["<h3>Given</h3>","<p>Train a perceptron for 2 epochs with η = 1, initial weights and bias 0, threshold 0.</p>","<p>Samples in order: [1,1,1,1] → 1.</p>","<p>[−1,1,−1,−1] → 1.</p>","<p>[1,1,1,−1] → −1.</p>","<p>[1,−1,−1,1] → −1.</p>","<p>Bias input is 1.</p>","<h3>To find</h3>","<p>Process samples in order for the stated epochs and report the final weights and bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Target-based perceptron correction.</strong> This worked convention changes parameters only on a wrong prediction. Use the target itself as the signed multiplier; it differs from the binary error rule.</p>","<p>t is the bipolar target; η is the learning rate. Output is +1 above zero, −1 below zero and 0 at exactly zero.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:153.52px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aae3c82602ee4336.svg\"><img class=\"math display-math\" src=\"assets/equations/9f96d47c421b72ff.svg\" alt=\"\\Delta w=\\eta t x,\\quad\\Delta b=\\eta t\\quad\\text{on a mismatch}\" width=\"403.01\" height=\"22.78\" style=\"width:403.01px;height:22.78px;aspect-ratio:403.01/22.78\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Is convention mein galat hua toh target × input se correction.</p>","<h3>Solution — step by step</h3>","<p><strong>State the threshold rule.</strong> Use output +1 if z&gt;0, −1 if z&lt;0, and 0 at z = 0. On a mismatch use Δw = η tx and Δb = ηt; on a match make no update. η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.</p>","<h3>Epoch 1, sample 1</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, 1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × 1) + (0 × 1) + (0 × 1) + (0 × 1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [1, 1, 1, 1] = [1, 1, 1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [1, 1, 1, 1], new b = 1.</p>","<h3>Epoch 1, sample 2</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, -1, -1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (1 × -1) + (1 × 1) + (1 × -1) + (1 × -1) + (1) = -1</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = -1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [-1, 1, -1, -1] = [-1, 1, -1, -1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 2, 0, 0], new b = 2.</p>","<h3>Epoch 1, sample 3</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, 1, 1, -1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × 1) + (2 × 1) + (0 × 1) + (0 × -1) + (2) = 4</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = -1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = -1 × [1, 1, 1, -1] = [-1, -1, -1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = -1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-1, 1, -1, 1], new b = 1.</p>","<h3>Epoch 1, sample 4</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, -1, -1, 1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-1 × 1) + (1 × -1) + (-1 × -1) + (1 × 1) + (1) = 1</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = -1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = -1 × [1, -1, -1, 1] = [-1, 1, 1, -1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = -1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-2, 2, 0, 0], new b = 0.</p>","<h3>Epoch 2, sample 1</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, 1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-2 × 1) + (2 × 1) + (0 × 1) + (0 × 1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [1, 1, 1, 1] = [1, 1, 1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-1, 3, 1, 1], new b = 1.</p>","<h3>Epoch 2, sample 2</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, -1, -1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-1 × -1) + (3 × 1) + (1 × -1) + (1 × -1) + (1) = 3</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [-1, 1, -1, -1] = [0, 0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-1, 3, 1, 1], new b = 1.</p>","<h3>Epoch 2, sample 3</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, 1, 1, -1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-1 × 1) + (3 × 1) + (1 × 1) + (1 × -1) + (1) = 3</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = -1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = -1 × [1, 1, 1, -1] = [-1, -1, -1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = -1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-2, 2, 0, 2], new b = 0.</p>","<h3>Epoch 2, sample 4</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, -1, -1, 1], target = -1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-2 × 1) + (2 × -1) + (0 × -1) + (2 × 1) + (0) = -2</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = -1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [1, -1, -1, 1] = [0, 0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-2, 2, 0, 2], new b = 0.</p>","<p><strong>Final after exactly the requested epochs: </strong> w = <strong>[-2, 2, 0, 2]</strong>, b = <strong>0</strong>. A finite number of requested epochs does not itself prove convergence or correct classification of every sample.</p>"],"kind":"practice","id":"tee-c14-s8","search":"R24 Q4a **Question (10 marks).** Train a perceptron for 2 epochs with η = 1, initial weights and bias 0, threshold 0. Samples in order: [1,1,1,1] → 1; [−1,1,−1,−1] → 1; [1,1,1,−1] → −1; [1,−1,−1,1] → −1. Bias input is 1.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nTrain a perceptron for 2 epochs with η = 1, initial weights and bias 0, threshold 0.\n\nSamples in order: [1,1,1,1] → 1.\n\n[−1,1,−1,−1] → 1.\n\n[1,1,1,−1] → −1.\n\n[1,−1,−1,1] → −1.\n\nBias input is 1.\n\n### To find\n\nProcess samples in order for the stated epochs and report the final weights and bias.\n\n### Formula — which one and why\n\n**Target-based perceptron correction.** This worked convention changes parameters only on a wrong prediction. Use the target itself as the signed multiplier; it differs from the binary error rule.\n\nt is the bipolar target; η is the learning rate. Output is +1 above zero, −1 below zero and 0 at exactly zero.\n\n\n\n**Yaad rakhne ka cue:** Is convention mein galat hua toh target × input se correction.\n\n### Solution — step by step\n\n\n\n\n**State the threshold rule.** Use output +1 if z>0, −1 if z<0, and 0 at z = 0. On a mismatch use Δw = η tx and Δb = ηt; on a match make no update. η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.\n### Epoch 1, sample 1\n\n**Step 1: copy this sample and target.**\n\nx = [1, 1, 1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × 1) + (0 × 1) + (0 × 1) + (0 × 1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [1, 1, 1, 1] = [1, 1, 1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [1, 1, 1, 1], new b = 1.\n\n\n### Epoch 1, sample 2\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, -1, -1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (1 × -1) + (1 × 1) + (1 × -1) + (1 × -1) + (1) = -1\n\n**Step 3: apply the threshold.**\n\noutput = -1.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [-1, 1, -1, -1] = [-1, 1, -1, -1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 2, 0, 0], new b = 2.\n\n\n### Epoch 1, sample 3\n\n**Step 1: copy this sample and target.**\n\nx = [1, 1, 1, -1], target = -1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × 1) + (2 × 1) + (0 × 1) + (0 × -1) + (2) = 4\n\n**Step 3: apply the threshold.**\n\noutput = 1.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = -1\n\n**Step 5: calculate all weight changes.**\n\nΔw = -1 × [1, 1, 1, -1] = [-1, -1, -1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = -1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [-1, 1, -1, 1], new b = 1.\n\n\n### Epoch 1, sample 4\n\n**Step 1: copy this sample and target.**\n\nx = [1, -1, -1, 1], target = -1.\n\n**Step 2: calculate the current net.**\n\nz = (-1 × 1) + (1 × -1) + (-1 × -1) + (1 × 1) + (1) = 1\n\n**Step 3: apply the threshold.**\n\noutput = 1.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = -1\n\n**Step 5: calculate all weight changes.**\n\nΔw = -1 × [1, -1, -1, 1] = [-1, 1, 1, -1]\n\n**Step 6: calculate the bias change.**\n\nΔb = -1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [-2, 2, 0, 0], new b = 0.\n\n\n### Epoch 2, sample 1\n\n**Step 1: copy this sample and target.**\n\nx = [1, 1, 1, 1], target = 1.\n\n**Step "},{"title":"R24 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Calculate weights, biases and feature-map sizes of the CNN: Input 227 × 227 × 3. → Conv K = 9, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 120 units. → Dense 84 units. → Dense 10 units.</p>"],"answer":["<h3>Given</h3>","<p>Input 227 × 227 × 3.</p>","<p>Conv K = 9, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 64, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 64, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 120 units.</p>","<p>Dense 84 units.</p>","<p>Dense 10 units.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">227 × 227 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 9 × 9 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">219 × 219 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">7,776</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">7,808</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>227 × 227 × 3</strong>. Use 32 filters of spatial size 9 × 9, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0d078197de388e4c.svg\"><img class=\"math display-math\" src=\"assets/equations/d3b5ab84e61f126d.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{227+2(0)-9}{1}\\right\\rfloor+1=219\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>219 × 219 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90e2d92ad9867cbd.svg\"><img class=\"math display-math\" src=\"assets/equations/c97378e50b8b5ac8.svg\" alt=\"N_{\\mathrm{weights}}=9\\times9\\times3\\times32=7{,}776\" width=\"349.90\" height=\"23.91\" style=\"width:349.90px;height:23.91px;aspect-ratio:349.90/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/59616c98ab8fffe7.svg\" alt=\"P_1=7{,}776+32=7{,}808\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">219 × 219 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">109 × 109 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>219 × 219 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3f1c898ff7560508.svg\"><img class=\"math display-math\" src=\"assets/equations/73ff985869e15a08.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{219-2}{2}\\right\\rfloor+1=109\" width=\"308.50\" height=\"58.62\" style=\"width:308.50px;height:58.62px;aspect-ratio:308.50/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>109 × 109 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 108.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">109 × 109 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">64 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">105 × 105 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">51,200</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">64</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">51,264</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>109 × 109 × 32</strong>. Use 64 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2cc5fced7b8ab11.svg\"><img class=\"math display-math\" src=\"assets/equations/fc0be4ce48988be6.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{109+2(0)-5}{1}\\right\\rfloor+1=105\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>105 × 105 × 64</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 32 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a22447ce668f8dbf.svg\"><img class=\"math display-math\" src=\"assets/equations/5b861b3fc768032c.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times32\\times64=51{,}200\" width=\"374.33\" height=\"23.91\" style=\"width:374.33px;height:23.91px;aspect-ratio:374.33/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc3a74202b89cbd8.svg\" alt=\"N_{\\mathrm{biases}}=64\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/101c0d0d89af6010.svg\" alt=\"P_3=51{,}200+64=51{,}264\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">105 × 105 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">52 × 52 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>105 × 105 × 64</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/616d6791b658eeb9.svg\"><img class=\"math display-math\" src=\"assets/equations/c5c0ee2fb6dc698d.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{105-2}{2}\\right\\rfloor+1=52\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>52 × 52 × 64</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 51.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">52 × 52 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">64 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">48 × 48 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">102,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">64</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">102,464</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>52 × 52 × 64</strong>. Use 64 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/58a6dd2bccbabd6a.svg\"><img class=\"math display-math\" src=\"assets/equations/87809c641f196e58.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{52+2(0)-5}{1}\\right\\rfloor+1=48\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>48 × 48 × 64</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 64 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c1baccc90afa895b.svg\"><img class=\"math display-math\" src=\"assets/equations/3a9b9e818c6252de.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times64\\times64=102{,}400\" width=\"386.55\" height=\"23.91\" style=\"width:386.55px;height:23.91px;aspect-ratio:386.55/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc3a74202b89cbd8.svg\" alt=\"N_{\\mathrm{biases}}=64\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bf8643a16a94e64.svg\"><img class=\"math display-math\" src=\"assets/equations/be86652891fb9307.svg\" alt=\"P_5=102{,}400+64=102{,}464\" width=\"306.02\" height=\"21.43\" style=\"width:306.02px;height:21.43px;aspect-ratio:306.02/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">48 × 48 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">24 × 24 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>48 × 48 × 64</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64a91a8e536e0765.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{48-2}{2}\\right\\rfloor+1=24\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>24 × 24 × 64</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 7 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">24 × 24 × 64</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">36,864</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>24 × 24 × 64</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5ee055840a7e6f06.svg\"><img class=\"math display-math\" src=\"assets/equations/d2c7c9ed057461d8.svg\" alt=\"n_{\\mathrm{flat}}=24\\times24\\times64=36{,}864\" width=\"308.23\" height=\"21.29\" style=\"width:308.23px;height:21.29px;aspect-ratio:308.23/21.29\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>36,864 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">36,864</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,423,680</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,423,800</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>36,864 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b963fc1e5d67938a.svg\"><img class=\"math display-math\" src=\"assets/equations/3d52ede2004cebfb.svg\" alt=\"N_{\\mathrm{weights}}=36{,}864\\times120=4{,}423{,}680\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99a27e646d35bbda.svg\"><img class=\"math display-math\" src=\"assets/equations/c09e1443401b8c28.svg\" alt=\"P_8=4{,}423{,}680+120=4{,}423{,}800\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 9 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">84 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">10,080</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">84</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">10,164</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>84 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.92px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4874c9639ae8a286.svg\"><img class=\"math display-math\" src=\"assets/equations/0b5956346ee0f9d2.svg\" alt=\"N_{\\mathrm{weights}}=120\\times84=10{,}080\" width=\"302.38\" height=\"23.91\" style=\"width:302.38px;height:23.91px;aspect-ratio:302.38/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec58135349b68114.svg\" alt=\"N_{\\mathrm{biases}}=84\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cfadc0698f826a8.svg\" alt=\"P_9=10{,}080+84=10{,}164\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">10 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">10</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">840</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">10</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">850</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>84 features</strong>. Output: <strong>10 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/995f161a94dc7ae1.svg\" alt=\"N_{\\mathrm{weights}}=84\\times10=840\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8203d983cccce3a9.svg\" alt=\"N_{\\mathrm{biases}}=10\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be85fac4796ebc34.svg\" alt=\"P_10=840+10=850\" width=\"231.35\" height=\"20.36\" style=\"width:231.35px;height:20.36px;aspect-ratio:231.35/20.36\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/8a2a9eb5376c2557.svg\" alt=\"\\left\\lfloor\\frac{227+2 \\times  0-9}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>219 x 219 x 32</td><td>7,776</td><td>32</td><td>7,808</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4185cd16a03f14e2.svg\" alt=\"\\left\\lfloor\\frac{219-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>109 x 109 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e91c4793e36ecf45.svg\" alt=\"\\left\\lfloor\\frac{109+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>105 x 105 x 64</td><td>51,200</td><td>64</td><td>51,264</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/02f6d3536f89b2ae.svg\" alt=\"\\left\\lfloor\\frac{105-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>52 x 52 x 64</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/6619d9b65db6ea0f.svg\" alt=\"\\left\\lfloor\\frac{52+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>48 x 48 x 64</td><td>102,400</td><td>64</td><td>102,464</td></tr><tr><td>6 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b6ef920332c6684a.svg\" alt=\"\\left\\lfloor\\frac{48-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>24 x 24 x 64</td><td>0</td><td>0</td><td>0</td></tr><tr><td>7 flat</td><td>24 × 24 × 64</td><td>36864</td><td>0</td><td>0</td><td>0</td></tr><tr><td>8 dense</td><td>36864 → 120</td><td>120</td><td>4,423,680</td><td>120</td><td>4,423,800</td></tr><tr><td>9 dense</td><td>120 → 84</td><td>84</td><td>10,080</td><td>84</td><td>10,164</td></tr><tr><td>10 dense</td><td>84 → 10</td><td>10</td><td>840</td><td>10</td><td>850</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (9 x 9 x 3 + 1) x 32 = 7,808.</p>","<p>Layer 3: (5 x 5 x 32 + 1) x 64 = 51,264.</p>","<p>Layer 5: (5 x 5 x 64 + 1) x 64 = 102,464.</p>","<p>Layer 8: (36864 + 1) x 120 = 4,423,800.</p>","<p>Layer 9: (120 + 1) x 84 = 10,164.</p>","<p>Layer 10: (84 + 1) x 10 = 850.</p>","<p><strong>Total: </strong> 7,808 + 51,264 + 102,464 + 4,423,800 + 10,164 + 850 = <strong>4,596,350 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>"],"kind":"practice","id":"tee-c14-s9","search":"R24 Q4b **Question (10 marks).** Calculate weights, biases and feature-map sizes of the CNN: Input 227 × 227 × 3. → Conv K = 9, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 5, filters = 64, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 120 units. → Dense 84 units. → Dense 10 units.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 227 × 227 × 3.\n\nConv K = 9, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 64, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 5, filters = 64, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 120 units.\n\nDense 84 units.\n\nDense 10 units.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{227+2 \\times  0-9}{1}\\right\\rfloor+1\\) | 219 x 219 x 32 | 7,776 | 32 | 7,808 |\n| 2 pool | \\(\\left\\lfloor\\frac{219-2}{2}\\right\\rfloor+1\\) | 109 x 109 x 32 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{109+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 105 x 105 x 64 | 51,200 | 64 | 51,264 |\n| 4 pool | \\(\\left\\lfloor\\frac{105-2}{2}\\right\\rfloor+1\\) | 52 x 52 x 64 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{52+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 48 x 48 x 64 | 102,400 | 64 | 102,464 |\n| 6 pool | \\(\\left\\lfloor\\frac{48-2}{2}\\right\\rfloor+1\\) | 24 x 24 x 64 | 0 | 0 | 0 |\n| 7 flat | 24 × 24 × 64 | 36864 | 0 | 0 | 0 |\n| 8 dense | 36864 → 120 | 120 | 4,423,680 | 120 | 4,423,800 |\n| 9 dense | 120 → 84 | 84 | 10,080 | 84 | 10,164 |\n| 10 dense | 84 → 10 | 10 | 840 | 10 | 850 |\n**Parameter substitutions, in layer order: **\nLayer 1: (9 x 9 x 3 + 1) x 32 = 7,808.\nLayer 3: (5 x 5 x 32 + 1) x 64 = 51,264.\nLayer 5: (5 x 5 x 64 + 1) x 64 = 102,464.\nLayer 8: (36864 + 1) x 120 = 4,423,800.\nLayer 9: (120 + 1) x 84 = 10,164.\nLayer 10: (84 + 1) x 10 = 850.\n**Total: ** 7,808 + 51,264 + 102,464 + 4,423,800 + 10,164 + 850 = **4,596,350 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n"},{"title":"R24 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A GoogLeNet classifier trains slowly and vanishing gradients are suspected. Suggest an architecture change and explain its important features.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>A ResNet is a suitable architecture to investigate because skip additions provide shorter gradient paths. First verify the diagnosis with gradients and training curves; slow training alone does not establish vanishing gradients. Match projection shortcuts when spatial size/channels change and compare validation performance after the redesign.</p>"],"kind":"practice","id":"tee-c14-s10","search":"R24 Q5a **Question (10 marks).** A GoogLeNet classifier trains slowly and vanishing gradients are suspected. Suggest an architecture change and explain its important features.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nA ResNet is a suitable architecture to investigate because skip additions provide shorter gradient paths. First verify the diagnosis with gradients and training curves; slow training alone does not establish vanishing gradients. Match projection shortcuts when spatial size/channels change and compare validation performance after the redesign.\n"},{"title":"R24 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> (i) Justify DL for chest-cancer diagnosis from X-ray images(5). (ii) List RNN advantages and disadvantages(5).</p>"],"answer":["<p>A convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/convolution.svg\" aria-label=\"Enlarge diagram: One filter is reused at successive spatial positions\"><img src=\"assets/figures/convolution.svg\" alt=\"One filter is reused at successive spatial positions\" width=\"960\" height=\"630\" loading=\"lazy\"></button><figcaption>One filter is reused at successive spatial positions <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Convolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.</p>","<p>Compared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.</p>","<p>For medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.</p>","<p><strong>RNN advantages: </strong> ordered context, shared weights over time, variable sequence lengths and flexible input/output mappings. <strong>Limitations: </strong> sequential computation reduces time-step parallelism; vanilla cells have vanishing/exploding gradient issues and limited learned long context; many training choices still require validation. Use CNNs for spatial image patterns and recurrent models when temporal/ordered structure is relevant.</p>"],"kind":"practice","id":"tee-c14-s11","search":"R24 Q5b **Question (10 marks).** (i) Justify DL for chest-cancer diagnosis from X-ray images(5). (ii) List RNN advantages and disadvantages(5).\n\n**Complete worked answer.**\nA convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.\n\nConvolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.\nCompared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.\nFor medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.\n**RNN advantages: ** ordered context, shared weights over time, variable sequence lengths and flexible input/output mappings. **Limitations: ** sequential computation reduces time-step parallelism; vanilla cells have vanishing/exploding gradient issues and limited learned long context; many training choices still require validation. Use CNNs for spatial image patterns and recurrent models when temporal/ordered structure is relevant.\n"},{"title":"R24 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For a GRU time step, explain the significance of update and reset gates and develop their equations.</p>"],"answer":["<p>A GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:279.17px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/552178cdb39642a9.svg\"><img class=\"math display-math\" src=\"assets/equations/4c9f5914ab749b31.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z),\\quad r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"618.24\" height=\"24.43\" style=\"width:618.24px;height:24.43px;aspect-ratio:618.24/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:388.02px;--narrow-height:155.11px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/24dba2ef5a8c9844.svg\"><img class=\"math display-math\" src=\"assets/equations/e0ad3b2f8e3f246b.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h),\\quad h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"750.51\" height=\"31.13\" style=\"width:750.51px;height:31.13px;aspect-ratio:750.51/31.13\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gru.svg\" aria-label=\"Enlarge diagram: Reset controls candidate context and update controls the old new mixture\"><img src=\"assets/figures/gru.svg\" alt=\"Reset controls candidate context and update controls the old new mixture\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Reset controls candidate context and update controls the old new mixture <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.</p>","<p>Compared with an LSTM&#x27;s input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.</p>"],"kind":"practice","id":"tee-c14-s12","search":"R24 Q6a **Question (10 marks).** For a GRU time step, explain the significance of update and reset gates and develop their equations.\n\n**Complete worked answer.**\nA GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:\n\n\n\nThe reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.\nCompared with an LSTM's input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.\n"},{"title":"R24 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A supermarket vegetable classifier has 10 classes but few examples per class and limited training resources. Explain different ways to use a pretrained model.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>","<p>For vegetables, replace the source head with 10 softmax outputs. Strategy 1: freeze the base and train only this head. Strategy 2: initialize from the same pretrained model and fine-tune selected later blocks at a small rate after head training. The first is cheaper and less prone to fitting all parameters from limited examples; the second can adapt features more closely to vegetables when validation supports it.</p>"],"kind":"practice","id":"tee-c14-s13","search":"R24 Q6b **Question (10 marks).** A supermarket vegetable classifier has 10 classes but few examples per class and limited training resources. Explain different ways to use a pretrained model.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\nFor vegetables, replace the source head with 10 softmax outputs. Strategy 1: freeze the base and train only this head. Strategy 2: initialize from the same pretrained model and fine-tune selected later blocks at a small rate after head training. The first is cheaper and less prone to fitting all parameters from limited examples; the second can adapt features more closely to vegetables when validation supports it.\n"},{"title":"R24 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Draw and explain LSTM architecture.</p>"],"answer":["<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>"],"kind":"practice","id":"tee-c14-s14","search":"R24 Q7a **Question (10 marks).** Draw and explain LSTM architecture.\n\n**Complete worked answer.**\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\n"},{"title":"R24 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain different RNN input/output sequence types with architecture sketches.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: One-to-many many-to-one and two many-to-many arrangements\"><img src=\"assets/figures/sequences.svg\" alt=\"One-to-many many-to-one and two many-to-many arrangements\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>One-to-many many-to-one and two many-to-many arrangements <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>One-to-many: one image representation generates a caption. Many-to-one: a review produces one sentiment. Aligned many-to-many: each video frame receives a label. Unaligned many-to-many: an encoder reads a source sentence and a decoder generates a translation of possibly different length. Specify which outputs carry losses during training; variable lengths do not require new weights for each position.</p>"],"kind":"practice","id":"tee-c14-s15","search":"R24 Q7b **Question (10 marks).** Explain different RNN input/output sequence types with architecture sketches.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n\nOne-to-many: one image representation generates a caption. Many-to-one: a review produces one sentiment. Aligned many-to-many: each video frame receives a label. Unaligned many-to-many: an encoder reads a source sentence and a decoder generates a translation of possibly different length. Specify which outputs carry losses during training; variable lengths do not require new weights for each position.\n\n\n"}]},{"n":15,"title":"Final examination November 2022 fully solved","sections":[{"title":"Start here","blocks":["<p>F22 = S16, 19 November 2022. The older LeNet calculation is retained as standard CNN arithmetic and because the current course policy includes a LeNet lab. Historical diagram ambiguities are stated rather than silently guessed.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c15-intro"},{"title":"F22 Q1a","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> A normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3]. Convolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding. Compute the output and identify the feature.</p>"],"answer":["<h3>Given</h3>","<p>A normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3].</p>","<p>Convolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding.</p>","<h3>To find</h3>","<p>Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/966c8fb493880239.svg\" alt=\"\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.5 + 0 + (−0.3) = 0.2</b></div></div><p class=\"lv-combine\"><b>0.2 + 0.2 + 0.2 = 0.6</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46893fc8d069d1a9.svg\"><img class=\"math display-math\" src=\"assets/equations/27b98fade189b3cb.svg\" alt=\"R_1=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a410c53ff471ca9.svg\"><img class=\"math display-math\" src=\"assets/equations/227859c9722c8d9d.svg\" alt=\"R_2=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c0f1258f7cc1b3a.svg\"><img class=\"math display-math\" src=\"assets/equations/23643e567273ca91.svg\" alt=\"R_3=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.24px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb7d1b049e078f58.svg\"><img class=\"math display-math\" src=\"assets/equations/c15a1021698c03e8.svg\" alt=\"Y_{1,1}=(0.2)+(0.2)+(0.2)=0.6\" width=\"345.16\" height=\"25.35\" style=\"width:345.16px;height:25.35px;aspect-ratio:345.16/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.3\">0.3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.3\">0.3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.3\">0.3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.3 + 0 + (−0.3) = 0</b></div></div><p class=\"lv-combine\"><b>0 + 0 + 0 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8fffc5f555fb2f95.svg\"><img class=\"math display-math\" src=\"assets/equations/54a80ceab4517447.svg\" alt=\"R_1=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a27c355bf724dc1d.svg\"><img class=\"math display-math\" src=\"assets/equations/4f1d831d541f9cae.svg\" alt=\"R_2=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9405479984ca544c.svg\"><img class=\"math display-math\" src=\"assets/equations/41420636bdf1878d.svg\" alt=\"R_3=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a79dadbe7e581b.svg\" alt=\"Y_{1,2}=(0)+(0)+(0)=0\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.5 + 0 + (−0.3) = 0.2</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.5 + 0 + (−0.3) = 0.2</b></div></div><p class=\"lv-combine\"><b>0.2 + 0.2 + 0.2 = 0.6</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46893fc8d069d1a9.svg\"><img class=\"math display-math\" src=\"assets/equations/27b98fade189b3cb.svg\" alt=\"R_1=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6a410c53ff471ca9.svg\"><img class=\"math display-math\" src=\"assets/equations/227859c9722c8d9d.svg\" alt=\"R_2=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3c0f1258f7cc1b3a.svg\"><img class=\"math display-math\" src=\"assets/equations/23643e567273ca91.svg\" alt=\"R_3=(0.5)\\times(1)+(0.5)\\times(0)+(0.3)\\times(-1)=0.2\" width=\"538.36\" height=\"24.43\" style=\"width:538.36px;height:24.43px;aspect-ratio:538.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.24px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e16ceceb6a0a438.svg\"><img class=\"math display-math\" src=\"assets/equations/32aaa578d4b2a675.svg\" alt=\"Y_{2,1}=(0.2)+(0.2)+(0.2)=0.6\" width=\"345.16\" height=\"25.35\" style=\"width:345.16px;height:25.35px;aspect-ratio:345.16/25.35\" loading=\"lazy\"></picture></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 0.3\">0.3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0.5\">0.5</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0.3\">0.3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0.5\">0.5</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 0.3\">0.3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 0.3\">0.3</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 0.5\">0.5</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 0.5\">0.5</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 0.3\">0.3</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 0.3\">0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 1\">1</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.3\">0.3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.3\">0.3</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −0.3\">−0.3</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0.3\">0.3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −0.3\">−0.3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0.3 + 0 + (−0.3) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0.3 + 0 + (−0.3) = 0</b></div></div><p class=\"lv-combine\"><b>0 + 0 + 0 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0.6\">0.6</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0.6\">0.6</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8fffc5f555fb2f95.svg\"><img class=\"math display-math\" src=\"assets/equations/54a80ceab4517447.svg\" alt=\"R_1=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a27c355bf724dc1d.svg\"><img class=\"math display-math\" src=\"assets/equations/4f1d831d541f9cae.svg\" alt=\"R_2=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9405479984ca544c.svg\"><img class=\"math display-math\" src=\"assets/equations/41420636bdf1878d.svg\" alt=\"R_3=(0.3)\\times(1)+(0.3)\\times(0)+(0.3)\\times(-1)=0\" width=\"519.35\" height=\"24.43\" style=\"width:519.35px;height:24.43px;aspect-ratio:519.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d6dfc0f38e45b75.svg\" alt=\"Y_{2,2}=(0)+(0)+(0)=0\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/14d5a1ec1325dcc6.svg\" alt=\"\\begin{bmatrix}0.6 &amp; 0\\\\0.6 &amp; 0\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>","<p>The filter compares left and right neighborhoods and responds to a vertical brightness boundary. Inputs are already normalized. No additional output-normalization rule is supplied, so the determined convolution is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/14d5a1ec1325dcc6.svg\" alt=\"\\begin{bmatrix}0.6 &amp; 0\\\\0.6 &amp; 0\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. If an examiner explicitly requests min-max normalization of this result, divide by 0.6 to obtain <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/40c2bacd9336c7bb.svg\" alt=\"\\begin{bmatrix}1 &amp; 0\\\\1 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>; that is a separate stated operation.</p>"],"kind":"practice","id":"tee-c15-s0","search":"F22 Q1a **Question (4 marks).** A normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3]. Convolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding. Compute the output and identify the feature.\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nA normalized 5 × 5 image has every row [0.5,0.5,0.3,0.3,0.3].\n\nConvolve it with a 3 × 3 filter whose every row is [1,0,−1], stride 2, no padding.\n\n### To find\n\nFind every convolution output cell.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\\) = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.\n**Output (1,1): ** (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) = **0.6**.\n**Output (1,2): ** (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) = **0**.\n**Output (2,1): ** (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) + (0.5 × (1)) + (0.5 × (0)) + (0.3 × (-1)) = **0.6**.\n**Output (2,2): ** (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) + (0.3 × (1)) + (0.3 × (0)) + (0.3 × (-1)) = **0**.\n**Final output: ** . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.\nThe filter compares left and right neighborhoods and responds to a vertical brightness boundary. Inputs are already normalized. No additional output-normalization rule is supplied, so the determined convolution is . If an examiner explicitly requests min-max normalization of this result, divide by 0.6 to obtain ; that is a separate stated operation.\n"},{"title":"F22 Q1b","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Weights are 0.55 and 0.65; their gradients are+0.3 and−0.25. With η = 0.1, compute gradient-descent changes and new weights.</p>"],"answer":["<h3>Given</h3>","<p>Old weights = [0.55,0.65].</p>","<p>Corresponding supplied gradients = [0.3,−0.25]; η = 0.1.</p>","<h3>To find</h3>","<p>Calculate the signed weight changes and both new weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the change in weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaf1d1bad63a2309.svg\" alt=\"\\Delta w_1=-0.1(0.3)=-0.03\" width=\"276.61\" height=\"24.43\" style=\"width:276.61px;height:24.43px;aspect-ratio:276.61/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add that change to old weight 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.64px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278794747f889246.svg\"><img class=\"math display-math\" src=\"assets/equations/c5de9a5a93170dac.svg\" alt=\"w_1^{\\mathrm{new}}=0.55+(-0.03)=0.52\" width=\"312.67\" height=\"24.43\" style=\"width:312.67px;height:24.43px;aspect-ratio:312.67/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the change in weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1c844e3b7026fa3a.svg\"><img class=\"math display-math\" src=\"assets/equations/43503938e7c174a7.svg\" alt=\"\\Delta w_2=-0.1(-0.25)=0.025\" width=\"301.05\" height=\"24.43\" style=\"width:301.05px;height:24.43px;aspect-ratio:301.05/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: add that change to old weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.84px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99431f20567e072c.svg\"><img class=\"math display-math\" src=\"assets/equations/2bfe89025b1bd27a.svg\" alt=\"w_2^{\\mathrm{new}}=0.65+0.025=0.675\" width=\"299.08\" height=\"23.87\" style=\"width:299.08px;height:23.87px;aspect-ratio:299.08/23.87\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> changes = [−0.03, +0.025]; new weights = [0.52, 0.675]. A negative gradient increases its weight under descent.</p>"],"kind":"practice","id":"tee-c15-s1","search":"F22 Q1b **Question (4 marks).** Weights are 0.55 and 0.65; their gradients are+0.3 and−0.25. With η = 0.1, compute gradient-descent changes and new weights.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nOld weights = [0.55,0.65].\n\nCorresponding supplied gradients = [0.3,−0.25]; η = 0.1.\n\n### To find\n\nCalculate the signed weight changes and both new weights.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: calculate the change in weight 1.**\n\n\n\n\n\n\n\n**Step 2: add that change to old weight 1.**\n\n\n\n\n\n\n\n**Step 3: calculate the change in weight 2.**\n\n\n\n\n\n\n\n**Step 4: add that change to old weight 2.**\n\n\n\n\n\n\n\n**Final answer:** changes = [−0.03, +0.025]; new weights = [0.52, 0.675]. A negative gradient increases its weight under descent.\n"},{"title":"F22 Q1c","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Compare ML and DL algorithms.</p>"],"answer":["<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>"],"kind":"practice","id":"tee-c15-s2","search":"F22 Q1c **Question (4 marks).** Compare ML and DL algorithms.\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n"},{"title":"F22 Q1d","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Compare sigmoid and tanh, emphasizing tanh’s advantage.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>","<p>The requested advantage is that tanh is zero-centered, so hidden activations can be positive or negative. Sigmoid activations lie above 0. Both functions saturate and can produce small derivatives; zero-centering does not eliminate the vanishing-gradient problem.</p>"],"kind":"practice","id":"tee-c15-s3","search":"F22 Q1d **Question (4 marks).** Compare sigmoid and tanh, emphasizing tanh’s advantage.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\nThe requested advantage is that tanh is zero-centered, so hidden activations can be positive or negative. Sigmoid activations lie above 0. Both functions saturate and can produce small derivatives; zero-centering does not eliminate the vanishing-gradient problem.\n"},{"title":"F22 Q1e","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Suggest and sketch an RNN architecture for image captioning.</p>"],"answer":["<p>Use a CNN encoder to map the image to a visual representation and a recurrent decoder (RNN/LSTM/GRU) to generate words one at a time. Condition the decoder’s initial state or its inputs on image features. At each step, vocabulary softmax predicts the next word based on the image and earlier words. Train using correct next-word targets and cross-entropy; stop generation at an end token. This is a one-to-many mapping from one image to a caption sequence.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: The one-to-many pattern models image captioning\"><img src=\"assets/figures/sequences.svg\" alt=\"The one-to-many pattern models image captioning\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>The one-to-many pattern models image captioning <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c15-s4","search":"F22 Q1e **Question (4 marks).** Suggest and sketch an RNN architecture for image captioning.\n\n**Complete worked answer.**\nUse a CNN encoder to map the image to a visual representation and a recurrent decoder (RNN/LSTM/GRU) to generate words one at a time. Condition the decoder’s initial state or its inputs on image features. At each step, vocabulary softmax predicts the next word based on the image and earlier words. Train using correct next-word targets and cross-entropy; stop generation at an end token. This is a one-to-many mapping from one image to a caption sequence.\n\n"},{"title":"F22 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain GRU advantages over a normal RNN. For “The student who did not submit the assignment was bound to loose marks,” show how memory and update gates can retain the subject before predicting “was”.</p>"],"answer":["<p>A GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:279.17px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/552178cdb39642a9.svg\"><img class=\"math display-math\" src=\"assets/equations/4c9f5914ab749b31.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z),\\quad r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"618.24\" height=\"24.43\" style=\"width:618.24px;height:24.43px;aspect-ratio:618.24/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:388.02px;--narrow-height:155.11px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/24dba2ef5a8c9844.svg\"><img class=\"math display-math\" src=\"assets/equations/e0ad3b2f8e3f246b.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h),\\quad h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"750.51\" height=\"31.13\" style=\"width:750.51px;height:31.13px;aspect-ratio:750.51/31.13\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gru.svg\" aria-label=\"Enlarge diagram: Reset controls candidate context and update controls the old new mixture\"><img src=\"assets/figures/gru.svg\" alt=\"Reset controls candidate context and update controls the old new mixture\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Reset controls candidate context and update controls the old new mixture <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.</p>","<p>Compared with an LSTM&#x27;s input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.</p>","<p><strong>Important data limit: </strong> no numerical weights or token vectors are supplied, so actual gate outputs cannot be uniquely calculated. The following is an explicitly idealized one-component illustration: candidate subject feature = 1 at “student”; use hnew = (1−z) hold+z candidate. Exact 0/1 gates are limiting idealizations of sigmoid values.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Time and token</th><th>Illustrative z</th><th>Singular-subject memory after step</th></tr></thead><tbody><tr><td>1 The</td><td>0 while retaining this illustrative feature</td><td>0 before subject is read</td></tr><tr><td>2 student</td><td>1 when admitting subject feature</td><td>1 after subject is read</td></tr><tr><td>3 who</td><td>0 while retaining this illustrative feature</td><td>1 after subject is read</td></tr><tr><td>4 did</td><td>0 while retaining this illustrative feature</td><td>1 after subject is read</td></tr><tr><td>5 not</td><td>0 while retaining this illustrative feature</td><td>1 after subject is read</td></tr><tr><td>6 submit</td><td>0 while retaining this illustrative feature</td><td>1 after subject is read</td></tr><tr><td>7 the</td><td>0 while retaining this illustrative feature</td><td>1 after subject is read</td></tr><tr><td>8 assignment</td><td>0 while retaining this illustrative feature</td><td>1 after subject is read</td></tr></tbody></table></div>","<p>At “student”: hnew = (1−1) × 0+1 × 1 = 1. At each intervening token in this illustrative component: hnew = (1−0) × 1+0 × candidate = 1. The retained singular subject helps the output layer choose “was”. Other hidden components may still update to represent intervening words; this table is not a computed trace from an actual trained network.</p>"],"kind":"practice","id":"tee-c15-s5","search":"F22 Q2a **Question (10 marks).** Explain GRU advantages over a normal RNN. For “The student who did not submit the assignment was bound to loose marks,” show how memory and update gates can retain the subject before predicting “was”.\n\n**Complete worked answer.**\nA GRU uses an update gate and reset gate, with one hidden state and no separate LSTM-style cell state. Under the convention used here, z admits the new candidate:\n\n\n\nThe reset gate controls how much prior hidden information enters the candidate. The update gate balances retention and replacement. A small z retains most of the old state under this formula; another textbook convention swaps z and 1−z. State the formula before interpreting the gate.\nCompared with an LSTM's input, forget and output gates plus candidate transform, a standard GRU has two gates plus a candidate transform and usually fewer parameters at equal hidden width. This may reduce training cost and the amount of data needed to estimate parameters, but small-dataset superiority is not guaranteed. Validation should decide. To ignore an unhelpful token, a trained GRU can keep the prior state by admitting little candidate content; it still executes the recurrence rather than literally deleting the token. Both GRU and LSTM help long-range learning compared with an ungated vanilla RNN.\n**Important data limit: ** no numerical weights or token vectors are supplied, so actual gate outputs cannot be uniquely calculated. The following is an explicitly idealized one-component illustration: candidate subject feature = 1 at “student”; use hnew = (1−z) hold+z candidate. Exact 0/1 gates are limiting idealizations of sigmoid values.\n| Time and token | Illustrative z | Singular-subject memory after step |\n| 1 The | 0 while retaining this illustrative feature | 0 before subject is read |\n| 2 student | 1 when admitting subject feature | 1 after subject is read |\n| 3 who | 0 while retaining this illustrative feature | 1 after subject is read |\n| 4 did | 0 while retaining this illustrative feature | 1 after subject is read |\n| 5 not | 0 while retaining this illustrative feature | 1 after subject is read |\n| 6 submit | 0 while retaining this illustrative feature | 1 after subject is read |\n| 7 the | 0 while retaining this illustrative feature | 1 after subject is read |\n| 8 assignment | 0 while retaining this illustrative feature | 1 after subject is read |\n\nAt “student”: hnew = (1−1) × 0+1 × 1 = 1. At each intervening token in this illustrative component: hnew = (1−0) × 1+0 × candidate = 1. The retained singular subject helps the output layer choose “was”. Other hidden components may still update to represent intervening words; this table is not a computed trace from an actual trained network.\n"},{"title":"F22 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For a three-stage sigmoid network, use samples [0.3,0.2,0.4] → 0 and [0.5,0.6,0.8] → 1. First-stage feature multipliers are [0.3,0.4,0.6]. Next receiving rows are [0.5,0.2,0.3], [0.3,0.3,0.3], and output weights [0.3,0.3]. Find both predictions, average MSE and output-weight updates after the first backward pass with η = 0.2. Assume zero biases.</p>"],"answer":["<h3>Given</h3>","<p>For a three-stage sigmoid network, use samples [0.3,0.2,0.4] → 0 and [0.5,0.6,0.8] → 1.</p>","<p>First-stage feature multipliers are [0.3,0.4,0.6].</p>","<p>Next receiving rows are [0.5,0.2,0.3], [0.3,0.3,0.3], and output weights [0.3,0.3].</p>","<p>Find both predictions, average MSE and output-weight updates after the first backward pass with η = 0.2.</p>","<p>Assume zero biases.</p>","<h3>To find</h3>","<p>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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Mean squared loss.</strong> Average the squared scalar prediction errors. The derivative retains the factor 2/n; n must count the outputs included in this mean.</p>","<p>n = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f5544f3d0af79c26.svg\" alt=\"L=\\frac1n\\sum_j(o_j-y_j)^2\" width=\"215.65\" height=\"65.25\" style=\"width:215.65px;height:65.25px;aspect-ratio:215.65/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b0ae494a9901408.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=\\frac2n(o_j-y_j)\" width=\"194.57\" height=\"57.94\" style=\"width:194.57px;height:57.94px;aspect-ratio:194.57/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p><strong>Interpretation.</strong> Follow the supplied diagram: each raw feature is multiplied by 0.3, 0.4 or 0.6, then passed through sigmoid before the next two-neuron layer. Unspecified biases are zero. MSE is averaged over the two samples. The phrase “first backward pass” does not specify batch versus single-sample updating, so both interpretations are identified below.</p>","<h3>Step 1: apply the first-stage multipliers and sigmoid</h3>","<p>For sample 1, the preactivations are [0.3 × 0.3, 0.2 × 0.4, 0.4 × 0.6] = [0.09, 0.08, 0.24]. Sigmoid gives [0.522484825, 0.519989340, 0.559713649].</p>","<p>For sample 2, they are [0.5 × 0.3, 0.6 × 0.4, 0.8 × 0.6] = [0.15, 0.24, 0.48]. Sigmoid gives [0.537429845, 0.559713649, 0.617747875].</p>","<h3>Step 2: evaluate the two hidden neurons</h3>","<p>For each first-stage output a, calculate z₁ = 0.5a₁ + 0.2a₂ + 0.3a₃ and z₂ = 0.3a₁ + 0.3a₂ + 0.3a₃, then apply sigmoid.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Sample</th><th>Hidden preactivation 1</th><th>Hidden preactivation 2</th><th>Hidden output 1</th><th>Hidden output 2</th></tr></thead><tbody><tr><td>1</td><td>0.533154375</td><td>0.480656344</td><td>0.630218519</td><td>0.617902849</td></tr><tr><td>2</td><td>0.565982015</td><td>0.514467411</td><td>0.637835530</td><td>0.625853155</td></tr></tbody></table></div>","<p>For example, sample 1&#x27;s first hidden sum is 0.5(0.522484825) + 0.2(0.519989340) + 0.3(0.559713649) = 0.533154375.</p>","<h3>Step 3: evaluate the output neuron</h3>","<p>The output preactivation is 0.3h₁ + 0.3h₂; apply sigmoid to the complete sum.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Sample</th><th>Output preactivation</th><th>Prediction</th><th>Target</th><th>Squared error</th></tr></thead><tbody><tr><td>1</td><td>0.374436410</td><td>0.592530535</td><td>0</td><td>0.351092435</td></tr><tr><td>2</td><td>0.379106605</td><td>0.593657609</td><td>1</td><td>0.165114139</td></tr></tbody></table></div>","<h3>Step 4: calculate the average MSE</h3>","<p>MSE = (0.351092435 + 0.165114139)/2 = <strong>0.258103287</strong>.</p>","<h3>Step 5: differentiate each sample&#x27;s squared error</h3>","<p>For one sample, output delta = 2(o − y)o(1 − o); each output-weight gradient is this delta multiplied by its sending hidden activation. Calculate both samples at the original weights before taking their mean.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Sample</th><th>Output delta</th><th>Gradient for h₁ → output</th><th>Gradient for h₂ → output</th></tr></thead><tbody><tr><td>1</td><td>0.286118893</td><td>0.180317425</td><td>0.176793679</td></tr><tr><td>2</td><td>−0.196042530</td><td>−0.125042891</td><td>−0.122693836</td></tr></tbody></table></div>","<h3>Step 6: average gradients and make one batch update</h3>","<p>The mean gradients are [(0.180317425 − 0.125042891)/2, (0.176793679 − 0.122693836)/2] ≈ [0.027637267, 0.027049922].</p>","<p>First weight: 0.3 − 0.2(0.027637267) = <strong>0.294472547</strong>.</p>","<p>Second weight: 0.3 − 0.2(0.027049922) = <strong>0.294590016</strong>.</p>","<p><strong>Final answer under batch MSE:</strong> predictions [0.592530535, 0.593657609], average MSE 0.258103287, updated output weights [0.294472547, 0.294590016]. Averaging the sample gradients is required because the stated objective is their mean loss.</p>","<h3>Alternative: first-sample SGD</h3>","<p>If “first backward pass” means an update after sample 1 alone, use its gradients without averaging: 0.3 − 0.2(0.180317425) = <strong>0.263936515</strong> and 0.3 − 0.2(0.176793679) = <strong>0.264641264</strong>. This is a different update schedule. State the interpretation and do not combine a batch loss with an unexplained single-sample gradient.</p>"],"kind":"practice","id":"tee-c15-s6","search":"F22 Q2b **Question (10 marks).** For a three-stage sigmoid network, use samples [0.3,0.2,0.4] → 0 and [0.5,0.6,0.8] → 1. First-stage feature multipliers are [0.3,0.4,0.6]. Next receiving rows are [0.5,0.2,0.3], [0.3,0.3,0.3], and output weights [0.3,0.3]. Find both predictions, average MSE and output-weight updates after the first backward pass with η = 0.2. Assume zero biases.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nFor a three-stage sigmoid network, use samples [0.3,0.2,0.4] → 0 and [0.5,0.6,0.8] → 1.\n\nFirst-stage feature multipliers are [0.3,0.4,0.6].\n\nNext receiving rows are [0.5,0.2,0.3], [0.3,0.3,0.3], and output weights [0.3,0.3].\n\nFind both predictions, average MSE and output-weight updates after the first backward pass with η = 0.2.\n\nAssume zero biases.\n\n### To find\n\nFind 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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\nn = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.\n\n\n\n\n\n**Yaad rakhne ka cue:** MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n**Interpretation.** Follow the supplied diagram: each raw feature is multiplied by 0.3, 0.4 or 0.6, then passed through sigmoid before the next two-neuron layer. Unspecified biases are zero. MSE is averaged over the two samples. The phrase “first backward pass” does not specify batch versus single-sample updating, so both interpretations are identified below.\n\n### Step 1: apply the first-stage multipliers and sigmoid\nFor sample 1, the preactivations are [0.3 × 0.3, 0.2 × 0.4, 0.4 × 0.6] = [0.09, 0.08, 0.24]. Sigmoid gives [0.522484825, 0.519989340, 0.559713649].\n\nFor sample 2, they are [0.5 × 0.3, 0.6 × 0.4, 0.8 × 0.6] = [0.15, 0.24, 0.48]. Sigmoid gives [0.537429845, 0.559713649, 0.617747875].\n\n### Step 2: evaluate the two hidden neurons\nFor each first-stage output a, c"},{"title":"F22 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain bias, variance, underfitting and overfitting. A four-feature product-texture classifier has four grades including reject. Choose output activation/loss. Diagnose training error 15% and validation error 18% and suggest remedies.</p>"],"answer":["<p>Bias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/overfitting.svg\" aria-label=\"Enlarge diagram: Validation behavior distinguishes useful fitting from prolonged fitting to training details\"><img src=\"assets/figures/overfitting.svg\" alt=\"Validation behavior distinguishes useful fitting from prolonged fitting to training details\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Validation behavior distinguishes useful fitting from prolonged fitting to training details <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Increasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model&#x27;s approximation bias much. These are typical trends, not unconditional numerical laws.</p>","<p>Underfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.</p>","<p>Training and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.</p>","<p><strong>Classifier: </strong> four mutually exclusive grades require 4 output scores, softmax probabilities and categorical cross-entropy. A reject class is still a labeled class in this formulation.</p>","<p><strong>Diagnosis: </strong> a modest 3 percentage-point gap with both errors appreciable suggests underfitting/high bias if a much better attainable baseline exists. Confirm learning curves and label quality. Improve relevant features or model capacity, train sufficiently, tune the optimizer and reduce excessive regularization. The percentages alone do not prove the cause.</p>"],"kind":"practice","id":"tee-c15-s7","search":"F22 Q3a **Question (10 marks).** Explain bias, variance, underfitting and overfitting. A four-feature product-texture classifier has four grades including reject. Choose output activation/loss. Diagnose training error 15% and validation error 18% and suggest remedies.\n\n**Complete worked answer.**\nBias is error caused by restrictive assumptions or insufficient fit; variance is sensitivity to the particular training sample. A high-bias model may miss useful structure and perform poorly even on training data. A high-variance model can fit training data very well but perform much worse on comparable validation data.\n\nIncreasing model capacity can reduce bias but may increase variance. Stronger regularization usually increases bias and reduces variance. More representative training data often reduces variance without changing the model's approximation bias much. These are typical trends, not unconditional numerical laws.\nUnderfitting remedies include improving features, using a more expressive appropriate model, training sufficiently and reducing excessive regularization. Overfitting remedies include representative extra data, data augmentation, appropriate L1/L2 or dropout, early stopping and sometimes reducing model size. Keep an untouched test set for final evaluation. Repeatedly tuning on test results turns that set into another validation set and requires a fresh test set for an unbiased final estimate.\nTraining and validation errors alone do not determine a diagnosis without task difficulty, evaluation consistency and learning curves. A small gap with both errors high suggests underfitting; a large gap with very low training error suggests overfitting.\n**Classifier: ** four mutually exclusive grades require 4 output scores, softmax probabilities and categorical cross-entropy. A reject class is still a labeled class in this formulation.\n**Diagnosis: ** a modest 3 percentage-point gap with both errors appreciable suggests underfitting/high bias if a much better attainable baseline exists. Confirm learning curves and label quality. Improve relevant features or model capacity, train sufficiently, tune the optimizer and reduce excessive regularization. The percentages alone do not prove the cause.\n"},{"title":"F22 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Count trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2; convolution 5 × 5: 16 filters, pooling 2; dense 120, dense 84, softmax 10. Use the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.</p>"],"answer":["<h3>Given</h3>","<p>Count trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2.</p>","<p>convolution 5 × 5: 16 filters, pooling 2.</p>","<p>dense 120, dense 84, softmax 10.</p>","<p>Use the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">32 × 32 × 1</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">6 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">28 × 28 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">150</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">6</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">156</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>32 × 32 × 1</strong>. Use 6 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a58485fe718e957c.svg\"><img class=\"math display-math\" src=\"assets/equations/b2fe45e42e65423c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{32+2(0)-5}{1}\\right\\rfloor+1=28\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>28 × 28 × 6</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 1 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.44px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4503fe259db6cc31.svg\"><img class=\"math display-math\" src=\"assets/equations/d75bc00144d70f4e.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times1\\times6=150\" width=\"318.68\" height=\"23.91\" style=\"width:318.68px;height:23.91px;aspect-ratio:318.68/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/07df0417eea506bc.svg\" alt=\"N_{\\mathrm{biases}}=6\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60d683ee579f75b5.svg\" alt=\"P_1=150+6=156\" width=\"206.92\" height=\"20.36\" style=\"width:206.92px;height:20.36px;aspect-ratio:206.92/20.36\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">28 × 28 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">14 × 14 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>28 × 28 × 6</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d66b872d3a8b7d76.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{28-2}{2}\\right\\rfloor+1=14\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>14 × 14 × 6</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">14 × 14 × 6</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">16 filters · 5 × 5 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">10 × 10 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">2,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">16</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">2,416</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>14 × 14 × 6</strong>. Use 16 filters of spatial size 5 × 5, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/85506bf5dfa9eb3a.svg\"><img class=\"math display-math\" src=\"assets/equations/44a93c57d72f0b31.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{14+2(0)-5}{1}\\right\\rfloor+1=10\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>10 × 10 × 16</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 6 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/95205b29ca5fb5db.svg\"><img class=\"math display-math\" src=\"assets/equations/5d2e007b43373429.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times6\\times16=2{,}400\" width=\"349.90\" height=\"23.91\" style=\"width:349.90px;height:23.91px;aspect-ratio:349.90/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc0c940eb69b41c0.svg\" alt=\"N_{\\mathrm{biases}}=16\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0985f033fb9785fd.svg\" alt=\"P_3=2{,}400+16=2{,}416\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">10 × 10 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">5 × 5 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>10 × 10 × 16</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c2393768f5c7cc6f.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{10-2}{2}\\right\\rfloor+1=5\" width=\"271.85\" height=\"58.62\" style=\"width:271.85px;height:58.62px;aspect-ratio:271.85/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>5 × 5 × 16</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">5 × 5 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">400</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>5 × 5 × 16</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b7fdfd1b9a608954.svg\" alt=\"n_{\\mathrm{flat}}=5\\times5\\times16=400\" width=\"252.57\" height=\"20.40\" style=\"width:252.57px;height:20.40px;aspect-ratio:252.57/20.40\" loading=\"lazy\"></div>","<p>Output: a vector with <strong>400 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 6 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">400</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">48,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">48,120</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>400 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.13px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/142c2516a0279849.svg\"><img class=\"math display-math\" src=\"assets/equations/19a0a131878ed831.svg\" alt=\"N_{\\mathrm{weights}}=400\\times120=48{,}000\" width=\"314.59\" height=\"23.91\" style=\"width:314.59px;height:23.91px;aspect-ratio:314.59/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee00c5a42d90e348.svg\"><img class=\"math display-math\" src=\"assets/equations/fd12e231aa432c56.svg\" alt=\"P_6=48{,}000+120=48{,}120\" width=\"293.80\" height=\"21.43\" style=\"width:293.80px;height:21.43px;aspect-ratio:293.80/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">84 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">10,080</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">84</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">10,164</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>84 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:201.92px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4874c9639ae8a286.svg\"><img class=\"math display-math\" src=\"assets/equations/0b5956346ee0f9d2.svg\" alt=\"N_{\\mathrm{weights}}=120\\times84=10{,}080\" width=\"302.38\" height=\"23.91\" style=\"width:302.38px;height:23.91px;aspect-ratio:302.38/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec58135349b68114.svg\" alt=\"N_{\\mathrm{biases}}=84\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c9fa89f780aa10aa.svg\" alt=\"P_7=10{,}080+84=10{,}164\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">84</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">10 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">10</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">840</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">10</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">850</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>84 features</strong>. Output: <strong>10 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/995f161a94dc7ae1.svg\" alt=\"N_{\\mathrm{weights}}=84\\times10=840\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8203d983cccce3a9.svg\" alt=\"N_{\\mathrm{biases}}=10\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b9609ba48ce42f1.svg\" alt=\"P_8=840+10=850\" width=\"219.13\" height=\"20.74\" style=\"width:219.13px;height:20.74px;aspect-ratio:219.13/20.74\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/77e2ec6d75d55591.svg\" alt=\"\\left\\lfloor\\frac{32+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>28 x 28 x 6</td><td>150</td><td>6</td><td>156</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/0f4985548e8cd39b.svg\" alt=\"\\left\\lfloor\\frac{28-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>14 x 14 x 6</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/104aadf49e642e25.svg\" alt=\"\\left\\lfloor\\frac{14+2 \\times  0-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>10 x 10 x 16</td><td>2,400</td><td>16</td><td>2,416</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/0c637a47bfb54036.svg\" alt=\"\\left\\lfloor\\frac{10-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>5 x 5 x 16</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 flat</td><td>5 × 5 × 16</td><td>400</td><td>0</td><td>0</td><td>0</td></tr><tr><td>6 dense</td><td>400 → 120</td><td>120</td><td>48,000</td><td>120</td><td>48,120</td></tr><tr><td>7 dense</td><td>120 → 84</td><td>84</td><td>10,080</td><td>84</td><td>10,164</td></tr><tr><td>8 dense</td><td>84 → 10</td><td>10</td><td>840</td><td>10</td><td>850</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (5 x 5 x 1 + 1) x 6 = 156.</p>","<p>Layer 3: (5 x 5 x 6 + 1) x 16 = 2,416.</p>","<p>Layer 6: (400 + 1) x 120 = 48,120.</p>","<p>Layer 7: (120 + 1) x 84 = 10,164.</p>","<p>Layer 8: (84 + 1) x 10 = 850.</p>","<p><strong>Total: </strong> 156 + 2,416 + 48,120 + 10,164 + 850 = <strong>61,706 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p>This is the standard classroom full-channel interpretation with nontrainable pooling and a dense 10-class softmax. The historical original LeNet used partial channel connections and other details, so its published parameter count need not equal this diagram-based count. If an input label is read as 28, the stated later 28 map after valid 5 × 5 convolution is inconsistent; record the 32 input assumption rather than silently ignoring the mismatch.</p>"],"kind":"practice","id":"tee-c15-s8","search":"F22 Q3b **Question (10 marks).** Count trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2; convolution 5 × 5: 16 filters, pooling 2; dense 120, dense 84, softmax 10. Use the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nCount trainable parameters of the illustrated LeNet-style digit classifier with convolution 5 × 5: 6 filters, pooling 2.\n\nconvolution 5 × 5: 16 filters, pooling 2.\n\ndense 120, dense 84, softmax 10.\n\nUse the consistent 32 × 32 × 1 input that produces the drawn 28,14,10,5 spatial maps.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{32+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 28 x 28 x 6 | 150 | 6 | 156 |\n| 2 pool | \\(\\left\\lfloor\\frac{28-2}{2}\\right\\rfloor+1\\) | 14 x 14 x 6 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{14+2 \\times  0-5}{1}\\right\\rfloor+1\\) | 10 x 10 x 16 | 2,400 | 16 | 2,416 |\n| 4 pool | \\(\\left\\lfloor\\frac{10-2}{2}\\right\\rfloor+1\\) | 5 x 5 x 16 | 0 | 0 | 0 |\n| 5 flat | 5 × 5 × 16 | 400 | 0 | 0 | 0 |\n| 6 dense | 400 → 120 | 120 | 48,000 | 120 | 48,120 |\n| 7 dense | 120 → 84 | 84 | 10,080 | 84 | 10,164 |\n| 8 dense | 84 → 10 | 10 | 840 | 10 | 850 |\n**Parameter substitutions, in layer order: **\nLayer 1: (5 x 5 x 1 + 1) x 6 = 156.\nLayer 3: (5 x 5 x 6 + 1) x 16 = 2,416.\nLayer 6: (400 + 1) x 120 = 48,120.\nLayer 7: (120 + 1) x 84 = 10,164.\nLayer 8: (84 + 1) x 10 = 850.\n**Total: ** 156 + 2,416 + 48,120 + 10,164 + 850 = **61,706 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\nThis is the standard classroom full-channel interpretation with nontrainable pooling and a dense 10-class softmax. The historical original LeNet used partial channel connections and other details, so its published parameter count need not equal this diagram-based count. If an input label is read as 28, the stated later 28 map after valid 5 × 5 convolution is inconsistent; record the 32 input assumption rather than silently ignoring the mismatch.\n"},{"title":"F22 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> An Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved. Compute operations and explain 1 × 1 convolution.</p>"],"answer":["<h3>Given</h3>","<p>An Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved.</p>","<h3>To find</h3>","<p>Find direct and bottleneck computation counts and the requested saving.</p>","<h3>Formula — which one and why</h3>","<p><strong>Multiply–accumulate count.</strong> Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.</p>","<p>H_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output cell ka kaam × kitne output cells.</p>","<h3>Solution — step by step</h3>","<h3>Direct path</h3>","<p class=\"worked-step\"><strong>Step 2: direct path.</strong></p>","<p>output stays 28 × 28 with 32 channels.</p>","<p class=\"worked-step\"><strong>Step 3: direct path.</strong></p>","<p>MACs = 28 × 28 × 192 × 32 × 5 × 5 = <strong>120,422,400</strong>.</p>","<h3>Bottleneck path with 16 reduction channels</h3>","<p class=\"worked-step\"><strong>Step 4: bottleneck path with 16 reduction channels.</strong></p>","<p>1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.</p>","<p class=\"worked-step\"><strong>Step 5: bottleneck path with 16 reduction channels.</strong></p>","<p>The 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.</p>","<p class=\"worked-step\"><strong>Step 6: bottleneck path with 16 reduction channels.</strong></p>","<p>Total = <strong>12,443,648</strong>.</p>","<h3>Saving</h3>","<p class=\"worked-step\"><strong>Step 7: saving.</strong></p>","<p>120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = <strong>89.666667%</strong>. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = <strong>777,728r</strong></p>","<p class=\"worked-step\"><strong>Step 8: saving.</strong></p>","<p>there is no unique numeric bottleneck cost until r is chosen.</p>","<p class=\"worked-step\"><strong>Step 9: calculate this quantity.</strong></p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 10: calculate this quantity.</strong></p>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>"],"kind":"practice","id":"tee-c15-s9","search":"F22 Q4a **Question (10 marks).** An Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved. Compute operations and explain 1 × 1 convolution.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nAn Inception branch receives 28 × 28 × 192, uses 16 filters of 1 × 1 then 32 filters of 5 × 5 with spatial size preserved.\n\n### To find\n\nFind direct and bottleneck computation counts and the requested saving.\n\n### Formula — which one and why\n\n**Multiply–accumulate count.** Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.\n\nH_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har output cell ka kaam × kitne output cells.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n\n\n### Direct path\n\n**Step 2: direct path.**\n\noutput stays 28 × 28 with 32 channels.\n\n**Step 3: direct path.**\n\nMACs = 28 × 28 × 192 × 32 × 5 × 5 = **120,422,400**.\n\n### Bottleneck path with 16 reduction channels\n\n**Step 4: bottleneck path with 16 reduction channels.**\n\n1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.\n\n**Step 5: bottleneck path with 16 reduction channels.**\n\nThe 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.\n\n**Step 6: bottleneck path with 16 reduction channels.**\n\nTotal = **12,443,648**.\n\n### Saving\n\n**Step 7: saving.**\n\n120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = **89.666667%**. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = **777,728r**\n\n**Step 8: saving.**\n\nthere is no unique numeric bottleneck cost until r is chosen.\n\n**Step 9: calculate this quantity.**\n\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\n\n\n**Step 10: calculate this quantity.**\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\n\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\n"},{"title":"F22 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Draw a 6-input, two-hidden-layer network with 5 neurons each and 4 classes, trained by AdaGrad. Identify learned parameters and tunable hyperparameters; no input-layer weights or biases.</p>"],"answer":["<h3>Given</h3>","<p>6 inputs → hidden 5 → hidden 5 → 4 output classes.</p>","<p>AdaGrad is the specified training algorithm; one bias per receiving neuron.</p>","<h3>To find</h3>","<p>Draw the architecture and count its learned weights/biases. The optimizer name does not change the count.</p>","<h3>Formula — which one and why</h3>","<p><strong>Dense-layer parameters.</strong> Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.</p>","<p>n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/494312d0893d20d2.svg\" alt=\"P=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"184.79\" height=\"24.43\" style=\"width:184.79px;height:24.43px;aspect-ratio:184.79/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output ke liye saare inputs plus ek bias.</p>","<h3>Solution — step by step</h3>","<p>Architecture: 6 → 5 → 5 → 4. Each non-input neuron has one bias.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/dense_6_5_5_4.svg\" aria-label=\"Enlarge diagram: F22 Q4b the input has six features and the output has four classes\"><img src=\"assets/figures/dense_6_5_5_4.svg\" alt=\"F22 Q4b the input has six features and the output has four classes\" width=\"960\" height=\"495\" loading=\"lazy\"></button><figcaption>F22 Q4b the input has six features and the output has four classes <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>Layer 6 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9aa0cefe0fe7172a.svg\" alt=\"6(5)=30\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e27ba4eb6d98f55b.svg\" alt=\"30+5=35\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 5</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d16b109d87f9088b.svg\" alt=\"5(5)=25\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 5 receiving neurons, so 5 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/862c71dcbfedc68d.svg\" alt=\"25+5=30\" width=\"123.54\" height=\"18.27\" style=\"width:123.54px;height:18.27px;aspect-ratio:123.54/18.27\" loading=\"lazy\"></div>","<h3>Layer 5 → 4</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b06f6eedc0b0c61f.svg\" alt=\"5(4)=20\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 4 receiving neurons, so 4 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/92df7685dd83d921.svg\" alt=\"20+4=24\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<p><strong>Total = 89</strong>. Input values and activations are not trainable parameters.</p>","<p>The learned parameters are input-to-hidden, hidden-to-hidden and hidden-to-output weights plus biases at receiving neurons. AdaGrad accumulators are optimizer state, not additional predictive weights. Hyperparameters include hidden widths/depth, learning rate η,ε, batch size, epochs, activations and regularization settings. Use 4-class softmax with categorical cross-entropy.</p>","<p>AdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p>Frequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.</p>","<p>Example with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.</p>","<p>Advantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.</p>"],"kind":"practice","id":"tee-c15-s10","search":"F22 Q4b **Question (10 marks).** Draw a 6-input, two-hidden-layer network with 5 neurons each and 4 classes, trained by AdaGrad. Identify learned parameters and tunable hyperparameters; no input-layer weights or biases.\n\n**Complete worked answer.**\n\n\n\n### Given\n\n6 inputs → hidden 5 → hidden 5 → 4 output classes.\n\nAdaGrad is the specified training algorithm; one bias per receiving neuron.\n\n### To find\n\nDraw the architecture and count its learned weights/biases. The optimizer name does not change the count.\n\n### Formula — which one and why\n\n**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\nn_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.\n\n\n\n**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.\n\n### Solution — step by step\n\n\n\n\nArchitecture: 6 → 5 → 5 → 4. Each non-input neuron has one bias.\n\n### Layer 6 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 5\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 5 receiving neurons, so 5 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 5 → 4\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 4 receiving neurons, so 4 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n**Total = 89**. Input values and activations are not trainable parameters.\nThe learned parameters are input-to-hidden, hidden-to-hidden and hidden-to-output weights plus biases at receiving neurons. AdaGrad accumulators are optimizer state, not additional predictive weights. Hyperparameters include hidden widths/depth, learning rate η,ε, batch size, epochs, activations and regularization settings. Use 4-class softmax with categorical cross-entropy.\nAdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:\n\nFrequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.\nExample with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.\nAdvantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.\n"},{"title":"F22 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Develop an RNN with hidden states and explain gradient updates using backpropagation.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p>Backpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.</p>","<p>1. Initialize the hidden state and run the forward recurrence from the first input to the last.</p>","<p>2. Compute the specified output loss, at the final step or across several steps.</p>","<p>3. Start from the last loss and propagate derivatives backwards through output and hidden operations.</p>","<p>4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.</p>","<p>5. Sum all uses of each shared weight before applying the optimizer update.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:371.04px;--narrow-height:147.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fdf1ee48fdcfd79f.svg\"><img class=\"math display-math\" src=\"assets/equations/43466db031266f9c.svg\" alt=\"\\delta_t=(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1})\\odot(1-h_t^2),\\quad \\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T}\" width=\"623.72\" height=\"62.51\" style=\"width:623.72px;height:62.51px;aspect-ratio:623.72/62.51\" loading=\"lazy\"></picture></div>","<p>The tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: BPTT follows this unrolled network backwards and sums gradients of shared weights\"><img src=\"assets/figures/rnn.svg\" alt=\"BPTT follows this unrolled network backwards and sums gradients of shared weights\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>BPTT follows this unrolled network backwards and sums gradients of shared weights <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c15-s11","search":"F22 Q5a **Question (10 marks).** Develop an RNN with hidden states and explain gradient updates using backpropagation.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\nBackpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.\n1. Initialize the hidden state and run the forward recurrence from the first input to the last.\n2. Compute the specified output loss, at the final step or across several steps.\n3. Start from the last loss and propagate derivatives backwards through output and hidden operations.\n4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.\n5. Sum all uses of each shared weight before applying the optimizer update.\n\nThe tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.\n\n"},{"title":"F22 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain DL optimization challenges and the advantage of momentum over plain mini-batch gradient descent.</p>"],"answer":["<p>The learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative full batch and stochastic traces distinguish smoothness from progress\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative full batch and stochastic traces distinguish smoothness from progress\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative full batch and stochastic traces distinguish smoothness from progress <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Batch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.</p>","<p>Momentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.</p>","<p>Diagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.</p>","<p>Momentum uses vnew = βv−ηg and θ new = θ+vnew; consistent gradients accumulate direction, whereas some alternating components cancel. Plain mini-batch descent uses only the current batch gradient. Both can be combined: momentum with mini-batch gradients is a standard coherent choice.</p>"],"kind":"practice","id":"tee-c15-s12","search":"F22 Q5b **Question (10 marks).** Explain DL optimization challenges and the advantage of momentum over plain mini-batch gradient descent.\n\n**Complete worked answer.**\nThe learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.\n\nBatch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.\nMomentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.\nDiagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.\nMomentum uses vnew = βv−ηg and θ new = θ+vnew; consistent gradients accumulate direction, whereas some alternating components cancel. Plain mini-batch descent uses only the current batch gradient. Both can be combined: momentum with mini-batch gradients is a standard coherent choice.\n"},{"title":"F22 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A CNN image classifier performs poorly because of vanishing gradients. Explain remedies.</p>"],"answer":["<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>Also inspect saturated sigmoid/tanh hidden units, initialization and gradient magnitudes. Appropriate ReLU-family activations and initialization can help preserve usable gradients. Residual blocks require shape-compatible additions or projections. Verify that the diagnosis is correct; additional training time alone cannot repair gradients that are consistently negligible.</p>"],"kind":"practice","id":"tee-c15-s13","search":"F22 Q6a **Question (10 marks).** A CNN image classifier performs poorly because of vanishing gradients. Explain remedies.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nAlso inspect saturated sigmoid/tanh hidden units, initialization and gradient magnitudes. Appropriate ReLU-family activations and initialization can help preserve usable gradients. Residual blocks require shape-compatible additions or projections. Verify that the diagnosis is correct; additional training time alone cannot repair gradients that are consistently negligible.\n"},{"title":"F22 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design a clothes classifier for 250,000 six-dimensional samples,6 classes and 2 hidden layers. Give train/validation/test split, activations/loss, actions for 15% training 20% validation error, interpret improvement to 1%/1.5%, then address 15% test error.</p>"],"answer":["<p><strong>One explicit design: </strong>6 → 16 → 8 → 6, ReLU hidden layers,6-unit softmax output, categorical cross-entropy. The hidden widths are chosen assumptions, not supplied numerical requirements.</p>","<p>Architecture: 6 → 16 → 8 → 6. Each non-input neuron has one bias.</p>","<h3>Layer 6 → 16</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35a3fea4574170f0.svg\" alt=\"6(16)=96\" width=\"112.68\" height=\"24.43\" style=\"width:112.68px;height:24.43px;aspect-ratio:112.68/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 16 receiving neurons, so 16 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/77dd73646865b98e.svg\" alt=\"96+16=112\" width=\"147.97\" height=\"18.27\" style=\"width:147.97px;height:18.27px;aspect-ratio:147.97/18.27\" loading=\"lazy\"></div>","<h3>Layer 16 → 8</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3a81b7540b48b829.svg\" alt=\"16(8)=128\" width=\"124.90\" height=\"24.43\" style=\"width:124.90px;height:24.43px;aspect-ratio:124.90/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 8 receiving neurons, so 8 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c4ed13ec1c4089a9.svg\" alt=\"128+8=136\" width=\"147.97\" height=\"18.27\" style=\"width:147.97px;height:18.27px;aspect-ratio:147.97/18.27\" loading=\"lazy\"></div>","<h3>Layer 8 → 6</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42c41d8c1f1be799.svg\" alt=\"8(6)=48\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 6 receiving neurons, so 6 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/935190190dc4ddae.svg\" alt=\"48+6=54\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<p><strong>Total = 302</strong>. Input values and activations are not trainable parameters.</p>","<p><strong>Split: </strong> a stratified 70/15/15 split gives 175,000 training,37,500 validation,37,500 test samples. Fit preprocessing on training data only and keep related duplicates within a single split.</p>","<p><strong>15%/20%: </strong> inspect learning curves and baseline difficulty. Substantial training error suggests capacity/optimization or data-quality issues; the 5 point gap also suggests a generalization issue. Improve training fit, tune regularization and collect useful representative data instead of blindly increasing capacity.</p>","<p><strong>1%/1.5%: </strong> good comparable-set results with a small gap are encouraging; verify that validation has not leaked into training.</p>","<p><strong>15% test: </strong> inspect distribution shift, preprocessing differences, label quality, leakage or repeated validation overfitting. Compare per-class errors and collection conditions. Address the actual cause and collect representative data if necessary. If test results guide retuning, use a fresh untouched final test set.</p>"],"kind":"practice","id":"tee-c15-s14","search":"F22 Q6b **Question (10 marks).** Design a clothes classifier for 250,000 six-dimensional samples,6 classes and 2 hidden layers. Give train/validation/test split, activations/loss, actions for 15% training 20% validation error, interpret improvement to 1%/1.5%, then address 15% test error.\n\n**Complete worked answer.**\n**One explicit design: **6 → 16 → 8 → 6, ReLU hidden layers,6-unit softmax output, categorical cross-entropy. The hidden widths are chosen assumptions, not supplied numerical requirements.\nArchitecture: 6 → 16 → 8 → 6. Each non-input neuron has one bias.\n### Layer 6 → 16\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 16 receiving neurons, so 16 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 16 → 8\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 8 receiving neurons, so 8 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 8 → 6\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 6 receiving neurons, so 6 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n**Total = 302**. Input values and activations are not trainable parameters.\n**Split: ** a stratified 70/15/15 split gives 175,000 training,37,500 validation,37,500 test samples. Fit preprocessing on training data only and keep related duplicates within a single split.\n**15%/20%: ** inspect learning curves and baseline difficulty. Substantial training error suggests capacity/optimization or data-quality issues; the 5 point gap also suggests a generalization issue. Improve training fit, tune regularization and collect useful representative data instead of blindly increasing capacity.\n**1%/1.5%: ** good comparable-set results with a small gap are encouraging; verify that validation has not leaked into training.\n**15% test: ** inspect distribution shift, preprocessing differences, label quality, leakage or repeated validation overfitting. Compare per-class errors and collection conditions. Address the actual cause and collect representative data if necessary. If test results guide retuning, use a fresh untouched final test set.\n"},{"title":"F22 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain with an example how LSTM handles long sequences in language modeling.</p>"],"answer":["<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>","<p>Example: “The student, after several difficult assignments and a long discussion, was relieved.” Useful singular-subject information can be retained in selected cell components while intervening words update other components. At the final step a vocabulary softmax predicts the next token using h. Gates close to 1 on the retained path preserve context; numerical gate values require learned weights and cannot be inferred uniquely from the sentence.</p>"],"kind":"practice","id":"tee-c15-s15","search":"F22 Q7a **Question (10 marks).** Explain with an example how LSTM handles long sequences in language modeling.\n\n**Complete worked answer.**\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\nExample: “The student, after several difficult assignments and a long discussion, was relieved.” Useful singular-subject information can be retained in selected cell components while intervening words update other components. At the final step a vocabulary softmax predicts the next token using h. Gates close to 1 on the retained path preserve context; numerical gate values require learned weights and cannot be inferred uniquely from the sentence.\n"},{"title":"F22 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Justify that single-layer perceptrons cannot classify nonlinearly separable data using an example, and suggest a solution.</p>"],"answer":["<p>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.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/xor.svg\" aria-label=\"Enlarge diagram: Opposite corners for XOR cannot be split by one straight line\"><img src=\"assets/figures/xor.svg\" alt=\"Opposite corners for XOR cannot be split by one straight line\" width=\"960\" height=\"430\" loading=\"lazy\"></button><figcaption>Opposite corners for XOR cannot be split by one straight line <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>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.</p>","<p>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.</p>","<p>A multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.</p>"],"kind":"practice","id":"tee-c15-s16","search":"F22 Q7b **Question (10 marks).** Justify that single-layer perceptrons cannot classify nonlinearly separable data using an example, and suggest a solution.\n\n**Complete worked answer.**\nA 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.\n\nFor 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.\nFor 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.\nA multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.\n\n\n"}]},{"n":16,"title":"Re examination January 2023 fully solved","sections":[{"title":"Start here","blocks":["<p>R23 = S15, 28 January 2023. Its AlexNet and convolution questions are retained by current Unit 4; sequence questions map to current Unit 5.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c16-intro"},{"title":"R23 Q1a","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Suggest and sketch an RNN architecture to synthesize a musical tune.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p>Represent notes as discrete tokens or suitable pitch-duration vectors. Train a recurrent decoder to predict the next note from preceding notes. A vocabulary softmax handles discrete note tokens; repeatedly feed generated notes to continue the tune until a stop condition. This is autoregressive sequence generation, typically a many-to-many next-token training pattern.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/sequences.svg\" aria-label=\"Enlarge diagram: Music generation can predict a next note at every recurrent step\"><img src=\"assets/figures/sequences.svg\" alt=\"Music generation can predict a next note at every recurrent step\" width=\"960\" height=\"610\" loading=\"lazy\"></button><figcaption>Music generation can predict a next note at every recurrent step <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c16-s0","search":"R23 Q1a **Question (4 marks).** Suggest and sketch an RNN architecture to synthesize a musical tune.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\nRepresent notes as discrete tokens or suitable pitch-duration vectors. Train a recurrent decoder to predict the next note from preceding notes. A vocabulary softmax handles discrete note tokens; repeatedly feed generated notes to continue the tune until a stop condition. This is autoregressive sequence generation, typically a many-to-many next-token training pattern.\n\n"},{"title":"R23 Q1b","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Apply 3 × 3 average pooling with stride 2 to Matrix 1 shown below. Give the output and justify pooling.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_847554ea0e.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_847554ea0e.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"470\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Apply 3 × 3 average pooling with stride 2 to Matrix 1 shown below.</p>","<h3>To find</h3>","<p>Find the requested pooled output(s).</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cc7bf1ef4d7c44f8.svg\" alt=\"\\left\\lfloor\\frac{5-3}{2}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[1, 2, 3, 5, 3, 4, 7, 4, 8]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>1 + 2 + 3 + 5 + 3 + 4 + 7 + 4 + 8 = 37</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>37/9 = <strong>4.111111111</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[3, 2, 5, 4, 6, 3, 8, 5, 9]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>3 + 2 + 5 + 4 + 6 + 3 + 8 + 5 + 9 = 45</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>45/9 = <strong>5</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[7, 4, 8, 8, 5, 10, 9, 10, 3]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>7 + 4 + 8 + 8 + 5 + 10 + 9 + 10 + 3 = 64</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>64/9 = <strong>7.111111111</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[8, 5, 9, 10, 4, 2, 3, 4, 3]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>8 + 5 + 9 + 10 + 4 + 2 + 3 + 4 + 3 = 48</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 9 entries in this window.</strong></p>","<p>48/9 = <strong>5.333333333</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/072844f2570c1168.svg\" alt=\"\\begin{bmatrix}4.111111111 &amp; 5\\\\7.111111111 &amp; 5.333333333\\end{bmatrix}\" width=\"239.69\" height=\"45.61\" style=\"width:239.69px;height:45.61px;aspect-ratio:239.69/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>"],"kind":"practice","id":"tee-c16-s1","search":"R23 Q1b **Question (4 marks).** Apply 3 × 3 average pooling with stride 2 to Matrix 1 shown below. Give the output and justify pooling.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nApply 3 × 3 average pooling with stride 2 to Matrix 1 shown below.\n\n### To find\n\nFind the requested pooled output(s).\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n**Shape: ** \\(\\left\\lfloor\\frac{5-3}{2}\\right\\rfloor+1\\) = 2 on each axis; channels stay unchanged.\n### Pooling window (1,1)\n\n**Step 1: select the entries.**\n\n[1, 2, 3, 5, 3, 4, 7, 4, 8]\n\n**Step 2: add all selected entries.**\n\n1 + 2 + 3 + 5 + 3 + 4 + 7 + 4 + 8 = 37\n\n**Step 3: divide by the 9 entries in this window.**\n\n37/9 = **4.111111111**\n\n\n### Pooling window (1,2)\n\n**Step 1: select the entries.**\n\n[3, 2, 5, 4, 6, 3, 8, 5, 9]\n\n**Step 2: add all selected entries.**\n\n3 + 2 + 5 + 4 + 6 + 3 + 8 + 5 + 9 = 45\n\n**Step 3: divide by the 9 entries in this window.**\n\n45/9 = **5**\n\n\n### Pooling window (2,1)\n\n**Step 1: select the entries.**\n\n[7, 4, 8, 8, 5, 10, 9, 10, 3]\n\n**Step 2: add all selected entries.**\n\n7 + 4 + 8 + 8 + 5 + 10 + 9 + 10 + 3 = 64\n\n**Step 3: divide by the 9 entries in this window.**\n\n64/9 = **7.111111111**\n\n\n### Pooling window (2,2)\n\n**Step 1: select the entries.**\n\n[8, 5, 9, 10, 4, 2, 3, 4, 3]\n\n**Step 2: add all selected entries.**\n\n8 + 5 + 9 + 10 + 4 + 2 + 3 + 4 + 3 = 48\n\n**Step 3: divide by the 9 entries in this window.**\n\n48/9 = **5.333333333**\n\n\n**Average output: ** . Pooling normally has zero trainable parameters and reduces spatial dimensions.\n"},{"title":"R23 Q1c","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> State DL advantages and limitations.</p>"],"answer":["<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>"],"kind":"practice","id":"tee-c16-s2","search":"R23 Q1c **Question (4 marks).** State DL advantages and limitations.\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n"},{"title":"R23 Q1d","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Evaluate how mini-batch size affects optimization and parallel processing.</p>"],"answer":["<p>A mini-batch forms one gradient from B examples. Smaller B usually gives noisier gradients, lower activation memory and more updates per epoch. Larger B averages more examples, often uses vectorized hardware more efficiently up to resource limits, but needs more memory and gives fewer updates per epoch. N examples produce ceil(N/B) updates if the last partial batch is kept. Too-large B does not guarantee faster wall-clock progress or better generalization. Tune batch size with learning rate and resource constraints. Computation within a batch can be parallelized; successive optimizer steps remain dependent on the updated parameters.</p>"],"kind":"practice","id":"tee-c16-s3","search":"R23 Q1d **Question (4 marks).** Evaluate how mini-batch size affects optimization and parallel processing.\n\n**Complete worked answer.**\nA mini-batch forms one gradient from B examples. Smaller B usually gives noisier gradients, lower activation memory and more updates per epoch. Larger B averages more examples, often uses vectorized hardware more efficiently up to resource limits, but needs more memory and gives fewer updates per epoch. N examples produce ceil(N/B) updates if the last partial batch is kept. Too-large B does not guarantee faster wall-clock progress or better generalization. Tune batch size with learning rate and resource constraints. Computation within a batch can be parallelized; successive optimizer steps remain dependent on the updated parameters.\n"},{"title":"R23 Q1e","question":["<p class=\"inline-question\"><strong>Question (4 marks).</strong> Design a perceptron network for inputs 00 → 0,10 → 0,01 → 0,11 → 1; choose suitable weights.</p>"],"answer":["<h3>Given</h3>","<p>Truth table: 00→0,10→0,01→0,11→1.</p>","<p>Weights and bias are to be designed.</p>","<h3>To find</h3>","<p>Choose a perceptron that implements AND and show its four outputs.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<p>Choose weights w₁ = w₂ = 1 and bias −1.5. Use output 1 for z ≥ 0.</p>","<h3>Input (0, 0)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3798c4898b2e9ea7.svg\" alt=\"1(0)=0\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3798c4898b2e9ea7.svg\" alt=\"1(0)=0\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e725afda84fc9ed3.svg\" alt=\"s=0+0=0\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e7029152ef49c01f.svg\" alt=\"z=0+(-1.5)=-1.5\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -1.5; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (0, 1)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3798c4898b2e9ea7.svg\" alt=\"1(0)=0\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e75a800ad85088f5.svg\" alt=\"1(1)=1\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4ae62ee9eceeaffe.svg\" alt=\"s=0+1=1\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/740ecc8b0234d38c.svg\" alt=\"z=1+(-1.5)=-0.5\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.5; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (1, 0)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e75a800ad85088f5.svg\" alt=\"1(1)=1\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3798c4898b2e9ea7.svg\" alt=\"1(0)=0\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2707337aabb06170.svg\" alt=\"s=1+0=1\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/740ecc8b0234d38c.svg\" alt=\"z=1+(-1.5)=-0.5\" width=\"238.11\" height=\"24.43\" style=\"width:238.11px;height:24.43px;aspect-ratio:238.11/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = -0.5; output = 0 because output is 1 exactly when z ≥ 0.</p>","<h3>Input (1, 1)</h3>","<p class=\"worked-step\"><strong>Step 1: multiply input 1 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e75a800ad85088f5.svg\" alt=\"1(1)=1\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: multiply input 2 by its weight.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e75a800ad85088f5.svg\" alt=\"1(1)=1\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two products.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1c8553f39604f98c.svg\" alt=\"s=1+1=2\" width=\"143.15\" height=\"18.27\" style=\"width:143.15px;height:18.27px;aspect-ratio:143.15/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: add the bias once.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/174899e28e234350.svg\" alt=\"z=2+(-1.5)=0.5\" width=\"219.09\" height=\"24.43\" style=\"width:219.09px;height:24.43px;aspect-ratio:219.09/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: apply the stated threshold.</strong></p>","<p>z = 0.5; output = 1 because output is 1 exactly when z ≥ 0.</p>","<p><strong>Final answer:</strong> outputs are [0, 0, 0, 1] for inputs 00, 01, 10, 11: exactly AND.</p>","<p>A hidden layer is unnecessary for this linearly separable truth table.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/and_perceptron.svg\" aria-label=\"Enlarge diagram: Two inputs with weights one and bias minus one point five implement AND\"><img src=\"assets/figures/and_perceptron.svg\" alt=\"Two inputs with weights one and bias minus one point five implement AND\" width=\"960\" height=\"425\" loading=\"lazy\"></button><figcaption>Two inputs with weights one and bias minus one point five implement AND <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c16-s4","search":"R23 Q1e **Question (4 marks).** Design a perceptron network for inputs 00 → 0,10 → 0,01 → 0,11 → 1; choose suitable weights.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nTruth table: 00→0,10→0,01→0,11→1.\n\nWeights and bias are to be designed.\n\n### To find\n\nChoose a perceptron that implements AND and show its four outputs.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\nChoose weights w₁ = w₂ = 1 and bias −1.5. Use output 1 for z ≥ 0.\n\n### Input (0, 0)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -1.5; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (0, 1)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.5; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (1, 0)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = -0.5; output = 0 because output is 1 exactly when z ≥ 0.\n\n\n### Input (1, 1)\n\n**Step 1: multiply input 1 by its weight.**\n\n\n\n\n\n\n\n**Step 2: multiply input 2 by its weight.**\n\n\n\n\n\n\n\n**Step 3: add the two products.**\n\n\n\n\n\n\n\n**Step 4: add the bias once.**\n\n\n\n\n\n\n\n**Step 5: apply the stated threshold.**\n\nz = 0.5; output = 1 because output is 1 exactly when z ≥ 0.\n\n**Final answer:** outputs are [0, 0, 0, 1] for inputs 00, 01, 10, 11: exactly AND.\n\nA hidden layer is unnecessary for this linearly separable truth table.\n\n"},{"title":"R23 Q2a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A CNN with convolution, pooling, dense and output layers receives 127 × 127 images for 5 classes and trains with Adam. Identify learned parameters and tunable hyperparameters.</p>"],"answer":["<p>Convolutional kernel entries and filter biases are learned parameters. Dense weight matrices and biases are learned parameters. Pooling, flattening and ordinary activations have no learned weights. The output has 5 class scores and usually softmax with categorical cross-entropy. Adam’s m, v are running optimizer states, not extra predictive parameters.</p>","<p>Hyperparameters include kernel sizes, filter counts, strides, padding, pooling configuration, dense widths, activations, learning rate, Adam β₁/β₂/ε, batch size, epochs and regularization. Architecture choices control representation capacity and resource demand; optimizer settings control update behavior. No filter counts or dense widths are specified, so a unique numerical parameter total cannot be calculated from 127 × 127 and 5 classes alone.</p>","<p>Adam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.71px;--narrow-height:202.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92678247acd594b0.svg\"><img class=\"math display-math\" src=\"assets/equations/c443fc0367c152b1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\widehat v_t=\\frac{v_t}{1-\\beta_2^t},\\quad\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"571.98\" height=\"66.85\" style=\"width:571.98px;height:66.85px;aspect-ratio:571.98/66.85\" loading=\"lazy\"></picture></div>","<p>Use update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.</p>","<p>For g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.</p>","<p>Compared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.</p>"],"kind":"practice","id":"tee-c16-s5","search":"R23 Q2a **Question (10 marks).** A CNN with convolution, pooling, dense and output layers receives 127 × 127 images for 5 classes and trains with Adam. Identify learned parameters and tunable hyperparameters.\n\n**Complete worked answer.**\nConvolutional kernel entries and filter biases are learned parameters. Dense weight matrices and biases are learned parameters. Pooling, flattening and ordinary activations have no learned weights. The output has 5 class scores and usually softmax with categorical cross-entropy. Adam’s m, v are running optimizer states, not extra predictive parameters.\nHyperparameters include kernel sizes, filter counts, strides, padding, pooling configuration, dense widths, activations, learning rate, Adam β₁/β₂/ε, batch size, epochs and regularization. Architecture choices control representation capacity and resource demand; optimizer settings control update behavior. No filter counts or dense widths are specified, so a unique numerical parameter total cannot be calculated from 127 × 127 and 5 classes alone.\nAdam combines an exponentially weighted first moment of gradients with a second moment of squared gradients. Both start at zero; early bias correction compensates for this zero initialization.\n\n\nUse update count t = 1 for the first update; t = 0 would make the correction denominator zero. m stores direction with momentum-like smoothing; v stores gradient magnitude information; division by its square root adapts coordinate step sizes. Do not multiply the final fraction by another copy of g.\nFor g₁ = 2, β₁ = 0.9 and β₂ = 0.999, m₁ = 0.2 and v₁ = 0.004. Corrected moments are 2 and 4. With θ₀ = 1, η = 0.1 and negligible ε, θ₁ = 1−0.1 × 2/2 = 0.9.\nCompared with ordinary SGD, Adam often provides a useful adaptive starting point and can cope with uneven or sparse gradient scales. It needs two state arrays per parameter, several hyperparameters and validation of generalization; it is not universally more accurate or guaranteed to converge to the global optimum.\n"},{"title":"R23 Q2b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Justify ReLU over sigmoid/tanh for deep hidden layers. For predicting brand ratings on a scale of 10, choose output activation and loss. Diagnose 2% training versus 18% validation error and suggest remedies.</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>","<p><strong>Rating regression: </strong> for a continuous score, one linear output with MSE is a standard baseline. If strict 0–10 bounds are required, use 10 × sigmoid(z) and the matching regression loss, noting saturation near the endpoints. If labels are categorical rating bins, a categorical formulation would be different; state the continuous-score assumption.</p>","<p><strong>2% versus 18%: </strong> if errors use the same comparable metric and distribution, this large generalization gap strongly suggests overfitting. Use appropriate regularization, early stopping, more representative data and possibly a smaller model; inspect leakage and preprocessing too.</p>","<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>"],"kind":"practice","id":"tee-c16-s6","search":"R23 Q2b **Question (10 marks).** Justify ReLU over sigmoid/tanh for deep hidden layers. For predicting brand ratings on a scale of 10, choose output activation and loss. Diagnose 2% training versus 18% validation error and suggest remedies.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n**Rating regression: ** for a continuous score, one linear output with MSE is a standard baseline. If strict 0–10 bounds are required, use 10 × sigmoid(z) and the matching regression loss, noting saturation near the endpoints. If labels are categorical rating bins, a categorical formulation would be different; state the continuous-score assumption.\n**2% versus 18%: ** if errors use the same comparable metric and distribution, this large generalization gap strongly suggests overfitting. Use appropriate regularization, early stopping, more representative data and possibly a smaller model; inspect leakage and preprocessing too.\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of u"},{"title":"R23 Q3a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Build and train an RNN language model for “Mumbai is the financial capital of Maharashtra.” Draw the architecture and write next-token conditional probabilities at each step.</p>"],"answer":["<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>","<p>Tokenize, build a vocabulary, encode tokens, pair each prefix with its next token, unroll the recurrence, apply vocabulary softmax, sum/average cross-entropy, then use BPTT and an optimizer to update shared weights. Include start/end tokens consistently.</p>","<p><strong>Explicit next-token conditionals ignoring punctuation: </strong></p>","<p>1. P(Mumbai | START).</p>","<p>2. P(is | Mumbai).</p>","<p>3. P(the | Mumbai is).</p>","<p>4. P(financial | Mumbai is the).</p>","<p>5. P(capital | Mumbai is the financial).</p>","<p>6. P(of | Mumbai is the financial capital).</p>","<p>7. P(Maharashtra | Mumbai is the financial capital of).</p>","<p>8. P(END | Mumbai is the financial capital of Maharashtra).</p>","<p>The sequence likelihood is their product; the negative log-likelihood is the sum of negative log conditionals. No numeric probabilities are determined without weights.</p>","<p>Backpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.</p>","<p>1. Initialize the hidden state and run the forward recurrence from the first input to the last.</p>","<p>2. Compute the specified output loss, at the final step or across several steps.</p>","<p>3. Start from the last loss and propagate derivatives backwards through output and hidden operations.</p>","<p>4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.</p>","<p>5. Sum all uses of each shared weight before applying the optimizer update.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:371.04px;--narrow-height:147.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fdf1ee48fdcfd79f.svg\"><img class=\"math display-math\" src=\"assets/equations/43466db031266f9c.svg\" alt=\"\\delta_t=(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1})\\odot(1-h_t^2),\\quad \\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T}\" width=\"623.72\" height=\"62.51\" style=\"width:623.72px;height:62.51px;aspect-ratio:623.72/62.51\" loading=\"lazy\"></picture></div>","<p>The tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: BPTT follows this unrolled network backwards and sums gradients of shared weights\"><img src=\"assets/figures/rnn.svg\" alt=\"BPTT follows this unrolled network backwards and sums gradients of shared weights\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>BPTT follows this unrolled network backwards and sums gradients of shared weights <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"kind":"practice","id":"tee-c16-s7","search":"R23 Q3a **Question (10 marks).** Build and train an RNN language model for “Mumbai is the financial capital of Maharashtra.” Draw the architecture and write next-token conditional probabilities at each step.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\nTokenize, build a vocabulary, encode tokens, pair each prefix with its next token, unroll the recurrence, apply vocabulary softmax, sum/average cross-entropy, then use BPTT and an optimizer to update shared weights. Include start/end tokens consistently.\n**Explicit next-token conditionals ignoring punctuation: **\n1. P(Mumbai | START).\n2. P(is | Mumbai).\n3. P(the | Mumbai is).\n4. P(financial | Mumbai is the).\n5. P(capital | Mumbai is the financial).\n6. P(of | Mumbai is the financial capital).\n7. P(Maharashtra | Mumbai is the financial capital of).\n8. P(END | Mumbai is the financial capital of Maharashtra).\nThe sequence likelihood is their product; the negative log-likelihood is the sum of negative log conditionals. No numeric probabilities are determined without weights.\nBackpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.\n1. Initialize the hidden state and run the forward recurrence from the first input to the last.\n2. Compute the specified output loss, at the final step or across several steps.\n3. Start from the last loss and propagate derivatives backwards through output and hidden operations.\n4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.\n5. Sum all uses of each shared weight before applying the optimizer update.\n\nThe tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.\n\n"},{"title":"R23 Q3b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For input [0.5,0.7,0.8], first-stage multipliers [0.3,0.4,0.6], next receiving rows [0.5,0.2,0.3], [0.3,0.3,0.3], output rows [0.3,0.2], [0.2,0.3], use ReLU in the first two stages and sigmoid at outputs. Targets [0,1], zero biases, η = 0.1. Find predictions, MSE and all four hidden-to-output weight updates.</p>"],"answer":["<h3>Given</h3>","<p>For input [0.5,0.7,0.8], first-stage multipliers [0.3,0.4,0.6], next receiving rows [0.5,0.2,0.3], [0.3,0.3,0.3], output rows [0.3,0.2], [0.2,0.3], use ReLU in the first two stages and sigmoid at outputs.</p>","<p>Targets [0,1], zero biases, η = 0.1.</p>","<h3>To find</h3>","<p>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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Mean squared loss.</strong> Average the squared scalar prediction errors. The derivative retains the factor 2/n; n must count the outputs included in this mean.</p>","<p>n = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f5544f3d0af79c26.svg\" alt=\"L=\\frac1n\\sum_j(o_j-y_j)^2\" width=\"215.65\" height=\"65.25\" style=\"width:215.65px;height:65.25px;aspect-ratio:215.65/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b0ae494a9901408.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=\\frac2n(o_j-y_j)\" width=\"194.57\" height=\"57.94\" style=\"width:194.57px;height:57.94px;aspect-ratio:194.57/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Step 1: evaluate the first ReLU stage</h3>","<p>The raw feature products are [0.5 × 0.3, 0.7 × 0.4, 0.8 × 0.6] = <strong>[0.15, 0.28, 0.48]</strong>. All are positive, so ReLU leaves them unchanged. Biases are zero.</p>","<h3>Step 2: evaluate the second ReLU stage</h3>","<p>h₁ = max(0, 0.5(0.15) + 0.2(0.28) + 0.3(0.48)) = max(0, 0.075 + 0.056 + 0.144) = <strong>0.275</strong>.</p>","<p>h₂ = max(0, 0.3(0.15) + 0.3(0.28) + 0.3(0.48)) = max(0, 0.045 + 0.084 + 0.144) = <strong>0.273</strong>.</p>","<h3>Step 3: evaluate both sigmoid outputs</h3>","<p>z₁ = 0.3(0.275) + 0.2(0.273) = 0.1371; o₁ = σ(z₁) = <strong>0.534221413</strong>.</p>","<p>z₂ = 0.2(0.275) + 0.3(0.273) = 0.1369; o₂ = σ(z₂) = <strong>0.534171647</strong>.</p>","<h3>Step 4: calculate MSE and the output deltas</h3>","<p>MSE = [(o₁ − 0)² + (o₂ − 1)²]/2 = <strong>0.251194286</strong>. There are exactly two output components, so the square derivative&#x27;s factor 2 cancels the division by 2.</p>","<p>δ₁ = (o₁ − 0)o₁(1 − o₁) = <strong>0.132929724</strong>.</p>","<p>δ₂ = (o₂ − 1)o₂(1 − o₂) = <strong>−0.115913140</strong>.</p>","<h3>Step 5: calculate each output-weight gradient</h3>","<p>A weight gradient equals its receiving output delta multiplied by its sending hidden activation. Use the same old forward pass for all four connections.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Connection</th><th>Gradient calculation</th><th>Gradient</th></tr></thead><tbody><tr><td>h₁ → o₁</td><td>0.132929724 × 0.275</td><td>0.036555674</td></tr><tr><td>h₂ → o₁</td><td>0.132929724 × 0.273</td><td>0.036289815</td></tr><tr><td>h₁ → o₂</td><td>−0.115913140 × 0.275</td><td>−0.031876113</td></tr><tr><td>h₂ → o₂</td><td>−0.115913140 × 0.273</td><td>−0.031644287</td></tr></tbody></table></div>","<h3>Step 6: subtract learning rate times each gradient</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Connection</th><th>Update at η = 0.1</th><th>New weight</th></tr></thead><tbody><tr><td>h₁ → o₁</td><td>0.3 − 0.1(0.036555674)</td><td>0.296344433</td></tr><tr><td>h₂ → o₁</td><td>0.2 − 0.1(0.036289815)</td><td>0.196371019</td></tr><tr><td>h₁ → o₂</td><td>0.2 − 0.1(−0.031876113)</td><td>0.203187611</td></tr><tr><td>h₂ → o₂</td><td>0.3 − 0.1(−0.031644287)</td><td>0.303164429</td></tr></tbody></table></div>","<p><strong>Final answer:</strong> predictions [0.534221413, 0.534171647], MSE 0.251194286, and output-weight rows <strong>[0.296344433, 0.196371019]</strong>, <strong>[0.203187611, 0.303164429]</strong>. The positive gradients decrease weights feeding output 1, while the negative gradients increase weights feeding output 2.</p>"],"kind":"practice","id":"tee-c16-s8","search":"R23 Q3b **Question (10 marks).** For input [0.5,0.7,0.8], first-stage multipliers [0.3,0.4,0.6], next receiving rows [0.5,0.2,0.3], [0.3,0.3,0.3], output rows [0.3,0.2], [0.2,0.3], use ReLU in the first two stages and sigmoid at outputs. Targets [0,1], zero biases, η = 0.1. Find predictions, MSE and all four hidden-to-output weight updates.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nFor input [0.5,0.7,0.8], first-stage multipliers [0.3,0.4,0.6], next receiving rows [0.5,0.2,0.3], [0.3,0.3,0.3], output rows [0.3,0.2], [0.2,0.3], use ReLU in the first two stages and sigmoid at outputs.\n\nTargets [0,1], zero biases, η = 0.1.\n\n### To find\n\nFind 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**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\nn = number of scalar prediction errors in the stated mean; oⱼ = prediction; yⱼ = target.\n\n\n\n\n\n**Yaad rakhne ka cue:** MSE mein derivative 2/n times error; half SSE ka rule blindly mat lagao.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n### Step 1: evaluate the first ReLU stage\nThe raw feature products are [0.5 × 0.3, 0.7 × 0.4, 0.8 × 0.6] = **[0.15, 0.28, 0.48]**. All are positive, so ReLU leaves them unchanged. Biases are zero.\n\n### Step 2: evaluate the second ReLU stage\nh₁ = max(0, 0.5(0.15) + 0.2(0.28) + 0.3(0.48)) = max(0, 0.075 + 0.056 + 0.144) = **0.275**.\n\nh₂ = max(0, 0.3(0.15) + 0.3(0.28) + 0.3(0.48)) = max(0, 0.045 + 0.084 + 0.144) = **0.273**.\n\n### Step 3: evaluate both sigmoid outputs\nz₁ = 0.3(0.275) + 0.2(0.273) = 0.1371; o₁ = σ(z₁) = **0.534221413**.\n\nz₂ = 0.2(0.275) + 0.3(0.273) = 0.1369; o₂ = σ(z₂) = **0.534171647**.\n\n### Step 4: calculate MSE and the output deltas\nMSE = [(o₁ − 0)² + (o₂ − 1)²]/2 = **0.251194286**. There are exactly two output components, so the square derivative's factor 2 cancels the division by 2.\n\nδ₁ = (o₁ − 0)o₁(1 − o₁) = **0.132929724**.\n\nδ₂ = (o₂ − 1)o₂(1 − o₂) = **−0.115913140**.\n\n### Step 5: calculate each"},{"title":"R23 Q4a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design employee face-recognition attendance using a CNN with too few training images. Explain solutions.</p>"],"answer":["<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>"],"kind":"practice","id":"tee-c16-s9","search":"R23 Q4a **Question (10 marks).** Design employee face-recognition attendance using a CNN with too few training images. Explain solutions.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n"},{"title":"R23 Q4b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Estimate parameters of the AlexNet diagram. Use Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.</p>"],"answer":["<h3>Given</h3>","<p>Use Input 227 × 227 × 3.</p>","<p>Conv K = 11, filters = 96, stride = 4, padding = 0.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 5, filters = 256, stride = 1, padding = 2.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 384, stride = 1, padding = 1.</p>","<p>Conv K = 3, filters = 256, stride = 1, padding = 1.</p>","<p>Pool K = 3, stride = 2, padding = 0.</p>","<p>Dense 4096 units.</p>","<p>Dense 4096 units.</p>","<p>Dense 1000 units.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">227 × 227 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">96 filters · 11 × 11 · S = 4 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">34,848</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">96</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">34,944</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>227 × 227 × 3</strong>. Use 96 filters of spatial size 11 × 11, stride 4, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.10px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/441a061296efda7a.svg\"><img class=\"math display-math\" src=\"assets/equations/1ca643e3f874dc98.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{227+2(0)-11}{4}\\right\\rfloor+1=55\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>55 × 55 × 96</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9a11e5db4a09d338.svg\"><img class=\"math display-math\" src=\"assets/equations/e8a26a7b03e38af6.svg\" alt=\"N_{\\mathrm{weights}}=11\\times11\\times3\\times96=34{,}848\" width=\"386.55\" height=\"23.91\" style=\"width:386.55px;height:23.91px;aspect-ratio:386.55/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a3b19ed994769f54.svg\" alt=\"N_{\\mathrm{biases}}=96\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ae51bc20750a112f.svg\" alt=\"P_1=34{,}848+96=34{,}944\" width=\"281.59\" height=\"21.43\" style=\"width:281.59px;height:21.43px;aspect-ratio:281.59/21.43\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">55 × 55 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>55 × 55 × 96</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d42806d80c07005c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1=27\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>27 × 27 × 96</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 96</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 5 × 5 · S = 1 · P = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">614,400</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">614,656</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>27 × 27 × 96</strong>. Use 256 filters of spatial size 5 × 5, stride 1, and padding 2 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f4e102905e6bf9f.svg\"><img class=\"math display-math\" src=\"assets/equations/da9a62eaf99ea1e8.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27+2(2)-5}{1}\\right\\rfloor+1=27\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>27 × 27 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 96 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b720c78ffc948913.svg\"><img class=\"math display-math\" src=\"assets/equations/05edf5328cb35876.svg\" alt=\"N_{\\mathrm{weights}}=5\\times5\\times96\\times256=614{,}400\" width=\"398.77\" height=\"23.91\" style=\"width:398.77px;height:23.91px;aspect-ratio:398.77/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29c935e56c01ee26.svg\"><img class=\"math display-math\" src=\"assets/equations/67ebf4d50d295918.svg\" alt=\"P_3=614{,}400+256=614{,}656\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">27 × 27 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>27 × 27 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ca522f15a3632877.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1=13\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 5 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">885,120</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 256 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/492d70515e0406f9.svg\"><img class=\"math display-math\" src=\"assets/equations/0f457ff5f3c6b74f.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times256\\times384=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e9338e40808aff5.svg\"><img class=\"math display-math\" src=\"assets/equations/0cca75bb5a08cdeb.svg\" alt=\"P_5=884{,}736+384=885{,}120\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 6 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">384 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">1,327,104</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">384</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">1,327,488</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 384 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 384</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3729f79bf2b69fab.svg\"><img class=\"math display-math\" src=\"assets/equations/a2fb560ecf5f18c3.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times384=1{,}327{,}104\" width=\"429.99\" height=\"23.91\" style=\"width:429.99px;height:23.91px;aspect-ratio:429.99/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/558f11bf6ad2aa25.svg\" alt=\"N_{\\mathrm{biases}}=384\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4565bf3714918ad3.svg\"><img class=\"math display-math\" src=\"assets/equations/8d8b08cc6480d083.svg\" alt=\"P_6=1{,}327{,}104+384=1{,}327{,}488\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 384</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">256 filters · 3 × 3 · S = 1 · P = 1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">884,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">256</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">884,992</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>13 × 13 × 384</strong>. Use 256 filters of spatial size 3 × 3, stride 1, and padding 1 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1fa159221b64b09.svg\"><img class=\"math display-math\" src=\"assets/equations/3eda49dc7f4fca09.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13+2(1)-3}{1}\\right\\rfloor+1=13\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>13 × 13 × 256</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 384 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.78px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/be0b63ec1f7ffb8c.svg\"><img class=\"math display-math\" src=\"assets/equations/42a81620f94360dd.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times384\\times256=884{,}736\" width=\"410.98\" height=\"23.91\" style=\"width:410.98px;height:23.91px;aspect-ratio:410.98/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96c4c1de3aa70d55.svg\" alt=\"N_{\\mathrm{biases}}=256\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c304d00633ff2322.svg\"><img class=\"math display-math\" src=\"assets/equations/a803766772104e69.svg\" alt=\"P_7=884{,}736+256=884{,}992\" width=\"318.23\" height=\"21.43\" style=\"width:318.23px;height:21.43px;aspect-ratio:318.23/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">13 × 13 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">3 × 3 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>13 × 13 × 256</strong>. Use a 3 × 3 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/117abcc38db86957.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1=6\" width=\"271.85\" height=\"58.62\" style=\"width:271.85px;height:58.62px;aspect-ratio:271.85/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>6 × 6 × 256</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 9 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 9: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">6 × 6 × 256</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>6 × 6 × 256</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d9921c92554e599.svg\" alt=\"n_{\\mathrm{flat}}=6\\times6\\times256=9{,}216\" width=\"283.79\" height=\"21.02\" style=\"width:283.79px;height:21.02px;aspect-ratio:283.79/21.02\" loading=\"lazy\"></div>","<p>Output: a vector with <strong>9,216 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 10 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 10: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">9,216</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">37,748,736</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">37,752,832</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>9,216 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/253a54d671a02309.svg\"><img class=\"math display-math\" src=\"assets/equations/864d5792c1506a4b.svg\" alt=\"N_{\\mathrm{weights}}=9{,}216\\times4{,}096=37{,}748{,}736\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a6d14bbf5757207.svg\"><img class=\"math display-math\" src=\"assets/equations/42e41d5d625e4b33.svg\" alt=\"P_10=37{,}748{,}736+4{,}096=37{,}752{,}832\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 11 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 11: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">4,096 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">16,777,216</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">4,096</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">16,781,312</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>4,096 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe4cfd667cc7b7ce.svg\"><img class=\"math display-math\" src=\"assets/equations/37f33b938916c485.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times4{,}096=16{,}777{,}216\" width=\"396.06\" height=\"23.91\" style=\"width:396.06px;height:23.91px;aspect-ratio:396.06/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc9a0e4319a0da43.svg\" alt=\"N_{\\mathrm{biases}}=4{,}096\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.44px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3652163d527344ad.svg\"><img class=\"math display-math\" src=\"assets/equations/ca42e0122e881f05.svg\" alt=\"P_11=16{,}777{,}216+4{,}096=16{,}781{,}312\" width=\"411.92\" height=\"21.43\" style=\"width:411.92px;height:21.43px;aspect-ratio:411.92/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 12 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 12: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">4,096</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">1,000 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">1,000</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,096,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">1,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,097,000</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>4,096 features</strong>. Output: <strong>1,000 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.15px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3d7876f0d5fdb4fa.svg\"><img class=\"math display-math\" src=\"assets/equations/a47853490ec706c7.svg\" alt=\"N_{\\mathrm{weights}}=4{,}096\\times1{,}000=4{,}096{,}000\" width=\"383.84\" height=\"23.91\" style=\"width:383.84px;height:23.91px;aspect-ratio:383.84/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d0008f88a44995b2.svg\" alt=\"N_{\\mathrm{biases}}=1{,}000\" width=\"154.23\" height=\"21.43\" style=\"width:154.23px;height:21.43px;aspect-ratio:154.23/21.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3adeefbc3dbe4d6b.svg\"><img class=\"math display-math\" src=\"assets/equations/91b7bd4147e4b8d6.svg\" alt=\"P_12=4{,}096{,}000+1{,}000=4{,}097{,}000\" width=\"387.48\" height=\"21.43\" style=\"width:387.48px;height:21.43px;aspect-ratio:387.48/21.43\" loading=\"lazy\"></picture></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/74235148b2b7312a.svg\" alt=\"\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\" width=\"199.47\" height=\"45.60\" style=\"width:199.47px;height:45.60px;aspect-ratio:199.47/45.60\" loading=\"lazy\"></span></td><td>55 x 55 x 96</td><td>34,848</td><td>96</td><td>34,944</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cdac8f1c682bc40a.svg\" alt=\"\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 96</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/71046f85d0cc0ca5.svg\" alt=\"\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>27 x 27 x 256</td><td>614,400</td><td>256</td><td>614,656</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/55802f10aac3668d.svg\" alt=\"\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>884,736</td><td>384</td><td>885,120</td></tr><tr><td>6 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 384</td><td>1,327,104</td><td>384</td><td>1,327,488</td></tr><tr><td>7 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e30499da6b8e9d4a.svg\" alt=\"\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>13 x 13 x 256</td><td>884,736</td><td>256</td><td>884,992</td></tr><tr><td>8 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/73ab07c24eb836b2.svg\" alt=\"\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>6 x 6 x 256</td><td>0</td><td>0</td><td>0</td></tr><tr><td>9 flat</td><td>6 × 6 × 256</td><td>9216</td><td>0</td><td>0</td><td>0</td></tr><tr><td>10 dense</td><td>9216 → 4096</td><td>4096</td><td>37,748,736</td><td>4,096</td><td>37,752,832</td></tr><tr><td>11 dense</td><td>4096 → 4096</td><td>4096</td><td>16,777,216</td><td>4,096</td><td>16,781,312</td></tr><tr><td>12 dense</td><td>4096 → 1000</td><td>1000</td><td>4,096,000</td><td>1,000</td><td>4,097,000</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (11 x 11 x 3 + 1) x 96 = 34,944.</p>","<p>Layer 3: (5 x 5 x 96 + 1) x 256 = 614,656.</p>","<p>Layer 5: (3 x 3 x 256 + 1) x 384 = 885,120.</p>","<p>Layer 6: (3 x 3 x 384 + 1) x 384 = 1,327,488.</p>","<p>Layer 7: (3 x 3 x 384 + 1) x 256 = 884,992.</p>","<p>Layer 10: (9216 + 1) x 4096 = 37,752,832.</p>","<p>Layer 11: (4096 + 1) x 4096 = 16,781,312.</p>","<p>Layer 12: (4096 + 1) x 1000 = 4,097,000.</p>","<p><strong>Total: </strong> 34,944 + 614,656 + 885,120 + 1,327,488 + 884,992 + 37,752,832 + 16,781,312 + 4,097,000 = <strong>62,378,344 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p>The diagram labels its final pooled map 6 × 6 × 256; a 3 × 3, stride 2 pool from 13 × 13 produces 6. If a small printed stride label is read as 3, it conflicts with the shown 6 × 6 map. The answer uses the consistent classic stride 2 interpretation. Original grouped AlexNet counts are a different architecture assumption.</p>"],"kind":"practice","id":"tee-c16-s10","search":"R23 Q4b **Question (10 marks).** Estimate parameters of the AlexNet diagram. Use Input 227 × 227 × 3. → Conv K = 11, filters = 96, stride = 4, padding = 0. → Pool K = 3, stride = 2, padding = 0. → Conv K = 5, filters = 256, stride = 1, padding = 2. → Pool K = 3, stride = 2, padding = 0. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 384, stride = 1, padding = 1. → Conv K = 3, filters = 256, stride = 1, padding = 1. → Pool K = 3, stride = 2, padding = 0. → Flatten. → Dense 4096 units. → Dense 4096 units. → Dense 1000 units.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nUse Input 227 × 227 × 3.\n\nConv K = 11, filters = 96, stride = 4, padding = 0.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 5, filters = 256, stride = 1, padding = 2.\n\nPool K = 3, stride = 2, padding = 0.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 384, stride = 1, padding = 1.\n\nConv K = 3, filters = 256, stride = 1, padding = 1.\n\nPool K = 3, stride = 2, padding = 0.\n\nDense 4096 units.\n\nDense 4096 units.\n\nDense 1000 units.\n\n### To find\n\nFind every layer shape, its parameter count and the network total.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{227+2 \\times  0-11}{4}\\right\\rfloor+1\\) | 55 x 55 x 96 | 34,848 | 96 | 34,944 |\n| 2 pool | \\(\\left\\lfloor\\frac{55-3}{2}\\right\\rfloor+1\\) | 27 x 27 x 96 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{27+2 \\times  2-5}{1}\\right\\rfloor+1\\) | 27 x 27 x 256 | 614,400 | 256 | 614,656 |\n| 4 pool | \\(\\left\\lfloor\\frac{27-3}{2}\\right\\rfloor+1\\) | 13 x 13 x 256 | 0 | 0 | 0 |\n| 5 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 884,736 | 384 | 885,120 |\n| 6 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 384 | 1,327,104 | 384 | 1,327,488 |\n| 7 conv | \\(\\left\\lfloor\\frac{13+2 \\times  1-3}{1}\\right\\rfloor+1\\) | 13 x 13 x 256 | 884,736 | 256 | 884,992 |\n| 8 pool | \\(\\left\\lfloor\\frac{13-3}{2}\\right\\rfloor+1\\) | 6 x 6 x 256 | 0 | 0 | 0 |\n| 9 flat | 6 × 6 × 256 | 9216 | 0 | 0 | 0 |\n| 10 dense | 9216 → 4096 | 4096 | 37,748,736 | 4,096 | 37,752,832 |\n| 11 dense | 4096 → 4096 | 4096 | 16,777,216 | 4,096 | 16,781,312 |\n| 12 dense | 4096 → 1000 | 1000 | 4,096,000 | 1,000 | 4,097,000 |\n**Parameter substitutions, in layer order: **\nLayer 1: (11 x 11 x 3 + 1) x 96 = 34,944.\nLayer 3: (5 x 5 x 96 + 1) x 256 = 614,656.\nLayer 5: (3 x 3 x 256 + 1) x 384 = 885,120.\nLayer 6: (3 x 3 x 384 + 1) x 384 = 1,327,488.\nLayer 7: (3 x 3 x 384 + 1) x 256 = 884,992.\nLayer 10: (9216 + 1) x 4096 = 3"},{"title":"R23 Q5a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> An RNN does not improve because vanishing gradients prevent useful parameter updates. Suggest a solution and explain required architectural changes.</p>"],"answer":["<p>Backpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.</p>","<p>1. Initialize the hidden state and run the forward recurrence from the first input to the last.</p>","<p>2. Compute the specified output loss, at the final step or across several steps.</p>","<p>3. Start from the last loss and propagate derivatives backwards through output and hidden operations.</p>","<p>4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.</p>","<p>5. Sum all uses of each shared weight before applying the optimizer update.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:371.04px;--narrow-height:147.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fdf1ee48fdcfd79f.svg\"><img class=\"math display-math\" src=\"assets/equations/43466db031266f9c.svg\" alt=\"\\delta_t=(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1})\\odot(1-h_t^2),\\quad \\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T}\" width=\"623.72\" height=\"62.51\" style=\"width:623.72px;height:62.51px;aspect-ratio:623.72/62.51\" loading=\"lazy\"></picture></div>","<p>The tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: BPTT follows this unrolled network backwards and sums gradients of shared weights\"><img src=\"assets/figures/rnn.svg\" alt=\"BPTT follows this unrolled network backwards and sums gradients of shared weights\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>BPTT follows this unrolled network backwards and sums gradients of shared weights <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Replace the vanilla cell with an LSTM or GRU while preserving a suitable sequence output. An LSTM introduces cell state and learned forget, input, output gates; a GRU introduces reset/update gates and a gated hidden-state mixture. These paths make retaining long context easier. Tune initialization and learning rate and inspect gradients.</p>","<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>"],"kind":"practice","id":"tee-c16-s11","search":"R23 Q5a **Question (10 marks).** An RNN does not improve because vanishing gradients prevent useful parameter updates. Suggest a solution and explain required architectural changes.\n\n**Complete worked answer.**\nBackpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.\n1. Initialize the hidden state and run the forward recurrence from the first input to the last.\n2. Compute the specified output loss, at the final step or across several steps.\n3. Start from the last loss and propagate derivatives backwards through output and hidden operations.\n4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.\n5. Sum all uses of each shared weight before applying the optimizer update.\n\nThe tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.\n\nReplace the vanilla cell with an LSTM or GRU while preserving a suitable sequence output. An LSTM introduces cell state and learned forget, input, output gates; a GRU introduces reset/update gates and a gated hidden-state mixture. These paths make retaining long context easier. Tune initialization and learning rate and inspect gradients.\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\n"},{"title":"R23 Q5b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Justify multiple ANN layers. Design a fraudulent/non-fraudulent transaction classifier for 10,000 samples with 4 features; choose layers/units and count parameters.</p>"],"answer":["<h3>Given</h3>","<p>10,000 samples; 4 features per sample; two target classes: fraudulent/non-fraudulent.</p>","<p>Hidden layer sizes are design choices, not fixed in the question.</p>","<h3>To find</h3>","<p>Explain multiple layers, propose an appropriate classifier and count parameters for that explicit design.</p>","<h3>Formula — which one and why</h3>","<p><strong>Dense-layer parameters.</strong> Every output neuron receives every input, so multiply inputs by outputs for weights. Add one bias per receiving neuron. Sum separate layers.</p>","<p>n_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/494312d0893d20d2.svg\" alt=\"P=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"184.79\" height=\"24.43\" style=\"width:184.79px;height:24.43px;aspect-ratio:184.79/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output ke liye saare inputs plus ek bias.</p>","<h3>Solution — step by step</h3>","<p>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.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/xor.svg\" aria-label=\"Enlarge diagram: Opposite corners for XOR cannot be split by one straight line\"><img src=\"assets/figures/xor.svg\" alt=\"Opposite corners for XOR cannot be split by one straight line\" width=\"960\" height=\"430\" loading=\"lazy\"></button><figcaption>Opposite corners for XOR cannot be split by one straight line <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>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.</p>","<p>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.</p>","<p>A multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.</p>","<p><strong>Chosen design: </strong>4 → 8 → 4 → 1 with ReLU hidden layers, one sigmoid output and binary cross-entropy. Hidden widths are explicit design assumptions.</p>","<p>Architecture: 4 → 8 → 4 → 1. Each non-input neuron has one bias.</p>","<h3>Layer 4 → 8</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69e92d1e9a3f1ea7.svg\" alt=\"4(8)=32\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 8 receiving neurons, so 8 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b223db7a6cdbf384.svg\" alt=\"32+8=40\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<h3>Layer 8 → 4</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e2ee029f7f3db879.svg\" alt=\"8(4)=32\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 4 receiving neurons, so 4 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c052c15ffd718757.svg\" alt=\"32+4=36\" width=\"123.54\" height=\"18.54\" style=\"width:123.54px;height:18.54px;aspect-ratio:123.54/18.54\" loading=\"lazy\"></div>","<h3>Layer 4 → 1</h3>","<p class=\"worked-step\"><strong>Step 1: count connections.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6d1e399cd2e46091.svg\" alt=\"4(1)=4\" width=\"88.25\" height=\"24.43\" style=\"width:88.25px;height:24.43px;aspect-ratio:88.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count receiving-neuron biases.</strong></p>","<p>There are 1 receiving neurons, so 1 biases.</p>","<p class=\"worked-step\"><strong>Step 3: add weights and biases.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c79fa7cad3c69e9.svg\" alt=\"4+1=5\" width=\"99.10\" height=\"18.54\" style=\"width:99.10px;height:18.54px;aspect-ratio:99.10/18.54\" loading=\"lazy\"></div>","<p><strong>Total = 81</strong>. Input values and activations are not trainable parameters.</p>","<p>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.</p>","<h3>Verify input (0,0)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aac6904086092425.svg\" alt=\"z_1=0+0-0.5=-0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/738e2d766424863e.svg\" alt=\"h_1=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad20a476f045fd25.svg\" alt=\"z_2=0+0-1.5=-1.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1de867d02667e910.svg\" alt=\"h_2=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65c6f2e86202561b.svg\"><img class=\"math display-math\" src=\"assets/equations/d3b2998fcd8ceee6.svg\" alt=\"z_{XOR}=0-2(0)-0.5=-0.5\" width=\"316.44\" height=\"24.43\" style=\"width:316.44px;height:24.43px;aspect-ratio:316.44/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3624761b5a00605.svg\" alt=\"y_{XOR}=0\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/458da5139ca95df2.svg\"><img class=\"math display-math\" src=\"assets/equations/824ad51bf0e571df.svg\" alt=\"z_{XNOR}=-0+2(0)+0.5=0.5\" width=\"331.79\" height=\"24.43\" style=\"width:331.79px;height:24.43px;aspect-ratio:331.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/016b62d9d7436c82.svg\" alt=\"y_{XNOR}=1\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<h3>Verify input (0,1)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90f88a492c8d4d66.svg\" alt=\"z_1=0+1-0.5=0.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6025713e0c4b56ee.svg\" alt=\"h_1=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60ef65c2ea0ecf5f.svg\" alt=\"z_2=0+1-1.5=-0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1de867d02667e910.svg\" alt=\"h_2=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ee6edf14f171730.svg\"><img class=\"math display-math\" src=\"assets/equations/2d91f383d484e960.svg\" alt=\"z_{XOR}=1-2(0)-0.5=0.5\" width=\"297.43\" height=\"24.43\" style=\"width:297.43px;height:24.43px;aspect-ratio:297.43/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/43f7e4fce3fb5771.svg\" alt=\"y_{XOR}=1\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fbcbb7c54a55ba6f.svg\"><img class=\"math display-math\" src=\"assets/equations/573087efcdde0646.svg\" alt=\"z_{XNOR}=-1+2(0)+0.5=-0.5\" width=\"350.79\" height=\"24.43\" style=\"width:350.79px;height:24.43px;aspect-ratio:350.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51f578d6708881af.svg\" alt=\"y_{XNOR}=0\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<h3>Verify input (1,0)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/318ee2a6640d10f0.svg\" alt=\"z_1=1+0-0.5=0.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6025713e0c4b56ee.svg\" alt=\"h_1=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6d1cd15a27d9572e.svg\" alt=\"z_2=1+0-1.5=-0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1de867d02667e910.svg\" alt=\"h_2=0\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ee6edf14f171730.svg\"><img class=\"math display-math\" src=\"assets/equations/2d91f383d484e960.svg\" alt=\"z_{XOR}=1-2(0)-0.5=0.5\" width=\"297.43\" height=\"24.43\" style=\"width:297.43px;height:24.43px;aspect-ratio:297.43/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/43f7e4fce3fb5771.svg\" alt=\"y_{XOR}=1\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fbcbb7c54a55ba6f.svg\"><img class=\"math display-math\" src=\"assets/equations/573087efcdde0646.svg\" alt=\"z_{XNOR}=-1+2(0)+0.5=-0.5\" width=\"350.79\" height=\"24.43\" style=\"width:350.79px;height:24.43px;aspect-ratio:350.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51f578d6708881af.svg\" alt=\"y_{XNOR}=0\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<h3>Verify input (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: calculate hidden OR preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/285947e47dfebe51.svg\" alt=\"z_1=1+1-0.5=1.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6025713e0c4b56ee.svg\" alt=\"h_1=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate hidden AND preactivation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86c5a45ae836809c.svg\" alt=\"z_2=1+1-1.5=0.5\" width=\"233.83\" height=\"19.94\" style=\"width:233.83px;height:19.94px;aspect-ratio:233.83/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply its threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/397f5515899ffae5.svg\" alt=\"h_2=1\" width=\"69.54\" height=\"20.63\" style=\"width:69.54px;height:20.63px;aspect-ratio:69.54/20.63\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate XOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.61px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd1914e888d3b3fb.svg\"><img class=\"math display-math\" src=\"assets/equations/eac20b8fec07829f.svg\" alt=\"z_{XOR}=1-2(1)-0.5=-1.5\" width=\"316.44\" height=\"24.43\" style=\"width:316.44px;height:24.43px;aspect-ratio:316.44/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: apply the XOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3624761b5a00605.svg\" alt=\"y_{XOR}=0\" width=\"99.82\" height=\"21.29\" style=\"width:99.82px;height:21.29px;aspect-ratio:99.82/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: calculate XNOR output preactivation.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.87px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ce164dbb1fd1549.svg\"><img class=\"math display-math\" src=\"assets/equations/7d050e174f67d846.svg\" alt=\"z_{XNOR}=-1+2(1)+0.5=1.5\" width=\"331.79\" height=\"24.43\" style=\"width:331.79px;height:24.43px;aspect-ratio:331.79/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: apply the XNOR threshold.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/016b62d9d7436c82.svg\" alt=\"y_{XNOR}=1\" width=\"115.16\" height=\"21.29\" style=\"width:115.16px;height:21.29px;aspect-ratio:115.16/21.29\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> XOR = [0,1,1,0]; XNOR = [1,0,0,1] for 00,01,10,11. The hidden nonlinear units make this possible.</p>"],"kind":"practice","id":"tee-c16-s12","search":"R23 Q5b **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.\n\n**Complete worked answer.**\n\n\n\n### Given\n\n10,000 samples; 4 features per sample; two target classes: fraudulent/non-fraudulent.\n\nHidden layer sizes are design choices, not fixed in the question.\n\n### To find\n\nExplain multiple layers, propose an appropriate classifier and count parameters for that explicit design.\n\n### Formula — which one and why\n\n**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\nn_in = incoming features; n_out = receiving neurons. The input layer itself has no learned receiving weights or biases.\n\n\n\n**Yaad rakhne ka cue:** Har output ke liye saare inputs plus ek bias.\n\n### Solution — step by step\n\n\n\n\n\n\nA 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.\n\nFor 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.\nFor 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.\nA multilayer feedforward network adds hidden nonlinear features before the final boundary. Without hidden nonlinearities, adding linear layers still produces one affine map.\n**Chosen design: **4 → 8 → 4 → 1 with ReLU hidden layers, one sigmoid output and binary cross-entropy. Hidden widths are explicit design assumptions.\nArchitecture: 4 → 8 → 4 → 1. Each non-input neuron has one bias.\n### Layer 4 → 8\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 8 receiving neurons, so 8 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 8 → 4\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 4 receiving neurons, so 4 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n### Layer 4 → 1\n\n**Step 1: count connections.**\n\n\n\n\n\n\n\n**Step 2: count receiving-neuron biases.**\n\nThere are 1 receiving neurons, so 1 biases.\n\n**Step 3: add weights and biases.**\n\n\n\n\n\n\n\n\n**Total = 81**. Input values and activations are not trainable parameters.\nUse 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.\n\n\n### Verify input (0,0)\n\n**Step 1: calculate hidden OR preactivation.**\n\n\n\n\n\n\n\n**Step 2: apply its threshold.**\n\n\n\n\n\n\n\n**Step 3: calculate hidden AND preactivation.**\n\n\n\n\n\n\n\n**Step 4: apply its threshold.**\n\n\n\n\n\n\n\n**Step 5: calculate XOR output preactivation.**\n\n\n\n\n\n\n\n**Step 6: apply the XOR threshold.**\n\n\n\n\n\n\n\n**Step 7: calculate XNOR output preactivation.**\n\n\n\n\n\n\n\n**Step 8: apply the XNOR threshold.**\n\n\n\n\n\n\n\n\n### Verify input (0"},{"title":"R23 Q6a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Suggest and justify remedies when (1) loss does not minimize after many epochs, (2) gradients are noisy and loss oscillates, (3) loss falls then rises because updates miss a minimum.</p>"],"answer":["<p>The learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative full batch and stochastic traces distinguish smoothness from progress\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative full batch and stochastic traces distinguish smoothness from progress\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative full batch and stochastic traces distinguish smoothness from progress <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Batch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.</p>","<p>Momentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.</p>","<p>Diagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.</p>","<p><strong>Scenario 1: </strong> check correctness and gradient magnitudes, then tune learning rate, activation, initialization or optimizer. <strong>Scenario 2: </strong> consider an appropriate larger mini-batch or momentum; distinguish ordinary stochastic noise from divergence. <strong>Scenario 3: </strong> reduce learning rate or use a schedule; momentum/Nesterov can help but excessive momentum can worsen overshoot. Judge training and validation curves separately.</p>"],"kind":"practice","id":"tee-c16-s13","search":"R23 Q6a **Question (10 marks).** Suggest and justify remedies when (1) loss does not minimize after many epochs, (2) gradients are noisy and loss oscillates, (3) loss falls then rises because updates miss a minimum.\n\n**Complete worked answer.**\nThe learning rate η determines update size: θ new = θ old − ηg. A rate that is too small can make progress extremely slow; one that is too large can overshoot, oscillate or diverge. Nonconvex objectives can contain flat regions, saddle points and local minima. Poor scaling can cause long zig-zag paths; vanishing or exploding gradients can make training ineffective or unstable.\n\nBatch gradient descent uses all N samples per update, SGD uses one sample, and mini-batch uses B samples. Batch updates are less noisy for a fixed dataset but costly; SGD makes frequent noisy updates; mini-batches balance vectorized computation and stochasticity. Data need not all reside in memory even for a full gradient because gradients can be accumulated, but larger simultaneous batches require more activation memory.\nMomentum accumulates a running direction, helping movement persist across consistent gradients and damping some oscillation. Mini-batching describes which data forms a gradient; momentum describes how that gradient is used. They can be combined, so they are not competing categories.\nDiagnose stalled training by checking data, preprocessing, losses and gradients before blindly adding layers. Compare training and validation curves, tune learning rate, inspect saturation and use appropriate initialization or adaptive optimization. A noisy curve with a decreasing trend can be normal for SGD.\n**Scenario 1: ** check correctness and gradient magnitudes, then tune learning rate, activation, initialization or optimizer. **Scenario 2: ** consider an appropriate larger mini-batch or momentum; distinguish ordinary stochastic noise from divergence. **Scenario 3: ** reduce learning rate or use a schedule; momentum/Nesterov can help but excessive momentum can worsen overshoot. Judge training and validation curves separately.\n"},{"title":"R23 Q6b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A 28 × 28 × 192 input is convolved with 32 same-padded 5 × 5 filters to produce 28 × 28 × 32. Count computations. What happens if a 1 × 1 convolution precedes it? The reduction-channel count is not supplied.</p>"],"answer":["<h3>Given</h3>","<p>Input = 28 × 28 × 192; 32 same-padded 5 × 5 filters.</p>","<p>A preceding 1 × 1 convolution would reduce to C channels.</p>","<p>C is not supplied, so first give the symbolic bottleneck count; 16 channels is only an illustrative assumption.</p>","<h3>To find</h3>","<p>Calculate direct cost and express bottleneck cost in C; explain when the bottleneck saves computation.</p>","<h3>Formula — which one and why</h3>","<p><strong>Multiply–accumulate count.</strong> Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.</p>","<p>H_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output cell ka kaam × kitne output cells.</p>","<h3>Solution — step by step</h3>","<h3>Direct path</h3>","<p class=\"worked-step\"><strong>Step 2: direct path.</strong></p>","<p>output stays 28 × 28 with 32 channels.</p>","<p class=\"worked-step\"><strong>Step 3: direct path.</strong></p>","<p>MACs = 28 × 28 × 192 × 32 × 5 × 5 = <strong>120,422,400</strong>.</p>","<h3>Bottleneck path with 16 reduction channels</h3>","<p class=\"worked-step\"><strong>Step 4: bottleneck path with 16 reduction channels.</strong></p>","<p>1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.</p>","<p class=\"worked-step\"><strong>Step 5: bottleneck path with 16 reduction channels.</strong></p>","<p>The 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.</p>","<p class=\"worked-step\"><strong>Step 6: bottleneck path with 16 reduction channels.</strong></p>","<p>Total = <strong>12,443,648</strong>.</p>","<h3>Saving</h3>","<p class=\"worked-step\"><strong>Step 7: saving.</strong></p>","<p>120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = <strong>89.666667%</strong>. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = <strong>777,728r</strong></p>","<p class=\"worked-step\"><strong>Step 8: saving.</strong></p>","<p>there is no unique numeric bottleneck cost until r is chosen.</p>","<p>The 16-channel bottleneck is an explicitly chosen illustrative value, consistent with a related paper; the symbolic 777,728 r answer is required when r has not been specified.</p>","<p class=\"worked-step\"><strong>Step 9: calculate this quantity.</strong></p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p class=\"worked-step\"><strong>Step 10: calculate this quantity.</strong></p>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>"],"kind":"practice","id":"tee-c16-s14","search":"R23 Q6b **Question (10 marks).** A 28 × 28 × 192 input is convolved with 32 same-padded 5 × 5 filters to produce 28 × 28 × 32. Count computations. What happens if a 1 × 1 convolution precedes it? The reduction-channel count is not supplied.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput = 28 × 28 × 192; 32 same-padded 5 × 5 filters.\n\nA preceding 1 × 1 convolution would reduce to C channels.\n\nC is not supplied, so first give the symbolic bottleneck count; 16 channels is only an illustrative assumption.\n\n### To find\n\nCalculate direct cost and express bottleneck cost in C; explain when the bottleneck saves computation.\n\n### Formula — which one and why\n\n**Multiply–accumulate count.** Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.\n\nH_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har output cell ka kaam × kitne output cells.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\n\n\n### Direct path\n\n**Step 2: direct path.**\n\noutput stays 28 × 28 with 32 channels.\n\n**Step 3: direct path.**\n\nMACs = 28 × 28 × 192 × 32 × 5 × 5 = **120,422,400**.\n\n### Bottleneck path with 16 reduction channels\n\n**Step 4: bottleneck path with 16 reduction channels.**\n\n1 × 1 stage costs 28 × 28 × 192 × 16 = 2,408,448 MACs.\n\n**Step 5: bottleneck path with 16 reduction channels.**\n\nThe 5 × 5 stage costs 28 × 28 × 16 × 32 × 25 = 10,035,200 MACs.\n\n**Step 6: bottleneck path with 16 reduction channels.**\n\nTotal = **12,443,648**.\n\n### Saving\n\n**Step 7: saving.**\n\n120,422,400−12,443,648 = 107,978,752 MACs, or 107,978,752/120,422,400 × 100 = **89.666667%**. This counts multiplications with accumulation as MACs and omits biases/nonlinearities. Padding preserves spatial size. If the reduction width is not specified, call it r: total = 784 × 192r + 784 × 25 × 32r = **777,728r**\n\n**Step 8: saving.**\n\nthere is no unique numeric bottleneck cost until r is chosen.\n\nThe 16-channel bottleneck is an explicitly chosen illustrative value, consistent with a related paper; the symbolic 777,728 r answer is required when r has not been specified.\n\n**Step 9: calculate this quantity.**\n\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\n\n\n**Step 10: calculate this quantity.**\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\n\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kern"},{"title":"R23 Q7a","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Process with LSTM: “XYZ was very brave soldier. He was a part of the Kargil war and laid down his life fighting against the enemy. The president of India honored patriotic ___.” Explain the need for its gates.</p>"],"answer":["<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>","<p>The model can retain the earlier entity XYZ and the soldier context while updating intervening events. At the final prefix a vocabulary softmax predicts a suitable next token; “soldier” is a plausible completion. The exact output is not uniquely determined by the text or architecture alone. The forget gate retains useful entity content, the input gate adds the war/honor context, and the output gate exposes relevant state for prediction. Do not invent numerical gate values when no weights are provided.</p>"],"kind":"practice","id":"tee-c16-s15","search":"R23 Q7a **Question (10 marks).** Process with LSTM: “XYZ was very brave soldier. He was a part of the Kargil war and laid down his life fighting against the enemy. The president of India honored patriotic ___.” Explain the need for its gates.\n\n**Complete worked answer.**\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\nThe model can retain the earlier entity XYZ and the soldier context while updating intervening events. At the final prefix a vocabulary softmax predicts a suitable next token; “soldier” is a plausible completion. The exact output is not uniquely determined by the text or architecture alone. The forget gate retains useful entity content, the input gate adds the war/honor context, and the output gate exposes relevant state for prediction. Do not invent numerical gate values when no weights are provided.\n"},{"title":"R23 Q7b","question":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Training performance is good but unseen-data performance degrades. Identify the issue and explain ways to improve it.</p>"],"answer":["<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>","<p>A comparable-distribution train/unseen gap suggests overfitting. Also check whether the new data have shifted, preprocessing differs or labels are inconsistent. Select regularization using validation performance, not final-test tuning. Improvement must be demonstrated on representative held-out examples.</p>"],"kind":"practice","id":"tee-c16-s16","search":"R23 Q7b **Question (10 marks).** Training performance is good but unseen-data performance degrades. Identify the issue and explain ways to improve it.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\nA comparable-distribution train/unseen gap suggests overfitting. Also check whether the new data have shifted, preprocessing differs or labels are inconsistent. Select regularization using validation performance, not final-test tuning. Improvement must be demonstrated on representative held-out examples.\n\n\n"}]},{"n":17,"title":"Numerical practice from direct to mixed","sections":[{"title":"Start here","blocks":["<p>These are <strong>authored learning exercises</strong>, not additional PYQs. Their purpose is to practise the methods before attempting the full examination questions in the past exam questions under Solved Questions. Any practice marks describe an exercise&#x27;s suggested size, not marks or frequency observed in a past paper. For TEE priorities, start with the December 2025 and February 2026 paper question forms; use extra variants to repair a method that is still unclear.</p>","<p>These 52 original drills supplement every solved PYQ. They are not predicted exam questions. Use a blank page: copy the question, cover the answer, choose the formula, solve, then compare. After an error, redo the same type with the answer covered later that day and once the next morning. Reading or copying a solution once is not the same as being able to retrieve its method.</p>","<p>For TEE, complete every family, including drills 42–45 and 50 on gates and BPTT. A ten-minute block can contain one long numerical or three short ones. Repeat a solved family later with its answer covered before counting it as reliable.</p>"],"kind":"read","id":"tee-c17-intro"},{"title":"How to solve a mixed numerical without guessing","blocks":["<p>A mixed question is a chain of familiar operations. First circle the requested final quantity. Underline the given activation, loss, padding, stride, threshold, learning rate and any fixed parameters. Draw a small box for each stage. Write the output of one box as the input to the next. Never skip a stage because its title looks unfamiliar.</p>","<p><strong>If the question says output or prediction:</strong> do only the forward chain, unless training is separately requested. For a neuron, multiply and add before activating. For a CNN, determine spatial shapes before flattening. For an RNN, carry the previous state into the next time step.</p>","<p><strong>If it says train or update:</strong> finish the entire old forward pass, calculate the stated loss derivative, move backward, store every gradient, then update together. If there are several output branches, add their effects at the shared hidden unit. For a batch, follow the stated sum or mean loss before updating.</p>","<p><strong>If it mixes dropout and a loss:</strong> apply the given training mask and scaling first; then predict from the resulting activations. The gradient to a dropped path is zero for that mask. If it also specifies L2, add its gradient to the data gradient before the optimizer step. If it also specifies momentum or Adam, carry their stored states as well as the parameter.</p>","<p><strong>If it mixes convolution, pooling and a dense classifier:</strong> output shape → next layer input shape → flatten length → dense scores → activation → loss. Count learned parameters separately from output values. Pooling and flattening have zero learned parameters in these questions.</p>","<p><strong>If it changes a familiar problem:</strong> an extra input adds another product; an extra output adds another backward path; a new channel adds another kernel sum; a new time step adds another shared-state calculation. The method stays the same. The drills below deliberately change signs, targets, loss scales and layer combinations.</p>","<p><strong>Your completion rule:</strong> solve a representative problem today without the answer, repeat it after several hours, then solve a changed-number or mixed version tomorrow. Mark the exact line where your reasoning failed. Correcting that line is what builds reliable recall; reading an open solution does not test it.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c17-s0","search":"How to solve a mixed numerical without guessing A mixed question is a chain of familiar operations. First circle the requested final quantity. Underline the given activation, loss, padding, stride, threshold, learning rate and any fixed parameters. Draw a small box for each stage. Write the output of one box as the input to the next. Never skip a stage because its title looks unfamiliar.\n**If the question says output or prediction:** do only the forward chain, unless training is separately requested. For a neuron, multiply and add before activating. For a CNN, determine spatial shapes before flattening. For an RNN, carry the previous state into the next time step.\n**If it says train or update:** finish the entire old forward pass, calculate the stated loss derivative, move backward, store every gradient, then update together. If there are several output branches, add their effects at the shared hidden unit. For a batch, follow the stated sum or mean loss before updating.\n**If it mixes dropout and a loss:** apply the given training mask and scaling first; then predict from the resulting activations. The gradient to a dropped path is zero for that mask. If it also specifies L2, add its gradient to the data gradient before the optimizer step. If it also specifies momentum or Adam, carry their stored states as well as the parameter.\n**If it mixes convolution, pooling and a dense classifier:** output shape → next layer input shape → flatten length → dense scores → activation → loss. Count learned parameters separately from output values. Pooling and flattening have zero learned parameters in these questions.\n**If it changes a familiar problem:** an extra input adds another product; an extra output adds another backward path; a new channel adds another kernel sum; a new time step adds another shared-state calculation. The method stays the same. The drills below deliberately change signs, targets, loss scales and layer combinations.\n**Your completion rule:** solve a representative problem today without the answer, repeat it after several hours, then solve a changed-number or mixed version tomorrow. Mark the exact line where your reasoning failed. Correcting that line is what builds reliable recall; reading an open solution does not test it.\n"},{"title":"Drill 1 Signs and brackets","question":["<p class=\"inline-question\"><strong>Question.</strong> Evaluate 2−0.1 × (−3), then (2−0.1) × (−3). Explain why they differ.</p>"],"answer":["<h3>Given</h3>","<p>Expressions: 2−0.1×(−3) and (2−0.1)×(−3).</p>","<h3>To find</h3>","<p>Evaluate both and explain the effect of grouping.</p>","<h3>Formula — which one and why</h3>","<p><strong>Order of operations.</strong> Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.</p>","<p>A minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/204904c78b9dfc36.svg\" alt=\"a-(-b)=a+b\" width=\"177.16\" height=\"24.43\" style=\"width:177.16px;height:24.43px;aspect-ratio:177.16/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the calculation</h3>","<p>A minus sign can mean subtraction or a negative number. Brackets tell us which part belongs together. These two expressions have different brackets, so they describe different calculations.</p>","<h3>Rule used</h3>","<p>Do brackets first, then multiplication, then addition or subtraction. Subtracting a negative number means adding its positive size.</p>","<p class=\"worked-step\"><strong>Step 1: First expression: multiply before subtracting.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5b11a126e768858f.svg\" alt=\"2-0.1\\times(-3)\" width=\"153.42\" height=\"24.43\" style=\"width:153.42px;height:24.43px;aspect-ratio:153.42/24.43\" loading=\"lazy\"></div>","<p>First multiply: a positive number times a negative number is negative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/189f052516957693.svg\" alt=\"0.1\\times(-3)=-0.3\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<p>Put this complete result back into the expression. Keep its negative sign inside brackets.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2d796303b17c0e32.svg\" alt=\"2-(-0.3)=2+0.3=2.3\" width=\"281.05\" height=\"24.43\" style=\"width:281.05px;height:24.43px;aspect-ratio:281.05/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Second expression: finish the bracket first.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26a467850584ea86.svg\" alt=\"2-0.1=1.9\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p>Now multiply the whole bracket result by negative 3.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f4e294dd1ab7a8aa.svg\" alt=\"1.9\\times(-3)=-5.7\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> first expression = 2.3; second expression = −5.7. In a weight update, multiply learning rate by gradient first, then subtract that product from the old weight.</p>"],"kind":"practice","id":"tee-c17-s1","search":"Drill 1 Signs and brackets **Question.** Evaluate 2−0.1 × (−3), then (2−0.1) × (−3). Explain why they differ.\n\n**Full solution.**\n\n\n\n### Given\n\nExpressions: 2−0.1×(−3) and (2−0.1)×(−3).\n\n### To find\n\nEvaluate both and explain the effect of grouping.\n\n### Formula — which one and why\n\n**Order of operations.** Grouping decides which operation is performed first. Evaluate brackets, then powers, then multiplication/division, then addition/subtraction.\n\nA minus sign inside brackets belongs to that number. Subtracting a negative changes the operation to addition.\n\n\n\n**Yaad rakhne ka cue:** Bracket pehle; phir power; phir multiply/divide; aakhir mein plus-minus.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the calculation\nA minus sign can mean subtraction or a negative number. Brackets tell us which part belongs together. These two expressions have different brackets, so they describe different calculations.\n### Rule used\nDo brackets first, then multiplication, then addition or subtraction. Subtracting a negative number means adding its positive size.\n**Step 1: First expression: multiply before subtracting.**\n\nFirst multiply: a positive number times a negative number is negative.\n\nPut this complete result back into the expression. Keep its negative sign inside brackets.\n\n**Step 2: Second expression: finish the bracket first.**\n\nNow multiply the whole bracket result by negative 3.\n\n**Final answer:** first expression = 2.3; second expression = −5.7. In a weight update, multiply learning rate by gradient first, then subtract that product from the old weight.\n"},{"title":"Drill 2 Half sum versus mean","question":["<p class=\"inline-question\"><strong>Question.</strong> Predictions = [0.2,0.7,0.4], targets = [0,1,1]. Find SSE, half SSE and MSE.</p>"],"answer":["<h3>Given</h3>","<p>Predictions = [0.2, 0.7, 0.4].</p>","<p>Targets = [0, 1, 1]; number of outputs n = 3.</p>","<h3>To find</h3>","<p>Find SSE, half SSE, MSE and the prediction gradients requested in the question.</p>","<h3>Formula — which one and why</h3>","<p><strong>Squared-error objectives.</strong> Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.</p>","<p>ŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4b31e4fcfd52ba58.svg\" alt=\"e_i=\\hat y_i-y_i\" width=\"121.75\" height=\"24.80\" style=\"width:121.75px;height:24.80px;aspect-ratio:121.75/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8dd5fa4e080919c.svg\" alt=\"\\mathrm{SSE}=\\sum_i e_i^2\" width=\"137.81\" height=\"52.35\" style=\"width:137.81px;height:52.35px;aspect-ratio:137.81/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef8982ea86700e61.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i e_i^2\" width=\"169.18\" height=\"61.92\" style=\"width:169.18px;height:61.92px;aspect-ratio:169.18/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d9bd32ee9a4320cb.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i e_i^2\" width=\"176.10\" height=\"61.92\" style=\"width:176.10px;height:61.92px;aspect-ratio:176.10/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle error square; phir question ke hisaab se sum, half ya mean.</p>","<h3>Solution — step by step</h3>","<h3>Given values and loss definitions</h3>","<p>There are n = 3 prediction–target pairs. Use the supplied predictions directly; no rounding to class labels is required. Let eᵢ = ŷᵢ − yᵢ be the signed residual for pair i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5312f21f7180b663.svg\" alt=\"\\mathrm{SSE}=\\sum_{i=1}^{n}e_i^2\" width=\"137.81\" height=\"68.62\" style=\"width:137.81px;height:68.62px;aspect-ratio:137.81/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8370703d0e22f365.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_{i=1}^{n}e_i^2=\\frac{\\mathrm{SSE}}2\" width=\"256.33\" height=\"68.62\" style=\"width:256.33px;height:68.62px;aspect-ratio:256.33/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bde24be7fa074ec1.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_{i=1}^{n}e_i^2=\\frac{\\mathrm{SSE}}n\" width=\"263.26\" height=\"68.62\" style=\"width:263.26px;height:68.62px;aspect-ratio:263.26/68.62\" loading=\"lazy\"></div>","<p>SSE is the sum of squared errors. Half SSE and MSE rescale that same sum by different denominators: 2 and n, respectively.</p>","<h3>Step 1: calculate each residual and its square</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Pair</th><th>Prediction ŷᵢ</th><th>Target yᵢ</th><th>Residual ŷᵢ − yᵢ</th><th>Squared residual</th></tr></thead><tbody><tr><td>1</td><td>0.2</td><td>0</td><td>0.2 − 0 = 0.2</td><td>(0.2)² = 0.04</td></tr><tr><td>2</td><td>0.7</td><td>1</td><td>0.7 − 1 = −0.3</td><td>(−0.3)² = 0.09</td></tr><tr><td>3</td><td>0.4</td><td>1</td><td>0.4 − 1 = −0.6</td><td>(−0.6)² = 0.36</td></tr></tbody></table></div>","<h3>Step 2: sum the squared residuals</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4890329b3b657194.svg\"><img class=\"math display-math\" src=\"assets/equations/36128683498bbba3.svg\" alt=\"\\mathrm{SSE}=0.04+0.09+0.36=0.49\" width=\"342.50\" height=\"19.23\" style=\"width:342.50px;height:19.23px;aspect-ratio:342.50/19.23\" loading=\"lazy\"></picture></div>","<p>Square each residual before summing. Squaring the sum of signed residuals would be a different quantity, because positive and negative residuals could cancel.</p>","<h3>Step 3: apply each requested normalization</h3>","<p>For half SSE, the denominator is 2:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3d10f476bd1cf13c.svg\" alt=\"L_{\\mathrm{half}}=\\frac{0.49}{2}=0.245\" width=\"223.17\" height=\"49.82\" style=\"width:223.17px;height:49.82px;aspect-ratio:223.17/49.82\" loading=\"lazy\"></div>","<p>For MSE, the denominator is the number of pairs, n = 3:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.26px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4cd1db7c5158eb6.svg\"><img class=\"math display-math\" src=\"assets/equations/2f7b20630e72d239.svg\" alt=\"\\mathrm{MSE}=\\frac{0.49}{3}=0.163333333\\ldots\" width=\"333.67\" height=\"50.36\" style=\"width:333.67px;height:50.36px;aspect-ratio:333.67/50.36\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> SSE = 0.49; half SSE = 0.245; MSE ≈ 0.163333. They represent the same residuals at different scales. Half SSE and MSE coincide when n = 2; they do not coincide for these three nonzero residuals. No derivative is required by this question.</p>"],"kind":"practice","id":"tee-c17-s2","search":"Drill 2 Half sum versus mean \n**Question.** Predictions = [0.2,0.7,0.4], targets = [0,1,1]. Find SSE, half SSE and MSE.\n\n**Full solution.**\n\n\n\n### Given\n\nPredictions = [0.2, 0.7, 0.4].\n\nTargets = [0, 1, 1]; number of outputs n = 3.\n\n### To find\n\nFind SSE, half SSE, MSE and the prediction gradients requested in the question.\n\n### Formula — which one and why\n\n**Squared-error objectives.** Calculate signed errors first and square them. SSE adds the squares; half SSE divides that sum by 2; MSE divides by the number of scalar predictions. These denominators are different conventions.\n\nŷᵢ = prediction; yᵢ = target; eᵢ = signed error; n = number of scalar predictions included in the stated loss.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle error square; phir question ke hisaab se sum, half ya mean.\n\n### Solution — step by step\n\n\n\n\n\n### Given values and loss definitions\nThere are n = 3 prediction–target pairs. Use the supplied predictions directly; no rounding to class labels is required. Let eᵢ = ŷᵢ − yᵢ be the signed residual for pair i.\n\n\n\nSSE is the sum of squared errors. Half SSE and MSE rescale that same sum by different denominators: 2 and n, respectively.\n\n### Step 1: calculate each residual and its square\n| Pair | Prediction ŷᵢ | Target yᵢ | Residual ŷᵢ − yᵢ | Squared residual |\n| 1 | 0.2 | 0 | 0.2 − 0 = 0.2 | (0.2)² = 0.04 |\n| 2 | 0.7 | 1 | 0.7 − 1 = −0.3 | (−0.3)² = 0.09 |\n| 3 | 0.4 | 1 | 0.4 − 1 = −0.6 | (−0.6)² = 0.36 |\n\n### Step 2: sum the squared residuals\n\nSquare each residual before summing. Squaring the sum of signed residuals would be a different quantity, because positive and negative residuals could cancel.\n\n### Step 3: apply each requested normalization\nFor half SSE, the denominator is 2:\n\nFor MSE, the denominator is the number of pairs, n = 3:\n\n\n**Final answer:** SSE = 0.49; half SSE = 0.245; MSE ≈ 0.163333. They represent the same residuals at different scales. Half SSE and MSE coincide when n = 2; they do not coincide for these three nonzero residuals. No derivative is required by this question.\n\n"},{"title":"Drill 3 Natural log and probability","question":["<p class=\"inline-question\"><strong>Question.</strong> Compute −ln(0.9),−ln(0.1), and <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/b7f5712356b73942.svg\" alt=\"e^{-\\ln 2}\" width=\"43.29\" height=\"17.39\" style=\"width:43.29px;height:17.39px;aspect-ratio:43.29/17.39\" loading=\"lazy\"></span>.</p>"],"answer":["<h3>Given</h3>","<p>Probabilities: 0.9 and 0.1.</p>","<p>Exponential expression: exp(−ln 2).</p>","<h3>To find</h3>","<p>Find −ln(0.9), −ln(0.1) and exp(−ln 2).</p>","<h3>Formula — which one and why</h3>","<p><strong>Natural logarithms.</strong> The natural logarithm reverses the exponential. A negative log turns a small correct-class probability into a larger positive loss.</p>","<p>ln uses base e ≈ 2.71828. exp(a) means e raised to the power a. Keep the minus outside ln when the question says −ln(p).</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/45890ca9be189629.svg\" alt=\"-\\ln p=\\ln\\frac1p\" width=\"139.90\" height=\"54.29\" style=\"width:139.90px;height:54.29px;aspect-ratio:139.90/54.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/04d92df0f222846e.svg\" alt=\"e^{\\ln a}=a\" width=\"85.35\" height=\"24.08\" style=\"width:85.35px;height:24.08px;aspect-ratio:85.35/24.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5953def5a7690c0e.svg\" alt=\"e^{-\\ln a}=\\frac1a\" width=\"112.43\" height=\"49.80\" style=\"width:112.43px;height:49.80px;aspect-ratio:112.43/49.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> exp banata hai power; ln us power ko wapas nikaalta hai.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The natural logarithm ln tells us the power of e needed to obtain a number. It reverses the exponential operation. A calculator evaluates ln; it is not ordinary division.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:114.24px;--narrow-height:106.38px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/794f58bf694147ad.svg\"><img class=\"math display-math\" src=\"assets/equations/16ba8aa03cb4b3ca.svg\" alt=\"\\ln(e^a)=a,\\qquad e^{\\ln a}=a\\quad(a&gt;0)\" width=\"353.71\" height=\"28.19\" style=\"width:353.71px;height:28.19px;aspect-ratio:353.71/28.19\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ee2a4da74df0c61.svg\" alt=\"e^{-a}=\\frac1{e^a}\" width=\"101.89\" height=\"49.82\" style=\"width:101.89px;height:49.82px;aspect-ratio:101.89/49.82\" loading=\"lazy\"></div>","<h3>Step 1: calculate the first logarithm, then its minus sign</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5deadd8f45d24fdd.svg\" alt=\"\\ln(0.9)\\approx-0.105360516\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.58px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b17db90c0b1eab0.svg\"><img class=\"math display-math\" src=\"assets/equations/a07489f729a63131.svg\" alt=\"-\\ln(0.9)=-(-0.105360516)=0.105360516\" width=\"473.83\" height=\"24.43\" style=\"width:473.83px;height:24.43px;aspect-ratio:473.83/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: calculate the second logarithm</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ccbedb0aa22add9.svg\" alt=\"\\ln(0.1)\\approx-2.302585093\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.58px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc081502a0ccb2a9.svg\"><img class=\"math display-math\" src=\"assets/equations/63eac781aee3c744.svg\" alt=\"-\\ln(0.1)=-(-2.302585093)=2.302585093\" width=\"473.83\" height=\"24.43\" style=\"width:473.83px;height:24.43px;aspect-ratio:473.83/24.43\" loading=\"lazy\"></picture></div>","<p>When these are correct-class probabilities, 0.1 represents a worse prediction than 0.9, so its negative-log loss is larger.</p>","<h3>Step 3: simplify the exponential using the inverse rule</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b612f5289fa6fa44.svg\" alt=\"e^{-\\ln2}=\\frac1{e^{\\ln2}}=\\frac12=0.5\" width=\"257.71\" height=\"51.14\" style=\"width:257.71px;height:51.14px;aspect-ratio:257.71/51.14\" loading=\"lazy\"></div>","<p><strong>Final answers:</strong> 0.105360516, 2.302585093 and 0.5. Use the ln key; base-10 log gives different first and second answers.</p>"],"kind":"practice","id":"tee-c17-s3","search":"Drill 3 Natural log and probability **Question.** Compute −ln(0.9),−ln(0.1), and \\(e^{-\\ln 2}\\).\n\n**Full solution.**\n\n\n\n### Given\n\nProbabilities: 0.9 and 0.1.\n\nExponential expression: exp(−ln 2).\n\n### To find\n\nFind −ln(0.9), −ln(0.1) and exp(−ln 2).\n\n### Formula — which one and why\n\n**Natural logarithms.** The natural logarithm reverses the exponential. A negative log turns a small correct-class probability into a larger positive loss.\n\nln uses base e ≈ 2.71828. exp(a) means e raised to the power a. Keep the minus outside ln when the question says −ln(p).\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** exp banata hai power; ln us power ko wapas nikaalta hai.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe natural logarithm ln tells us the power of e needed to obtain a number. It reverses the exponential operation. A calculator evaluates ln; it is not ordinary division.\n\n\n### Step 1: calculate the first logarithm, then its minus sign\n\n\n### Step 2: calculate the second logarithm\n\n\nWhen these are correct-class probabilities, 0.1 represents a worse prediction than 0.9, so its negative-log loss is larger.\n### Step 3: simplify the exponential using the inverse rule\n\n**Final answers:** 0.105360516, 2.302585093 and 0.5. Use the ln key; base-10 log gives different first and second answers.\n"},{"title":"Drill 4 Dot product and bias","question":["<p class=\"inline-question\"><strong>Question.</strong> Find z for x = [2,−1,0.5], w = [0.3,0.4,−0.2], b = 0.1; then apply ReLU.</p>"],"answer":["<h3>Given</h3>","<p>Inputs x = [2, −1, 0.5].</p>","<p>Weights w = [0.3, 0.4, −0.2]; bias b = 0.1.</p>","<p>Activation: ReLU.</p>","<h3>To find</h3>","<p>Find the weighted sum z and ReLU output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>A dot product means multiply corresponding entries, then add the products. A bias is one extra value added after the sum. ReLU keeps a positive result and replaces a negative result with zero.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:179.43px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d429a2592c8f926e.svg\"><img class=\"math display-math\" src=\"assets/equations/d2b18ce5f8c75557.svg\" alt=\"z=w_1x_1+w_2x_2+w_3x_3+b,\\qquad a=\\max(0,z)\" width=\"506.63\" height=\"24.43\" style=\"width:506.63px;height:24.43px;aspect-ratio:506.63/24.43\" loading=\"lazy\"></picture></div>","<p>Here x contains inputs, w contains weights, b is bias, z is the weighted sum, and a is the activated output.</p>","<h3>Step 1: multiply the matching pairs</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6092f2a718fe356.svg\" alt=\"w_1x_1=0.3\\times2=0.6\" width=\"222.51\" height=\"19.94\" style=\"width:222.51px;height:19.94px;aspect-ratio:222.51/19.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d39443d0dbfaaa2b.svg\" alt=\"w_2x_2=0.4\\times(-1)=-0.4\" width=\"279.55\" height=\"24.43\" style=\"width:279.55px;height:24.43px;aspect-ratio:279.55/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6f257d4f869d8fa2.svg\"><img class=\"math display-math\" src=\"assets/equations/8173a34611c8e936.svg\" alt=\"w_3x_3=(-0.2)\\times0.5=-0.1\" width=\"298.56\" height=\"24.43\" style=\"width:298.56px;height:24.43px;aspect-ratio:298.56/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: add all products and add bias once</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72dd56dcc4bb45b6.svg\"><img class=\"math display-math\" src=\"assets/equations/aa77eba1df26bb28.svg\" alt=\"z=0.6+(-0.4)+(-0.1)+0.1\" width=\"334.51\" height=\"24.43\" style=\"width:334.51px;height:24.43px;aspect-ratio:334.51/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3991f5f0c7df172.svg\" alt=\"z=0.2-0.1+0.1=0.2\" width=\"261.18\" height=\"18.27\" style=\"width:261.18px;height:18.27px;aspect-ratio:261.18/18.27\" loading=\"lazy\"></div>","<h3>Step 3: apply the activation</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b62624e146d1934.svg\" alt=\"a=\\max(0,0.2)=0.2\" width=\"228.12\" height=\"24.43\" style=\"width:228.12px;height:24.43px;aspect-ratio:228.12/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> weighted sum z = 0.2; ReLU output a = 0.2. The two numbers happen to match because z is positive.</p>"],"kind":"practice","id":"tee-c17-s4","search":"Drill 4 Dot product and bias **Question.** Find z for x = [2,−1,0.5], w = [0.3,0.4,−0.2], b = 0.1; then apply ReLU.\n\n**Full solution.**\n\n\n\n### Given\n\nInputs x = [2, −1, 0.5].\n\nWeights w = [0.3, 0.4, −0.2]; bias b = 0.1.\n\nActivation: ReLU.\n\n### To find\n\nFind the weighted sum z and ReLU output.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nA dot product means multiply corresponding entries, then add the products. A bias is one extra value added after the sum. ReLU keeps a positive result and replaces a negative result with zero.\n\nHere x contains inputs, w contains weights, b is bias, z is the weighted sum, and a is the activated output.\n### Step 1: multiply the matching pairs\n\n\n\n### Step 2: add all products and add bias once\n\n\n### Step 3: apply the activation\n\n**Final answer:** weighted sum z = 0.2; ReLU output a = 0.2. The two numbers happen to match because z is positive.\n"},{"title":"Drill 5 Matrix rows receive inputs","question":["<p class=\"inline-question\"><strong>Question.</strong> For the weight matrix W shown below, x = [2,1], b = [0.5,−0.5], find Wx+b and ReLU.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_ed1fcbfdf5.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_ed1fcbfdf5.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>W = <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/47c671c1553de484.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\-1 &amp; 3\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>.</p>","<p>Input column x = [2,1]ᵀ; bias column b = [0.5,−0.5]ᵀ.</p>","<p>Activation: ReLU on each result.</p>","<h3>To find</h3>","<p>Find Wx+b and the activated output.</p>","<h3>Formula — which one and why</h3>","<p><strong>Row–column multiplication.</strong> Each receiving neuron uses one weight row. Multiply that row by the input column, add the products, then add that neuron’s bias.</p>","<p>Wⱼᵢ = weight from input i to receiver j; xᵢ = input i; bⱼ = bias of receiver j; zⱼ = its preactivation. A superscript T means transpose: exchange rows and columns.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc40cdac8ad4c81c.svg\" alt=\"z_j=\\sum_i W_{ji}x_i+b_j\" width=\"202.09\" height=\"52.35\" style=\"width:202.09px;height:52.35px;aspect-ratio:202.09/52.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek row × poora input column = ek receiving neuron ka answer.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>Each row supplies the weights of one receiving neuron. Multiply that row by the input column, then add that neuron&#x27;s own bias. The two biases are separate; do not add both to every row.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.73px;--narrow-height:64.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa52f339dd0d5a91.svg\"><img class=\"math display-math\" src=\"assets/equations/6f48223c352868b0.svg\" alt=\"z=Wx+b,\\qquad a_j=\\max(0,z_j)\" width=\"346.35\" height=\"25.52\" style=\"width:346.35px;height:25.52px;aspect-ratio:346.35/25.52\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e990284b43290d2.svg\" alt=\"W=\\begin{bmatrix}1&amp;2\\\\-1&amp;3\\end{bmatrix},\\quad x=\\begin{bmatrix}2\\\\1\\end{bmatrix},\\quad b=\\begin{bmatrix}0.5\\\\-0.5\\end{bmatrix}\" width=\"426.16\" height=\"58.64\" style=\"width:426.16px;height:58.64px;aspect-ratio:426.16/58.64\" loading=\"lazy\"></div>","<h3>Step 1: calculate receiving neuron 1 from row 1</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eaa341baa6e16b1f.svg\"><img class=\"math display-math\" src=\"assets/equations/46e8f36136a4c4d2.svg\" alt=\"z_1=(1\\times2)+(2\\times1)+0.5\" width=\"292.20\" height=\"24.43\" style=\"width:292.20px;height:24.43px;aspect-ratio:292.20/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/50386fe91979c412.svg\" alt=\"z_1=2+2+0.5=4.5\" width=\"233.83\" height=\"20.21\" style=\"width:233.83px;height:20.21px;aspect-ratio:233.83/20.21\" loading=\"lazy\"></div>","<h3>Step 2: calculate receiving neuron 2 from row 2</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b0b4c769cba96d49.svg\"><img class=\"math display-math\" src=\"assets/equations/fe996afd770f8834.svg\" alt=\"z_2=((-1)\\times2)+(3\\times1)+(-0.5)\" width=\"368.25\" height=\"24.43\" style=\"width:368.25px;height:24.43px;aspect-ratio:368.25/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8bdba182228536bc.svg\" alt=\"z_2=-2+3-0.5=0.5\" width=\"252.84\" height=\"19.94\" style=\"width:252.84px;height:19.94px;aspect-ratio:252.84/19.94\" loading=\"lazy\"></div>","<h3>Step 3: apply ReLU to each entry</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/43cee11d40484528.svg\"><img class=\"math display-math\" src=\"assets/equations/e48d03ac9b49ea16.svg\" alt=\"a_1=\\max(0,4.5)=4.5,\\qquad a_2=\\max(0,0.5)=0.5\" width=\"537.30\" height=\"24.43\" style=\"width:537.30px;height:24.43px;aspect-ratio:537.30/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b93dfe6da27f9705.svg\" alt=\"z=\\begin{bmatrix}4.5\\\\0.5\\end{bmatrix},\\qquad a=\\begin{bmatrix}4.5\\\\0.5\\end{bmatrix}\" width=\"263.25\" height=\"58.64\" style=\"width:263.25px;height:58.64px;aspect-ratio:263.25/58.64\" loading=\"lazy\"></div>","<p>The shape is 2 rows by 1 column: one output for each receiving row.</p>"],"kind":"practice","id":"tee-c17-s5","search":"Drill 5 Matrix rows receive inputs **Question.** For the weight matrix W shown below, x = [2,1], b = [0.5,−0.5], find Wx+b and ReLU.\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nW = .\n\nInput column x = [2,1]ᵀ; bias column b = [0.5,−0.5]ᵀ.\n\nActivation: ReLU on each result.\n\n### To find\n\nFind Wx+b and the activated output.\n\n### Formula — which one and why\n\n**Row–column multiplication.** Each receiving neuron uses one weight row. Multiply that row by the input column, add the products, then add that neuron’s bias.\n\nWⱼᵢ = weight from input i to receiver j; xᵢ = input i; bⱼ = bias of receiver j; zⱼ = its preactivation. A superscript T means transpose: exchange rows and columns.\n\n\n\n**Yaad rakhne ka cue:** Ek row × poora input column = ek receiving neuron ka answer.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nEach row supplies the weights of one receiving neuron. Multiply that row by the input column, then add that neuron's own bias. The two biases are separate; do not add both to every row.\n\n\n### Step 1: calculate receiving neuron 1 from row 1\n\n\n### Step 2: calculate receiving neuron 2 from row 2\n\n\n### Step 3: apply ReLU to each entry\n\n\nThe shape is 2 rows by 1 column: one output for each receiving row.\n"},{"title":"Drill 6 Chain rule on a tiny loss","question":["<p class=\"inline-question\"><strong>Question.</strong> Let o = wx+b, L = ½(o−y)², x = 3, w = 0.2, b = 0.1, y = 1. Find dL/dw, dL/db and update at η = 0.1.</p>"],"answer":["<h3>Given</h3>","<p>Model: o = wx+b; loss L = ½(o−y)².</p>","<p>x = 3; y = 1; w = 0.2; b = 0.1.</p>","<p>Learning rate η = 0.1.</p>","<h3>To find</h3>","<p>Find ∂L/∂w, ∂L/∂b and the updated weight and bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Chain rule for a linear neuron.</strong> The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.</p>","<p>z = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/00f49c1127dda70e.svg\" alt=\"z=wx+b\" width=\"115.77\" height=\"18.96\" style=\"width:115.77px;height:18.96px;aspect-ratio:115.77/18.96\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f50d7e1cde6462d5.svg\" alt=\"L=\\frac12(z-y)^2\" width=\"155.08\" height=\"49.55\" style=\"width:155.08px;height:49.55px;aspect-ratio:155.08/49.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/955c63d58ce8cb9b.svg\" alt=\"g_w=\\frac{\\partial L}{\\partial w}=(z-y)x\" width=\"219.49\" height=\"51.29\" style=\"width:219.49px;height:51.29px;aspect-ratio:219.49/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a5a6192e644e19b.svg\" alt=\"g_b=\\frac{\\partial L}{\\partial b}=z-y\" width=\"180.69\" height=\"51.29\" style=\"width:180.69px;height:51.29px;aspect-ratio:180.69/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33df8d5a70c57c14.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_w\" width=\"167.42\" height=\"19.53\" style=\"width:167.42px;height:19.53px;aspect-ratio:167.42/19.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c2843cb0410cd77b.svg\" alt=\"b_{\\mathrm{new}}=b-\\eta g_b\" width=\"148.44\" height=\"22.24\" style=\"width:148.44px;height:22.24px;aspect-ratio:148.44/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek path mein multiply; alag paths mil rahe hon toh add.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The output o is a linear prediction: no sigmoid or ReLU is specified. Changing w changes o, which changes L. The chain rule multiplies those linked effects.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:155.56px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/90379cab01aa101e.svg\"><img class=\"math display-math\" src=\"assets/equations/e9fdca67a77fbb78.svg\" alt=\"o=wx+b,\\qquad L=\\frac12(o-y)^2\" width=\"331.56\" height=\"49.55\" style=\"width:331.56px;height:49.55px;aspect-ratio:331.56/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:134.29px;--narrow-height:183.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7ae2da1d297dac40.svg\"><img class=\"math display-math\" src=\"assets/equations/ca7badc8e4620a3c.svg\" alt=\"\\frac{\\partial L}{\\partial o}=o-y,\\quad \\frac{\\partial o}{\\partial w}=x,\\quad \\frac{\\partial o}{\\partial b}=1\" width=\"367.97\" height=\"51.29\" style=\"width:367.97px;height:51.29px;aspect-ratio:367.97/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:168.13px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a63ae410089093d5.svg\"><img class=\"math display-math\" src=\"assets/equations/6ffe92ced0000c23.svg\" alt=\"\\frac{\\partial L}{\\partial w}=(o-y)x,\\qquad \\frac{\\partial L}{\\partial b}=o-y\" width=\"348.57\" height=\"51.29\" style=\"width:348.57px;height:51.29px;aspect-ratio:348.57/51.29\" loading=\"lazy\"></picture></div>","<p>The learning rate η says how much of the gradient to subtract.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.24px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9cca82416f4ee903.svg\"><img class=\"math display-math\" src=\"assets/equations/8c595e12402e35b1.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta\\frac{\\partial L}{\\partial w},\\qquad b_{\\mathrm{new}}=b-\\eta\\frac{\\partial L}{\\partial b}\" width=\"411.74\" height=\"51.29\" style=\"width:411.74px;height:51.29px;aspect-ratio:411.74/51.29\" loading=\"lazy\"></picture></div>","<h3>Step 1: obtain the current prediction and error</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.86px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d8d618e9d2cfc7d.svg\"><img class=\"math display-math\" src=\"assets/equations/259368438902dc69.svg\" alt=\"o=(0.2\\times3)+0.1=0.6+0.1=0.7\" width=\"386.58\" height=\"24.43\" style=\"width:386.58px;height:24.43px;aspect-ratio:386.58/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f0bd8184760ad600.svg\" alt=\"o-y=0.7-1=-0.3\" width=\"242.42\" height=\"21.52\" style=\"width:242.42px;height:21.52px;aspect-ratio:242.42/21.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.26px;--narrow-height:113.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/21397d642a37130f.svg\"><img class=\"math display-math\" src=\"assets/equations/6ccc7a83cb90d797.svg\" alt=\"L=\\frac12(-0.3)^2=\\frac12(0.09)=0.045\" width=\"358.35\" height=\"49.55\" style=\"width:358.35px;height:49.55px;aspect-ratio:358.35/49.55\" loading=\"lazy\"></picture></div>","<h3>Step 2: calculate both gradients from this same prediction</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ed97f79ab4475569.svg\" alt=\"\\frac{\\partial L}{\\partial w}=(-0.3)\\times3=-0.9\" width=\"268.81\" height=\"51.29\" style=\"width:268.81px;height:51.29px;aspect-ratio:268.81/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/80efe080f6cbf4d3.svg\" alt=\"\\frac{\\partial L}{\\partial b}=(-0.3)\\times1=-0.3\" width=\"267.96\" height=\"51.29\" style=\"width:267.96px;height:51.29px;aspect-ratio:267.96/51.29\" loading=\"lazy\"></div>","<h3>Step 3: update the weight</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/187fe0232f317977.svg\"><img class=\"math display-math\" src=\"assets/equations/c80322ecffe9a16b.svg\" alt=\"w_{\\mathrm{new}}=0.2-0.1(-0.9)=0.2-(-0.09)=0.29\" width=\"494.61\" height=\"24.43\" style=\"width:494.61px;height:24.43px;aspect-ratio:494.61/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 4: update the bias</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/15129640706302ac.svg\"><img class=\"math display-math\" src=\"assets/equations/c3e5531ea9063ace.svg\" alt=\"b_{\\mathrm{new}}=0.1-0.1(-0.3)=0.1-(-0.03)=0.13\" width=\"487.59\" height=\"24.43\" style=\"width:487.59px;height:24.43px;aspect-ratio:487.59/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> weight gradient −0.9; bias gradient −0.3; new weight 0.29; new bias 0.13. Both updates use the old forward pass.</p>"],"kind":"practice","id":"tee-c17-s6","search":"Drill 6 Chain rule on a tiny loss **Question.** Let o = wx+b, L = ½(o−y)², x = 3, w = 0.2, b = 0.1, y = 1. Find dL/dw, dL/db and update at η = 0.1.\n\n**Full solution.**\n\n\n\n### Given\n\nModel: o = wx+b; loss L = ½(o−y)².\n\nx = 3; y = 1; w = 0.2; b = 0.1.\n\nLearning rate η = 0.1.\n\n### To find\n\nFind ∂L/∂w, ∂L/∂b and the updated weight and bias.\n\n### Formula — which one and why\n\n**Chain rule for a linear neuron.** The weight changes the prediction, and the prediction changes the loss. Multiply those two local rates. Half squared loss differentiates to prediction minus target; the neuron contributes input x.\n\nz = prediction; y = target; e = z−y; g_w and g_b = loss derivatives for weight and bias. ∂L/∂w means “how fast loss changes when w changes”. η (eta) = learning rate.\n\n\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek path mein multiply; alag paths mil rahe hon toh add.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe output o is a linear prediction: no sigmoid or ReLU is specified. Changing w changes o, which changes L. The chain rule multiplies those linked effects.\n\n\n\nThe learning rate η says how much of the gradient to subtract.\n\n### Step 1: obtain the current prediction and error\n\n\n\n### Step 2: calculate both gradients from this same prediction\n\n\n### Step 3: update the weight\n\n### Step 4: update the bias\n\n**Final answer:** weight gradient −0.9; bias gradient −0.3; new weight 0.29; new bias 0.13. Both updates use the old forward pass.\n"},{"title":"Drill 7 Sigmoid with binary cross entropy","question":["<p class=\"inline-question\"><strong>Question.</strong> A binary classifier has logit z = 1, target 1. Find probability, BCE and the gradient with respect to z.</p>"],"answer":["<h3>Given</h3>","<p>Logit z = 1; binary target y = 1.</p>","<p>Output: sigmoid; loss: binary cross-entropy.</p>","<h3>To find</h3>","<p>Find probability, BCE and the loss derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Binary cross-entropy.</strong> For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.</p>","<p>y is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bbef5a5d1c7047f.svg\" alt=\"\\frac{\\partial L}{\\partial z}=p-y\" width=\"127.94\" height=\"51.29\" style=\"width:127.94px;height:51.29px;aspect-ratio:127.94/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>A logit is the raw score before sigmoid. Sigmoid converts it to a probability p. The target y = 1 says the positive class is correct. Binary cross-entropy measures how little probability the model assigned to the correct binary outcome.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06236932ea7e53d0.svg\" alt=\"p=\\frac1{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6b608fdfba7ba2f.svg\" alt=\"L=-\\left[y\\ln p+(1-y)\\ln(1-p)\\right]\" width=\"339.45\" height=\"24.43\" style=\"width:339.45px;height:24.43px;aspect-ratio:339.45/24.43\" loading=\"lazy\"></div>","<p>For sigmoid combined with this loss, the gradient with respect to the logit has the simplified form:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bbef5a5d1c7047f.svg\" alt=\"\\frac{\\partial L}{\\partial z}=p-y\" width=\"127.94\" height=\"51.29\" style=\"width:127.94px;height:51.29px;aspect-ratio:127.94/51.29\" loading=\"lazy\"></div>","<h3>Step 1: convert logit 1 into probability</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8b081af8baa5f1b.svg\" alt=\"e^{-1}\\approx0.367879441\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f1586fb666c5061e.svg\" alt=\"1+e^{-1}\\approx1.367879441\" width=\"239.13\" height=\"23.60\" style=\"width:239.13px;height:23.60px;aspect-ratio:239.13/23.60\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:184.59px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f55393e129c6628.svg\"><img class=\"math display-math\" src=\"assets/equations/6617ec66ea10120e.svg\" alt=\"p=\\frac1{1.367879441}\\approx0.731058579\" width=\"346.14\" height=\"50.09\" style=\"width:346.14px;height:50.09px;aspect-ratio:346.14/50.09\" loading=\"lazy\"></picture></div>","<h3>Step 2: substitute the target in the full loss formula</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fca94e6b25348fdc.svg\" alt=\"L=-\\left[1\\ln(0.731058579)+(1-1)\\ln(1-0.731058579)\\right]\" width=\"588.23\" height=\"24.43\" style=\"width:588.23px;height:24.43px;aspect-ratio:588.23/24.43\" loading=\"lazy\"></div>","<p>The second term has multiplier zero, so it contributes zero.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f41a1bed5052539d.svg\"><img class=\"math display-math\" src=\"assets/equations/36829459a4aa6b4b.svg\" alt=\"L=-\\ln(0.731058579)\\approx0.313261688\" width=\"402.21\" height=\"24.43\" style=\"width:402.21px;height:24.43px;aspect-ratio:402.21/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 3: calculate the combined gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.86px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d503567052ec89af.svg\"><img class=\"math display-math\" src=\"assets/equations/24cc736ea2ce6146.svg\" alt=\"\\frac{\\partial L}{\\partial z}=0.731058579-1=-0.268941421\" width=\"425.41\" height=\"51.29\" style=\"width:425.41px;height:51.29px;aspect-ratio:425.41/51.29\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> probability ≈ 0.731059; BCE ≈ 0.313262; logit gradient ≈ −0.268941. The simplified gradient already includes sigmoid&#x27;s effect. Multiplying by sigmoid&#x27;s slope again would apply it twice.</p>"],"kind":"practice","id":"tee-c17-s7","search":"Drill 7 Sigmoid with binary cross entropy **Question.** A binary classifier has logit z = 1, target 1. Find probability, BCE and the gradient with respect to z.\n\n**Full solution.**\n\n\n\n### Given\n\nLogit z = 1; binary target y = 1.\n\nOutput: sigmoid; loss: binary cross-entropy.\n\n### To find\n\nFind probability, BCE and the loss derivative with respect to z.\n\n### Formula — which one and why\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Binary cross-entropy.** For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.\n\ny is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.\n\n\n\n\n\n**Yaad rakhne ka cue:** Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nA logit is the raw score before sigmoid. Sigmoid converts it to a probability p. The target y = 1 says the positive class is correct. Binary cross-entropy measures how little probability the model assigned to the correct binary outcome.\n\n\nFor sigmoid combined with this loss, the gradient with respect to the logit has the simplified form:\n\n### Step 1: convert logit 1 into probability\n\n\n\n### Step 2: substitute the target in the full loss formula\n\nThe second term has multiplier zero, so it contributes zero.\n\n### Step 3: calculate the combined gradient\n\n**Final answer:** probability ≈ 0.731059; BCE ≈ 0.313262; logit gradient ≈ −0.268941. The simplified gradient already includes sigmoid's effect. Multiplying by sigmoid's slope again would apply it twice.\n"},{"title":"Drill 8 Activation contrast","question":["<p class=\"inline-question\"><strong>Question.</strong> For z = [−3,0,2], find ReLU and Leaky ReLU with α = 0.1, and the sigmoid derivative at z = 0.</p>"],"answer":["<h3>Given</h3>","<p>Inputs z = [−3,0,2].</p>","<p>Leaky-ReLU negative slope α = 0.1.</p>","<p>For the sigmoid derivative, use z = 0.</p>","<h3>To find</h3>","<p>Find ReLU and Leaky-ReLU outputs and the sigmoid slope at zero.</p>","<h3>Formula — which one and why</h3>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<h3>Solution — step by step</h3>","<h3>Formulas and their meanings</h3>","<p>ReLU compares the input with zero and returns the larger value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<p>Leaky ReLU uses the input unchanged when nonnegative, and multiplies it by α when negative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<h3>Step 1: apply ReLU separately to all three inputs</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.46px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3202f6e374a86c4c.svg\"><img class=\"math display-math\" src=\"assets/equations/7a53989c39d25faa.svg\" alt=\"\\max(0,-3)=0,\\quad \\max(0,0)=0,\\quad \\max(0,2)=2\" width=\"523.36\" height=\"24.43\" style=\"width:523.36px;height:24.43px;aspect-ratio:523.36/24.43\" loading=\"lazy\"></picture></div>","<p><strong>ReLU output = [0, 0, 2].</strong></p>","<h3>Step 2: use α = 0.1 only on the negative input</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/189f052516957693.svg\" alt=\"0.1\\times(-3)=-0.3\" width=\"194.15\" height=\"24.43\" style=\"width:194.15px;height:24.43px;aspect-ratio:194.15/24.43\" loading=\"lazy\"></div>","<p>The zero and positive entries remain 0 and 2. <strong>Leaky ReLU output = [−0.3, 0, 2].</strong></p>","<h3>Step 3: calculate sigmoid before its derivative</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.01px;--narrow-height:92.09px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7727ce70c548ec20.svg\"><img class=\"math display-math\" src=\"assets/equations/4a542f0b5de210cf.svg\" alt=\"\\sigma(z)=\\frac1{1+e^{-z}},\\qquad \\sigma&#x27;(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"452.38\" height=\"51.56\" style=\"width:452.38px;height:51.56px;aspect-ratio:452.38/51.56\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.29px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1ef72ba6a1deae0f.svg\"><img class=\"math display-math\" src=\"assets/equations/8b3dd0cfc097c6b9.svg\" alt=\"\\sigma(0)=\\frac1{1+e^0}=\\frac1{1+1}=0.5\" width=\"314.11\" height=\"52.39\" style=\"width:314.11px;height:52.39px;aspect-ratio:314.11/52.39\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.09px;--narrow-height:64.97px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c6f6bc13772ea829.svg\"><img class=\"math display-math\" src=\"assets/equations/20af7f249f7a71f8.svg\" alt=\"\\sigma&#x27;(0)=0.5(1-0.5)=0.5\\times0.5=0.25\" width=\"409.03\" height=\"25.88\" style=\"width:409.03px;height:25.88px;aspect-ratio:409.03/25.88\" loading=\"lazy\"></picture></div>","<p>The sigmoid <strong>value</strong> is 0.5 but its <strong>slope</strong> is 0.25. They are different quantities.</p>"],"kind":"practice","id":"tee-c17-s8","search":"Drill 8 Activation contrast **Question.** For z = [−3,0,2], find ReLU and Leaky ReLU with α = 0.1, and the sigmoid derivative at z = 0.\n\n**Full solution.**\n\n\n\n### Given\n\nInputs z = [−3,0,2].\n\nLeaky-ReLU negative slope α = 0.1.\n\nFor the sigmoid derivative, use z = 0.\n\n### To find\n\nFind ReLU and Leaky-ReLU outputs and the sigmoid slope at zero.\n\n### Formula — which one and why\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and their meanings\nReLU compares the input with zero and returns the larger value.\n\nLeaky ReLU uses the input unchanged when nonnegative, and multiplies it by α when negative.\n\n### Step 1: apply ReLU separately to all three inputs\n\n**ReLU output = [0, 0, 2].**\n### Step 2: use α = 0.1 only on the negative input\n\nThe zero and positive entries remain 0 and 2. **Leaky ReLU output = [−0.3, 0, 2].**\n### Step 3: calculate sigmoid before its derivative\n\n\n\nThe sigmoid **value** is 0.5 but its **slope** is 0.25. They are different quantities.\n"},{"title":"Drill 9 Softmax and true class loss","question":["<p class=\"inline-question\"><strong>Question.</strong> Scores = [1,2,0], true one-hot class = [0,1,0]. Find probabilities and categorical cross-entropy.</p>"],"answer":["<h3>Given</h3>","<p>Logits = [1,2,0].</p>","<p>One-hot target = [0,1,0]: class 2 is correct.</p>","<h3>To find</h3>","<p>Find all three softmax probabilities and CCE.</p>","<h3>Formula — which one and why</h3>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The scores z are raw class scores. Softmax converts the whole group into class probabilities. The label [0,1,0] says class 2 is correct; it is not a set of predicted probabilities.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.27px;--narrow-height:118.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd0c8ddf71d7e5e7.svg\"><img class=\"math display-math\" src=\"assets/equations/b901ae0600ed0d36.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_jz_j\" width=\"324.43\" height=\"63.31\" style=\"width:324.43px;height:63.31px;aspect-ratio:324.43/63.31\" loading=\"lazy\"></picture></div>","<p>Subtracting the same c from every score keeps the probabilities unchanged and avoids very large exponentials.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a21d413c89b5a80.svg\" alt=\"L_{\\mathrm{CCE}}=-\\sum_i y_i\\ln p_i\" width=\"219.18\" height=\"52.35\" style=\"width:219.18px;height:52.35px;aspect-ratio:219.18/52.35\" loading=\"lazy\"></div>","<h3>Step 1: subtract the largest score</h3>","<p>The largest of [1,2,0] is 2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72ceba57b734c648.svg\"><img class=\"math display-math\" src=\"assets/equations/b6bd92da9301ed16.svg\" alt=\"[1-2,\\;2-2,\\;0-2]=[-1,0,-2]\" width=\"354.38\" height=\"24.43\" style=\"width:354.38px;height:24.43px;aspect-ratio:354.38/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: calculate the three exponentials</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:203.84px;--narrow-height:112.44px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b2c277f81e3d9881.svg\"><img class=\"math display-math\" src=\"assets/equations/c1751b34781aca62.svg\" alt=\"e^{-1}=0.367879441,\\quad e^0=1,\\quad e^{-2}=0.135335283\" width=\"531.54\" height=\"26.34\" style=\"width:531.54px;height:26.34px;aspect-ratio:531.54/26.34\" loading=\"lazy\"></picture></div>","<h3>Step 3: add them to get one common denominator</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.87px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc4d03dcae0355c5.svg\"><img class=\"math display-math\" src=\"assets/equations/95814cf2d0de3a7e.svg\" alt=\"D=0.367879441+1+0.135335283=1.503214724\" width=\"544.26\" height=\"18.69\" style=\"width:544.26px;height:18.69px;aspect-ratio:544.26/18.69\" loading=\"lazy\"></picture></div>","<h3>Step 4: divide each exponential by this denominator</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa686bb14848b0d1.svg\"><img class=\"math display-math\" src=\"assets/equations/55ba241642d89ad8.svg\" alt=\"p_1=\\frac{0.367879441}{1.503214724}=0.244728471\" width=\"356.81\" height=\"50.36\" style=\"width:356.81px;height:50.36px;aspect-ratio:356.81/50.36\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/361efa91829285c7.svg\"><img class=\"math display-math\" src=\"assets/equations/b2c010d4d592ad18.svg\" alt=\"p_2=\\frac{1}{1.503214724}=0.665240956\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/54c91e5ed1921172.svg\"><img class=\"math display-math\" src=\"assets/equations/8024840665a8cd1c.svg\" alt=\"p_3=\\frac{0.135335283}{1.503214724}=0.090030573\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p>The probabilities add to 1, apart from rounding. Class 2 has the highest score and the highest probability.</p>","<h3>Step 5: use the probability of the correct class in CCE</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:316.01px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cc77914badc24790.svg\"><img class=\"math display-math\" src=\"assets/equations/1e41b81b1fc86ad6.svg\" alt=\"L=-[0\\ln p_1+1\\ln p_2+0\\ln p_3]=-\\ln p_2\" width=\"435.73\" height=\"24.43\" style=\"width:435.73px;height:24.43px;aspect-ratio:435.73/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65db0db7f14d7ab8.svg\"><img class=\"math display-math\" src=\"assets/equations/c6ddf889d37419c3.svg\" alt=\"L=-\\ln(0.665240956)=0.407605964\" width=\"402.21\" height=\"24.43\" style=\"width:402.21px;height:24.43px;aspect-ratio:402.21/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> probabilities ≈ [0.244728, 0.665241, 0.090031]; CCE ≈ 0.407606.</p>"],"kind":"practice","id":"tee-c17-s9","search":"Drill 9 Softmax and true class loss **Question.** Scores = [1,2,0], true one-hot class = [0,1,0]. Find probabilities and categorical cross-entropy.\n\n**Full solution.**\n\n\n\n### Given\n\nLogits = [1,2,0].\n\nOne-hot target = [0,1,0]: class 2 is correct.\n\n### To find\n\nFind all three softmax probabilities and CCE.\n\n### Formula — which one and why\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe scores z are raw class scores. Softmax converts the whole group into class probabilities. The label [0,1,0] says class 2 is correct; it is not a set of predicted probabilities.\n\nSubtracting the same c from every score keeps the probabilities unchanged and avoids very large exponentials.\n\n### Step 1: subtract the largest score\nThe largest of [1,2,0] is 2.\n\n### Step 2: calculate the three exponentials\n\n### Step 3: add them to get one common denominator\n\n### Step 4: divide each exponential by this denominator\n\n\n\nThe probabilities add to 1, apart from rounding. Class 2 has the highest score and the highest probability.\n### Step 5: use the probability of the correct class in CCE\n\n\n**Final answer:** probabilities ≈ [0.244728, 0.665241, 0.090031]; CCE ≈ 0.407606.\n"},{"title":"Drill 10 Sigmoid neuron gradient","question":["<p class=\"inline-question\"><strong>Question.</strong> x = 2, w = 0.5, b = 0, y = 1, half squared loss, η = 0.1. Find one weight and bias update.</p>"],"answer":["<h3>Given</h3>","<p>x = 2; w = 0.5; b = 0; target y = 1.</p>","<p>Activation: sigmoid; loss: half squared error.</p>","<p>Learning rate η = 0.1.</p>","<h3>To find</h3>","<p>Find the output, delta, weight/bias gradients and one update.</p>","<h3>Formula — which one and why</h3>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>Here the loss is half squared error. It is different from binary cross-entropy, so we include the sigmoid derivative explicitly.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:156.01px;--narrow-height:154.86px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72569e3d1cf18215.svg\"><img class=\"math display-math\" src=\"assets/equations/c39b7cba136e59b8.svg\" alt=\"z=wx+b,\\quad p=\\frac1{1+e^{-z}},\\quad L=\\frac12(p-y)^2\" width=\"474.97\" height=\"51.56\" style=\"width:474.97px;height:51.56px;aspect-ratio:474.97/51.56\" loading=\"lazy\"></picture></div>","<p>The symbol δ (delta) is a short name for the loss gradient with respect to the neuron&#x27;s raw score z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf8f40120fc7de9a.svg\" alt=\"\\delta=(p-y)p(1-p)\" width=\"202.25\" height=\"24.43\" style=\"width:202.25px;height:24.43px;aspect-ratio:202.25/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6678df97903ca342.svg\" alt=\"\\frac{\\partial L}{\\partial w}=\\delta x,\\quad \\frac{\\partial L}{\\partial b}=\\delta\" width=\"219.45\" height=\"51.29\" style=\"width:219.45px;height:51.29px;aspect-ratio:219.45/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.98px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e125df8665bd715.svg\"><img class=\"math display-math\" src=\"assets/equations/46cbd30453d64730.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta\\delta x,\\quad b_{\\mathrm{new}}=b-\\eta\\delta\" width=\"339.68\" height=\"22.80\" style=\"width:339.68px;height:22.80px;aspect-ratio:339.68/22.80\" loading=\"lazy\"></picture></div>","<h3>Step 1: weighted sum and sigmoid</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88322b08817273b7.svg\" alt=\"z=0.5\\times2+0=1\" width=\"204.15\" height=\"18.27\" style=\"width:204.15px;height:18.27px;aspect-ratio:204.15/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:91.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/496f72f75e4bdba9.svg\"><img class=\"math display-math\" src=\"assets/equations/d48b6096bc280c6f.svg\" alt=\"p=\\frac1{1+e^{-1}}=0.731058579\" width=\"294.75\" height=\"52.39\" style=\"width:294.75px;height:52.39px;aspect-ratio:294.75/52.39\" loading=\"lazy\"></picture></div>","<h3>Step 2: error and activation slope</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/95ba7a4e62bbaee0.svg\"><img class=\"math display-math\" src=\"assets/equations/8773c0aada00e672.svg\" alt=\"p-y=0.731058579-1=-0.268941421\" width=\"438.33\" height=\"21.55\" style=\"width:438.33px;height:21.55px;aspect-ratio:438.33/21.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.22px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe81a8ae8e93cc3b.svg\"><img class=\"math display-math\" src=\"assets/equations/116080684bb307ac.svg\" alt=\"p(1-p)=0.731058579\\times0.268941421=0.196611933\" width=\"567.62\" height=\"24.43\" style=\"width:567.62px;height:24.43px;aspect-ratio:567.62/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 3: multiply the linked effects to obtain delta</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.42px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca75a0d20742f652.svg\"><img class=\"math display-math\" src=\"assets/equations/c963a470be9b7811.svg\" alt=\"\\delta=(-0.268941421)\\times0.196611933=-0.052877093\" width=\"549.81\" height=\"24.43\" style=\"width:549.81px;height:24.43px;aspect-ratio:549.81/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 4: multiply delta by the input to each parameter</h3>","<p>The weight receives x = 2. The bias effectively receives the constant input 1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.65px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/909d6c4ba3b4dba5.svg\"><img class=\"math display-math\" src=\"assets/equations/904a6dac1e6b4e5a.svg\" alt=\"\\frac{\\partial L}{\\partial w}=(-0.052877093)\\times2=-0.105754186\" width=\"464.29\" height=\"51.29\" style=\"width:464.29px;height:51.29px;aspect-ratio:464.29/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/385f9ff4016d4aa5.svg\" alt=\"\\frac{\\partial L}{\\partial b}=-0.052877093\" width=\"221.78\" height=\"51.29\" style=\"width:221.78px;height:51.29px;aspect-ratio:221.78/51.29\" loading=\"lazy\"></div>","<h3>Step 5: subtract learning rate times each gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/48c8e5f15b7994a8.svg\"><img class=\"math display-math\" src=\"assets/equations/b4289d1b3f149e0a.svg\" alt=\"w_{\\mathrm{new}}=0.5-0.1(-0.105754186)=0.510575419\" width=\"502.72\" height=\"24.43\" style=\"width:502.72px;height:24.43px;aspect-ratio:502.72/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b7af577aaec3d7cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bc4fa856481c3256.svg\" alt=\"b_{\\mathrm{new}}=0-0.1(-0.052877093)=0.005287709\" width=\"476.69\" height=\"24.43\" style=\"width:476.69px;height:24.43px;aspect-ratio:476.69/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> new weight ≈ 0.510575419; new bias ≈ 0.005287709. Subtracting negative gradients increases both values here.</p>"],"kind":"practice","id":"tee-c17-s10","search":"Drill 10 Sigmoid neuron gradient **Question.** x = 2, w = 0.5, b = 0, y = 1, half squared loss, η = 0.1. Find one weight and bias update.\n\n**Full solution.**\n\n\n\n### Given\n\nx = 2; w = 0.5; b = 0; target y = 1.\n\nActivation: sigmoid; loss: half squared error.\n\nLearning rate η = 0.1.\n\n### To find\n\nFind the output, delta, weight/bias gradients and one update.\n\n### Formula — which one and why\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nHere the loss is half squared error. It is different from binary cross-entropy, so we include the sigmoid derivative explicitly.\n\nThe symbol δ (delta) is a short name for the loss gradient with respect to the neuron's raw score z.\n\n\n\n### Step 1: weighted sum and sigmoid\n\n\n### Step 2: error and activation slope\n\n\n### Step 3: multiply the linked effects to obtain delta\n\n### Step 4: multiply delta by the input to each parameter\nThe weight receives x = 2. The bias effectively receives the constant input 1.\n\n\n### Step 5: subtract learning rate times each gradient\n\n\n**Final answer:** new weight ≈ 0.510575419; new bias ≈ 0.005287709. Subtracting negative gradients increases both values here.\n"},{"title":"Drill 11 One perceptron learning update","question":["<p class=\"inline-question\"><strong>Question.</strong> Binary perceptron, w = [0,0], b = 0, x = [1,1], target 1, η = 0.5. Use output 1 if z&gt;0 else 0. Perform one update.</p>"],"answer":["<h3>Given</h3>","<p>w = [0,0]; b = 0; x = [1,1]; target t = 1.</p>","<p>Learning rate η = 0.5.</p>","<p>Output 1 only when z &gt; 0; otherwise output 0.</p>","<h3>To find</h3>","<p>Perform one update and report new weights and bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Perceptron learning rule.</strong> Evaluate the stated threshold, compare the predicted class with its target, then correct weights and bias. The next sample uses the newly updated parameters.</p>","<p>t = target; o = thresholded output; η = learning rate; xᵢ = input i. Binary and bipolar output conventions must follow the question.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fccc40e029a1d4e.svg\" alt=\"w_i^{\\mathrm{new}}=w_i+\\eta(t-o)x_i\" width=\"240.87\" height=\"24.55\" style=\"width:240.87px;height:24.55px;aspect-ratio:240.87/24.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/58dd8fcb5fcd562f.svg\" alt=\"b^{\\mathrm{new}}=b+\\eta(t-o)\" width=\"196.89\" height=\"24.43\" style=\"width:196.89px;height:24.43px;aspect-ratio:196.89/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Prediction nikalo; target−prediction se correction nikalo.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>A perceptron first computes a weighted sum z and then applies the exact threshold rule in the question. This question uses <strong>strictly greater than zero</strong>, so z = 0 produces output 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/10b03fc6ae774e47.svg\" alt=\"z=w_1x_1+w_2x_2+b,\\qquad o=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z\\le0\\end{cases}\" width=\"435.09\" height=\"58.62\" style=\"width:435.09px;height:58.62px;aspect-ratio:435.09/58.62\" loading=\"lazy\"></div>","<p>The perceptron learning rule uses target minus output, written e below. This is a discrete perceptron rule, not the sigmoid backpropagation derivative.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:203.74px;--narrow-height:103.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd56f1cf8ec70869.svg\"><img class=\"math display-math\" src=\"assets/equations/e4615db5fadb580f.svg\" alt=\"e=t-o,\\qquad w_{j,\\mathrm{new}}=w_j+\\eta e x_j,\\qquad b_{\\mathrm{new}}=b+\\eta e\" width=\"549.66\" height=\"24.15\" style=\"width:549.66px;height:24.15px;aspect-ratio:549.66/24.15\" loading=\"lazy\"></picture></div>","<h3>Step 1: obtain the old output</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.51px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6eff381fa8ae5b02.svg\"><img class=\"math display-math\" src=\"assets/equations/6f31e8743e028b72.svg\" alt=\"z=0\\times1+0\\times1+0=0,\\qquad o=0\" width=\"385.70\" height=\"21.02\" style=\"width:385.70px;height:21.02px;aspect-ratio:385.70/21.02\" loading=\"lazy\"></picture></div>","<h3>Step 2: compare it with the target</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a3b896434f77ddd.svg\" alt=\"e=1-0=1\" width=\"143.08\" height=\"18.27\" style=\"width:143.08px;height:18.27px;aspect-ratio:143.08/18.27\" loading=\"lazy\"></div>","<h3>Step 3: update each weight separately</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.78px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/61526c5e9b2167a4.svg\"><img class=\"math display-math\" src=\"assets/equations/3bbcbc135cd52b17.svg\" alt=\"w_{1,\\mathrm{new}}=0+0.5\\times1\\times1=0.5\" width=\"316.60\" height=\"23.30\" style=\"width:316.60px;height:23.30px;aspect-ratio:316.60/23.30\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.78px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1e2f50640ebb5c1e.svg\"><img class=\"math display-math\" src=\"assets/equations/6067f1cf6b435026.svg\" alt=\"w_{2,\\mathrm{new}}=0+0.5\\times1\\times1=0.5\" width=\"316.60\" height=\"23.30\" style=\"width:316.60px;height:23.30px;aspect-ratio:316.60/23.30\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ef3a575874682e63.svg\" alt=\"b_{\\mathrm{new}}=0+0.5\\times1=0.5\" width=\"254.06\" height=\"20.81\" style=\"width:254.06px;height:20.81px;aspect-ratio:254.06/20.81\" loading=\"lazy\"></div>","<h3>Step 4: interpret the updated prediction</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9b6e487add8bda9e.svg\"><img class=\"math display-math\" src=\"assets/equations/195cc54e0942b6c7.svg\" alt=\"z_{\\mathrm{new}}=0.5\\times1+0.5\\times1+0.5=1.5\" width=\"377.14\" height=\"20.13\" style=\"width:377.14px;height:20.13px;aspect-ratio:377.14/20.13\" loading=\"lazy\"></picture></div>","<p>Since 1.5 &gt; 0, the new output is 1. <strong>Final parameters: w = [0.5, 0.5], b = 0.5.</strong></p>"],"kind":"practice","id":"tee-c17-s11","search":"Drill 11 One perceptron learning update **Question.** Binary perceptron, w = [0,0], b = 0, x = [1,1], target 1, η = 0.5. Use output 1 if z>0 else 0. Perform one update.\n\n**Full solution.**\n\n\n\n### Given\n\nw = [0,0]; b = 0; x = [1,1]; target t = 1.\n\nLearning rate η = 0.5.\n\nOutput 1 only when z > 0; otherwise output 0.\n\n### To find\n\nPerform one update and report new weights and bias.\n\n### Formula — which one and why\n\n**Perceptron learning rule.** Evaluate the stated threshold, compare the predicted class with its target, then correct weights and bias. The next sample uses the newly updated parameters.\n\nt = target; o = thresholded output; η = learning rate; xᵢ = input i. Binary and bipolar output conventions must follow the question.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Prediction nikalo; target−prediction se correction nikalo.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nA perceptron first computes a weighted sum z and then applies the exact threshold rule in the question. This question uses **strictly greater than zero**, so z = 0 produces output 0.\n\nThe perceptron learning rule uses target minus output, written e below. This is a discrete perceptron rule, not the sigmoid backpropagation derivative.\n\n### Step 1: obtain the old output\n\n### Step 2: compare it with the target\n\n### Step 3: update each weight separately\n\n\n\n### Step 4: interpret the updated prediction\n\nSince 1.5 > 0, the new output is 1. **Final parameters: w = [0.5, 0.5], b = 0.5.**\n"},{"title":"Drill 12 XOR using two hidden units","question":["<p class=\"inline-question\"><strong>Question.</strong> 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.</p>"],"answer":["<h3>Given</h3>","<p>h₁ = step(x₁+x₂−0.5); h₂ = step(x₁+x₂−1.5).</p>","<p>Output = step(h₁−2h₂−0.5).</p>","<p>step(z) = 1 when z ≥ 0, otherwise 0.</p>","<h3>To find</h3>","<p>Calculate hidden values and output for 00, 01, 10 and 11.</p>","<h3>Formula — which one and why</h3>","<p><strong>Threshold logic.</strong> 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.</p>","<p>step(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecb2a58d23e67edf.svg\" alt=\"\\operatorname{step}(z)=\\begin{cases}1&amp;z\\ge0\\\\0&amp;z&lt;0\\end{cases}\" width=\"217.66\" height=\"58.62\" style=\"width:217.66px;height:58.62px;aspect-ratio:217.66/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Har input row ka sum nikalo, phir threshold lagao.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the given network</h3>","<p>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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bbffb2524956d0e5.svg\" alt=\"h_1=\\operatorname{step}(x_1+x_2-0.5)\" width=\"260.15\" height=\"24.43\" style=\"width:260.15px;height:24.43px;aspect-ratio:260.15/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31fad4d0ea8f08ac.svg\" alt=\"h_2=\\operatorname{step}(x_1+x_2-1.5)\" width=\"260.15\" height=\"24.43\" style=\"width:260.15px;height:24.43px;aspect-ratio:260.15/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0af913266b36a0b9.svg\" alt=\"o=\\operatorname{step}(h_1-2h_2-0.5)\" width=\"259.68\" height=\"24.43\" style=\"width:259.68px;height:24.43px;aspect-ratio:259.68/24.43\" loading=\"lazy\"></div>","<p>For this question, step returns 1 at nonnegative input and 0 at negative input.</p>","<p class=\"worked-step\"><strong>Step 1: Input pair 0, 0.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.37px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6669d48b7635634e.svg\"><img class=\"math display-math\" src=\"assets/equations/8b21d73077236089.svg\" alt=\"z_{h_1}=0+0-0.5=-0.5\\Rightarrow h_1=0\" width=\"369.24\" height=\"23.21\" style=\"width:369.24px;height:23.21px;aspect-ratio:369.24/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.37px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dcc9f2d8a503f369.svg\"><img class=\"math display-math\" src=\"assets/equations/4cb4887fc9401848.svg\" alt=\"z_{h_2}=0+0-1.5=-1.5\\Rightarrow h_2=0\" width=\"369.24\" height=\"23.21\" style=\"width:369.24px;height:23.21px;aspect-ratio:369.24/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:200.98px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/96a5d17e0b8dd052.svg\"><img class=\"math display-math\" src=\"assets/equations/90628ef67242e4d9.svg\" alt=\"z_o=0-2(0)-0.5=-0.5\\Rightarrow o=0\" width=\"378.46\" height=\"24.43\" style=\"width:378.46px;height:24.43px;aspect-ratio:378.46/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Input pair 0, 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:178.87px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f9475f1991e07af3.svg\"><img class=\"math display-math\" src=\"assets/equations/aadd7c29e1061db5.svg\" alt=\"z_{h_1}=0+1-0.5=0.5\\Rightarrow h_1=1\" width=\"350.23\" height=\"23.21\" style=\"width:350.23px;height:23.21px;aspect-ratio:350.23/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.37px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/45e0fb48b7159e24.svg\"><img class=\"math display-math\" src=\"assets/equations/3eb9b9d929e96417.svg\" alt=\"z_{h_2}=0+1-1.5=-0.5\\Rightarrow h_2=0\" width=\"369.24\" height=\"23.21\" style=\"width:369.24px;height:23.21px;aspect-ratio:369.24/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:200.98px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0ba860b3391cf5c7.svg\"><img class=\"math display-math\" src=\"assets/equations/9e3e9239cb2ed70d.svg\" alt=\"z_o=1-2(0)-0.5=0.5\\Rightarrow o=1\" width=\"359.46\" height=\"24.43\" style=\"width:359.46px;height:24.43px;aspect-ratio:359.46/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: Input pair 1, 0.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:178.87px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/986114a7a93ab89f.svg\"><img class=\"math display-math\" src=\"assets/equations/7c04e117ce2375c9.svg\" alt=\"z_{h_1}=1+0-0.5=0.5\\Rightarrow h_1=1\" width=\"350.23\" height=\"23.21\" style=\"width:350.23px;height:23.21px;aspect-ratio:350.23/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.37px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b9f2126aba5c12cc.svg\"><img class=\"math display-math\" src=\"assets/equations/d8ee9449e01e7c58.svg\" alt=\"z_{h_2}=1+0-1.5=-0.5\\Rightarrow h_2=0\" width=\"369.24\" height=\"23.21\" style=\"width:369.24px;height:23.21px;aspect-ratio:369.24/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:200.98px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0ba860b3391cf5c7.svg\"><img class=\"math display-math\" src=\"assets/equations/9e3e9239cb2ed70d.svg\" alt=\"z_o=1-2(0)-0.5=0.5\\Rightarrow o=1\" width=\"359.46\" height=\"24.43\" style=\"width:359.46px;height:24.43px;aspect-ratio:359.46/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: Input pair 1, 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:178.87px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c6382db6dca562bf.svg\"><img class=\"math display-math\" src=\"assets/equations/7236f1129a18b80e.svg\" alt=\"z_{h_1}=1+1-0.5=1.5\\Rightarrow h_1=1\" width=\"350.23\" height=\"23.21\" style=\"width:350.23px;height:23.21px;aspect-ratio:350.23/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:178.87px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/208b1fc802d6494c.svg\"><img class=\"math display-math\" src=\"assets/equations/ef884a3d2271fe60.svg\" alt=\"z_{h_2}=1+1-1.5=0.5\\Rightarrow h_2=1\" width=\"350.23\" height=\"23.21\" style=\"width:350.23px;height:23.21px;aspect-ratio:350.23/23.21\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:200.98px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f0db03c68af4ca9e.svg\"><img class=\"math display-math\" src=\"assets/equations/6f8b6a8f26883852.svg\" alt=\"z_o=1-2(1)-0.5=-1.5\\Rightarrow o=0\" width=\"378.46\" height=\"24.43\" style=\"width:378.46px;height:24.43px;aspect-ratio:378.46/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final truth table:</strong> 00 → 0; 01 → 1; 10 → 1; 11 → 0.</p>"],"kind":"practice","id":"tee-c17-s12","search":"Drill 12 XOR using two hidden units **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.\n\n**Full solution.**\n\n\n\n### Given\n\nh₁ = step(x₁+x₂−0.5); h₂ = step(x₁+x₂−1.5).\n\nOutput = step(h₁−2h₂−0.5).\n\nstep(z) = 1 when z ≥ 0, otherwise 0.\n\n### To find\n\nCalculate hidden values and output for 00, 01, 10 and 11.\n\n### Formula — which one and why\n\n**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.\n\nstep(z) returns 1 at or above zero unless the question specifies a strict inequality; otherwise it returns 0.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har input row ka sum nikalo, phir threshold lagao.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the given network\nXOR 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.\n\n\n\nFor this question, step returns 1 at nonnegative input and 0 at negative input.\n**Step 1: Input pair 0, 0.**\n\n\n\n**Step 2: Input pair 0, 1.**\n\n\n\n**Step 3: Input pair 1, 0.**\n\n\n\n**Step 4: Input pair 1, 1.**\n\n\n\n**Final truth table:** 00 → 0; 01 → 1; 10 → 1; 11 → 0.\n"},{"title":"Drill 13 Full ReLU backpropagation","question":["<p class=\"inline-question\"><strong>Question.</strong> Input x = [1, 2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.1. Use half squared loss and update all weights and biases.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_0601bfe757.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_0601bfe757.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_drill13.svg\" aria-label=\"Enlarge diagram: Worked example: all incoming weights and biases\"><img src=\"assets/figures/net_drill13.svg\" alt=\"Worked example: all incoming weights and biases\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>Worked example: all incoming weights and biases <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [1, 2].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.1].</p>","<p>Hidden and output activations are ReLU.</p>","<p>Target y = [1].</p>","<p>Learning rate η = 0.1.</p>","<p>Use half squared loss and update all weights and biases.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used before substituting numbers</h3>","<p>For every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.98px;--narrow-height:169.67px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc1bda021c501564.svg\"><img class=\"math display-math\" src=\"assets/equations/b6818e3243c5ede2.svg\" alt=\"z_j=\\sum_iw_{ji}a_i+b_j,\\quad a_j=f(z_j),\\quad L=\\frac12\\sum_k(o_k-y_k)^2\" width=\"590.65\" height=\"62.49\" style=\"width:590.65px;height:62.49px;aspect-ratio:590.65/62.49\" loading=\"lazy\"></picture></div>","<p>Delta means the loss gradient with respect to a neuron&#x27;s raw score. First calculate output deltas, then hidden deltas using every connected output path.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e56bc6ef11f21beb.svg\" alt=\"\\delta_{o_k}=(o_k-y_k)f&#x27;(z_{o_k})\" width=\"226.50\" height=\"26.16\" style=\"width:226.50px;height:26.16px;aspect-ratio:226.50/26.16\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6086310bbc701ed1.svg\" alt=\"\\delta_{h_j}=\\left(\\sum_kw_{kj}\\delta_{o_k}\\right)f&#x27;(z_{h_j})\" width=\"274.97\" height=\"73.28\" style=\"width:274.97px;height:73.28px;aspect-ratio:274.97/73.28\" loading=\"lazy\"></div>","<p>The gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f883fcc3e95816b.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i,\\qquad \\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"287.20\" height=\"57.94\" style=\"width:287.20px;height:57.94px;aspect-ratio:287.20/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.06px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7c0c7e8cef31635.svg\"><img class=\"math display-math\" src=\"assets/equations/289f74bc5d59b047.svg\" alt=\"w_{ji,\\mathrm{new}}=w_{ji}-\\eta\\delta_j a_i,\\quad b_{j,\\mathrm{new}}=b_j-\\eta\\delta_j\" width=\"418.98\" height=\"24.71\" style=\"width:418.98px;height:24.71px;aspect-ratio:418.98/24.71\" loading=\"lazy\"></picture></div>","<p>For sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d12052a5268cb30c.svg\"><img class=\"math display-math\" src=\"assets/equations/9b009885daaa5779.svg\" alt=\"z_{h_1} = (0.2 \\times  1) + (0.1 \\times  2) + (0.1) = 0.5\" width=\"421.90\" height=\"24.58\" style=\"width:421.90px;height:24.58px;aspect-ratio:421.90/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b78961f402336b21.svg\" alt=\"h_{1} = \\max(0,0.5) = 0.5\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0eb4dbe7db30c72c.svg\"><img class=\"math display-math\" src=\"assets/equations/840732725d47f1fe.svg\" alt=\"z_{h_2} = (0.3 \\times  1) + (-0.1 \\times  2) + (0.2) = 0.3\" width=\"440.92\" height=\"24.58\" style=\"width:440.92px;height:24.58px;aspect-ratio:440.92/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3ca4b1ac8771a1a8.svg\" alt=\"h_{2} = \\max(0,0.3) = 0.3\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/24202b454fb4dad2.svg\"><img class=\"math display-math\" src=\"assets/equations/f22e357a250f5762.svg\" alt=\"z_{o_1} = (0.4 \\times  0.5) + (0.5 \\times  0.3) + (0.1) = 0.45\" width=\"470.57\" height=\"24.58\" style=\"width:470.57px;height:24.58px;aspect-ratio:470.57/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e6f7822c28a4fdd9.svg\" alt=\"o_{1} = \\max(0,0.45) = 0.45\" width=\"262.14\" height=\"24.43\" style=\"width:262.14px;height:24.43px;aspect-ratio:262.14/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.55]. Squared errors = [0.3025]. Half-sum squared loss = 0.15125; mean squared error = 0.3025. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/08c65e290585835f.svg\"><img class=\"math display-math\" src=\"assets/equations/e54a4bff1059c242.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.45-1) \\times  1 = -0.55\" width=\"345.14\" height=\"24.58\" style=\"width:345.14px;height:24.58px;aspect-ratio:345.14/24.58\" loading=\"lazy\"></picture></div>","<p>The ReLU derivative is 1 here because this preactivation is positive.</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.5</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.55</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.4275</strong></div></div><p>Subtract η × gradient = <b>−0.0275</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.92px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a95215144e52b49.svg\"><img class=\"math display-math\" src=\"assets/equations/1452e508c28a6d93.svg\" alt=\"g_{1,1}^{(2)}=(-0.55)\\times(0.5)\\approx -0.275\" width=\"337.18\" height=\"36.54\" style=\"width:337.18px;height:36.54px;aspect-ratio:337.18/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5bb285fe6a5d5ca6.svg\"><img class=\"math display-math\" src=\"assets/equations/c98fe26955db1400.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.4-0.1(-0.275)\\approx 0.4275\" width=\"400.79\" height=\"36.54\" style=\"width:400.79px;height:36.54px;aspect-ratio:400.79/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.3</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.55</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.165</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.5165</strong></div></div><p>Subtract η × gradient = <b>−0.0165</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.92px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9dd543c1a4cfe977.svg\"><img class=\"math display-math\" src=\"assets/equations/9325b59e9bc80f3d.svg\" alt=\"g_{1,2}^{(2)}=(-0.55)\\times(0.3)\\approx -0.165\" width=\"337.18\" height=\"36.54\" style=\"width:337.18px;height:36.54px;aspect-ratio:337.18/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6b95f80af95c8ca3.svg\"><img class=\"math display-math\" src=\"assets/equations/8b302d0b5078734a.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.5-0.1(-0.165)\\approx 0.5165\" width=\"400.79\" height=\"36.54\" style=\"width:400.79px;height:36.54px;aspect-ratio:400.79/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.22</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b6b2e13098fb66e7.svg\"><img class=\"math display-math\" src=\"assets/equations/a0677d80f1fb0659.svg\" alt=\"C_1=(0.4)\\times(-0.55)\\approx -0.22\" width=\"317.34\" height=\"24.43\" style=\"width:317.34px;height:24.43px;aspect-ratio:317.34/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b39852d5faaf11fb.svg\" alt=\"\\text{Sum}=C_1\\approx -0.22\" width=\"203.29\" height=\"20.89\" style=\"width:203.29px;height:20.89px;aspect-ratio:203.29/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f452f757c3f0207e.svg\" alt=\"\\delta_{h_1} = -0.22 \\times  1 = -0.22\" width=\"262.54\" height=\"23.78\" style=\"width:262.54px;height:23.78px;aspect-ratio:262.54/23.78\" loading=\"lazy\"></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.55</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.275</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7150a7153bb561f5.svg\"><img class=\"math display-math\" src=\"assets/equations/2daae1e05e9f3afa.svg\" alt=\"C_1=(0.5)\\times(-0.55)\\approx -0.275\" width=\"329.55\" height=\"24.43\" style=\"width:329.55px;height:24.43px;aspect-ratio:329.55/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d346b0df4b69bd95.svg\" alt=\"\\text{Sum}=C_1\\approx -0.275\" width=\"215.50\" height=\"20.89\" style=\"width:215.50px;height:20.89px;aspect-ratio:215.50/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7ad50eed6d4c12e2.svg\" alt=\"\\delta_{h_2} = -0.275 \\times  1 = -0.275\" width=\"286.97\" height=\"23.78\" style=\"width:286.97px;height:23.78px;aspect-ratio:286.97/23.78\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.222</strong></div></div><p>Subtract η × gradient = <b>−0.022</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.91px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c1b77c7df67c595.svg\"><img class=\"math display-math\" src=\"assets/equations/d2c8214211374554.svg\" alt=\"g_{1,1}^{(1)}=(-0.22)\\times(1)\\approx -0.22\" width=\"305.95\" height=\"36.54\" style=\"width:305.95px;height:36.54px;aspect-ratio:305.95/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e91b335304219c5c.svg\"><img class=\"math display-math\" src=\"assets/equations/1103f1b43164b612.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.2-0.1(-0.22)\\approx 0.222\" width=\"376.35\" height=\"36.54\" style=\"width:376.35px;height:36.54px;aspect-ratio:376.35/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.22</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.44</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.144</strong></div></div><p>Subtract η × gradient = <b>−0.044</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.91px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/828d4390f7c40527.svg\"><img class=\"math display-math\" src=\"assets/equations/7306e7ed77d36dd1.svg\" alt=\"g_{1,2}^{(1)}=(-0.22)\\times(2)\\approx -0.44\" width=\"305.95\" height=\"36.54\" style=\"width:305.95px;height:36.54px;aspect-ratio:305.95/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0bf76ef563b87e1.svg\"><img class=\"math display-math\" src=\"assets/equations/679cfd3e82742ab1.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.1-0.1(-0.44)\\approx 0.144\" width=\"376.35\" height=\"36.54\" style=\"width:376.35px;height:36.54px;aspect-ratio:376.35/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.3275</strong></div></div><p>Subtract η × gradient = <b>−0.0275</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.13px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a0689c05816a3a3a.svg\"><img class=\"math display-math\" src=\"assets/equations/efc4ca15325664fa.svg\" alt=\"g_{2,1}^{(1)}=(-0.275)\\times(1)\\approx -0.275\" width=\"330.38\" height=\"36.54\" style=\"width:330.38px;height:36.54px;aspect-ratio:330.38/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/950cba298eb25531.svg\"><img class=\"math display-math\" src=\"assets/equations/c874099b770b95c2.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.3-0.1(-0.275)\\approx 0.3275\" width=\"400.79\" height=\"36.54\" style=\"width:400.79px;height:36.54px;aspect-ratio:400.79/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">2</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.275</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.55</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.045</strong></div></div><p>Subtract η × gradient = <b>−0.055</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.13px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/27b6c549a9eafc2d.svg\"><img class=\"math display-math\" src=\"assets/equations/a96b50c26c1fb262.svg\" alt=\"g_{2,2}^{(1)}=(-0.275)\\times(2)\\approx -0.55\" width=\"318.17\" height=\"36.54\" style=\"width:318.17px;height:36.54px;aspect-ratio:318.17/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.81px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c7fab0773a9a18b8.svg\"><img class=\"math display-math\" src=\"assets/equations/3c1258873b38aaf8.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=-0.1-0.1(-0.55)\\approx -0.045\" width=\"414.37\" height=\"36.54\" style=\"width:414.37px;height:36.54px;aspect-ratio:414.37/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31940cedcf20decc.svg\"><img class=\"math display-math\" src=\"assets/equations/9f4d72c657ffcbf4.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.1-0.1(-0.220000000)=0.122000000\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6350b7de1a7fd962.svg\"><img class=\"math display-math\" src=\"assets/equations/a1c182cfafd9e6ab.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.2-0.1(-0.275000000)=0.227500000\" width=\"518.00\" height=\"25.35\" style=\"width:518.00px;height:25.35px;aspect-ratio:518.00/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ce690df86543a5bc.svg\"><img class=\"math display-math\" src=\"assets/equations/42cf2912fda00eff.svg\" alt=\"b_{o_1,\\mathrm{new}}=0.1-0.1(-0.550000000)=0.155000000\" width=\"516.43\" height=\"25.35\" style=\"width:516.43px;height:25.35px;aspect-ratio:516.43/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>"],"kind":"practice","id":"tee-c17-s13","search":"Drill 13 Full ReLU backpropagation **Question.** Input x = [1, 2]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU. Target y = [1]. Learning rate η = 0.1. Use half squared loss and update all weights and biases.\n\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput x = [1, 2].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.1].\n\nHidden and output activations are ReLU.\n\nTarget y = [1].\n\nLearning rate η = 0.1.\n\nUse half squared loss and update all weights and biases.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss and its output derivatives. Find the requested deltas and parameter gradients, then update the specified parameters.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used before substituting numbers\nFor every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.\n\nDelta means the loss gradient with respect to a neuron's raw score. First calculate output deltas, then hidden deltas using every connected output path.\n\n\nThe gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.\n\n\nFor sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.\n\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.55]."},{"title":"Drill 14 Two output sigmoid backpropagation","question":["<p class=\"inline-question\"><strong>Question.</strong> Input x = [0.2, 0.4]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.1]; W₂ is shown below; b₂ = [0, 0.1]. Hidden and output activations are sigmoid. Target y = [1, 0]. Learning rate η = 0.2. Use half summed squared loss and update all parameters.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_907c03b5dc.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_907c03b5dc.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_drill14.svg\" aria-label=\"Enlarge diagram: Worked example: both output paths must contribute to hidden gradients\"><img src=\"assets/figures/net_drill14.svg\" alt=\"Worked example: both output paths must contribute to hidden gradients\" width=\"960\" height=\"638\" loading=\"lazy\"></button><figcaption>Worked example: both output paths must contribute to hidden gradients <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input x = [0.2, 0.4].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.1].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0, 0.1].</p>","<p>Hidden and output activations are sigmoid.</p>","<p>Target y = [1, 0].</p>","<p>Learning rate η = 0.2.</p>","<p>Use half summed squared loss and update all parameters.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used before substituting numbers</h3>","<p>For every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.98px;--narrow-height:169.67px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc1bda021c501564.svg\"><img class=\"math display-math\" src=\"assets/equations/b6818e3243c5ede2.svg\" alt=\"z_j=\\sum_iw_{ji}a_i+b_j,\\quad a_j=f(z_j),\\quad L=\\frac12\\sum_k(o_k-y_k)^2\" width=\"590.65\" height=\"62.49\" style=\"width:590.65px;height:62.49px;aspect-ratio:590.65/62.49\" loading=\"lazy\"></picture></div>","<p>Delta means the loss gradient with respect to a neuron&#x27;s raw score. First calculate output deltas, then hidden deltas using every connected output path.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e56bc6ef11f21beb.svg\" alt=\"\\delta_{o_k}=(o_k-y_k)f&#x27;(z_{o_k})\" width=\"226.50\" height=\"26.16\" style=\"width:226.50px;height:26.16px;aspect-ratio:226.50/26.16\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6086310bbc701ed1.svg\" alt=\"\\delta_{h_j}=\\left(\\sum_kw_{kj}\\delta_{o_k}\\right)f&#x27;(z_{h_j})\" width=\"274.97\" height=\"73.28\" style=\"width:274.97px;height:73.28px;aspect-ratio:274.97/73.28\" loading=\"lazy\"></div>","<p>The gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f883fcc3e95816b.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i,\\qquad \\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"287.20\" height=\"57.94\" style=\"width:287.20px;height:57.94px;aspect-ratio:287.20/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.06px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7c0c7e8cef31635.svg\"><img class=\"math display-math\" src=\"assets/equations/289f74bc5d59b047.svg\" alt=\"w_{ji,\\mathrm{new}}=w_{ji}-\\eta\\delta_j a_i,\\quad b_{j,\\mathrm{new}}=b_j-\\eta\\delta_j\" width=\"418.98\" height=\"24.71\" style=\"width:418.98px;height:24.71px;aspect-ratio:418.98/24.71\" loading=\"lazy\"></picture></div>","<p>For sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b34f23de35a7cf0c.svg\"><img class=\"math display-math\" src=\"assets/equations/c91412b204993ed6.svg\" alt=\"z_{h_1} = (0.1 \\times  0.2) + (0.2 \\times  0.4) + (0.1) = 0.2\" width=\"459.93\" height=\"24.58\" style=\"width:459.93px;height:24.58px;aspect-ratio:459.93/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.54px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/acdd5499eb345eef.svg\"><img class=\"math display-math\" src=\"assets/equations/94bdd56fd67f70d6.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(0.2)}}=0.549833997\" width=\"334.10\" height=\"53.84\" style=\"width:334.10px;height:53.84px;aspect-ratio:334.10/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6178667245d07427.svg\"><img class=\"math display-math\" src=\"assets/equations/0c8577da1dc8776a.svg\" alt=\"z_{h_2} = (-0.2 \\times  0.2) + (0.3 \\times  0.4) + (0.1) = 0.18\" width=\"491.15\" height=\"24.58\" style=\"width:491.15px;height:24.58px;aspect-ratio:491.15/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.18px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/63a52c4f6d59b8f1.svg\"><img class=\"math display-math\" src=\"assets/equations/e227b5ddfa70fc91.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(0.18)}}=0.544878892\" width=\"342.73\" height=\"53.84\" style=\"width:342.73px;height:53.84px;aspect-ratio:342.73/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.95px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/897314316dee8982.svg\"><img class=\"math display-math\" src=\"assets/equations/e5fd2ad81db5cb12.svg\" alt=\"z_{o_1} = (0.2 \\times  0.549833997) + (-0.1 \\times  0.544878892) + (0) = 0.05547891\" width=\"739.35\" height=\"24.58\" style=\"width:739.35px;height:24.58px;aspect-ratio:739.35/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.80px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/247adbbc93580b44.svg\"><img class=\"math display-math\" src=\"assets/equations/4890faea42fbcddd.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.05547891)}}=0.513866171\" width=\"392.34\" height=\"53.84\" style=\"width:392.34px;height:53.84px;aspect-ratio:392.34/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0e0191df53ed3741.svg\"><img class=\"math display-math\" src=\"assets/equations/4e7177927a4b11d4.svg\" alt=\"z_{o_2} = (0.3 \\times  0.549833997) + (0.4 \\times  0.544878892) + (0.1) = 0.482901756\" width=\"751.56\" height=\"24.58\" style=\"width:751.56px;height:24.58px;aspect-ratio:751.56/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9a8b37a15ece040e.svg\"><img class=\"math display-math\" src=\"assets/equations/b4bdac71b195a0cc.svg\" alt=\"o_{2}=\\frac{1}{1+e^{-(0.482901756)}}=0.618432848\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.486133829, 0.618432848]. Squared errors = [0.2363261, 0.382459187]. Half-sum squared loss = 0.309392643; mean squared error = 0.309392643. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f1f5b1787fc59def.svg\"><img class=\"math display-math\" src=\"assets/equations/32cdbe21f65e2b06.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.513866171-1) \\times  0.249807729 = -0.121439988\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p><strong>Output delta 2:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6546421fef60e0c5.svg\"><img class=\"math display-math\" src=\"assets/equations/76cba5dae26e3af0.svg\" alt=\"\\delta_{o_2} = 1 \\times  (0.618432848-0) \\times  0.235973661 = 0.145933863\" width=\"613.92\" height=\"24.58\" style=\"width:613.92px;height:24.58px;aspect-ratio:613.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.549833997</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.121439988</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.066771834</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.213354367</strong></div></div><p>Subtract η × gradient = <b>−0.013354367</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8335141cc6234897.svg\"><img class=\"math display-math\" src=\"assets/equations/918d32ea9955cc69.svg\" alt=\"g_{1,1}^{(2)}=(-0.121439988)\\times(0.549833997)\\approx -0.066771834\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4c9c4df3cf58176a.svg\"><img class=\"math display-math\" src=\"assets/equations/f6338ce1a52bb766.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.2-0.2(-0.066771834)\\approx 0.213354367\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.544878892</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.121439988</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.066170086</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.086765983</strong></div></div><p>Subtract η × gradient = <b>−0.013234017</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e6cb2fb79ea00bc6.svg\"><img class=\"math display-math\" src=\"assets/equations/28a4d3d30f2657c9.svg\" alt=\"g_{1,2}^{(2)}=(-0.121439988)\\times(0.544878892)\\approx -0.066170086\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1f30020d32cef10b.svg\"><img class=\"math display-math\" src=\"assets/equations/c29bb818f965c973.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=-0.1-0.2(-0.066170086)\\approx -0.086765983\" width=\"573.19\" height=\"36.54\" style=\"width:573.19px;height:36.54px;aspect-ratio:573.19/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h1 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.549833997</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.145933863</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.080239399</strong><span class=\"lv-detail\">h1 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.28395212</strong></div></div><p>Subtract η × gradient = <b>0.01604788</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dde4ee7e9e8f997c.svg\" alt=\"g_{2,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,1}}=\\delta_{o_2}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/16c40d7d34614dcb.svg\"><img class=\"math display-math\" src=\"assets/equations/5b06ea5d37905422.svg\" alt=\"g_{2,1}^{(2)}=(0.145933863)\\times(0.549833997)\\approx 0.080239399\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5660f8c2c8b62a6f.svg\"><img class=\"math display-math\" src=\"assets/equations/d900aa21d0b17c7e.svg\" alt=\"W^{(2)}_{2,1,\\mathrm{new}}=0.3-0.2(0.080239399)\\approx 0.28395212\" width=\"503.95\" height=\"36.54\" style=\"width:503.95px;height:36.54px;aspect-ratio:503.95/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.544878892</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.145933863</strong><span class=\"lv-detail\">δ at o2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.079516282</strong><span class=\"lv-detail\">h2 → o2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.384096744</strong></div></div><p>Subtract η × gradient = <b>0.015903256</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/57d7e754e94fe533.svg\" alt=\"g_{2,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{2,2}}=\\delta_{o_2}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.32px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2bf8871d8771b0c8.svg\"><img class=\"math display-math\" src=\"assets/equations/ca3eeac86363862f.svg\" alt=\"g_{2,2}^{(2)}=(0.145933863)\\times(0.544878892)\\approx 0.079516282\" width=\"555.71\" height=\"36.54\" style=\"width:555.71px;height:36.54px;aspect-ratio:555.71/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d6e1bdf461c23702.svg\"><img class=\"math display-math\" src=\"assets/equations/320cca8c034f0c86.svg\" alt=\"W^{(2)}_{2,2,\\mathrm{new}}=0.4-0.2(0.079516282)\\approx 0.384096744\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.121439988</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.024287998</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.145933863</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.043780159</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.019492161</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7be9181956492e01.svg\"><img class=\"math display-math\" src=\"assets/equations/da1d2225b6cf0b3e.svg\" alt=\"C_1=(0.2)\\times(-0.121439988)\\approx -0.024287998\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0025ef2e4f3926ed.svg\"><img class=\"math display-math\" src=\"assets/equations/01c7679493ca990b.svg\" alt=\"C_2=(0.3)\\times(0.145933863)\\approx 0.043780159\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6abb0857809f8db8.svg\"><img class=\"math display-math\" src=\"assets/equations/66b0d378cdd2503f.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.019492161\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3348b1ba7e091393.svg\"><img class=\"math display-math\" src=\"assets/equations/206e786abddd6488.svg\" alt=\"\\delta_{h_1} = 0.019492161 \\times  0.247516573 = 0.004824633\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.121439988</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">−0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.012143999</strong></div></div></div><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 2</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">0.145933863</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.4</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">0.058373545</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">0.070517544</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/909a9296285664eb.svg\"><img class=\"math display-math\" src=\"assets/equations/7e59b3ad426aa9b6.svg\" alt=\"C_1=(-0.1)\\times(-0.121439988)\\approx 0.012143999\" width=\"488.38\" height=\"24.43\" style=\"width:488.38px;height:24.43px;aspect-ratio:488.38/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Contribution from output 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/14154a8890e8abb8.svg\"><img class=\"math display-math\" src=\"assets/equations/b190ef59d9695988.svg\" alt=\"C_2=(0.4)\\times(0.145933863)\\approx 0.058373545\" width=\"450.35\" height=\"24.43\" style=\"width:450.35px;height:24.43px;aspect-ratio:450.35/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:166.26px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1538baedb3bcff3c.svg\"><img class=\"math display-math\" src=\"assets/equations/41fc299f66c265e9.svg\" alt=\"\\text{Sum}=C_1+C_2\\approx 0.070517544\" width=\"327.80\" height=\"20.89\" style=\"width:327.80px;height:20.89px;aspect-ratio:327.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.92px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b6511e93ffa2060f.svg\"><img class=\"math display-math\" src=\"assets/equations/d2104a629894d5d4.svg\" alt=\"\\delta_{h_2} = 0.070517544 \\times  0.247985885 = 0.017487356\" width=\"512.31\" height=\"23.78\" style=\"width:512.31px;height:23.78px;aspect-ratio:512.31/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.004824633</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.000964927</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.1</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.099807015</strong></div></div><p>Subtract η × gradient = <b>0.000192985</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a8abe88d39c4a4c9.svg\"><img class=\"math display-math\" src=\"assets/equations/1785a1b288336ba6.svg\" alt=\"g_{1,1}^{(1)}=(0.004824633)\\times(0.2)\\approx 0.000964927\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e34dab3cfb2bef31.svg\"><img class=\"math display-math\" src=\"assets/equations/429125d2eee69ed4.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.1-0.2(0.000964927)\\approx 0.099807015\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.004824633</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.001929853</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.199614029</strong></div></div><p>Subtract η × gradient = <b>0.000385971</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a45450793aa1fbee.svg\"><img class=\"math display-math\" src=\"assets/equations/fef8b9d9db76a45d.svg\" alt=\"g_{1,2}^{(1)}=(0.004824633)\\times(0.4)\\approx 0.001929853\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff165bc32cce96bf.svg\"><img class=\"math display-math\" src=\"assets/equations/86e7e16686d8ad69.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.2-0.2(0.001929853)\\approx 0.199614029\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.2</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.017487356</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.003497471</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">−0.2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">−0.200699494</strong></div></div><p>Subtract η × gradient = <b>0.000699494</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5a519701097922e5.svg\"><img class=\"math display-math\" src=\"assets/equations/2c7569fc93ce3696.svg\" alt=\"g_{2,1}^{(1)}=(0.017487356)\\times(0.2)\\approx 0.003497471\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/251cd8c98d77e90c.svg\"><img class=\"math display-math\" src=\"assets/equations/d31db2b9d2bae391.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=-0.2-0.2(0.003497471)\\approx -0.200699494\" width=\"554.18\" height=\"36.54\" style=\"width:554.18px;height:36.54px;aspect-ratio:554.18/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">0.4</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">0.017487356</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">0.006994942</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.3</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.298601012</strong></div></div><p>Subtract η × gradient = <b>0.001398988</b>. This weight <b>decreases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/253913dce1e316cf.svg\"><img class=\"math display-math\" src=\"assets/equations/f1825dbaa53d6e64.svg\" alt=\"g_{2,2}^{(1)}=(0.017487356)\\times(0.4)\\approx 0.006994942\" width=\"457.98\" height=\"36.54\" style=\"width:457.98px;height:36.54px;aspect-ratio:457.98/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30eae54a2d6333bf.svg\"><img class=\"math display-math\" src=\"assets/equations/f4cac41f24ea1d22.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.3-0.2(0.006994942)\\approx 0.298601012\" width=\"516.16\" height=\"36.54\" style=\"width:516.16px;height:36.54px;aspect-ratio:516.16/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d95f499c8cf92af.svg\"><img class=\"math display-math\" src=\"assets/equations/fc185daa7ea868a7.svg\" alt=\"b_{h_1,\\mathrm{new}}=0.1-0.2(0.004824633)=0.099035073\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/574987d80e93f51f.svg\"><img class=\"math display-math\" src=\"assets/equations/7e8c76ed543b6526.svg\" alt=\"b_{h_2,\\mathrm{new}}=0.1-0.2(0.017487356)=0.096502529\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c0bf69b79bc6be7c.svg\"><img class=\"math display-math\" src=\"assets/equations/7f891f57c5f4c76f.svg\" alt=\"b_{o_1,\\mathrm{new}}=0-0.2(-0.121439988)=0.024287998\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.07px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ab34abf185daf06.svg\"><img class=\"math display-math\" src=\"assets/equations/54d821197ed88717.svg\" alt=\"b_{o_2,\\mathrm{new}}=0.1-0.2(0.145933863)=0.070813227\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>"],"kind":"practice","id":"tee-c17-s14","search":"Drill 14 Two output sigmoid backpropagation **Question.** Input x = [0.2, 0.4]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.1]; W₂ is shown below; b₂ = [0, 0.1]. Hidden and output activations are sigmoid. Target y = [1, 0]. Learning rate η = 0.2. Use half summed squared loss and update all parameters.\n\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput x = [0.2, 0.4].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.1].\n\nW₂ is printed with the question.\n\nb₂ = [0, 0.1].\n\nHidden and output activations are sigmoid.\n\nTarget y = [1, 0].\n\nLearning rate η = 0.2.\n\nUse half summed squared loss and update all parameters.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Calculate the half summed squared loss 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.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used before substituting numbers\nFor every receiving neuron, z is its weighted sum and a is its activated output. The half squared loss sums the errors from all output neurons.\n\nDelta means the loss gradient with respect to a neuron's raw score. First calculate output deltas, then hidden deltas using every connected output path.\n\n\nThe gradient of a connection is its receiving delta multiplied by its sending activation. A bias receives the constant 1.\n\n\nFor sigmoid, use f′ = a(1 − a). For ReLU, use f′ = 1 for a positive raw score and 0 for a negative raw score. Store the old weights until all gradients have been calculated.\n\n**Step 1 map the arrows.** Each row of W₁ receives all inputs; each "},{"title":"Drill 15 A negative ReLU blocks this path","question":["<p class=\"inline-question\"><strong>Question.</strong> x = 2, w1 = −0.4, b1 = 0.1, w2 = 0.5, b2 = 0.2; hidden ReLU, linear output, y = 1, half squared loss. Find dw 1 and dw 2.</p>"],"answer":["<h3>Given</h3>","<p>x = 2; w₁ = −0.4; b₁ = 0.1; w₂ = 0.5; b₂ = 0.2.</p>","<p>Hidden activation: ReLU; output activation: linear.</p>","<p>Target y = 1; loss: half squared error.</p>","<h3>To find</h3>","<p>Find the gradients of w₁ and w₂ and explain any zero gradients.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used</h3>","<p>The hidden neuron uses ReLU, but the output is linear. “Linear output” means its weighted sum is already its output.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.35px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2107914ba4f232f1.svg\"><img class=\"math display-math\" src=\"assets/equations/96964269705ef1b5.svg\" alt=\"z_h=w_1x+b_1,\\quad h=\\max(0,z_h),\\quad o=w_2h+b_2\" width=\"514.94\" height=\"24.43\" style=\"width:514.94px;height:24.43px;aspect-ratio:514.94/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.36px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/160d78635e6efcbf.svg\"><img class=\"math display-math\" src=\"assets/equations/e9baab27f7f33ee2.svg\" alt=\"L=\\frac12(o-y)^2,\\quad \\delta_o=o-y\" width=\"298.39\" height=\"49.55\" style=\"width:298.39px;height:49.55px;aspect-ratio:298.39/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.25px;--narrow-height:164.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a9eda432984ec8da.svg\"><img class=\"math display-math\" src=\"assets/equations/51a8b01e1bee8834.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=\\delta_o h,\\quad \\delta_h=\\delta_o w_2\\operatorname{ReLU}&#x27;(z_h),\\quad \\frac{\\partial L}{\\partial w_1}=\\delta_h x\" width=\"533.85\" height=\"54.41\" style=\"width:533.85px;height:54.41px;aspect-ratio:533.85/54.41\" loading=\"lazy\"></picture></div>","<h3>Step 1: hidden weighted sum and activation</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.36px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81ce8e4429aab67a.svg\"><img class=\"math display-math\" src=\"assets/equations/b94d4768d9ba8e6f.svg\" alt=\"z_h=(-0.4)\\times2+0.1=-0.8+0.1=-0.7\" width=\"455.10\" height=\"24.43\" style=\"width:455.10px;height:24.43px;aspect-ratio:455.10/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0f4049c82bf618fd.svg\" alt=\"h=\\max(0,-0.7)=0\" width=\"229.26\" height=\"24.43\" style=\"width:229.26px;height:24.43px;aspect-ratio:229.26/24.43\" loading=\"lazy\"></div>","<p>Because the raw hidden score is negative, ReLU&#x27;s derivative at this point is 0.</p>","<h3>Step 2: output prediction and output delta</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8775ad02ed7eaf6c.svg\" alt=\"o=0.5\\times0+0.2=0.2\" width=\"242.65\" height=\"18.27\" style=\"width:242.65px;height:18.27px;aspect-ratio:242.65/18.27\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ff295007085f430d.svg\" alt=\"\\delta_o=0.2-1=-0.8\" width=\"209.97\" height=\"21.37\" style=\"width:209.97px;height:21.37px;aspect-ratio:209.97/21.37\" loading=\"lazy\"></div>","<h3>Step 3: output weight gradient</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/400d3f8e82bf09fc.svg\" alt=\"\\frac{\\partial L}{\\partial w_2}=(-0.8)\\times0=0\" width=\"241.47\" height=\"54.41\" style=\"width:241.47px;height:54.41px;aspect-ratio:241.47/54.41\" loading=\"lazy\"></div>","<p>This is zero because the input to that connection, h, is zero.</p>","<h3>Step 4: hidden delta and input weight gradient</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1721f576f8f22211.svg\" alt=\"\\delta_h=(-0.8)\\times0.5\\times0=0\" width=\"272.65\" height=\"24.43\" style=\"width:272.65px;height:24.43px;aspect-ratio:272.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a131ac401273e09f.svg\" alt=\"\\frac{\\partial L}{\\partial w_1}=0\\times2=0\" width=\"184.43\" height=\"54.41\" style=\"width:184.43px;height:54.41px;aspect-ratio:184.43/54.41\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> both requested weight gradients are zero. The output bias gradient equals −0.8, so a zero weight gradient does not mean every parameter&#x27;s gradient is zero.</p>"],"kind":"practice","id":"tee-c17-s15","search":"Drill 15 A negative ReLU blocks this path **Question.** x = 2, w1 = −0.4, b1 = 0.1, w2 = 0.5, b2 = 0.2; hidden ReLU, linear output, y = 1, half squared loss. Find dw 1 and dw 2.\n\n**Full solution.**\n\n\n\n### Given\n\nx = 2; w₁ = −0.4; b₁ = 0.1; w₂ = 0.5; b₂ = 0.2.\n\nHidden activation: ReLU; output activation: linear.\n\nTarget y = 1; loss: half squared error.\n\n### To find\n\nFind the gradients of w₁ and w₂ and explain any zero gradients.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used\nThe hidden neuron uses ReLU, but the output is linear. “Linear output” means its weighted sum is already its output.\n\n\n\n### Step 1: hidden weighted sum and activation\n\n\nBecause the raw hidden score is negative, ReLU's derivative at this point is 0.\n### Step 2: output prediction and output delta\n\n\n### Step 3: output weight gradient\n\nThis is zero because the input to that connection, h, is zero.\n### Step 4: hidden delta and input weight gradient\n\n\n**Final answer:** both requested weight gradients are zero. The output bias gradient equals −0.8, so a zero weight gradient does not mean every parameter's gradient is zero.\n"},{"title":"Drill 16 Batch and sequential SGD","question":["<p class=\"inline-question\"><strong>Question.</strong> ŷ = wx, start w = 0, η = 0.1, data(1,1), (2,2). Use mean half squared loss for a batch. Compare one batch update with one sequential SGD epoch.</p>"],"answer":["<h3>Given</h3>","<p>Model ŷ = wx; initial w = 0; η = 0.1.</p>","<p>Samples in order: (x,y) = (1,1), then (2,2).</p>","<p>Batch objective: mean half squared loss.</p>","<h3>To find</h3>","<p>Compare the weight after one batch update and one sequential SGD epoch.</p>","<h3>Formula — which one and why</h3>","<p><strong>Batch mean versus sequential SGD.</strong> A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.</p>","<p>B = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/657f63b5043d3907.svg\" alt=\"g_{\\mathrm{batch}}=\\frac1B\\sum_i g_i\" width=\"180.88\" height=\"61.92\" style=\"width:180.88px;height:61.92px;aspect-ratio:180.88/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0b4939a48933eb0a.svg\" alt=\"g_i=(wx_i-y_i)x_i\" width=\"182.50\" height=\"24.43\" style=\"width:182.50px;height:24.43px;aspect-ratio:182.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/06b81f0d4da782b2.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g\" width=\"153.03\" height=\"19.53\" style=\"width:153.03px;height:19.53px;aspect-ratio:153.03/19.53\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Batch: same old weight par average; SGD: har sample ke baad weight change.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>For one sample, x is the input, y is the target, and w is the weight. Batch GD averages gradients evaluated at the <strong>same old weight</strong>. Sequential SGD updates after each sample and uses that new weight for the next sample.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.48px;--narrow-height:130.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e02d92789136f341.svg\"><img class=\"math display-math\" src=\"assets/equations/00e3dff87be9cc8c.svg\" alt=\"\\hat y=wx,\\quad L=\\frac12(\\hat y-y)^2,\\quad g=(\\hat y-y)x\" width=\"433.35\" height=\"49.55\" style=\"width:433.35px;height:49.55px;aspect-ratio:433.35/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.57px;--narrow-height:86.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7783293f367f0a09.svg\"><img class=\"math display-math\" src=\"assets/equations/070a9c1b54d9ac42.svg\" alt=\"g_{\\mathrm{batch}}=\\frac{g_1+g_2}{2},\\qquad w_{\\mathrm{new}}=w-\\eta g\" width=\"386.53\" height=\"47.52\" style=\"width:386.53px;height:47.52px;aspect-ratio:386.53/47.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Part A: one batch update from w = 0.</strong></p>","<p>For sample (1,1), prediction = 0 × 1 = 0, so:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/65b3616ae354de6a.svg\" alt=\"g_1=(0-1)\\times1=-1\" width=\"234.12\" height=\"24.43\" style=\"width:234.12px;height:24.43px;aspect-ratio:234.12/24.43\" loading=\"lazy\"></div>","<p>For sample (2,2), keep the same weight 0. Prediction = 0 × 2 = 0, so:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5e54f46939905d8.svg\" alt=\"g_2=(0-2)\\times2=-4\" width=\"234.12\" height=\"24.43\" style=\"width:234.12px;height:24.43px;aspect-ratio:234.12/24.43\" loading=\"lazy\"></div>","<p>Average these two gradients, then update once.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.60px;--narrow-height:91.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ae3a9f41f9f31680.svg\"><img class=\"math display-math\" src=\"assets/equations/6159bfc1e25aba9f.svg\" alt=\"g_{\\mathrm{batch}}=\\frac{-1+(-4)}2=-2.5\" width=\"293.41\" height=\"52.43\" style=\"width:293.41px;height:52.43px;aspect-ratio:293.41/52.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.91px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/568002eaa70aedb2.svg\"><img class=\"math display-math\" src=\"assets/equations/a5ec534d58a905c7.svg\" alt=\"w_{\\mathrm{batch}}=0-0.1(-2.5)=0.25\" width=\"312.94\" height=\"24.43\" style=\"width:312.94px;height:24.43px;aspect-ratio:312.94/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Part B: one SGD epoch, restarting at w = 0.</strong></p>","<p>The first sample has gradient −1, just as above.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f2b5721e0e1c67b4.svg\" alt=\"w_1=0-0.1(-1)=0.1\" width=\"248.11\" height=\"24.43\" style=\"width:248.11px;height:24.43px;aspect-ratio:248.11/24.43\" loading=\"lazy\"></div>","<p>For the second sample use this new weight, so prediction is:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/905f0951780ee22a.svg\" alt=\"\\hat y_2=0.1\\times2=0.2\" width=\"192.35\" height=\"24.80\" style=\"width:192.35px;height:24.80px;aspect-ratio:192.35/24.80\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.74px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f262bc5d6c22d8bb.svg\"><img class=\"math display-math\" src=\"assets/equations/4c4f586bc3f0f97e.svg\" alt=\"g_2=(0.2-2)\\times2=(-1.8)\\times2=-3.6\" width=\"416.06\" height=\"24.43\" style=\"width:416.06px;height:24.43px;aspect-ratio:416.06/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.32px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f8c5ce8387c2e254.svg\"><img class=\"math display-math\" src=\"assets/equations/ff99526a93e31696.svg\" alt=\"w_2=0.1-0.1(-3.6)=0.1+0.36=0.46\" width=\"435.48\" height=\"24.43\" style=\"width:435.48px;height:24.43px;aspect-ratio:435.48/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> batch result 0.25; sequential SGD result 0.46. The difference comes from the timing of the updates.</p>"],"kind":"practice","id":"tee-c17-s16","search":"Drill 16 Batch and sequential SGD **Question.** ŷ = wx, start w = 0, η = 0.1, data(1,1), (2,2). Use mean half squared loss for a batch. Compare one batch update with one sequential SGD epoch.\n\n**Full solution.**\n\n\n\n### Given\n\nModel ŷ = wx; initial w = 0; η = 0.1.\n\nSamples in order: (x,y) = (1,1), then (2,2).\n\nBatch objective: mean half squared loss.\n\n### To find\n\nCompare the weight after one batch update and one sequential SGD epoch.\n\n### Formula — which one and why\n\n**Batch mean versus sequential SGD.** A batch update averages gradients evaluated at the same old parameter. Sequential SGD updates after each sample, so later samples use the changed parameter.\n\nB = number of examples in the batch; gᵢ = sample gradient; η = learning rate. For the linear half squared objective, sample gradient is (wx−y)x.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Batch: same old weight par average; SGD: har sample ke baad weight change.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nFor one sample, x is the input, y is the target, and w is the weight. Batch GD averages gradients evaluated at the **same old weight**. Sequential SGD updates after each sample and uses that new weight for the next sample.\n\n\n**Step 1: Part A: one batch update from w = 0.**\nFor sample (1,1), prediction = 0 × 1 = 0, so:\n\nFor sample (2,2), keep the same weight 0. Prediction = 0 × 2 = 0, so:\n\nAverage these two gradients, then update once.\n\n\n**Step 2: Part B: one SGD epoch, restarting at w = 0.**\nThe first sample has gradient −1, just as above.\n\nFor the second sample use this new weight, so prediction is:\n\n\n\n**Final answer:** batch result 0.25; sequential SGD result 0.46. The difference comes from the timing of the updates.\n"},{"title":"Drill 17 Incomplete mini batch","question":["<p class=\"inline-question\"><strong>Question.</strong> N = 103, B = 20, epochs = 3. Count updates for batch GD, SGD, mini-batch keeping the remainder, and mini-batch dropping it.</p>"],"answer":["<h3>Given</h3>","<p>N = 103 samples; B = 20 samples per mini-batch.</p>","<p>E = 3 epochs.</p>","<p>Compare both remainder policies: keep or drop the final 3 examples.</p>","<h3>To find</h3>","<p>Find total updates for full-batch GD, SGD, and both mini-batch policies.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>An epoch means one pass through the dataset. An update happens once per batch used. N is the number of samples, B is the chosen batch size, and E is the number of epochs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:128.03px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e0f5f4a6b7d3af9c.svg\"><img class=\"math display-math\" src=\"assets/equations/9c0c1479389c6c19.svg\" alt=\"U_{\\mathrm{batch}}=E,\\qquad U_{\\mathrm{SGD}}=NE\" width=\"299.98\" height=\"21.43\" style=\"width:299.98px;height:21.43px;aspect-ratio:299.98/21.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:175.85px;--narrow-height:131.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/147e19d72acc4203.svg\"><img class=\"math display-math\" src=\"assets/equations/a6ec99ec225775f5.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil,\\qquad U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"398.39\" height=\"58.62\" style=\"width:398.39px;height:58.62px;aspect-ratio:398.39/58.62\" loading=\"lazy\"></picture></div>","<p>Ceiling rounds up to the next integer; floor rounds down. The final incomplete batch needs an update only if it is retained.</p>","<h3>Step 1: batch GD</h3>","<p>All 103 samples form one batch per epoch.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11f14a41e22f1916.svg\" alt=\"U_{\\mathrm{batch}}=3\\times1=3\" width=\"192.65\" height=\"20.54\" style=\"width:192.65px;height:20.54px;aspect-ratio:192.65/20.54\" loading=\"lazy\"></div>","<h3>Step 2: SGD</h3>","<p>Each sample gets its own update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4c08a8b839ca4b99.svg\" alt=\"U_{\\mathrm{SGD}}=103\\times3=309\" width=\"235.65\" height=\"20.74\" style=\"width:235.65px;height:20.74px;aspect-ratio:235.65/20.74\" loading=\"lazy\"></div>","<h3>Step 3: mini-batches with the remainder</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7600fce77b11dfac.svg\" alt=\"103=5\\times20+3\" width=\"177.84\" height=\"18.27\" style=\"width:177.84px;height:18.27px;aspect-ratio:177.84/18.27\" loading=\"lazy\"></div>","<p>The batch sizes are 20, 20, 20, 20, 20 and 3. Six batches per epoch give:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64422d140052bf5c.svg\" alt=\"U_{\\mathrm{keep}}=6\\times3=18\" width=\"196.70\" height=\"23.71\" style=\"width:196.70px;height:23.71px;aspect-ratio:196.70/23.71\" loading=\"lazy\"></div>","<h3>Step 4: mini-batches without the remainder</h3>","<p>Only the five complete batches are used each epoch.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b34106919fd6639.svg\" alt=\"U_{\\mathrm{drop}}=5\\times3=15\" width=\"197.25\" height=\"23.71\" style=\"width:197.25px;height:23.71px;aspect-ratio:197.25/23.71\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> 3, 309, 18 and 15 updates respectively.</p>"],"kind":"practice","id":"tee-c17-s17","search":"Drill 17 Incomplete mini batch **Question.** N = 103, B = 20, epochs = 3. Count updates for batch GD, SGD, mini-batch keeping the remainder, and mini-batch dropping it.\n\n**Full solution.**\n\n\n\n### Given\n\nN = 103 samples; B = 20 samples per mini-batch.\n\nE = 3 epochs.\n\nCompare both remainder policies: keep or drop the final 3 examples.\n\n### To find\n\nFind total updates for full-batch GD, SGD, and both mini-batch policies.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nAn epoch means one pass through the dataset. An update happens once per batch used. N is the number of samples, B is the chosen batch size, and E is the number of epochs.\n\n\nCeiling rounds up to the next integer; floor rounds down. The final incomplete batch needs an update only if it is retained.\n### Step 1: batch GD\nAll 103 samples form one batch per epoch.\n\n### Step 2: SGD\nEach sample gets its own update.\n\n### Step 3: mini-batches with the remainder\n\nThe batch sizes are 20, 20, 20, 20, 20 and 3. Six batches per epoch give:\n\n### Step 4: mini-batches without the remainder\nOnly the five complete batches are used each epoch.\n\n**Final answer:** 3, 309, 18 and 15 updates respectively.\n"},{"title":"Drill 18 GD variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two GD updates.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½θ².</p>","<p>Initial θ₀ = 1; η = 0.1; two iterations.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec670e56abfcf00.svg\"><img class=\"math display-math\" src=\"assets/equations/ad9f147031605f82.svg\" alt=\"J(\\theta)=\\frac12(\\theta-0)^2,\\qquad J\\prime(\\theta)=\\theta-0\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.</p>","<h3>Update formulas</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:156.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b3d142fa7d569702.svg\"><img class=\"math display-math\" src=\"assets/equations/1fa856180f9f092b.svg\" alt=\"g_t=J\\prime(\\theta_{t-1}),\\quad \\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"326.86\" height=\"24.43\" style=\"width:326.86px;height:24.43px;aspect-ratio:326.86/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51e0e1de442cadbf.svg\" alt=\"g_1=1-(0)=1\" width=\"173.03\" height=\"24.43\" style=\"width:173.03px;height:24.43px;aspect-ratio:173.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1f113e7fc6ecc1f4.svg\" alt=\"\\theta_1=1-0.1(1)=0.9\" width=\"223.06\" height=\"24.43\" style=\"width:223.06px;height:24.43px;aspect-ratio:223.06/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/acfaeec4e6af0c51.svg\" alt=\"g_2=0.9-(0)=0.9\" width=\"211.04\" height=\"24.43\" style=\"width:211.04px;height:24.43px;aspect-ratio:211.04/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1708353d6ee40680.svg\" alt=\"\\theta_2=0.9-0.1(0.9)=0.81\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Final parameter after two updates: 0.81.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"tee-c17-s18","search":"Drill 18 GD variation 1 **Question.** J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two GD updates. \n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½θ².\n\nInitial θ₀ = 1; η = 0.1; two iterations.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.\n### Update formulas\n\n**Step 1: Update 1.**\n\n\n**Step 2: Update 2.**\n\n\n**Final parameter after two updates: 0.81.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 19 GD variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two GD updates.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½(θ−1)².</p>","<p>Initial θ₀ = −0.5; η = 0.1; two iterations.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e49b01175757fe7.svg\"><img class=\"math display-math\" src=\"assets/equations/d9f043ffb887fd14.svg\" alt=\"J(\\theta)=\\frac12(\\theta-1)^2,\\qquad J\\prime(\\theta)=\\theta-1\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.</p>","<h3>Update formulas</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:156.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b3d142fa7d569702.svg\"><img class=\"math display-math\" src=\"assets/equations/1fa856180f9f092b.svg\" alt=\"g_t=J\\prime(\\theta_{t-1}),\\quad \\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"326.86\" height=\"24.43\" style=\"width:326.86px;height:24.43px;aspect-ratio:326.86/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce4034cb1a64ebf6.svg\" alt=\"g_1=-0.5-(1)=-1.5\" width=\"249.06\" height=\"24.43\" style=\"width:249.06px;height:24.43px;aspect-ratio:249.06/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c2dd4efda1f26eb.svg\"><img class=\"math display-math\" src=\"assets/equations/e397e226e8c7c566.svg\" alt=\"\\theta_1=-0.5-0.1(-1.5)=-0.35\" width=\"330.33\" height=\"24.43\" style=\"width:330.33px;height:24.43px;aspect-ratio:330.33/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e8a70b34a625603.svg\" alt=\"g_2=-0.35-(1)=-1.35\" width=\"273.50\" height=\"24.43\" style=\"width:273.50px;height:24.43px;aspect-ratio:273.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/354b5f7978875963.svg\"><img class=\"math display-math\" src=\"assets/equations/b21cdf85d50680f5.svg\" alt=\"\\theta_2=-0.35-0.1(-1.35)=-0.215\" width=\"366.98\" height=\"24.43\" style=\"width:366.98px;height:24.43px;aspect-ratio:366.98/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: -0.215.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"tee-c17-s19","search":"Drill 19 GD variation 2 **Question.** J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two GD updates. \n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½(θ−1)².\n\nInitial θ₀ = −0.5; η = 0.1; two iterations.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.\n### Update formulas\n\n**Step 1: Update 1.**\n\n\n**Step 2: Update 2.**\n\n\n**Final parameter after two updates: -0.215.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 20 Momentum variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½θ².</p>","<p>Initial θ₀ = 1; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec670e56abfcf00.svg\"><img class=\"math display-math\" src=\"assets/equations/ad9f147031605f82.svg\" alt=\"J(\\theta)=\\frac12(\\theta-0)^2,\\qquad J\\prime(\\theta)=\\theta-0\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51e0e1de442cadbf.svg\" alt=\"g_1=1-(0)=1\" width=\"173.03\" height=\"24.43\" style=\"width:173.03px;height:24.43px;aspect-ratio:173.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/acfaeec4e6af0c51.svg\" alt=\"g_2=0.9-(0)=0.9\" width=\"211.04\" height=\"24.43\" style=\"width:211.04px;height:24.43px;aspect-ratio:211.04/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.38px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0143acec3cdc1b06.svg\"><img class=\"math display-math\" src=\"assets/equations/9d76f7ff1692b41e.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.9)=-0.18\" width=\"361.95\" height=\"24.43\" style=\"width:361.95px;height:24.43px;aspect-ratio:361.95/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Final parameter after two updates: 0.72.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"tee-c17-s20","search":"Drill 20 Momentum variation 1 **Question.** J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½θ².\n\nInitial θ₀ = 1; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n**Step 2: Update 2.**\n\n\n\n**Final parameter after two updates: 0.72.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 21 Momentum variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½(θ−1)².</p>","<p>Initial θ₀ = −0.5; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e49b01175757fe7.svg\"><img class=\"math display-math\" src=\"assets/equations/d9f043ffb887fd14.svg\" alt=\"J(\\theta)=\\frac12(\\theta-1)^2,\\qquad J\\prime(\\theta)=\\theta-1\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce4034cb1a64ebf6.svg\" alt=\"g_1=-0.5-(1)=-1.5\" width=\"249.06\" height=\"24.43\" style=\"width:249.06px;height:24.43px;aspect-ratio:249.06/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.90px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e63b276a509c75c.svg\"><img class=\"math display-math\" src=\"assets/equations/2679c9e024274dac.svg\" alt=\"v_1=0.9(0)-0.1(-1.5)=0.15\" width=\"323.92\" height=\"24.43\" style=\"width:323.92px;height:24.43px;aspect-ratio:323.92/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3de31f4085d1f9eb.svg\"><img class=\"math display-math\" src=\"assets/equations/76cd873d8955bf17.svg\" alt=\"\\theta_1=-0.5+(0.15)=-0.35\" width=\"292.31\" height=\"24.43\" style=\"width:292.31px;height:24.43px;aspect-ratio:292.31/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e8a70b34a625603.svg\" alt=\"g_2=-0.35-(1)=-1.35\" width=\"273.50\" height=\"24.43\" style=\"width:273.50px;height:24.43px;aspect-ratio:273.50/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.59px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0b81155b82e98b2d.svg\"><img class=\"math display-math\" src=\"assets/equations/23765d6232402c77.svg\" alt=\"v_2=0.9(0.15)-0.1(-1.35)=0.27\" width=\"367.37\" height=\"24.43\" style=\"width:367.37px;height:24.43px;aspect-ratio:367.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5bc5d38d05f5667.svg\"><img class=\"math display-math\" src=\"assets/equations/035af79f7cb5dc94.svg\" alt=\"\\theta_2=-0.35+(0.27)=-0.08\" width=\"304.53\" height=\"24.43\" style=\"width:304.53px;height:24.43px;aspect-ratio:304.53/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: -0.08.</strong> The second gradient is evaluated again using the parameter obtained after the first update.</p>"],"kind":"practice","id":"tee-c17-s21","search":"Drill 21 Momentum variation 2 **Question.** J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Momentum updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½(θ−1)².\n\nInitial θ₀ = −0.5; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n**Step 2: Update 2.**\n\n\n\n**Final parameter after two updates: -0.08.** The second gradient is evaluated again using the parameter obtained after the first update.\n"},{"title":"Drill 22 Nesterov variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½θ².</p>","<p>Initial θ₀ = 1; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Nesterov lookahead.</strong> First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.</p>","<p>θ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d83df079bf260cc.svg\" alt=\"g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"138.39\" height=\"24.43\" style=\"width:138.39px;height:24.43px;aspect-ratio:138.39/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle look ahead; gradient wahan; update original position se.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec670e56abfcf00.svg\"><img class=\"math display-math\" src=\"assets/equations/ad9f147031605f82.svg\" alt=\"J(\\theta)=\\frac12(\\theta-0)^2,\\qquad J\\prime(\\theta)=\\theta-0\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/122d449c66d53648.svg\"><img class=\"math display-math\" src=\"assets/equations/eebc0b956dd1a540.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1},\\quad g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"378.67\" height=\"24.43\" style=\"width:378.67px;height:24.43px;aspect-ratio:378.67/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/44a5155fc196e4c6.svg\" alt=\"\\theta_{\\mathrm{look}}=1+0.9(0)=1\" width=\"226.62\" height=\"24.43\" style=\"width:226.62px;height:24.43px;aspect-ratio:226.62/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/51e0e1de442cadbf.svg\" alt=\"g_1=1-(0)=1\" width=\"173.03\" height=\"24.43\" style=\"width:173.03px;height:24.43px;aspect-ratio:173.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e23af655c3740539.svg\"><img class=\"math display-math\" src=\"assets/equations/0d1a08b9ece0e5ac.svg\" alt=\"v_1=0.9(0)-0.1(1)=-0.1\" width=\"292.70\" height=\"24.43\" style=\"width:292.70px;height:24.43px;aspect-ratio:292.70/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.84px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f8c51c39237a8f3.svg\"><img class=\"math display-math\" src=\"assets/equations/e3234cc25d1508de.svg\" alt=\"\\theta_{\\mathrm{look}}=0.9+0.9(-0.1)=0.81\" width=\"314.87\" height=\"24.43\" style=\"width:314.87px;height:24.43px;aspect-ratio:314.87/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f61619e280f936a0.svg\" alt=\"g_2=0.81-(0)=0.81\" width=\"235.47\" height=\"24.43\" style=\"width:235.47px;height:24.43px;aspect-ratio:235.47/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35f06a75a728a22a.svg\"><img class=\"math display-math\" src=\"assets/equations/e92dee4c49c58b06.svg\" alt=\"v_2=0.9(-0.1)-0.1(0.81)=-0.171\" width=\"386.38\" height=\"24.43\" style=\"width:386.38px;height:24.43px;aspect-ratio:386.38/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b7b6422b337bab9.svg\"><img class=\"math display-math\" src=\"assets/equations/2c96483424ef8929.svg\" alt=\"\\theta_2=0.9+(-0.171)=0.729\" width=\"297.73\" height=\"24.43\" style=\"width:297.73px;height:24.43px;aspect-ratio:297.73/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: 0.729.</strong> The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.</p>"],"kind":"practice","id":"tee-c17-s22","search":"Drill 22 Nesterov variation 1 **Question.** J(θ) = ½θ², θ₀ = 1, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½θ².\n\nInitial θ₀ = 1; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Nesterov lookahead.** First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.\n\nθ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle look ahead; gradient wahan; update original position se.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 0.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n\n**Step 2: Update 2.**\n\n\n\n\n**Final parameter after two updates: 0.729.** The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.\n"},{"title":"Drill 23 Nesterov variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.</p>"],"answer":["<h3>Given</h3>","<p>Objective: J(θ) = ½(θ−1)².</p>","<p>Initial θ₀ = −0.5; η = 0.1; two iterations.</p>","<p>β = 0.9; initial signed velocity v₀ = 0.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Nesterov lookahead.</strong> First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.</p>","<p>θ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4a295c7aac3f17.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1}\" width=\"204.97\" height=\"22.31\" style=\"width:204.97px;height:22.31px;aspect-ratio:204.97/22.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d83df079bf260cc.svg\" alt=\"g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"138.39\" height=\"24.43\" style=\"width:138.39px;height:24.43px;aspect-ratio:138.39/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle look ahead; gradient wahan; update original position se.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of the symbols</h3>","<p>θ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.</p>","<h3>Differentiate the objective first</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:191.51px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e49b01175757fe7.svg\"><img class=\"math display-math\" src=\"assets/equations/d9f043ffb887fd14.svg\" alt=\"J(\\theta)=\\frac12(\\theta-1)^2,\\qquad J\\prime(\\theta)=\\theta-1\" width=\"383.24\" height=\"49.55\" style=\"width:383.24px;height:49.55px;aspect-ratio:383.24/49.55\" loading=\"lazy\"></picture></div>","<p>The power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.</p>","<h3>Update formulas</h3>","<p>v stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/122d449c66d53648.svg\"><img class=\"math display-math\" src=\"assets/equations/eebc0b956dd1a540.svg\" alt=\"\\theta_{\\mathrm{look}}=\\theta_{t-1}+\\beta v_{t-1},\\quad g_t=J\\prime(\\theta_{\\mathrm{look}})\" width=\"378.67\" height=\"24.43\" style=\"width:378.67px;height:24.43px;aspect-ratio:378.67/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/91375a23b0e2fbcf.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\quad \\theta_t=\\theta_{t-1}+v_t\" width=\"350.06\" height=\"22.51\" style=\"width:350.06px;height:22.51px;aspect-ratio:350.06/22.51\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Update 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.83px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a4363d91dbba8cc0.svg\"><img class=\"math display-math\" src=\"assets/equations/f19658c31004feb6.svg\" alt=\"\\theta_{\\mathrm{look}}=-0.5+0.9(0)=-0.5\" width=\"302.66\" height=\"24.43\" style=\"width:302.66px;height:24.43px;aspect-ratio:302.66/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce4034cb1a64ebf6.svg\" alt=\"g_1=-0.5-(1)=-1.5\" width=\"249.06\" height=\"24.43\" style=\"width:249.06px;height:24.43px;aspect-ratio:249.06/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.90px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9e63b276a509c75c.svg\"><img class=\"math display-math\" src=\"assets/equations/2679c9e024274dac.svg\" alt=\"v_1=0.9(0)-0.1(-1.5)=0.15\" width=\"323.92\" height=\"24.43\" style=\"width:323.92px;height:24.43px;aspect-ratio:323.92/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3de31f4085d1f9eb.svg\"><img class=\"math display-math\" src=\"assets/equations/76cd873d8955bf17.svg\" alt=\"\\theta_1=-0.5+(0.15)=-0.35\" width=\"292.31\" height=\"24.43\" style=\"width:292.31px;height:24.43px;aspect-ratio:292.31/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Update 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f623b6f68ec5b35a.svg\"><img class=\"math display-math\" src=\"assets/equations/dade5906dabc1018.svg\" alt=\"\\theta_{\\mathrm{look}}=-0.35+0.9(0.15)=-0.215\" width=\"370.54\" height=\"24.43\" style=\"width:370.54px;height:24.43px;aspect-ratio:370.54/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.67px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f77fca68d44fde4d.svg\"><img class=\"math display-math\" src=\"assets/equations/b8b2f5a400acaace.svg\" alt=\"g_2=-0.215-(1)=-1.215\" width=\"297.93\" height=\"24.43\" style=\"width:297.93px;height:24.43px;aspect-ratio:297.93/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.24px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/afa161b36559b605.svg\"><img class=\"math display-math\" src=\"assets/equations/e1b4633f6988ed67.svg\" alt=\"v_2=0.9(0.15)-0.1(-1.215)=0.2565\" width=\"404.03\" height=\"24.43\" style=\"width:404.03px;height:24.43px;aspect-ratio:404.03/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cc919e70a6113df8.svg\"><img class=\"math display-math\" src=\"assets/equations/7e5dfb5f2581a338.svg\" alt=\"\\theta_2=-0.35+(0.2565)=-0.0935\" width=\"353.40\" height=\"24.43\" style=\"width:353.40px;height:24.43px;aspect-ratio:353.40/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final parameter after two updates: -0.0935.</strong> The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.</p>"],"kind":"practice","id":"tee-c17-s23","search":"Drill 23 Nesterov variation 2 **Question.** J(θ) = ½(θ−1)², θ₀ = -0.5, η = 0.1. Perform two Nesterov updates. Use β = 0.9, v₀ = 0 and signed velocity.\n\n**Full solution.**\n\n\n\n### Given\n\nObjective: J(θ) = ½(θ−1)².\n\nInitial θ₀ = −0.5; η = 0.1; two iterations.\n\nβ = 0.9; initial signed velocity v₀ = 0.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Nesterov lookahead.** First look ahead using the old velocity. Measure the gradient there, form the new velocity, then add that velocity to the original current parameter.\n\nθ_look = temporary gradient-evaluation point; v = signed displacement; β = momentum coefficient; η = learning rate.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle look ahead; gradient wahan; update original position se.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of the symbols\nθ (theta) is the number we update. η (eta) is learning rate 0.1. g is the derivative of the objective, evaluated at the required position. A subscript counts updates; θ₀ means the starting value.\n### Differentiate the objective first\n\nThe power rule brings down 2, which cancels the half. The inside derivative is 1, so the remaining gradient is θ minus 1.\n### Update formulas\nv stores the signed movement from the previous update. β = 0.9 retains 90% of that movement. Start v₀ = 0.\n\n\n**Step 1: Update 1.**\n\n\n\n\n**Step 2: Update 2.**\n\n\n\n\n**Final parameter after two updates: -0.0935.** The lookahead locates the gradient; the new velocity is added to the old actual parameter, not to the lookahead.\n"},{"title":"Drill 24 AdaGrad variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = 1; η = 0.1.</p>","<p>Supplied gradients: [2,1].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p>","<p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>G is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/49a0512d42c905d8.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\varepsilon}\" width=\"224.31\" height=\"52.24\" style=\"width:224.31px;height:52.24px;aspect-ratio:224.31/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient 2.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a2f78c9b3d52d653.svg\" alt=\"G_1=0+(2)^2=4\" width=\"191.24\" height=\"27.70\" style=\"width:191.24px;height:27.70px;aspect-ratio:191.24/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7923d1e84dd761ae.svg\" alt=\"\\sqrt{G_1}=\\sqrt{4}=2\" width=\"165.24\" height=\"30.79\" style=\"width:165.24px;height:30.79px;aspect-ratio:165.24/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1122171b0bd236e.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{4}}=0.9\" width=\"263.68\" height=\"60.60\" style=\"width:263.68px;height:60.60px;aspect-ratio:263.68/60.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 1.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd892c081c748bf2.svg\" alt=\"G_2=4+(1)^2=5\" width=\"191.24\" height=\"27.70\" style=\"width:191.24px;height:27.70px;aspect-ratio:191.24/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33c414269f4796af.svg\" alt=\"\\sqrt{G_2}=\\sqrt{5}=2.236067977\" width=\"281.99\" height=\"30.79\" style=\"width:281.99px;height:30.79px;aspect-ratio:281.99/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:218.88px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2a79e598e1b306b.svg\"><img class=\"math display-math\" src=\"assets/equations/0919f3ad17401c14.svg\" alt=\"\\theta_2=0.9-\\frac{0.1\\times(1)}{\\sqrt{5}}=0.85527864\" width=\"368.22\" height=\"60.60\" style=\"width:368.22px;height:60.60px;aspect-ratio:368.22/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c17-s24","search":"Drill 24 AdaGrad variation 1 **Question.** θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = 1; η = 0.1.\n\nSupplied gradients: [2,1].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**AdaGrad.** Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.\n\nG = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.\n\n\n\n\n\n**Yaad rakhne ka cue:** Square karo, purane sum mein jodo, root se scale karo.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nG is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient 2.**\nAdd the new squared gradient to all previous squares.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 1.**\nAdd the new squared gradient to all previous squares.\n\n\n\n"},{"title":"Drill 25 AdaGrad variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = −0.5; η = 0.1.</p>","<p>Supplied gradients: [−1,2].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p>","<p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>G is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/49a0512d42c905d8.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\varepsilon}\" width=\"224.31\" height=\"52.24\" style=\"width:224.31px;height:52.24px;aspect-ratio:224.31/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient -1.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bba453205f160315.svg\" alt=\"G_1=0+(-1)^2=1\" width=\"210.25\" height=\"27.70\" style=\"width:210.25px;height:27.70px;aspect-ratio:210.25/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1112f0b4d6224a38.svg\" alt=\"\\sqrt{G_1}=\\sqrt{1}=1\" width=\"165.24\" height=\"30.79\" style=\"width:165.24px;height:30.79px;aspect-ratio:165.24/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.90px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37395f4e33d5e1e8.svg\"><img class=\"math display-math\" src=\"assets/equations/771de6f5ff86a0f6.svg\" alt=\"\\theta_1=-0.5-\\frac{0.1\\times(-1)}{\\sqrt{1}}=-0.4\" width=\"339.72\" height=\"60.60\" style=\"width:339.72px;height:60.60px;aspect-ratio:339.72/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 2.</strong></p>","<p>Add the new squared gradient to all previous squares.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4e7c36432792b91c.svg\" alt=\"G_2=1+(2)^2=5\" width=\"191.24\" height=\"27.70\" style=\"width:191.24px;height:27.70px;aspect-ratio:191.24/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/33c414269f4796af.svg\" alt=\"\\sqrt{G_2}=\\sqrt{5}=2.236067977\" width=\"281.99\" height=\"30.79\" style=\"width:281.99px;height:30.79px;aspect-ratio:281.99/30.79\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.89px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1161742779014e25.svg\"><img class=\"math display-math\" src=\"assets/equations/cb523a64bc5840f4.svg\" alt=\"\\theta_2=-0.4-\\frac{0.1\\times(2)}{\\sqrt{5}}=-0.489442719\" width=\"418.46\" height=\"60.60\" style=\"width:418.46px;height:60.60px;aspect-ratio:418.46/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c17-s25","search":"Drill 25 AdaGrad variation 2 **Question.** θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use AdaGrad for two updates, zero initial accumulators and ε = 0 for this hand calculation.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = −0.5; η = 0.1.\n\nSupplied gradients: [−1,2].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**AdaGrad.** Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.\n\nG = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.\n\n\n\n\n\n**Yaad rakhne ka cue:** Square karo, purane sum mein jodo, root se scale karo.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nG is a running sum of squared gradients. Squaring removes the sign only inside G; keep the gradient sign in the update numerator. Start G₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient -1.**\nAdd the new squared gradient to all previous squares.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 2.**\nAdd the new squared gradient to all previous squares.\n\n\n\n"},{"title":"Drill 26 RMSProp variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = 1; η = 0.1.</p>","<p>Supplied gradients: [2,1].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>ρ = 0.9.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p>","<p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>s is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient 2.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a0575b9596aea909.svg\" alt=\"s_1=0.9(0)+0.1(2)^2=0.4\" width=\"283.96\" height=\"27.70\" style=\"width:283.96px;height:27.70px;aspect-ratio:283.96/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8724fbf30b88d3b5.svg\"><img class=\"math display-math\" src=\"assets/equations/ffb5003b52e07ea4.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.4}=0.632455532\" width=\"289.17\" height=\"30.34\" style=\"width:289.17px;height:30.34px;aspect-ratio:289.17/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:199.88px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/84ca434a6eea16db.svg\"><img class=\"math display-math\" src=\"assets/equations/a1a1a24a56913ad6.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{0.4}}=0.683772234\" width=\"361.42\" height=\"60.60\" style=\"width:361.42px;height:60.60px;aspect-ratio:361.42/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 1.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/99dd3340957517b7.svg\"><img class=\"math display-math\" src=\"assets/equations/ec584873dea573e6.svg\" alt=\"s_2=0.9(0.4)+0.1(1)^2=0.46\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7bc15fc56ff7b9f2.svg\"><img class=\"math display-math\" src=\"assets/equations/d68789eef851ad06.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.46}=0.678232998\" width=\"301.38\" height=\"30.34\" style=\"width:301.38px;height:30.34px;aspect-ratio:301.38/30.34\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.68px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dec405b6648724b8.svg\"><img class=\"math display-math\" src=\"assets/equations/555de02648791e71.svg\" alt=\"\\theta_2=0.683772234-\\frac{0.1\\times(1)}{\\sqrt{0.46}}=0.536330278\" width=\"478.17\" height=\"60.60\" style=\"width:478.17px;height:60.60px;aspect-ratio:478.17/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c17-s26","search":"Drill 26 RMSProp variation 1 **Question.** θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = 1; η = 0.1.\n\nSupplied gradients: [2,1].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nρ = 0.9.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**RMSProp.** Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.\n\ns = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.\n\n\n\n\n\n**Yaad rakhne ka cue:** Saare purane squares nahi—unki fading average.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\ns is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient 2.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 1.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n"},{"title":"Drill 27 RMSProp variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = −0.5; η = 0.1.</p>","<p>Supplied gradients: [−1,2].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>ρ = 0.9.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p>","<p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>s is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient -1.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81d06c696eada47a.svg\"><img class=\"math display-math\" src=\"assets/equations/859c9536cc17d749.svg\" alt=\"s_1=0.9(0)+0.1(-1)^2=0.1\" width=\"302.98\" height=\"27.70\" style=\"width:302.98px;height:27.70px;aspect-ratio:302.98/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.57px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8e43eda4dcf6bcb7.svg\"><img class=\"math display-math\" src=\"assets/equations/8a4a542960803c14.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.1}=0.316227766\" width=\"289.17\" height=\"30.20\" style=\"width:289.17px;height:30.20px;aspect-ratio:289.17/30.20\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.90px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1da7d1cdeda02890.svg\"><img class=\"math display-math\" src=\"assets/equations/3d6651cada170e8a.svg\" alt=\"\\theta_1=-0.5-\\frac{0.1\\times(-1)}{\\sqrt{0.1}}=-0.183772234\" width=\"437.46\" height=\"60.60\" style=\"width:437.46px;height:60.60px;aspect-ratio:437.46/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 2.</strong></p>","<p>Keep 90 percent of the old squared-gradient memory; add 10 percent of the new square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c7113e75687c23e.svg\"><img class=\"math display-math\" src=\"assets/equations/6351a5fcafc4c5e8.svg\" alt=\"s_2=0.9(0.1)+0.1(2)^2=0.49\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e14a6fd4eb271def.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.49}=0.7\" width=\"203.66\" height=\"30.34\" style=\"width:203.66px;height:30.34px;aspect-ratio:203.66/30.34\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.68px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dbbd9b6c37d99e9e.svg\"><img class=\"math display-math\" src=\"assets/equations/8c6d3f7be7bc6289.svg\" alt=\"\\theta_2=-0.183772234-\\frac{0.1\\times(2)}{\\sqrt{0.49}}=-0.46948652\" width=\"503.97\" height=\"60.60\" style=\"width:503.97px;height:60.60px;aspect-ratio:503.97/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c17-s27","search":"Drill 27 RMSProp variation 2 **Question.** θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use RMSProp for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use ρ = 0.9.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = −0.5; η = 0.1.\n\nSupplied gradients: [−1,2].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nρ = 0.9.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**RMSProp.** Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.\n\ns = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.\n\n\n\n\n\n**Yaad rakhne ka cue:** Saare purane squares nahi—unki fading average.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\ns is a moving average of squared gradients. ρ = 0.9 retains 90% of the old state; 1 − ρ = 0.1 supplies 10% of the new square. Start s₀ = 0.\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient -1.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n**Step 2: Iteration 2 with supplied gradient 2.**\nKeep 90 percent of the old squared-gradient memory; add 10 percent of the new square.\n\n\n\n"},{"title":"Drill 28 Adam variation 1","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = 1; η = 0.1.</p>","<p>Supplied gradients: [2,1].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>β₁ = 0.9; β₂ = 0.999; use bias correction.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Adam with bias correction.</strong> Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.</p>","<p>m = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1b0801ea4c5e3b1.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\epsilon}\" width=\"219.18\" height=\"66.12\" style=\"width:219.18px;height:66.12px;aspect-ratio:219.18/66.12\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Direction memory + square memory; hats lagao, phir update.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>m remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/cc72454f862696ef.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad \\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"329.41\" height=\"53.28\" style=\"width:329.41px;height:53.28px;aspect-ratio:329.41/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient 2.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ac027abcdfcdb75.svg\" alt=\"m_1=0.9(0)+0.1(2)=0.2\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b00fce2cf8ae5a5b.svg\"><img class=\"math display-math\" src=\"assets/equations/5ddaed21d0d6628c.svg\" alt=\"v_1=0.999(0)+0.001(2)^2=0.004\" width=\"357.66\" height=\"27.70\" style=\"width:357.66px;height:27.70px;aspect-ratio:357.66/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8975b50fed0845b.svg\" alt=\"\\widehat m_1=\\frac{0.2}{1-0.9^{1}}=2\" width=\"204.24\" height=\"54.93\" style=\"width:204.24px;height:54.93px;aspect-ratio:204.24/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f16a835e4241c7ed.svg\" alt=\"\\widehat v_1=\\frac{0.004}{1-0.999^{1}}=4\" width=\"219.07\" height=\"55.20\" style=\"width:219.07px;height:55.20px;aspect-ratio:219.07/55.20\" loading=\"lazy\"></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1122171b0bd236e.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{4}}=0.9\" width=\"263.68\" height=\"60.60\" style=\"width:263.68px;height:60.60px;aspect-ratio:263.68/60.60\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 1.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6a9a858d7c18aeb.svg\"><img class=\"math display-math\" src=\"assets/equations/4f47b7aabd4f81c4.svg\" alt=\"m_2=0.9(0.2)+0.1(1)=0.28\" width=\"314.52\" height=\"24.43\" style=\"width:314.52px;height:24.43px;aspect-ratio:314.52/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.32px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/308792cf26a22040.svg\"><img class=\"math display-math\" src=\"assets/equations/a1ecf2cf2c6e9e7e.svg\" alt=\"v_2=0.999(0.004)+0.001(1)^2=0.004996\" width=\"437.76\" height=\"27.70\" style=\"width:437.76px;height:27.70px;aspect-ratio:437.76/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2b1a3823c4815fe2.svg\"><img class=\"math display-math\" src=\"assets/equations/62512ed956356eba.svg\" alt=\"\\widehat m_2=\\frac{0.28}{1-0.9^{2}}=1.473684211\" width=\"320.99\" height=\"54.93\" style=\"width:320.99px;height:54.93px;aspect-ratio:320.99/54.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.27px;--narrow-height:94.29px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3922f5c0c13f3037.svg\"><img class=\"math display-math\" src=\"assets/equations/4ae265791f4d129d.svg\" alt=\"\\widehat v_2=\\frac{0.004996}{1-0.999^{2}}=2.499249625\" width=\"335.82\" height=\"55.20\" style=\"width:335.82px;height:55.20px;aspect-ratio:335.82/55.20\" loading=\"lazy\"></picture></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.70px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d6c4212f9eead9c.svg\"><img class=\"math display-math\" src=\"assets/equations/da23812bc6e746bd.svg\" alt=\"\\theta_2=0.9-\\frac{0.1\\times(1.473684211)}{\\sqrt{2.499249625}}=0.806782036\" width=\"497.18\" height=\"60.60\" style=\"width:497.18px;height:60.60px;aspect-ratio:497.18/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c17-s28","search":"Drill 28 Adam variation 1 **Question.** θ₀ = 1, η = 0.1, supplied successive gradients = [2, 1]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = 1; η = 0.1.\n\nSupplied gradients: [2,1].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nβ₁ = 0.9; β₂ = 0.999; use bias correction.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Adam with bias correction.** Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.\n\nm = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Direction memory + square memory; hats lagao, phir update.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nm remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.\n\n\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient 2.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n**Step 2: Iteration 2 with supplied gradient 1.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n"},{"title":"Drill 29 Adam variation 2","question":["<p class=\"inline-question\"><strong>Question.</strong> θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.</p>"],"answer":["<h3>Given</h3>","<p>Initial θ₀ = −0.5; η = 0.1.</p>","<p>Supplied gradients: [−1,2].</p>","<p>Initial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.</p>","<p>β₁ = 0.9; β₂ = 0.999; use bias correction.</p>","<h3>To find</h3>","<p>Find every stored state needed by the method and the parameter after each of two updates.</p>","<h3>Formula — which one and why</h3>","<p><strong>Adam with bias correction.</strong> Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.</p>","<p>m = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0be5e35b2aa1dc00.svg\" alt=\"s_t=\\beta_2s_{t-1}+(1-\\beta_2)g_t^2\" width=\"256.40\" height=\"27.82\" style=\"width:256.40px;height:27.82px;aspect-ratio:256.40/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6ee8d213ad96014.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39aff9d162818e1c.svg\" alt=\"\\hat s_t=\\frac{s_t}{1-\\beta_2^t}\" width=\"129.64\" height=\"53.25\" style=\"width:129.64px;height:53.25px;aspect-ratio:129.64/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1b0801ea4c5e3b1.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat s_t}+\\epsilon}\" width=\"219.18\" height=\"66.12\" style=\"width:219.18px;height:66.12px;aspect-ratio:219.18/66.12\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Direction memory + square memory; hats lagao, phir update.</p>","<h3>Solution — step by step</h3>","<h3>Symbols and formulas used</h3>","<p>θ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.</p>","<p>m remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/cc72454f862696ef.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad \\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"329.41\" height=\"53.28\" style=\"width:329.41px;height:53.28px;aspect-ratio:329.41/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>Use the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.</p>","<p class=\"worked-step\"><strong>Step 1: Iteration 1 with supplied gradient -1.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff0acbc11515087e.svg\"><img class=\"math display-math\" src=\"assets/equations/8cb1bdd325f9978f.svg\" alt=\"m_1=0.9(0)+0.1(-1)=-0.1\" width=\"321.31\" height=\"24.43\" style=\"width:321.31px;height:24.43px;aspect-ratio:321.31/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:234.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e44b2300355f9498.svg\"><img class=\"math display-math\" src=\"assets/equations/d05bfcaee435c205.svg\" alt=\"v_1=0.999(0)+0.001(-1)^2=0.001\" width=\"376.67\" height=\"27.70\" style=\"width:376.67px;height:27.70px;aspect-ratio:376.67/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/721803042ed359b9.svg\" alt=\"\\widehat m_1=\\frac{-0.1}{1-0.9^{1}}=-1\" width=\"223.25\" height=\"54.93\" style=\"width:223.25px;height:54.93px;aspect-ratio:223.25/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4d865fbfcf2b328.svg\" alt=\"\\widehat v_1=\\frac{0.001}{1-0.999^{1}}=1\" width=\"219.07\" height=\"54.93\" style=\"width:219.07px;height:54.93px;aspect-ratio:219.07/54.93\" loading=\"lazy\"></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.90px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37395f4e33d5e1e8.svg\"><img class=\"math display-math\" src=\"assets/equations/771de6f5ff86a0f6.svg\" alt=\"\\theta_1=-0.5-\\frac{0.1\\times(-1)}{\\sqrt{1}}=-0.4\" width=\"339.72\" height=\"60.60\" style=\"width:339.72px;height:60.60px;aspect-ratio:339.72/60.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Iteration 2 with supplied gradient 2.</strong></p>","<p>First calculate the signed-gradient mean m and squared-gradient mean v.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/89d9785f6f04be8b.svg\"><img class=\"math display-math\" src=\"assets/equations/dc1a680eebaa1164.svg\" alt=\"m_2=0.9(-0.1)+0.1(2)=0.11\" width=\"333.54\" height=\"24.43\" style=\"width:333.54px;height:24.43px;aspect-ratio:333.54/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.32px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0838089126c8ebdc.svg\"><img class=\"math display-math\" src=\"assets/equations/6ffede766a41d6bd.svg\" alt=\"v_2=0.999(0.001)+0.001(2)^2=0.004999\" width=\"437.76\" height=\"27.70\" style=\"width:437.76px;height:27.70px;aspect-ratio:437.76/27.70\" loading=\"lazy\"></picture></div>","<p>Correct each zero-initialized mean using this iteration number in the power.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e970513a5c078389.svg\"><img class=\"math display-math\" src=\"assets/equations/bee1e67cf69a8631.svg\" alt=\"\\widehat m_2=\\frac{0.11}{1-0.9^{2}}=0.578947368\" width=\"320.99\" height=\"54.93\" style=\"width:320.99px;height:54.93px;aspect-ratio:320.99/54.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.27px;--narrow-height:94.29px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a6410e8fada39e27.svg\"><img class=\"math display-math\" src=\"assets/equations/998deb4908102974.svg\" alt=\"\\widehat v_2=\\frac{0.004999}{1-0.999^{2}}=2.500750375\" width=\"335.82\" height=\"55.20\" style=\"width:335.82px;height:55.20px;aspect-ratio:335.82/55.20\" loading=\"lazy\"></picture></div>","<p>Divide the corrected direction by the corrected root, then subtract the scaled step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.70px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3e2be14fb02aba94.svg\"><img class=\"math display-math\" src=\"assets/equations/fc06a7b542215246.svg\" alt=\"\\theta_2=-0.4-\\frac{0.1\\times(0.578947368)}{\\sqrt{2.500750375}}=-0.436610353\" width=\"535.20\" height=\"60.60\" style=\"width:535.20px;height:60.60px;aspect-ratio:535.20/60.60\" loading=\"lazy\"></picture></div>"],"kind":"practice","id":"tee-c17-s29","search":"Drill 29 Adam variation 2 **Question.** θ₀ = -0.5, η = 0.1, supplied successive gradients = [-1, 2]. Use Adam for two updates, zero initial accumulators and ε = 0 for this hand calculation. Use β₁ = 0.9, β₂ = 0.999 and bias correction.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial θ₀ = −0.5; η = 0.1.\n\nSupplied gradients: [−1,2].\n\nInitial accumulator(s) = 0; ε = 0 for this nonzero-denominator hand calculation.\n\nβ₁ = 0.9; β₂ = 0.999; use bias correction.\n\n### To find\n\nFind every stored state needed by the method and the parameter after each of two updates.\n\n### Formula — which one and why\n\n**Adam with bias correction.** Keep two states: one averages signed gradients, the other averages squared gradients. Correct their initial bias toward zero before combining them in the parameter update.\n\nm = signed average; s (also written v) = squared average; β₁ and β₂ = retained fractions; t = iteration number. A hat marks a corrected value. Carry raw m and s into the next recurrence.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Direction memory + square memory; hats lagao, phir update.\n\n### Solution — step by step\n\n\n\n\n\n### Symbols and formulas used\nθ is the parameter; η is the base learning rate; gₜ is the supplied gradient for update t. The gradients are already given, so no loss differentiation is needed here. Use ε = 0 only as specified in this exercise.\nm remembers signed gradients; v remembers squared gradients. The hats mean bias-corrected values, compensating for memories starting at zero. They are not extra powers. Here β₁ = 0.9 and β₂ = 0.999.\n\n\n\n\n\nUse the supplied gradients in order. Initialize the stated memories to zero. Epsilon is set to zero only for this exercise because every denominator is nonzero. Keep calculator precision until the final result.\n**Step 1: Iteration 1 with supplied gradient -1.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n**Step 2: Iteration 2 with supplied gradient 2.**\nFirst calculate the signed-gradient mean m and squared-gradient mean v.\n\n\nCorrect each zero-initialized mean using this iteration number in the power.\n\n\nDivide the corrected direction by the corrected root, then subtract the scaled step.\n\n"},{"title":"Drill 30 Regularized objective","question":["<p class=\"inline-question\"><strong>Question.</strong> Data loss = 0.4, w = [−2,1,0.5], λ = 0.1. Calculate L1 objective and L2 objective using (λ/2)Σw².</p>"],"answer":["<h3>Given</h3>","<p>Data loss = 0.4; weights = [−2,1,0.5]; λ = 0.1.</p>","<p>For L2, the question includes the factor ½.</p>","<h3>To find</h3>","<p>Find each penalty and the total L1/L2 objective.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>L2 penalty with a factor of one-half.</strong> Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.</p>","<p>λ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29419cadd5578572.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc02963f72332f.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"179.88\" height=\"23.98\" style=\"width:179.88px;height:23.98px;aspect-ratio:179.88/23.98\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/616c8cbb90430248.svg\" alt=\"w_i^{\\mathrm{new}}=w_i-\\eta g_i\" width=\"169.00\" height=\"24.06\" style=\"width:169.00px;height:24.06px;aspect-ratio:169.00/24.06\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half wala L2 derivative mein lambda × weight deta hai.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The data loss measures prediction error. A regularization penalty adds a cost for large weights. The objective J is the total being minimized. λ sets the strength of the penalty.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14053316f92ab54d.svg\" alt=\"J_{L1}=L_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"247.46\" height=\"52.35\" style=\"width:247.46px;height:52.35px;aspect-ratio:247.46/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3cf9af2ddfa197c.svg\" alt=\"J_{L2}=L_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"247.31\" height=\"62.61\" style=\"width:247.31px;height:62.61px;aspect-ratio:247.31/62.61\" loading=\"lazy\"></div>","<p>Absolute value means ignore the sign. Squaring means multiply the number by itself. These are different operations.</p>","<p class=\"worked-step\"><strong>Step 1: Part A: L1 objective.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:108.63px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcceddf63f9341b2.svg\"><img class=\"math display-math\" src=\"assets/equations/9936fa64e265469b.svg\" alt=\"|-2|=2,\\quad |1|=1,\\quad |0.5|=0.5\" width=\"350.30\" height=\"24.41\" style=\"width:350.30px;height:24.41px;aspect-ratio:350.30/24.41\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.48px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb36584739f81886.svg\"><img class=\"math display-math\" src=\"assets/equations/2a71081b4845e558.svg\" alt=\"\\sum_i|w_i|=2+1+0.5=3.5\" width=\"290.22\" height=\"52.35\" style=\"width:290.22px;height:52.35px;aspect-ratio:290.22/52.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.95px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc6e588ea36fd61a.svg\"><img class=\"math display-math\" src=\"assets/equations/e5d16adbe508b8b5.svg\" alt=\"\\text{L1 penalty}=0.1\\times3.5=0.35\" width=\"313.97\" height=\"21.95\" style=\"width:313.97px;height:21.95px;aspect-ratio:313.97/21.95\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3ee4cac7da2daf6.svg\" alt=\"J_{L1}=0.4+0.35=0.75\" width=\"249.15\" height=\"20.36\" style=\"width:249.15px;height:20.36px;aspect-ratio:249.15/20.36\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: Part B: L2 objective with the given half.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:117.93px;--narrow-height:112.44px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ef16358fc81a0cdc.svg\"><img class=\"math display-math\" src=\"assets/equations/f1d2b6bccfe10f10.svg\" alt=\"(-2)^2=4,\\quad 1^2=1,\\quad 0.5^2=0.25\" width=\"361.92\" height=\"27.70\" style=\"width:361.92px;height:27.70px;aspect-ratio:361.92/27.70\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.79px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/18bd7cc9173340e8.svg\"><img class=\"math display-math\" src=\"assets/equations/ae0c24324eadcb63.svg\" alt=\"\\sum_iw_i^2=4+1+0.25=5.25\" width=\"303.75\" height=\"52.35\" style=\"width:303.75px;height:52.35px;aspect-ratio:303.75/52.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/482c5bfd76d38e6c.svg\" alt=\"\\frac\\lambda2=\\frac{0.1}2=0.05\" width=\"175.59\" height=\"50.24\" style=\"width:175.59px;height:50.24px;aspect-ratio:175.59/50.24\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.06px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/722ddb9c14ea7480.svg\"><img class=\"math display-math\" src=\"assets/equations/785c143e9ad28b18.svg\" alt=\"\\text{L2 penalty}=0.05\\times5.25=0.2625\" width=\"362.84\" height=\"21.95\" style=\"width:362.84px;height:21.95px;aspect-ratio:362.84/21.95\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6399f9c64b91d83f.svg\"><img class=\"math display-math\" src=\"assets/equations/318e776fa7639b85.svg\" alt=\"J_{L2}=0.4+0.2625=0.6625\" width=\"298.02\" height=\"20.36\" style=\"width:298.02px;height:20.36px;aspect-ratio:298.02/20.36\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> L1 objective 0.75; L2 objective 0.6625. These are total objectives, not just penalty values.</p>"],"kind":"practice","id":"tee-c17-s30","search":"Drill 30 Regularized objective **Question.** Data loss = 0.4, w = [−2,1,0.5], λ = 0.1. Calculate L1 objective and L2 objective using (λ/2)Σw².\n\n**Full solution.**\n\n\n\n### Given\n\nData loss = 0.4; weights = [−2,1,0.5]; λ = 0.1.\n\nFor L2, the question includes the factor ½.\n\n### To find\n\nFind each penalty and the total L1/L2 objective.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**L2 penalty with a factor of one-half.** Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.\n\nλ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Half wala L2 derivative mein lambda × weight deta hai.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe data loss measures prediction error. A regularization penalty adds a cost for large weights. The objective J is the total being minimized. λ sets the strength of the penalty.\n\n\nAbsolute value means ignore the sign. Squaring means multiply the number by itself. These are different operations.\n**Step 1: Part A: L1 objective.**\n\n\n\n\n**Step 2: Part B: L2 objective with the given half.**\n\n\n\n\n\n**Final answer:** L1 objective 0.75; L2 objective 0.6625. These are total objectives, not just penalty values.\n"},{"title":"Drill 31 L1 update on positive and negative weights","question":["<p class=\"inline-question\"><strong>Question.</strong> w = [−0.5,0.3], data gradients = [0.2,−0.1], λ = 0.1, η = 0.2. Use L1 and ordinary gradient descent away from zero.</p>"],"answer":["<h3>Given</h3>","<p>Old weights = [−0.5,0.3].</p>","<p>Data gradients = [0.2,−0.1]; λ = 0.1; η = 0.2.</p>","<h3>To find</h3>","<p>Find total gradients and the two updated weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>L1 penalty and gradient.</strong> Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.</p>","<p>λ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1baed4b772bbe05f.svg\" alt=\"J=J_{\\mathrm{data}}+\\lambda\\sum_i|w_i|\" width=\"223.86\" height=\"52.35\" style=\"width:223.86px;height:52.35px;aspect-ratio:223.86/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad178fc1be6044c9.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda\\operatorname{sign}(w_i)\" width=\"245.18\" height=\"25.35\" style=\"width:245.18px;height:25.35px;aspect-ratio:245.18/25.35\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> L1 absolute values leta hai; gradient mein sign aata hai.</p>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>The supplied data gradient is only one part of the total gradient. L1 adds λ times the sign of the old weight. Sign is −1 for a negative weight and +1 for a positive weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:152.92px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/edfc42b95078bb2c.svg\"><img class=\"math display-math\" src=\"assets/equations/9bff63bbdd0e51df.svg\" alt=\"g_{j,\\mathrm{total}}=g_{j,\\mathrm{data}}+\\lambda\\operatorname{sign}(w_j)\" width=\"288.99\" height=\"25.52\" style=\"width:288.99px;height:25.52px;aspect-ratio:288.99/25.52\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8e2c2fa59e985f4e.svg\" alt=\"w_{j,\\mathrm{new}}=w_j-\\eta g_{j,\\mathrm{total}}\" width=\"223.56\" height=\"21.44\" style=\"width:223.56px;height:21.44px;aspect-ratio:223.56/21.44\" loading=\"lazy\"></div>","<p>Both weights here are nonzero, so the ambiguous derivative of absolute value at zero is not needed.</p>","<p class=\"worked-step\"><strong>Step 1: Weight 1: old value −0.5.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:243.83px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/56f95d7675b65e54.svg\"><img class=\"math display-math\" src=\"assets/equations/ebeb8e1558332839.svg\" alt=\"\\lambda\\operatorname{sign}(-0.5)=0.1(-1)=-0.1\" width=\"326.66\" height=\"24.43\" style=\"width:326.66px;height:24.43px;aspect-ratio:326.66/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.58px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ee9041d822361870.svg\"><img class=\"math display-math\" src=\"assets/equations/7626b740cec3ed4d.svg\" alt=\"g_{1,\\mathrm{total}}=0.2+(-0.1)=0.1\" width=\"289.39\" height=\"25.35\" style=\"width:289.39px;height:25.35px;aspect-ratio:289.39/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.88px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6d4d841ab160b740.svg\"><img class=\"math display-math\" src=\"assets/equations/49b338a1efee1ae5.svg\" alt=\"w_{1,\\mathrm{new}}=-0.5-0.2(0.1)=-0.5-0.02=-0.52\" width=\"508.04\" height=\"25.35\" style=\"width:508.04px;height:25.35px;aspect-ratio:508.04/25.35\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Weight 2: old value 0.3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cce8304f0261d4a5.svg\" alt=\"\\lambda\\operatorname{sign}(0.3)=0.1(1)=0.1\" width=\"269.63\" height=\"24.43\" style=\"width:269.63px;height:24.43px;aspect-ratio:269.63/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/09ef0e91f63c60f6.svg\" alt=\"g_{2,\\mathrm{total}}=-0.1+0.1=0\" width=\"251.37\" height=\"23.30\" style=\"width:251.37px;height:23.30px;aspect-ratio:251.37/23.30\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/39fa74bf610f2797.svg\" alt=\"w_{2,\\mathrm{new}}=0.3-0.2(0)=0.3\" width=\"282.67\" height=\"25.35\" style=\"width:282.67px;height:25.35px;aspect-ratio:282.67/25.35\" loading=\"lazy\"></div>","<p><strong>Final answer: [−0.52, 0.3].</strong> L1&#x27;s own contribution pulls toward zero, but the combined data-plus-penalty update can move a weight away from zero.</p>"],"kind":"practice","id":"tee-c17-s31","search":"Drill 31 L1 update on positive and negative weights **Question.** w = [−0.5,0.3], data gradients = [0.2,−0.1], λ = 0.1, η = 0.2. Use L1 and ordinary gradient descent away from zero.\n\n**Full solution.**\n\n\n\n### Given\n\nOld weights = [−0.5,0.3].\n\nData gradients = [0.2,−0.1]; λ = 0.1; η = 0.2.\n\n### To find\n\nFind total gradients and the two updated weights.\n\n### Formula — which one and why\n\n**L1 penalty and gradient.** Add absolute weight magnitudes to penalize large weights. Away from zero, the penalty derivative depends on the weight’s sign.\n\nλ (lambda) = penalty strength; J_data = data loss; sign(w) is +1 for positive and −1 for negative weights. At zero a subgradient convention is needed.\n\n\n\n\n\n**Yaad rakhne ka cue:** L1 absolute values leta hai; gradient mein sign aata hai.\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nThe supplied data gradient is only one part of the total gradient. L1 adds λ times the sign of the old weight. Sign is −1 for a negative weight and +1 for a positive weight.\n\n\nBoth weights here are nonzero, so the ambiguous derivative of absolute value at zero is not needed.\n**Step 1: Weight 1: old value −0.5.**\n\n\n\n**Step 2: Weight 2: old value 0.3.**\n\n\n\n**Final answer: [−0.52, 0.3].** L1's own contribution pulls toward zero, but the combined data-plus-penalty update can move a weight away from zero.\n"},{"title":"Drill 32 L2 update","question":["<p class=\"inline-question\"><strong>Question.</strong> w = [0.5,−0.2], data gradients = [0.1,0.3], λ = 0.2, η = 0.1. Use(λ/2)Σw².</p>"],"answer":["<h3>Given</h3>","<p>Old weights = [0.5,−0.2]; data gradients = [0.1,0.3].</p>","<p>λ = 0.2; η = 0.1; penalty = (λ/2)Σw².</p>","<h3>To find</h3>","<p>Find penalty gradients, total gradients and updated weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>L2 penalty with a factor of one-half.</strong> Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.</p>","<p>λ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29419cadd5578572.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc02963f72332f.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"179.88\" height=\"23.98\" style=\"width:179.88px;height:23.98px;aspect-ratio:179.88/23.98\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/616c8cbb90430248.svg\" alt=\"w_i^{\\mathrm{new}}=w_i-\\eta g_i\" width=\"169.00\" height=\"24.06\" style=\"width:169.00px;height:24.06px;aspect-ratio:169.00/24.06\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half wala L2 derivative mein lambda × weight deta hai.</p>","<h3>Solution — step by step</h3>","<h3>Formula and its reason</h3>","<p>The derivative of (λ/2)w² is λw: the 2 from the square cancels the half. Add that regularization gradient to the given data gradient before updating.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6dece7c528660c2d.svg\" alt=\"g_{j,\\mathrm{total}}=g_{j,\\mathrm{data}}+\\lambda w_j\" width=\"223.68\" height=\"24.15\" style=\"width:223.68px;height:24.15px;aspect-ratio:223.68/24.15\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8e2c2fa59e985f4e.svg\" alt=\"w_{j,\\mathrm{new}}=w_j-\\eta g_{j,\\mathrm{total}}\" width=\"223.56\" height=\"21.44\" style=\"width:223.56px;height:21.44px;aspect-ratio:223.56/21.44\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 1: Weight 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26564fe78f783309.svg\" alt=\"\\lambda w_1=0.2\\times0.5=0.1\" width=\"231.13\" height=\"20.63\" style=\"width:231.13px;height:20.63px;aspect-ratio:231.13/20.63\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e611707728d90ba8.svg\" alt=\"g_{1,\\mathrm{total}}=0.1+0.1=0.2\" width=\"251.37\" height=\"23.30\" style=\"width:251.37px;height:23.30px;aspect-ratio:251.37/23.30\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.86px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/86b47a5bd5373b33.svg\"><img class=\"math display-math\" src=\"assets/equations/055c0eb9628a74ae.svg\" alt=\"w_{1,\\mathrm{new}}=0.5-0.1(0.2)=0.48\" width=\"313.89\" height=\"25.35\" style=\"width:313.89px;height:25.35px;aspect-ratio:313.89/25.35\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Weight 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d1d1a2ba29bb3862.svg\"><img class=\"math display-math\" src=\"assets/equations/469562aa281fbfba.svg\" alt=\"\\lambda w_2=0.2\\times(-0.2)=-0.04\" width=\"300.37\" height=\"24.43\" style=\"width:300.37px;height:24.43px;aspect-ratio:300.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.79px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/eeb80cfd582d91ed.svg\"><img class=\"math display-math\" src=\"assets/equations/0590c2b0e0fd2940.svg\" alt=\"g_{2,\\mathrm{total}}=0.3+(-0.04)=0.26\" width=\"313.83\" height=\"25.35\" style=\"width:313.83px;height:25.35px;aspect-ratio:313.83/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b559be4dc46e47e0.svg\"><img class=\"math display-math\" src=\"assets/equations/7c525ffa9dc17255.svg\" alt=\"w_{2,\\mathrm{new}}=-0.2-0.1(0.26)=-0.226\" width=\"376.35\" height=\"25.35\" style=\"width:376.35px;height:25.35px;aspect-ratio:376.35/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final answer: [0.48, −0.226].</strong> The second data gradient dominates the regularization term, explaining why that negative weight becomes more negative.</p>"],"kind":"practice","id":"tee-c17-s32","search":"Drill 32 L2 update **Question.** w = [0.5,−0.2], data gradients = [0.1,0.3], λ = 0.2, η = 0.1. Use(λ/2)Σw².\n\n**Full solution.**\n\n\n\n### Given\n\nOld weights = [0.5,−0.2]; data gradients = [0.1,0.3].\n\nλ = 0.2; η = 0.1; penalty = (λ/2)Σw².\n\n### To find\n\nFind penalty gradients, total gradients and updated weights.\n\n### Formula — which one and why\n\n**L2 penalty with a factor of one-half.** Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.\n\nλ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Half wala L2 derivative mein lambda × weight deta hai.\n\n### Solution — step by step\n\n\n\n\n\n### Formula and its reason\nThe derivative of (λ/2)w² is λw: the 2 from the square cancels the half. Add that regularization gradient to the given data gradient before updating.\n\n\n**Step 1: Weight 1.**\n\n\n\n**Step 2: Weight 2.**\n\n\n\n**Final answer: [0.48, −0.226].** The second data gradient dominates the regularization term, explaining why that negative weight becomes more negative.\n"},{"title":"Drill 33 Inverted dropout","question":["<p class=\"inline-question\"><strong>Question.</strong> Activations = [2,−1,0,3], keep probability 0.75, mask = [1,0,1,1]. Find training outputs and explain inference.</p>"],"answer":["<h3>Given</h3>","<p>Activations = [2,−1,0,3].</p>","<p>Keep probability q = 0.75; keep mask = [1,0,1,1].</p>","<h3>To find</h3>","<p>Find training outputs and state the inference rule.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>The mask entry m is 1 when an activation is kept and 0 when dropped. The keep probability q is 0.75. Inverted dropout divides the kept activations by q during training so that their expected value is preserved.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4210eb7af01249ba.svg\" alt=\"a&#x27;_j=\\frac{m_j a_j}{q}\" width=\"118.08\" height=\"50.73\" style=\"width:118.08px;height:50.73px;aspect-ratio:118.08/50.73\" loading=\"lazy\"></div>","<p>The multiplication is entry by entry; there is no dot-product sum.</p>","<h3>Step 1: apply the mask</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:259.35px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f0ff08cea46f6163.svg\"><img class=\"math display-math\" src=\"assets/equations/0a3991790719d436.svg\" alt=\"[1(2),\\;0(-1),\\;1(0),\\;1(3)]=[2,0,0,3]\" width=\"386.99\" height=\"24.43\" style=\"width:386.99px;height:24.43px;aspect-ratio:386.99/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: divide each result by 0.75</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4257cce51e38bfe0.svg\" alt=\"a&#x27;_1=\\frac2{0.75}=2.666666667\" width=\"271.92\" height=\"50.09\" style=\"width:271.92px;height:50.09px;aspect-ratio:271.92/50.09\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.97px;--narrow-height:114.84px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93312a45b7b42272.svg\"><img class=\"math display-math\" src=\"assets/equations/f7f43ac5cd2d312a.svg\" alt=\"a&#x27;_2=\\frac0{0.75}=0,\\qquad a&#x27;_3=\\frac0{0.75}=0\" width=\"370.08\" height=\"50.09\" style=\"width:370.08px;height:50.09px;aspect-ratio:370.08/50.09\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d5f3e01a5c059a83.svg\" alt=\"a&#x27;_4=\\frac3{0.75}=4\" width=\"155.17\" height=\"50.07\" style=\"width:155.17px;height:50.07px;aspect-ratio:155.17/50.07\" loading=\"lazy\"></div>","<p><strong>Training output = [2.666666667, 0, 0, 4].</strong> A kept activation that was already zero stays zero.</p>","<h3>During inference</h3>","<p>Disable the random mask and the division. If the incoming activations are the same [2,−1,0,3], they pass through unchanged. The scaling has already been accounted for during training.</p>"],"kind":"practice","id":"tee-c17-s33","search":"Drill 33 Inverted dropout **Question.** Activations = [2,−1,0,3], keep probability 0.75, mask = [1,0,1,1]. Find training outputs and explain inference.\n\n**Full solution.**\n\n\n\n### Given\n\nActivations = [2,−1,0,3].\n\nKeep probability q = 0.75; keep mask = [1,0,1,1].\n\n### To find\n\nFind training outputs and state the inference rule.\n\n### Formula — which one and why\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nThe mask entry m is 1 when an activation is kept and 0 when dropped. The keep probability q is 0.75. Inverted dropout divides the kept activations by q during training so that their expected value is preserved.\n\nThe multiplication is entry by entry; there is no dot-product sum.\n### Step 1: apply the mask\n\n### Step 2: divide each result by 0.75\n\n\n\n**Training output = [2.666666667, 0, 0, 4].** A kept activation that was already zero stays zero.\n### During inference\nDisable the random mask and the division. If the incoming activations are the same [2,−1,0,3], they pass through unchanged. The scaling has already been accounted for during training.\n"},{"title":"Drill 34 Convolution with a negative coefficient","question":["<p class=\"inline-question\"><strong>Question.</strong> Use the input A and kernel K shown below, stride 1, padding 0. Compute all outputs.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 1; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Input A and kernel K are printed with the question.</p>","<p>Stride S = 1; padding P = 0; bias = 0.</p>","<p>Use the kernel without flipping it.</p>","<h3>To find</h3>","<p>Calculate all nine output cells.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<h3>Formulas and the operation we are performing</h3>","<p>A filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:281.49px;--narrow-height:152.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1a1aa2b10ea1816e.svg\"><img class=\"math display-math\" src=\"assets/equations/33407dafb559f8d6.svg\" alt=\"Y_{ij}=\\sum_{u=0}^{K_h-1}\\sum_{v=0}^{K_w-1}X_{iS+u,jS+v}K_{uv}+b\" width=\"351.15\" height=\"73.34\" style=\"width:351.15px;height:73.34px;aspect-ratio:351.15/73.34\" loading=\"lazy\"></picture></div>","<p>Here i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.</p>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/99ba828c16946a06.svg\" alt=\"\\left\\lfloor\\frac{4+2 \\times  0-2}{1}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 3 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + (−2) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 1 = 1</b></div></div><p class=\"lv-combine\"><b>(−1) + 1 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d0c50421371c4116.svg\"><img class=\"math display-math\" src=\"assets/equations/62842635b6eb75f8.svg\" alt=\"R_1=(1)\\times(1)+(2)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8c103dd6ecdec24c.svg\"><img class=\"math display-math\" src=\"assets/equations/d060bcb31ccbcc5c.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(1)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23722ac152853b27.svg\" alt=\"Y_{1,1}=(-1)+(1)=0\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 3 = 3</b></div></div><p class=\"lv-combine\"><b>2 + 3 = 5</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92e95617002bb2ff.svg\"><img class=\"math display-math\" src=\"assets/equations/65b69a57c4f3db18.svg\" alt=\"R_1=(2)\\times(1)+(0)\\times(-1)=2\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/89af9e3096091f5c.svg\"><img class=\"math display-math\" src=\"assets/equations/651ec43291a6ceee.svg\" alt=\"R_2=(1)\\times(0)+(3)\\times(1)=3\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e073412e219f2310.svg\" alt=\"Y_{1,2}=(2)+(3)=5\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + (−1) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 2 = 2</b></div></div><p class=\"lv-combine\"><b>(−1) + 2 = 1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37f1662710810d02.svg\"><img class=\"math display-math\" src=\"assets/equations/4bff5878f34559b0.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1986dc904d99f31e.svg\"><img class=\"math display-math\" src=\"assets/equations/e54c044f72c7530b.svg\" alt=\"R_2=(3)\\times(0)+(2)\\times(1)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48b778ac3ad46a58.svg\" alt=\"Y_{1,3}=(-1)+(2)=1\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + (−1) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 1 = 1</b></div></div><p class=\"lv-combine\"><b>(−1) + 1 = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37f1662710810d02.svg\"><img class=\"math display-math\" src=\"assets/equations/4bff5878f34559b0.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e63832c06fcb7aed.svg\"><img class=\"math display-math\" src=\"assets/equations/bd0efbee152c1e5c.svg\" alt=\"R_2=(2)\\times(0)+(1)\\times(1)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cb2a77b737bf455.svg\" alt=\"Y_{2,1}=(-1)+(1)=0\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −3\">−3</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + (−3) = −2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>(−2) + 0 = −2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/540cabd018cf9dd5.svg\"><img class=\"math display-math\" src=\"assets/equations/ad79fb60fa82034f.svg\" alt=\"R_1=(1)\\times(1)+(3)\\times(-1)=-2\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75388bfbb51edc5c.svg\"><img class=\"math display-math\" src=\"assets/equations/b595ad69d60edb10.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(1)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a1f7599e33d0692.svg\" alt=\"Y_{2,2}=(-2)+(0)=-2\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + (−2) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 1 = 1</b></div></div><p class=\"lv-combine\"><b>1 + 1 = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/941c8bddd3a4fd90.svg\"><img class=\"math display-math\" src=\"assets/equations/142f16f0e77fc1bc.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(-1)=1\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8c103dd6ecdec24c.svg\"><img class=\"math display-math\" src=\"assets/equations/d060bcb31ccbcc5c.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(1)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba68e9967c8a5ec6.svg\" alt=\"Y_{2,3}=(1)+(1)=2\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + (−1) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>1 + 0 = 1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ed9de22182a739e4.svg\"><img class=\"math display-math\" src=\"assets/equations/271ba4631f61b76a.svg\" alt=\"R_1=(2)\\times(1)+(1)\\times(-1)=1\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75388bfbb51edc5c.svg\"><img class=\"math display-math\" src=\"assets/equations/b595ad69d60edb10.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(1)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/108e2edb8fe7afbe.svg\" alt=\"Y_{3,1}=(1)+(0)=1\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 2 = 2</b></div></div><p class=\"lv-combine\"><b>1 + 2 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/248757728423ee8c.svg\"><img class=\"math display-math\" src=\"assets/equations/56ab2f7173dad1a0.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(-1)=1\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8b2b9a5baccb2ea6.svg\"><img class=\"math display-math\" src=\"assets/equations/925c2ca7e5d512dc.svg\" alt=\"R_2=(0)\\times(0)+(2)\\times(1)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/50d4d84e0be67f18.svg\" alt=\"Y_{3,2}=(1)+(2)=3\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + (−1) = −1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 3 = 3</b></div></div><p class=\"lv-combine\"><b>(−1) + 3 = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 3\">3</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 2\">2</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/37f1662710810d02.svg\"><img class=\"math display-math\" src=\"assets/equations/4bff5878f34559b0.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c18dea868e99c1c8.svg\"><img class=\"math display-math\" src=\"assets/equations/410d185792d0d4e1.svg\" alt=\"R_2=(2)\\times(0)+(3)\\times(1)=3\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5248561d79f5d37a.svg\" alt=\"Y_{3,3}=(-1)+(3)=2\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/1659d27513ae9f09.svg\" alt=\"\\begin{bmatrix}0 &amp; 5 &amp; 1\\\\0 &amp; -2 &amp; 2\\\\1 &amp; 3 &amp; 2\\end{bmatrix}\" width=\"106.65\" height=\"72.21\" style=\"width:106.65px;height:72.21px;aspect-ratio:106.65/72.21\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"kind":"practice","id":"tee-c17-s34","search":"Drill 34 Convolution with a negative coefficient **Question.** Use the input A and kernel K shown below, stride 1, padding 0. Compute all outputs.\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput A and kernel K are printed with the question.\n\nStride S = 1; padding P = 0; bias = 0.\n\nUse the kernel without flipping it.\n\n### To find\n\nCalculate all nine output cells.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and the operation we are performing\nA filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.\n\nHere i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.\n\nN is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.\n\n\n\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{4+2 \\times  0-2}{1}\\right\\rfloor+1\\) = 3 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.\n**Output (1,1): ** (1 × (1)) + (2 × (-1)) + (0 × (0)) + (1 × (1)) = **0**.\n**Output (1,2): ** (2 × (1)) + (0 × (-1)) + (1 × (0)) + (3 × (1)) = **5**.\n**Output (1,3): ** (0 × (1)) + (1 × (-1)) + (3 × (0)) + (2 × (1)) = **1**.\n**Output (2,1): ** (0 × (1)) + (1 × (-1)) + (2 × (0)) + (1 × (1)) = **0**.\n**Output (2,2): ** (1 × (1)) + (3 × (-1)) + (1 × (0)) + (0 × (1)) = **-2**.\n**Output (2,3): ** (3 × (1)) + (2 × (-1)) + (0 × (0)) + (1 × (1)) = **2**.\n**Output (3,1): ** (2 × (1)) + (1 × (-1)) + (1 × (0)) + (0 × (1)) = **1**.\n**Output (3,2): ** (1 × (1)) + (0 × (-1)) + (0 × (0)) + (2 × (1)) = **3**.\n**Output (3,3): ** (0 × (1)) + (1 × (-1)) + (2 × (0)) + (3 × (1)) = **2**.\n**Final output: ** . Each output came from its own complete window; stride changes the next window position, not the multiplication rule.\n"},{"title":"Drill 35 Padding stride and channels","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 31 × 31 × 3; 5 × 5 convolution,8 filters, stride 2, padding 1. Find shape, weights, biases, total.</p>"],"answer":["<h3>Given</h3>","<p>Input shape = 31 × 31 × 3.</p>","<p>Filter size = 5 × 5; number of filters = 8.</p>","<p>Stride S = 2; padding P = 1 per side; one bias per filter.</p>","<h3>To find</h3>","<p>Find output shape, weights, biases and total parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Meaning of each given value</h3>","<p>The input has height 31, width 31 and 3 channels. K = 5 is the filter width/height; S = 2 is the stride; P = 1 is padding on each side. Eight filters create eight output channels.</p>","<h3>Formulas used</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.63px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4fb085a2eda022c5.svg\"><img class=\"math display-math\" src=\"assets/equations/391b54fdb0c0ef2b.svg\" alt=\"\\text{weights}=K^2C_{\\mathrm{in}}C_{\\mathrm{out}},\\quad \\text{biases}=C_{\\mathrm{out}}\" width=\"399.88\" height=\"26.63\" style=\"width:399.88px;height:26.63px;aspect-ratio:399.88/26.63\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/35882bbb02ddb8aa.svg\"><img class=\"math display-math\" src=\"assets/equations/37224dd4ef25f22f.svg\" alt=\"\\text{parameters}=\\text{weights}+\\text{biases}\" width=\"323.73\" height=\"21.99\" style=\"width:323.73px;height:21.99px;aspect-ratio:323.73/21.99\" loading=\"lazy\"></picture></div>","<h3>Step 1: find the output height and width</h3>","<p>Padding adds one cell on each side, so the padded width is 31 + 2 × 1 = 33.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:97.97px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f73307dcf9d893e8.svg\"><img class=\"math display-math\" src=\"assets/equations/a4fa49b6e311d65e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{31+2(1)-5}{2}\\right\\rfloor+1\" width=\"300.36\" height=\"58.87\" style=\"width:300.36px;height:58.87px;aspect-ratio:300.36/58.87\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.98px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c0ed9983d10f2a99.svg\"><img class=\"math display-math\" src=\"assets/equations/70537488f5dc8b8a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{28}{2}\\right\\rfloor+1=14+1=15\" width=\"341.09\" height=\"58.62\" style=\"width:341.09px;height:58.62px;aspect-ratio:341.09/58.62\" loading=\"lazy\"></picture></div>","<p>The height uses the same calculation. <strong>Output shape = 15 × 15 × 8.</strong></p>","<h3>Step 2: count weights in one filter</h3>","<p>Each filter covers 5 × 5 positions in each of 3 channels.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.57px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ce380d19eaf1a9e.svg\"><img class=\"math display-math\" src=\"assets/equations/56e79229382e122b.svg\" alt=\"5\\times5\\times3=75\\text{ weights per filter}\" width=\"336.96\" height=\"22.26\" style=\"width:336.96px;height:22.26px;aspect-ratio:336.96/22.26\" loading=\"lazy\"></picture></div>","<h3>Step 3: count all filters and their biases</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/19223176d175b12b.svg\" alt=\"\\text{weights}=75\\times8=600\" width=\"248.56\" height=\"21.99\" style=\"width:248.56px;height:21.99px;aspect-ratio:248.56/21.99\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.80px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e580536b54e8c233.svg\"><img class=\"math display-math\" src=\"assets/equations/311dd5c76d87d54c.svg\" alt=\"\\text{biases}=8,\\qquad \\text{total}=600+8=608\" width=\"398.03\" height=\"21.70\" style=\"width:398.03px;height:21.70px;aspect-ratio:398.03/21.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> shape 15 × 15 × 8; 600 weights; 8 biases; 608 parameters. The 15 × 15 output locations reuse those weights.</p>"],"kind":"practice","id":"tee-c17-s35","search":"Drill 35 Padding stride and channels **Question.** Input 31 × 31 × 3; 5 × 5 convolution,8 filters, stride 2, padding 1. Find shape, weights, biases, total.\n\n**Full solution.**\n\n\n\n### Given\n\nInput shape = 31 × 31 × 3.\n\nFilter size = 5 × 5; number of filters = 8.\n\nStride S = 2; padding P = 1 per side; one bias per filter.\n\n### To find\n\nFind output shape, weights, biases and total parameters.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning of each given value\nThe input has height 31, width 31 and 3 channels. K = 5 is the filter width/height; S = 2 is the stride; P = 1 is padding on each side. Eight filters create eight output channels.\n### Formulas used\n\n\n\n### Step 1: find the output height and width\nPadding adds one cell on each side, so the padded width is 31 + 2 × 1 = 33.\n\n\nThe height uses the same calculation. **Output shape = 15 × 15 × 8.**\n### Step 2: count weights in one filter\nEach filter covers 5 × 5 positions in each of 3 channels.\n\n### Step 3: count all filters and their biases\n\n\n**Final answer:** shape 15 × 15 × 8; 600 weights; 8 biases; 608 parameters. The 15 × 15 output locations reuse those weights.\n"},{"title":"Drill 36 Max and average pooling","question":["<p class=\"inline-question\"><strong>Question.</strong> Pool the input A shown below with 2 × 2 windows and stride 2. Find max and average outputs.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_563e4ee8f7.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_563e4ee8f7.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"405\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"answer":["<h3>Given</h3>","<p>Input A is printed with the question.</p>","<p>Window size = 2 × 2; stride = 2; no padding.</p>","<h3>To find</h3>","<p>Find the complete max-pooling and average-pooling outputs.</p>","<h3>Formula — which one and why</h3>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<h3>Solution — step by step</h3>","<h3>Formulas and meaning</h3>","<p>Each 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/870fc5e76c2ff285.svg\" alt=\"p_{\\mathrm{max}}=\\max(a_1,a_2,a_3,a_4)\" width=\"270.51\" height=\"24.43\" style=\"width:270.51px;height:24.43px;aspect-ratio:270.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf572bd2a565d88a.svg\" alt=\"p_{\\mathrm{avg}}=\\frac{a_1+a_2+a_3+a_4}{4}\" width=\"268.03\" height=\"47.52\" style=\"width:268.03px;height:47.52px;aspect-ratio:268.03/47.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.64px;--narrow-height:98.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a9854190bb7c9a.svg\"><img class=\"math display-math\" src=\"assets/equations/bd33b42a8814468f.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"300.97\" height=\"58.62\" style=\"width:300.97px;height:58.62px;aspect-ratio:300.97/58.62\" loading=\"lazy\"></picture></div>","<p>Use the input size at the pooling layer. The output keeps the same channel count.</p>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ad46d0c1b3646c71.svg\" alt=\"\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[1, 4, 0, 2]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>1 + 4 + 0 + 2 = 7</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>7/4 = <strong>1.75</strong>. Maximum = <strong>4</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[2, 3, 5, 1]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>2 + 3 + 5 + 1 = 11</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>11/4 = <strong>2.75</strong>. Maximum = <strong>5</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[6, 3, 1, 7]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>6 + 3 + 1 + 7 = 17</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>17/4 = <strong>4.25</strong>. Maximum = <strong>7</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[2, 0, 4, 8]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>2 + 0 + 4 + 8 = 14</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>14/4 = <strong>3.5</strong>. Maximum = <strong>8</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c4e510493e329d60.svg\" alt=\"\\begin{bmatrix}1.75 &amp; 2.75\\\\4.25 &amp; 3.5\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>. <strong>Max output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/71895dac90bdedf0.svg\" alt=\"\\begin{bmatrix}4 &amp; 5\\\\7 &amp; 8\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>"],"kind":"practice","id":"tee-c17-s36","search":"Drill 36 Max and average pooling **Question.** Pool the input A shown below with 2 × 2 windows and stride 2. Find max and average outputs.\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput A is printed with the question.\n\nWindow size = 2 × 2; stride = 2; no padding.\n\n### To find\n\nFind the complete max-pooling and average-pooling outputs.\n\n### Formula — which one and why\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and meaning\nEach 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.\n\n\n\nUse the input size at the pooling layer. The output keeps the same channel count.\n\n**Shape: ** \\(\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1\\) = 2 on each axis; channels stay unchanged.\n### Pooling window (1,1)\n\n**Step 1: select the entries.**\n\n[1, 4, 0, 2]\n\n**Step 2: add all selected entries.**\n\n1 + 4 + 0 + 2 = 7\n\n**Step 3: divide by the 4 entries in this window.**\n\n7/4 = **1.75**. Maximum = **4**\n\n\n### Pooling window (1,2)\n\n**Step 1: select the entries.**\n\n[2, 3, 5, 1]\n\n**Step 2: add all selected entries.**\n\n2 + 3 + 5 + 1 = 11\n\n**Step 3: divide by the 4 entries in this window.**\n\n11/4 = **2.75**. Maximum = **5**\n\n\n### Pooling window (2,1)\n\n**Step 1: select the entries.**\n\n[6, 3, 1, 7]\n\n**Step 2: add all selected entries.**\n\n6 + 3 + 1 + 7 = 17\n\n**Step 3: divide by the 4 entries in this window.**\n\n17/4 = **4.25**. Maximum = **7**\n\n\n### Pooling window (2,2)\n\n**Step 1: select the entries.**\n\n[2, 0, 4, 8]\n\n**Step 2: add all selected entries.**\n\n2 + 0 + 4 + 8 = 14\n\n**Step 3: divide by the 4 entries in this window.**\n\n14/4 = **3.5**. Maximum = **8**\n\n\n**Average output: ** . **Max output: ** . Pooling normally has zero trainable parameters and reduces spatial dimensions.\n"},{"title":"Drill 37 Complete small CNN","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 10 × 10 × 1 → Conv 3 × 3,4 filters, stride 1, valid → Pool 2 stride 2 → Flatten → Dense 3. Find all shapes and parameters.</p>"],"answer":["<h3>Given</h3>","<p>Input = 10 × 10 × 1.</p>","<p>Conv: 3 × 3, 4 filters, stride 1, valid padding.</p>","<p>Pool: 2 × 2, stride 2; then flatten and dense layer with 3 outputs.</p>","<p>Include one bias per filter/dense neuron.</p>","<h3>To find</h3>","<p>Find all output shapes, layer parameter counts and their sum.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<h3>Solution — step by step</h3>","<h3>Formulas and assumptions</h3>","<p>“Valid” means zero padding. The convolution and dense layers each have one bias per receiving filter or neuron. Pooling and flattening have no learned parameters.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4064c7b5aff30cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bf6a8c697b8e11ab.svg\" alt=\"n_{\\mathrm{flat}}=HWC,\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"425.84\" height=\"24.43\" style=\"width:425.84px;height:24.43px;aspect-ratio:425.84/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 1: convolution shape</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:250.72px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/79853ff0cb463822.svg\"><img class=\"math display-math\" src=\"assets/equations/7bc6460a33d41247.svg\" alt=\"N_{\\mathrm{conv}}=\\frac{10+0-3}{1}+1=7+1=8\" width=\"382.41\" height=\"49.55\" style=\"width:382.41px;height:49.55px;aspect-ratio:382.41/49.55\" loading=\"lazy\"></picture></div>","<p>Four filters produce four channels: <strong>8 × 8 × 4</strong>.</p>","<h3>Step 2: convolution parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.28px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d2206cecca6115a8.svg\"><img class=\"math display-math\" src=\"assets/equations/04061505b018b4db.svg\" alt=\"\\text{weights}=3\\times3\\times1\\times4=36\" width=\"308.30\" height=\"21.99\" style=\"width:308.30px;height:21.99px;aspect-ratio:308.30/21.99\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d97de20b29f5a9fb.svg\"><img class=\"math display-math\" src=\"assets/equations/76ea5b945615119b.svg\" alt=\"\\text{biases}=4,\\qquad P_{\\mathrm{conv}}=36+4=40\" width=\"376.11\" height=\"21.70\" style=\"width:376.11px;height:21.70px;aspect-ratio:376.11/21.70\" loading=\"lazy\"></picture></div>","<h3>Step 3: pooling shape</h3>","<p>Pooling now receives size 8, not the original size 10.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.55px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4578ff92c09a54ec.svg\"><img class=\"math display-math\" src=\"assets/equations/66d12a448520cead.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{8-2}{2}\\right\\rfloor+1=3+1=4\" width=\"353.25\" height=\"58.62\" style=\"width:353.25px;height:58.62px;aspect-ratio:353.25/58.62\" loading=\"lazy\"></picture></div>","<p>Channels remain 4: <strong>4 × 4 × 4</strong>. Pooling parameters = 0.</p>","<h3>Step 4: flatten</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b42325b09a6929a4.svg\" alt=\"n_{\\mathrm{flat}}=4\\times4\\times4=64\" width=\"228.13\" height=\"20.40\" style=\"width:228.13px;height:20.40px;aspect-ratio:228.13/20.40\" loading=\"lazy\"></div>","<p>Flatten creates a vector of 64 numbers. It rearranges values, so its parameter count is 0.</p>","<h3>Step 5: dense layer with 3 outputs</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/738d2c475096e79a.svg\" alt=\"\\text{weights}=64\\times3=192\" width=\"248.56\" height=\"21.99\" style=\"width:248.56px;height:21.99px;aspect-ratio:248.56/21.99\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.64px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f927a7fa1a913d20.svg\"><img class=\"math display-math\" src=\"assets/equations/5b290fab1b1da9d6.svg\" alt=\"\\text{biases}=3,\\qquad P_{\\mathrm{dense}}=192+3=195\" width=\"406.87\" height=\"21.70\" style=\"width:406.87px;height:21.70px;aspect-ratio:406.87/21.70\" loading=\"lazy\"></picture></div>","<h3>Step 6: add learned parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.43px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/468553004a2eb33c.svg\"><img class=\"math display-math\" src=\"assets/equations/2c4f62d57a39f2bf.svg\" alt=\"P_{\\mathrm{total}}=40+0+0+195=235\" width=\"330.19\" height=\"20.54\" style=\"width:330.19px;height:20.54px;aspect-ratio:330.19/20.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> shapes 8 × 8 × 4 → 4 × 4 × 4 → 64 → 3; total 235 parameters.</p>"],"kind":"practice","id":"tee-c17-s37","search":"Drill 37 Complete small CNN **Question.** Input 10 × 10 × 1 → Conv 3 × 3,4 filters, stride 1, valid → Pool 2 stride 2 → Flatten → Dense 3. Find all shapes and parameters.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 10 × 10 × 1.\n\nConv: 3 × 3, 4 filters, stride 1, valid padding.\n\nPool: 2 × 2, stride 2; then flatten and dense layer with 3 outputs.\n\nInclude one bias per filter/dense neuron.\n\n### To find\n\nFind all output shapes, layer parameter counts and their sum.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and assumptions\n“Valid” means zero padding. The convolution and dense layers each have one bias per receiving filter or neuron. Pooling and flattening have no learned parameters.\n\n\n\n### Step 1: convolution shape\n\nFour filters produce four channels: **8 × 8 × 4**.\n### Step 2: convolution parameters\n\n\n### Step 3: pooling shape\nPooling now receives size 8, not the original size 10.\n\nChannels remain 4: **4 × 4 × 4**. Pooling parameters = 0.\n### Step 4: flatten\n\nFlatten creates a vector of 64 numbers. It rearranges values, so its parameter count is 0.\n### Step 5: dense layer with 3 outputs\n\n\n### Step 6: add learned parameters\n\n**Final answer:** shapes 8 × 8 × 4 → 4 × 4 × 4 → 64 → 3; total 235 parameters.\n"},{"title":"Drill 38 Reverse a spatial formula","question":["<p class=\"inline-question\"><strong>Question.</strong> A stride-1, valid 3 × 3 convolution outputs 18 × 18 × 12. What input spatial size is needed? Is input channel count determined?</p>"],"answer":["<h3>Given</h3>","<p>Output shape = 18 × 18 × 12.</p>","<p>Kernel = 3 × 3; stride = 1; valid padding P = 0.</p>","<p>Input channel count is not supplied.</p>","<h3>To find</h3>","<p>Solve for input height/width; state whether input channels and parameter count are uniquely determined.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Formula used</h3>","<p>For stride 1 and valid padding, the output width is input width minus kernel width plus one.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6074916da488a8bc.svg\" alt=\"N_{\\mathrm{out}}=N-K+1\" width=\"194.57\" height=\"20.54\" style=\"width:194.57px;height:20.54px;aspect-ratio:194.57/20.54\" loading=\"lazy\"></div>","<h3>Step 1: substitute the known output and kernel sizes</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73b9e54fad32ca52.svg\" alt=\"18=N-3+1=N-2\" width=\"259.26\" height=\"18.69\" style=\"width:259.26px;height:18.69px;aspect-ratio:259.26/18.69\" loading=\"lazy\"></div>","<h3>Step 2: isolate the unknown input size</h3>","<p>Add 2 to both sides. Doing the same operation to both sides preserves the equality.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cfbfbce776e71cb1.svg\" alt=\"18+2=N-2+2\" width=\"204.97\" height=\"18.69\" style=\"width:204.97px;height:18.69px;aspect-ratio:204.97/18.69\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c758e056cb2f1688.svg\" alt=\"N=20\" width=\"78.72\" height=\"18.69\" style=\"width:78.72px;height:18.69px;aspect-ratio:78.72/18.69\" loading=\"lazy\"></div>","<h3>Step 3: interpret the channel information</h3>","<p>The 12 output channels tell us there are 12 filters. They do not say how many channels the input has. An RGB input and a many-channel intermediate map could both feed 12 filters.</p>","<p>With one bias per filter, the parameter formula would be:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f0b530e411679c54.svg\" alt=\"P=(3\\times3\\times C_{\\mathrm{in}}+1)\\times12\" width=\"284.42\" height=\"24.43\" style=\"width:284.42px;height:24.43px;aspect-ratio:284.42/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> input spatial shape 20 × 20; input channel count is undetermined from these givens.</p>"],"kind":"practice","id":"tee-c17-s38","search":"Drill 38 Reverse a spatial formula **Question.** A stride-1, valid 3 × 3 convolution outputs 18 × 18 × 12. What input spatial size is needed? Is input channel count determined?\n\n**Full solution.**\n\n\n\n### Given\n\nOutput shape = 18 × 18 × 12.\n\nKernel = 3 × 3; stride = 1; valid padding P = 0.\n\nInput channel count is not supplied.\n\n### To find\n\nSolve for input height/width; state whether input channels and parameter count are uniquely determined.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Formula used\nFor stride 1 and valid padding, the output width is input width minus kernel width plus one.\n\n### Step 1: substitute the known output and kernel sizes\n\n### Step 2: isolate the unknown input size\nAdd 2 to both sides. Doing the same operation to both sides preserves the equality.\n\n\n### Step 3: interpret the channel information\nThe 12 output channels tell us there are 12 filters. They do not say how many channels the input has. An RGB input and a many-channel intermediate map could both feed 12 filters.\nWith one bias per filter, the parameter formula would be:\n\n**Final answer:** input spatial shape 20 × 20; input channel count is undetermined from these givens.\n"},{"title":"Drill 39 Bottleneck cost with new values","question":["<p class=\"inline-question\"><strong>Question.</strong> A 16 × 16 × 64 map feeds 32 same-padded 3 × 3 filters. Compare direct MACs with an 8-channel 1 × 1 bottleneck first.</p>"],"answer":["<h3>Given</h3>","<p>Input = 16 × 16 × 64.</p>","<p>Direct branch: 32 same-padded 3 × 3 filters.</p>","<p>Alternative: 1 × 1 reduction to 8 channels, then the same 32-filter 3 × 3 layer.</p>","<p>Spatial size remains 16 × 16; exclude bias additions.</p>","<h3>To find</h3>","<p>Find both MAC counts, absolute saving and percentage saving.</p>","<h3>Formula — which one and why</h3>","<p><strong>Multiply–accumulate count.</strong> Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.</p>","<p>H_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Har output cell ka kaam × kitne output cells.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formula</h3>","<p>A MAC is one multiply–accumulate operation. For the convention used here, count the weight–input products over every output location. Bias additions are omitted. A 1 × 1 bottleneck reduces channels before the expensive 3 × 3 layer.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<h3>Step 1: direct 3 × 3 convolution</h3>","<p>Each output uses 3 × 3 × 64 = 576 weight–input pairs. There are 16 × 16 × 32 = 8,192 outputs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.21px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/673cd31676ab87d1.svg\"><img class=\"math display-math\" src=\"assets/equations/660ea75dfc92d56c.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=8192\\times576=4{,}718{,}592\" width=\"392.94\" height=\"22.24\" style=\"width:392.94px;height:22.24px;aspect-ratio:392.94/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 2: 1 × 1 reduction from 64 to 8 channels</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bcc137de649f71d.svg\"><img class=\"math display-math\" src=\"assets/equations/07ded70ae81c3cd5.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=16\\times16\\times8\\times1\\times1\\times64=131{,}072\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 3: 3 × 3 convolution now receives only 8 channels</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.07px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/da27ae2a69680cb6.svg\"><img class=\"math display-math\" src=\"assets/equations/798ae9e57f70e0ad.svg\" alt=\"\\mathrm{MACs}_{3\\times3}=16\\times16\\times32\\times3\\times3\\times8=589{,}824\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 4: add the two bottleneck stages</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/741f21ae6e5bfc83.svg\"><img class=\"math display-math\" src=\"assets/equations/ec8abadaa9257a67.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=131{,}072+589{,}824=720{,}896\" width=\"483.59\" height=\"22.24\" style=\"width:483.59px;height:22.24px;aspect-ratio:483.59/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 5: calculate the saving</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/005360b3f69dc10a.svg\"><img class=\"math display-math\" src=\"assets/equations/03fa81b05dc71237.svg\" alt=\"\\mathrm{saving}=4{,}718{,}592-720{,}896=3{,}997{,}696\" width=\"440.68\" height=\"21.58\" style=\"width:440.68px;height:21.58px;aspect-ratio:440.68/21.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.96px;--narrow-height:132.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2a96913f36caca06.svg\"><img class=\"math display-math\" src=\"assets/equations/46344c94632c2247.svg\" alt=\"\\mathrm{saving\\ percent}=\\frac{3{,}997{,}696}{4{,}718{,}592}\\times100=84.722222\\%\" width=\"518.68\" height=\"54.54\" style=\"width:518.68px;height:54.54px;aspect-ratio:518.68/54.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> direct 4,718,592 MACs; bottleneck 720,896 MACs; approximately 84.72% fewer. The output shape stays 16 × 16 × 32.</p>"],"kind":"practice","id":"tee-c17-s39","search":"Drill 39 Bottleneck cost with new values **Question.** A 16 × 16 × 64 map feeds 32 same-padded 3 × 3 filters. Compare direct MACs with an 8-channel 1 × 1 bottleneck first.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 16 × 16 × 64.\n\nDirect branch: 32 same-padded 3 × 3 filters.\n\nAlternative: 1 × 1 reduction to 8 channels, then the same 32-filter 3 × 3 layer.\n\nSpatial size remains 16 × 16; exclude bias additions.\n\n### To find\n\nFind both MAC counts, absolute saving and percentage saving.\n\n### Formula — which one and why\n\n**Multiply–accumulate count.** Each output position and output channel uses K²C_in products. A bottleneck requires two separate counts, one for the 1×1 reduction and one for the following spatial convolution.\n\nH_out,W_out = output map size; C_in,C_out = incoming/outgoing channels; K = kernel width. Count one multiply–accumulate as one MAC; bias additions are excluded.\n\n\n\n\n\n**Yaad rakhne ka cue:** Har output cell ka kaam × kitne output cells.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formula\nA MAC is one multiply–accumulate operation. For the convention used here, count the weight–input products over every output location. Bias additions are omitted. A 1 × 1 bottleneck reduces channels before the expensive 3 × 3 layer.\n\n### Step 1: direct 3 × 3 convolution\nEach output uses 3 × 3 × 64 = 576 weight–input pairs. There are 16 × 16 × 32 = 8,192 outputs.\n\n### Step 2: 1 × 1 reduction from 64 to 8 channels\n\n### Step 3: 3 × 3 convolution now receives only 8 channels\n\n### Step 4: add the two bottleneck stages\n\n### Step 5: calculate the saving\n\n\n**Final answer:** direct 4,718,592 MACs; bottleneck 720,896 MACs; approximately 84.72% fewer. The output shape stays 16 × 16 × 32.\n"},{"title":"Drill 40 Residual addition","question":["<p class=\"inline-question\"><strong>Question.</strong> x = [2,−3,1], F(x) = [−1,1,0.5]. Calculate residual output before and after ReLU and compare the plain block.</p>"],"answer":["<h3>Given</h3>","<p>x = [2,−3,1]; F(x) = [−1,1,0.5].</p>","<h3>To find</h3>","<p>Find x+F(x), apply ReLU, and compare with ReLU(F(x)).</p>","<h3>Formula — which one and why</h3>","<p><strong>Residual addition.</strong> Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.</p>","<p>x = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec48bb473e2d7934.svg\" alt=\"y=x+F(x)\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Same position ke numbers add; shape same rehni chahiye.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The main branch produces F(x). The shortcut carries x. A residual join adds matching entries from these equally sized vectors. ReLU is a separate operation after that join.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.19px;--narrow-height:64.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/78deb7e05ee3749d.svg\"><img class=\"math display-math\" src=\"assets/equations/16339c457d56baab.svg\" alt=\"H(x)=x+F(x),\\qquad a_j=\\max(0,H_j)\" width=\"413.81\" height=\"25.52\" style=\"width:413.81px;height:25.52px;aspect-ratio:413.81/25.52\" loading=\"lazy\"></picture></div>","<h3>Step 1: add each pair</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a26d4fa253f0177.svg\" alt=\"H_1=2+(-1)=1\" width=\"200.69\" height=\"24.43\" style=\"width:200.69px;height:24.43px;aspect-ratio:200.69/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b33025f78e725f0.svg\" alt=\"H_2=-3+1=-2\" width=\"200.69\" height=\"20.36\" style=\"width:200.69px;height:20.36px;aspect-ratio:200.69/20.36\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f50029ce8c5be41.svg\" alt=\"H_3=1+0.5=1.5\" width=\"200.69\" height=\"20.74\" style=\"width:200.69px;height:20.74px;aspect-ratio:200.69/20.74\" loading=\"lazy\"></div>","<p>The residual output before ReLU is <strong>[1, −2, 1.5]</strong>.</p>","<h3>Step 2: apply ReLU</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:372.69px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/09e521346431d0a8.svg\"><img class=\"math display-math\" src=\"assets/equations/78b039e2c7b066b2.svg\" alt=\"[\\max(0,1),\\max(0,-2),\\max(0,1.5)]=[1,0,1.5]\" width=\"496.24\" height=\"24.43\" style=\"width:496.24px;height:24.43px;aspect-ratio:496.24/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 3: compare with the plain branch</h3>","<p>Without a shortcut, the raw output is just F(x) = [−1, 1, 0.5]. Its ReLU output is <strong>[0, 1, 0.5]</strong>.</p>","<p>Residual addition keeps three entries. Concatenation would join the vectors into six entries and is a different operation.</p>"],"kind":"practice","id":"tee-c17-s40","search":"Drill 40 Residual addition **Question.** x = [2,−3,1], F(x) = [−1,1,0.5]. Calculate residual output before and after ReLU and compare the plain block.\n\n**Full solution.**\n\n\n\n### Given\n\nx = [2,−3,1]; F(x) = [−1,1,0.5].\n\n### To find\n\nFind x+F(x), apply ReLU, and compare with ReLU(F(x)).\n\n### Formula — which one and why\n\n**Residual addition.** Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.\n\nx = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.\n\n\n\n**Yaad rakhne ka cue:** Same position ke numbers add; shape same rehni chahiye.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe main branch produces F(x). The shortcut carries x. A residual join adds matching entries from these equally sized vectors. ReLU is a separate operation after that join.\n\n### Step 1: add each pair\n\n\n\nThe residual output before ReLU is **[1, −2, 1.5]**.\n### Step 2: apply ReLU\n\n### Step 3: compare with the plain branch\nWithout a shortcut, the raw output is just F(x) = [−1, 1, 0.5]. Its ReLU output is **[0, 1, 0.5]**.\nResidual addition keeps three entries. Concatenation would join the vectors into six entries and is a different operation.\n"},{"title":"Drill 41 Two RNN steps","question":["<p class=\"inline-question\"><strong>Question.</strong> h₀ = 0, Wxh = 0.5, Whh = 0.2, b = 0, x₁ = 1, x₂ = 2, tanh activation. Find h₁, h₂.</p>"],"answer":["<h3>Given</h3>","<p>Initial h₀ = 0; input weight Wxh = 0.5; recurrent weight Whh = 0.2; b = 0.</p>","<p>Inputs: x₁ = 1, x₂ = 2; activation: tanh.</p>","<h3>To find</h3>","<p>Calculate h₁, then use it to calculate h₂.</p>","<h3>Formula — which one and why</h3>","<p><strong>Recurrent forward pass.</strong> At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.</p>","<p>x_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cac638ba5ee98e1c.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b\" width=\"280.58\" height=\"22.04\" style=\"width:280.58px;height:22.04px;aspect-ratio:280.58/22.04\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e57a9d6af94ad1bb.svg\" alt=\"h_t=\\tanh(a_t)\" width=\"144.02\" height=\"24.43\" style=\"width:144.02px;height:24.43px;aspect-ratio:144.02/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya input + pichhla activated state; phir activation.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>At time t, the RNN combines the current input xₜ and the previous hidden state hₜ₋₁. The same two weights are reused at both times.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.24px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/53aa19b3509081a2.svg\"><img class=\"math display-math\" src=\"assets/equations/1a9a9845cda07cae.svg\" alt=\"a_t=W_{xh}x_t+W_{hh}h_{t-1}+b,\\qquad h_t=\\tanh(a_t)\" width=\"484.34\" height=\"24.43\" style=\"width:484.34px;height:24.43px;aspect-ratio:484.34/24.43\" loading=\"lazy\"></picture></div>","<p>The raw sum a is not the hidden state. Tanh converts that sum into the state that is carried forward.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/994b9a9f57dad438.svg\" alt=\"\\tanh(a)=\\frac{e^{2a}-1}{e^{2a}+1}\" width=\"197.45\" height=\"56.48\" style=\"width:197.45px;height:56.48px;aspect-ratio:197.45/56.48\" loading=\"lazy\"></div>","<h3>Step 1: calculate the first raw sum</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.04px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a11d26405f8ffbf6.svg\"><img class=\"math display-math\" src=\"assets/equations/6d7c2d3322af892b.svg\" alt=\"a_1=0.5(1)+0.2(0)+0=0.5\" width=\"316.85\" height=\"24.43\" style=\"width:316.85px;height:24.43px;aspect-ratio:316.85/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: activate it to obtain the first state</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a56af3f825290564.svg\" alt=\"h_1=\\tanh(0.5)=\\frac{e^1-1}{e^1+1}\" width=\"263.93\" height=\"56.48\" style=\"width:263.93px;height:56.48px;aspect-ratio:263.93/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.13px;--narrow-height:90.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8658aac9b96930a3.svg\"><img class=\"math display-math\" src=\"assets/equations/50c20979a353d66c.svg\" alt=\"h_1=\\frac{2.718281828-1}{2.718281828+1}=0.462117157\" width=\"400.68\" height=\"51.80\" style=\"width:400.68px;height:51.80px;aspect-ratio:400.68/51.80\" loading=\"lazy\"></picture></div>","<h3>Step 3: use that state in the second raw sum</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.15px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/05a3c9bcda834dc2.svg\"><img class=\"math display-math\" src=\"assets/equations/a620346ee9bd0632.svg\" alt=\"a_2=0.5(2)+0.2(0.462117157)+0\" width=\"369.79\" height=\"24.43\" style=\"width:369.79px;height:24.43px;aspect-ratio:369.79/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.23px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7019e7bc4f1316c8.svg\"><img class=\"math display-math\" src=\"assets/equations/dd63fd4bc0c56e9d.svg\" alt=\"a_2=1+0.092423431=1.092423431\" width=\"388.78\" height=\"20.21\" style=\"width:388.78px;height:20.21px;aspect-ratio:388.78/20.21\" loading=\"lazy\"></picture></div>","<h3>Step 4: activate the second sum</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.19px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b1963e3f6225d34f.svg\"><img class=\"math display-math\" src=\"assets/equations/b65e6ee603919e32.svg\" alt=\"h_2=\\tanh(1.092423431)=0.797760954\" width=\"415.75\" height=\"24.43\" style=\"width:415.75px;height:24.43px;aspect-ratio:415.75/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> h₁ ≈ 0.462117157; h₂ ≈ 0.797760954. Pass h₁ to the next step, not the unactivated value 0.5.</p>"],"kind":"practice","id":"tee-c17-s41","search":"Drill 41 Two RNN steps **Question.** h₀ = 0, Wxh = 0.5, Whh = 0.2, b = 0, x₁ = 1, x₂ = 2, tanh activation. Find h₁, h₂.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial h₀ = 0; input weight Wxh = 0.5; recurrent weight Whh = 0.2; b = 0.\n\nInputs: x₁ = 1, x₂ = 2; activation: tanh.\n\n### To find\n\nCalculate h₁, then use it to calculate h₂.\n\n### Formula — which one and why\n\n**Recurrent forward pass.** At each time step, combine the current input contribution with the previous activated hidden state, add the bias and apply tanh. The same weights are reused at every time step.\n\nx_t = current input; h_(t−1) = previous hidden state; W_xh = input weights; W_hh = recurrent weights; b = bias.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya input + pichhla activated state; phir activation.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nAt time t, the RNN combines the current input xₜ and the previous hidden state hₜ₋₁. The same two weights are reused at both times.\n\nThe raw sum a is not the hidden state. Tanh converts that sum into the state that is carried forward.\n\n### Step 1: calculate the first raw sum\n\n### Step 2: activate it to obtain the first state\n\n\n### Step 3: use that state in the second raw sum\n\n\n### Step 4: activate the second sum\n\n**Final answer:** h₁ ≈ 0.462117157; h₂ ≈ 0.797760954. Pass h₁ to the next step, not the unactivated value 0.5.\n"},{"title":"Drill 42 LSTM with a negative candidate","question":["<p class=\"inline-question\"><strong>Question.</strong> f = 0.8, i = 0.2, o = 0.6, candidate = −0.5, Cprevious = 0.3. Find C, h.</p>"],"answer":["<h3>Given</h3>","<p>Activated gates: f = 0.8, i = 0.2, o = 0.6.</p>","<p>Candidate = −0.5; old cell C = 0.3.</p>","<h3>To find</h3>","<p>Find the new cell and hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>An LSTM keeps a cell memory C and a visible hidden state h. The forget gate f controls old memory, the input gate i controls new candidate content, and the output gate o controls the visible state. These gate values are already supplied.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.78px;--narrow-height:71.40px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d40da391fed6757.svg\"><img class=\"math display-math\" src=\"assets/equations/09fa023c6943b010.svg\" alt=\"C=fC_{\\mathrm{previous}}+i\\widetilde C,\\qquad h=o\\tanh(C)\" width=\"412.78\" height=\"32.30\" style=\"width:412.78px;height:32.30px;aspect-ratio:412.78/32.30\" loading=\"lazy\"></picture></div>","<p>The candidate, written C with a tilde, may be negative. A negative candidate subtracts content when admitted.</p>","<h3>Step 1: retained old memory</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.87px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/692dcfa59ab03f38.svg\"><img class=\"math display-math\" src=\"assets/equations/9bf864ebb414856e.svg\" alt=\"fC_{\\mathrm{previous}}=0.8\\times0.3=0.24\" width=\"296.90\" height=\"24.25\" style=\"width:296.90px;height:24.25px;aspect-ratio:296.90/24.25\" loading=\"lazy\"></picture></div>","<h3>Step 2: admitted new content</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b92f4b1761bc1ff0.svg\" alt=\"i\\widetilde C=0.2\\times(-0.5)=-0.1\" width=\"272.75\" height=\"31.40\" style=\"width:272.75px;height:31.40px;aspect-ratio:272.75/31.40\" loading=\"lazy\"></div>","<h3>Step 3: add them to obtain the new cell memory</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/752dd644f97def6b.svg\" alt=\"C=0.24+(-0.1)=0.14\" width=\"269.74\" height=\"24.43\" style=\"width:269.74px;height:24.43px;aspect-ratio:269.74/24.43\" loading=\"lazy\"></div>","<h3>Step 4: apply tanh to the cell memory</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.90px;--narrow-height:95.58px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0cf22c6bf34159ce.svg\"><img class=\"math display-math\" src=\"assets/equations/80cec30ff5e2f701.svg\" alt=\"\\tanh(0.14)=\\frac{e^{0.28}-1}{e^{0.28}+1}=0.139092448\" width=\"402.45\" height=\"56.48\" style=\"width:402.45px;height:56.48px;aspect-ratio:402.45/56.48\" loading=\"lazy\"></picture></div>","<h3>Step 5: apply the output gate</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cc330c5bb2af2ffc.svg\"><img class=\"math display-math\" src=\"assets/equations/fe422cf3cbda4007.svg\" alt=\"h=0.6\\times0.139092448=0.083455469\" width=\"398.27\" height=\"18.96\" style=\"width:398.27px;height:18.96px;aspect-ratio:398.27/18.96\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> cell memory 0.14; hidden state approximately 0.083455469. C and h are different quantities.</p>"],"kind":"practice","id":"tee-c17-s42","search":"Drill 42 LSTM with a negative candidate **Question.** f = 0.8, i = 0.2, o = 0.6, candidate = −0.5, Cprevious = 0.3. Find C, h.\n\n**Full solution.**\n\n\n\n### Given\n\nActivated gates: f = 0.8, i = 0.2, o = 0.6.\n\nCandidate = −0.5; old cell C = 0.3.\n\n### To find\n\nFind the new cell and hidden state.\n\n### Formula — which one and why\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nAn LSTM keeps a cell memory C and a visible hidden state h. The forget gate f controls old memory, the input gate i controls new candidate content, and the output gate o controls the visible state. These gate values are already supplied.\n\nThe candidate, written C with a tilde, may be negative. A negative candidate subtracts content when admitted.\n### Step 1: retained old memory\n\n### Step 2: admitted new content\n\n### Step 3: add them to obtain the new cell memory\n\n### Step 4: apply tanh to the cell memory\n\n### Step 5: apply the output gate\n\n**Final answer:** cell memory 0.14; hidden state approximately 0.083455469. C and h are different quantities.\n"},{"title":"Drill 43 Calculate gates before the cell","question":["<p class=\"inline-question\"><strong>Question.</strong> Gate preactivations zf = zi = zo = 0, candidate preactivation 0.5, Cprevious = 0.2. Find gates, C, h.</p>"],"answer":["<h3>Given</h3>","<p>Raw gate scores: zf = zi = zo = 0.</p>","<p>Raw candidate score = 0.5; old cell C = 0.2.</p>","<h3>To find</h3>","<p>Activate gates/candidate, then calculate the new cell and hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>Activate raw gate scores first.</strong> A preactivation is an unprocessed score. Convert forget/input/output scores with sigmoid and candidate scores with tanh before using the cell-update equations.</p>","<p>z_f,z_i,z_o = gate preactivations; z_c = candidate preactivation. An already activated gate must not be passed through sigmoid again.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:108.67px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/82486bbd71caa406.svg\"><img class=\"math display-math\" src=\"assets/equations/cd80ed46001ad4fc.svg\" alt=\"f=\\sigma(z_f),\\quad i=\\sigma(z_i),\\quad o=\\sigma(z_o)\" width=\"364.98\" height=\"25.53\" style=\"width:364.98px;height:25.53px;aspect-ratio:364.98/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b3be31d6f9a03979.svg\" alt=\"\\widetilde C=\\tanh(z_c)\" width=\"139.92\" height=\"31.40\" style=\"width:139.92px;height:31.40px;aspect-ratio:139.92/31.40\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Raw score pehle activate; activated gate ko dobara sigmoid nahi.</p>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The question supplies raw gate scores, called preactivations. Convert them to gates using sigmoid first. Convert the candidate&#x27;s score using tanh.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:145.58px;--narrow-height:149.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/48a155da6647af6e.svg\"><img class=\"math display-math\" src=\"assets/equations/19237ddb83267bd8.svg\" alt=\"f=\\sigma(z_f),\\quad i=\\sigma(z_i),\\quad o=\\sigma(z_o),\\quad \\widetilde C=\\tanh(z_C)\" width=\"545.85\" height=\"32.50\" style=\"width:545.85px;height:32.50px;aspect-ratio:545.85/32.50\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.78px;--narrow-height:137.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2240d8201e156ff4.svg\"><img class=\"math display-math\" src=\"assets/equations/c660725ff6ab02eb.svg\" alt=\"\\sigma(z)=\\frac1{1+e^{-z}},\\quad C=fC_{\\mathrm{previous}}+i\\widetilde C,\\quad h=o\\tanh(C)\" width=\"588.29\" height=\"51.56\" style=\"width:588.29px;height:51.56px;aspect-ratio:588.29/51.56\" loading=\"lazy\"></picture></div>","<h3>Step 1: turn each zero score into a gate</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/171834ffe9579c30.svg\" alt=\"\\sigma(0)=\\frac1{1+e^0}=\\frac12=0.5\" width=\"272.02\" height=\"52.39\" style=\"width:272.02px;height:52.39px;aspect-ratio:272.02/52.39\" loading=\"lazy\"></div>","<p>Thus f = i = o = 0.5. A zero score is not a zero gate.</p>","<h3>Step 2: calculate candidate content</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4b709e4b1fd2b287.svg\"><img class=\"math display-math\" src=\"assets/equations/396b8090ffcbdc51.svg\" alt=\"\\widetilde C=\\tanh(0.5)=0.462117157\" width=\"311.84\" height=\"31.40\" style=\"width:311.84px;height:31.40px;aspect-ratio:311.84/31.40\" loading=\"lazy\"></picture></div>","<h3>Step 3: combine retained memory and new content</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc79f89f1b075375.svg\" alt=\"fC_{\\mathrm{previous}}=0.5\\times0.2=0.1\" width=\"284.69\" height=\"24.25\" style=\"width:284.69px;height:24.25px;aspect-ratio:284.69/24.25\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.64px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/17c2ce9389d35386.svg\"><img class=\"math display-math\" src=\"assets/equations/cc4de2d727b7f825.svg\" alt=\"i\\widetilde C=0.5\\times0.462117157=0.231058579\" width=\"411.20\" height=\"27.29\" style=\"width:411.20px;height:27.29px;aspect-ratio:411.20/27.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b3473959824ebef9.svg\"><img class=\"math display-math\" src=\"assets/equations/bd4c66227139045d.svg\" alt=\"C=0.1+0.231058579=0.331058579\" width=\"402.76\" height=\"19.23\" style=\"width:402.76px;height:19.23px;aspect-ratio:402.76/19.23\" loading=\"lazy\"></picture></div>","<h3>Step 4: compute the visible hidden state</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.46px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b0373022abd784e.svg\"><img class=\"math display-math\" src=\"assets/equations/64c9a601580cf0bc.svg\" alt=\"\\tanh(C)=\\tanh(0.331058579)\\approx0.319471636\" width=\"477.48\" height=\"24.43\" style=\"width:477.48px;height:24.43px;aspect-ratio:477.48/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1edcaccecc620bf5.svg\"><img class=\"math display-math\" src=\"assets/equations/3071cb7f6661d372.svg\" alt=\"h=0.5\\times0.319471636=0.159735818\" width=\"398.27\" height=\"18.96\" style=\"width:398.27px;height:18.96px;aspect-ratio:398.27/18.96\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> gates 0.5 each; candidate ≈ 0.462117157; C ≈ 0.331058579; h ≈ 0.159735818.</p>"],"kind":"practice","id":"tee-c17-s43","search":"Drill 43 Calculate gates before the cell **Question.** Gate preactivations zf = zi = zo = 0, candidate preactivation 0.5, Cprevious = 0.2. Find gates, C, h.\n\n**Full solution.**\n\n\n\n### Given\n\nRaw gate scores: zf = zi = zo = 0.\n\nRaw candidate score = 0.5; old cell C = 0.2.\n\n### To find\n\nActivate gates/candidate, then calculate the new cell and hidden state.\n\n### Formula — which one and why\n\n**Activate raw gate scores first.** A preactivation is an unprocessed score. Convert forget/input/output scores with sigmoid and candidate scores with tanh before using the cell-update equations.\n\nz_f,z_i,z_o = gate preactivations; z_c = candidate preactivation. An already activated gate must not be passed through sigmoid again.\n\n\n\n\n\n**Yaad rakhne ka cue:** Raw score pehle activate; activated gate ko dobara sigmoid nahi.\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe question supplies raw gate scores, called preactivations. Convert them to gates using sigmoid first. Convert the candidate's score using tanh.\n\n\n### Step 1: turn each zero score into a gate\n\nThus f = i = o = 0.5. A zero score is not a zero gate.\n### Step 2: calculate candidate content\n\n### Step 3: combine retained memory and new content\n\n\n\n### Step 4: compute the visible hidden state\n\n\n**Final answer:** gates 0.5 each; candidate ≈ 0.462117157; C ≈ 0.331058579; h ≈ 0.159735818.\n"},{"title":"Drill 44 GRU reset then mix","question":["<p class=\"inline-question\"><strong>Question.</strong> hprevious = 0.4, r = 0.5, z = 0.25, x = 1, W = 0.2, U = 0.5, b = 0. Use candidate = tanh(Wx+U(r × hprevious)) and h = (1−z) hprevious+z candidate.</p>"],"answer":["<h3>Given</h3>","<p>Old hidden state = 0.4; reset r = 0.5; update z = 0.25.</p>","<p>x = 1; W = 0.2; U = 0.5; b = 0.</p>","<p>Use h = (1−z)h_old + z×candidate.</p>","<h3>To find</h3>","<p>Find reset contribution, candidate and new hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>GRU reset and state mixture.</strong> The reset gate controls old-state information entering the candidate. The stated update convention then mixes the original old state and the candidate.</p>","<p>r = reset gate; z = update gate; h_old = previous state; h_tilde = candidate. Here z weights the candidate; some questions instead define z to weight the old state.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0823781665f17f77.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(r\\odot h_{\\mathrm{old}})+b)\" width=\"342.15\" height=\"31.13\" style=\"width:342.15px;height:31.13px;aspect-ratio:342.15/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/27ea37a678ab26e6.svg\" alt=\"h=(1-z)\\odot h_{\\mathrm{old}}+z\\odot\\widetilde h\" width=\"273.32\" height=\"31.13\" style=\"width:273.32px;height:31.13px;aspect-ratio:273.32/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Reset candidate ko control; update gate old-new mixture ko control.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and given convention</h3>","<p>The reset gate r scales the old state while making the candidate. The update gate z controls the amount of candidate used in the final mixture <strong>under this question&#x27;s convention</strong>. Some books reverse the roles of z and 1 − z, so copy the supplied formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7608696c8363c58.svg\" alt=\"\\widetilde h=\\tanh\\left(Wx+U(rh_{\\mathrm{previous}})+b\\right)\" width=\"356.35\" height=\"32.03\" style=\"width:356.35px;height:32.03px;aspect-ratio:356.35/32.03\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7c9d53d54875e282.svg\" alt=\"h=(1-z)h_{\\mathrm{previous}}+z\\widetilde h\" width=\"253.55\" height=\"32.03\" style=\"width:253.55px;height:32.03px;aspect-ratio:253.55/32.03\" loading=\"lazy\"></div>","<h3>Step 1: reset the old state for candidate construction</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90ee4b754abc5317.svg\" alt=\"rh_{\\mathrm{previous}}=0.5\\times0.4=0.2\" width=\"278.87\" height=\"23.98\" style=\"width:278.87px;height:23.98px;aspect-ratio:278.87/23.98\" loading=\"lazy\"></div>","<h3>Step 2: form the candidate&#x27;s raw score</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/545ce783984e0414.svg\" alt=\"Wx=0.2\\times1=0.2\" width=\"209.29\" height=\"18.69\" style=\"width:209.29px;height:18.69px;aspect-ratio:209.29/18.69\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.81px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/afd69509f26a8283.svg\"><img class=\"math display-math\" src=\"assets/equations/1db56b816164bc83.svg\" alt=\"U(rh_{\\mathrm{previous}})=0.5\\times0.2=0.1\" width=\"316.62\" height=\"25.35\" style=\"width:316.62px;height:25.35px;aspect-ratio:316.62/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/41862a6072aeaa37.svg\" alt=\"a=0.2+0.1+0=0.3\" width=\"243.73\" height=\"18.27\" style=\"width:243.73px;height:18.27px;aspect-ratio:243.73/18.27\" loading=\"lazy\"></div>","<h3>Step 3: apply tanh</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6ce7040fd0d1872b.svg\"><img class=\"math display-math\" src=\"assets/equations/49097e56740c770e.svg\" alt=\"\\widetilde h=\\tanh(0.3)=0.291312612\" width=\"307.34\" height=\"31.13\" style=\"width:307.34px;height:31.13px;aspect-ratio:307.34/31.13\" loading=\"lazy\"></picture></div>","<h3>Step 4: mix the original old state with the candidate</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/854154216ffe0396.svg\" alt=\"1-z=1-0.25=0.75\" width=\"247.59\" height=\"18.52\" style=\"width:247.59px;height:18.52px;aspect-ratio:247.59/18.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/82108e6e910af0fd.svg\"><img class=\"math display-math\" src=\"assets/equations/b56e2871d1cdeae5.svg\" alt=\"h=0.75(0.4)+0.25(0.291312612)\" width=\"361.63\" height=\"24.43\" style=\"width:361.63px;height:24.43px;aspect-ratio:361.63/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4fbe2a7f0d77a4fd.svg\"><img class=\"math display-math\" src=\"assets/equations/c192a426278a53e6.svg\" alt=\"h=0.3+0.072828153=0.372828153\" width=\"398.27\" height=\"18.96\" style=\"width:398.27px;height:18.96px;aspect-ratio:398.27/18.96\" loading=\"lazy\"></picture></div>","<p><strong>Final answer: h ≈ 0.372828153.</strong> The final old-state term uses 0.4, not the reset value 0.2.</p>"],"kind":"practice","id":"tee-c17-s44","search":"Drill 44 GRU reset then mix **Question.** hprevious = 0.4, r = 0.5, z = 0.25, x = 1, W = 0.2, U = 0.5, b = 0. Use candidate = tanh(Wx+U(r × hprevious)) and h = (1−z) hprevious+z candidate.\n\n**Full solution.**\n\n\n\n### Given\n\nOld hidden state = 0.4; reset r = 0.5; update z = 0.25.\n\nx = 1; W = 0.2; U = 0.5; b = 0.\n\nUse h = (1−z)h_old + z×candidate.\n\n### To find\n\nFind reset contribution, candidate and new hidden state.\n\n### Formula — which one and why\n\n**GRU reset and state mixture.** The reset gate controls old-state information entering the candidate. The stated update convention then mixes the original old state and the candidate.\n\nr = reset gate; z = update gate; h_old = previous state; h_tilde = candidate. Here z weights the candidate; some questions instead define z to weight the old state.\n\n\n\n\n\n**Yaad rakhne ka cue:** Reset candidate ko control; update gate old-new mixture ko control.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and given convention\nThe reset gate r scales the old state while making the candidate. The update gate z controls the amount of candidate used in the final mixture **under this question's convention**. Some books reverse the roles of z and 1 − z, so copy the supplied formula.\n\n\n### Step 1: reset the old state for candidate construction\n\n### Step 2: form the candidate's raw score\n\n\n\n### Step 3: apply tanh\n\n### Step 4: mix the original old state with the candidate\n\n\n\n**Final answer: h ≈ 0.372828153.** The final old-state term uses 0.4, not the reset value 0.2.\n"},{"title":"Drill 45 BPTT shared weights","question":["<p class=\"inline-question\"><strong>Question.</strong> Linear recurrence hₜ = uxₜ+vhₜ₋₁+b, output h₂, target 1, half squared loss. u = 0.2, v = 0.5, b = 0, h₀ = 0, x₁ = 1, x₂ = 2, η = 0.1. Find both states and one update.</p>"],"answer":["<h3>Given</h3>","<p>Linear recurrence hₜ = uxₜ+vhₜ₋₁+b.</p>","<p>u = 0.2; v = 0.5; b = 0; h₀ = 0.</p>","<p>x₁ = 1; x₂ = 2; target for h₂ = 1.</p>","<p>Half squared loss; learning rate η = 0.1.</p>","<h3>To find</h3>","<p>Find both states, all three shared-parameter gradients and one simultaneous update.</p>","<h3>Formula — which one and why</h3>","<p><strong>Backpropagation through time.</strong> Unroll the recurrence, send the loss derivative backward through its links and add contributions for each shared parameter before updating it once.</p>","<p>For h_t=ux_t+vh_(t−1)+b with loss only at the last state: δ_t = loss derivative at that state. The linear recurrence has activation slope 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61b2086787d829b8.svg\" alt=\"\\delta_T=h_T-y\" width=\"127.73\" height=\"22.53\" style=\"width:127.73px;height:22.53px;aspect-ratio:127.73/22.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba589b262a27bc88.svg\" alt=\"\\delta_t=v\\delta_{t+1}\" width=\"104.75\" height=\"22.60\" style=\"width:104.75px;height:22.60px;aspect-ratio:104.75/22.60\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad879502d644f051.svg\" alt=\"g_u=\\sum_t\\delta_tx_t\" width=\"136.86\" height=\"51.74\" style=\"width:136.86px;height:51.74px;aspect-ratio:136.86/51.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3065785a32d83c15.svg\" alt=\"g_v=\\sum_t\\delta_th_{t-1}\" width=\"157.54\" height=\"51.74\" style=\"width:157.54px;height:51.74px;aspect-ratio:157.54/51.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cc44b288566e90ca.svg\" alt=\"g_b=\\sum_t\\delta_t\" width=\"112.15\" height=\"51.74\" style=\"width:112.15px;height:51.74px;aspect-ratio:112.15/51.74\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Time ke har use ka gradient jodo; shared weight ko ek baar update karo.</p>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>The same u, v and b appear at both times. u multiplies the input, v multiplies the previous state, and b is a shared bias. The loss is only at the final state h₂. Because the recurrence is linear, its local activation derivative is 1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.42px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fd56e04419aef1fc.svg\"><img class=\"math display-math\" src=\"assets/equations/ba5840cf8abc2eb8.svg\" alt=\"h_t=ux_t+vh_{t-1}+b,\\qquad L=\\frac12(h_2-y)^2\" width=\"445.82\" height=\"49.55\" style=\"width:445.82px;height:49.55px;aspect-ratio:445.82/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/49cb0da4f4956b69.svg\" alt=\"\\delta_2=h_2-y,\\qquad \\delta_1=v\\delta_2\" width=\"267.88\" height=\"22.53\" style=\"width:267.88px;height:22.53px;aspect-ratio:267.88/22.53\" loading=\"lazy\"></div>","<p>Each shared parameter receives a contribution from both of its uses.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/94543a0839df0ed3.svg\" alt=\"\\frac{\\partial L}{\\partial u}=\\delta_1x_1+\\delta_2x_2\" width=\"196.00\" height=\"51.29\" style=\"width:196.00px;height:51.29px;aspect-ratio:196.00/51.29\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.99px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e7070aed32f74b9a.svg\"><img class=\"math display-math\" src=\"assets/equations/9e07d1c7fc0741ba.svg\" alt=\"\\frac{\\partial L}{\\partial v}=\\delta_1h_0+\\delta_2h_1,\\qquad \\frac{\\partial L}{\\partial b}=\\delta_1+\\delta_2\" width=\"402.63\" height=\"51.29\" style=\"width:402.63px;height:51.29px;aspect-ratio:402.63/51.29\" loading=\"lazy\"></picture></div>","<h3>Step 1: forward through time 1</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.19px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81bb99ddeeaa7079.svg\"><img class=\"math display-math\" src=\"assets/equations/600933d472001379.svg\" alt=\"h_1=0.2(1)+0.5(0)+0=0.2\" width=\"318.01\" height=\"24.43\" style=\"width:318.01px;height:24.43px;aspect-ratio:318.01/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 2: forward through time 2</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0cd838106937b9a7.svg\"><img class=\"math display-math\" src=\"assets/equations/5e340a1f975faf8c.svg\" alt=\"h_2=0.2(2)+0.5(0.2)+0=0.4+0.1=0.5\" width=\"461.92\" height=\"24.43\" style=\"width:461.92px;height:24.43px;aspect-ratio:461.92/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd42e4fe3cfc09.svg\" alt=\"L=\\frac12(0.5-1)^2=0.125\" width=\"263.43\" height=\"49.55\" style=\"width:263.43px;height:49.55px;aspect-ratio:263.43/49.55\" loading=\"lazy\"></div>","<h3>Step 3: carry the gradient backwards</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/50ef5b3a75d08159.svg\" alt=\"\\delta_2=0.5-1=-0.5\" width=\"210.23\" height=\"21.19\" style=\"width:210.23px;height:21.19px;aspect-ratio:210.23/21.19\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/98a077f6210fe712.svg\" alt=\"\\delta_1=0.5(-0.5)=-0.25\" width=\"249.61\" height=\"24.43\" style=\"width:249.61px;height:24.43px;aspect-ratio:249.61/24.43\" loading=\"lazy\"></div>","<h3>Step 4: add contributions for each shared parameter</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:267.47px;--narrow-height:129.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/af14a42daa22ee7b.svg\"><img class=\"math display-math\" src=\"assets/equations/ebd6a8221b328c2e.svg\" alt=\"\\frac{\\partial L}{\\partial u}=(-0.25)(1)+(-0.5)(2)=-0.25-1=-1.25\" width=\"549.01\" height=\"51.29\" style=\"width:549.01px;height:51.29px;aspect-ratio:549.01/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.25px;--narrow-height:129.48px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dadd294afa7bf158.svg\"><img class=\"math display-math\" src=\"assets/equations/ce956c0f17770985.svg\" alt=\"\\frac{\\partial L}{\\partial v}=(-0.25)(0)+(-0.5)(0.2)=0-0.1=-0.1\" width=\"524.57\" height=\"51.29\" style=\"width:524.57px;height:51.29px;aspect-ratio:524.57/51.29\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.36px;--narrow-height:90.39px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3e07d50d2b197b5f.svg\"><img class=\"math display-math\" src=\"assets/equations/41657b19e6fd16c8.svg\" alt=\"\\frac{\\partial L}{\\partial b}=-0.25-0.5=-0.75\" width=\"292.40\" height=\"51.29\" style=\"width:292.40px;height:51.29px;aspect-ratio:292.40/51.29\" loading=\"lazy\"></picture></div>","<h3>Step 5: update once after summing</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.13px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30e22de1103f6dec.svg\"><img class=\"math display-math\" src=\"assets/equations/7085a94b1a865ca8.svg\" alt=\"u_{\\mathrm{new}}=0.2-0.1(-1.25)=0.325\" width=\"340.37\" height=\"24.43\" style=\"width:340.37px;height:24.43px;aspect-ratio:340.37/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.78px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4822c14a12ff6b68.svg\"><img class=\"math display-math\" src=\"assets/equations/a9f8b51dd6b5c81d.svg\" alt=\"v_{\\mathrm{new}}=0.5-0.1(-0.1)=0.51\" width=\"313.82\" height=\"24.43\" style=\"width:313.82px;height:24.43px;aspect-ratio:313.82/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.63px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0fa40afe6a0cd296.svg\"><img class=\"math display-math\" src=\"assets/equations/cb22ad4d5122d6cb.svg\" alt=\"b_{\\mathrm{new}}=0-0.1(-0.75)=0.075\" width=\"317.88\" height=\"24.43\" style=\"width:317.88px;height:24.43px;aspect-ratio:317.88/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> states 0.2 and 0.5; new parameters u = 0.325, v = 0.51, b = 0.075.</p>"],"kind":"practice","id":"tee-c17-s45","search":"Drill 45 BPTT shared weights **Question.** Linear recurrence hₜ = uxₜ+vhₜ₋₁+b, output h₂, target 1, half squared loss. u = 0.2, v = 0.5, b = 0, h₀ = 0, x₁ = 1, x₂ = 2, η = 0.1. Find both states and one update.\n\n**Full solution.**\n\n\n\n### Given\n\nLinear recurrence hₜ = uxₜ+vhₜ₋₁+b.\n\nu = 0.2; v = 0.5; b = 0; h₀ = 0.\n\nx₁ = 1; x₂ = 2; target for h₂ = 1.\n\nHalf squared loss; learning rate η = 0.1.\n\n### To find\n\nFind both states, all three shared-parameter gradients and one simultaneous update.\n\n### Formula — which one and why\n\n**Backpropagation through time.** Unroll the recurrence, send the loss derivative backward through its links and add contributions for each shared parameter before updating it once.\n\nFor h_t=ux_t+vh_(t−1)+b with loss only at the last state: δ_t = loss derivative at that state. The linear recurrence has activation slope 1.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Time ke har use ka gradient jodo; shared weight ko ek baar update karo.\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThe same u, v and b appear at both times. u multiplies the input, v multiplies the previous state, and b is a shared bias. The loss is only at the final state h₂. Because the recurrence is linear, its local activation derivative is 1.\n\n\nEach shared parameter receives a contribution from both of its uses.\n\n\n### Step 1: forward through time 1\n\n### Step 2: forward through time 2\n\n\n### Step 3: carry the gradient backwards\n\n\n### Step 4: add contributions for each shared parameter\n\n\n\n### Step 5: update once after summing\n\n\n\n**Final answer:** states 0.2 and 0.5; new parameters u = 0.325, v = 0.51, b = 0.075.\n"},{"title":"Drill 46 Mixed convolution pool dense and loss","question":["<p class=\"inline-question\"><strong>Question.</strong> A is shown below, kernel Matrix 2 shown below, stride 1, valid. Apply ReLU, then 2 × 2 max pool stride 1. Flatten rowwise, use weight vector [0.1,0.2,0.3,0.4], bias 0, sigmoid output, target 1. Find all stages and BCE.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K · Matrix 2</div><table class=\"lv-matrix\" aria-label=\"Kernel K · Matrix 2\"><caption>Kernel K · Matrix 2</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 1; P = 0 (no padding).</p></figure>"],"answer":["<h3>Given</h3>","<p>Input A and kernel Matrix 2 are printed with the question.</p>","<p>Conv: stride 1, valid padding; follow with ReLU.</p>","<p>Max pool: 2 × 2, stride 1; flatten row by row.</p>","<p>Dense weights = [0.1,0.2,0.3,0.4]; bias = 0; sigmoid output.</p>","<p>Binary target = 1.</p>","<h3>To find</h3>","<p>Find convolution, activated map, pooled map, flattened values, prediction and BCE.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<p><strong>Pooling.</strong> Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.</p>","<p>V = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e5c101541d074f2.svg\" alt=\"y_{\\mathrm{avg}}=\\frac1n\\sum_{v\\in V}v\" width=\"153.67\" height=\"62.80\" style=\"width:153.67px;height:62.80px;aspect-ratio:153.67/62.80\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max mein biggest; average mein total ÷ window ka count.</p>","<p><strong>Weighted sum and activation.</strong> Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.</p>","<p>xᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Input × weight, sabka sum, bias once, phir activation.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Binary cross-entropy.</strong> For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.</p>","<p>y is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bbef5a5d1c7047f.svg\" alt=\"\\frac{\\partial L}{\\partial z}=p-y\" width=\"127.94\" height=\"51.29\" style=\"width:127.94px;height:51.29px;aspect-ratio:127.94/51.29\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).</p>","<h3>Solution — step by step</h3>","<h3>Formulas and the operation we are performing</h3>","<p>A filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:281.49px;--narrow-height:152.61px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1a1aa2b10ea1816e.svg\"><img class=\"math display-math\" src=\"assets/equations/33407dafb559f8d6.svg\" alt=\"Y_{ij}=\\sum_{u=0}^{K_h-1}\\sum_{v=0}^{K_w-1}X_{iS+u,jS+v}K_{uv}+b\" width=\"351.15\" height=\"73.34\" style=\"width:351.15px;height:73.34px;aspect-ratio:351.15/73.34\" loading=\"lazy\"></picture></div>","<p>Here i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>N is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.</p>","<h3>Formulas and meaning</h3>","<p>Each 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the given stride after producing one answer.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/870fc5e76c2ff285.svg\" alt=\"p_{\\mathrm{max}}=\\max(a_1,a_2,a_3,a_4)\" width=\"270.51\" height=\"24.43\" style=\"width:270.51px;height:24.43px;aspect-ratio:270.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cf572bd2a565d88a.svg\" alt=\"p_{\\mathrm{avg}}=\\frac{a_1+a_2+a_3+a_4}{4}\" width=\"268.03\" height=\"47.52\" style=\"width:268.03px;height:47.52px;aspect-ratio:268.03/47.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.64px;--narrow-height:98.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a9854190bb7c9a.svg\"><img class=\"math display-math\" src=\"assets/equations/bd33b42a8814468f.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"300.97\" height=\"58.62\" style=\"width:300.97px;height:58.62px;aspect-ratio:300.97/58.62\" loading=\"lazy\"></picture></div>","<p>Use the input size at the pooling layer. The output keeps the same channel count.</p>","<h3>Completing the network after pooling</h3>","<p>Flatten row by row. Multiply the resulting entries by the dense weights and add bias. Apply sigmoid to produce p. For target 1, binary cross-entropy is minus ln(p).</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.90px;--narrow-height:157.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a593381e0c37ce0b.svg\"><img class=\"math display-math\" src=\"assets/equations/2a2f870df03533ca.svg\" alt=\"z=\\sum_iw_ix_i+b,\\qquad p=\\frac1{1+e^{-z}},\\qquad L=-\\ln p\" width=\"532.22\" height=\"61.92\" style=\"width:532.22px;height:61.92px;aspect-ratio:532.22/61.92\" loading=\"lazy\"></picture></div>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/99ba828c16946a06.svg\" alt=\"\\left\\lfloor\\frac{4+2 \\times  0-2}{1}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 3 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−1) = −1</b></div></div><p class=\"lv-combine\"><b>1 + (−1) = 0</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10a146899dccf86a.svg\"><img class=\"math display-math\" src=\"assets/equations/029ae836b8cf695f.svg\" alt=\"R_1=(1)\\times(1)+(2)\\times(0)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a91d42dac9ba1633.svg\"><img class=\"math display-math\" src=\"assets/equations/d7380bbaffbc2948.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/059edda10c2ac26e.svg\" alt=\"Y_{1,1}=(1)+(-1)=0\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>2 + (−3) = −1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/13b97b59677316ed.svg\"><img class=\"math display-math\" src=\"assets/equations/11fea4ed5b78299e.svg\" alt=\"R_1=(2)\\times(1)+(0)\\times(0)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9cf98567181f7899.svg\"><img class=\"math display-math\" src=\"assets/equations/59a1357910dce5f4.svg\" alt=\"R_2=(1)\\times(0)+(3)\\times(-1)=-3\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6828ab91aa100a9.svg\" alt=\"Y_{1,2}=(2)+(-3)=-1\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–2</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−2) = −2</b></div></div><p class=\"lv-combine\"><b>0 + (−2) = −2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9602643188947584.svg\"><img class=\"math display-math\" src=\"assets/equations/38b1e54a3b119ea9.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(0)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/49c3d4aac1f50f22.svg\"><img class=\"math display-math\" src=\"assets/equations/893c6acf067ed4a9.svg\" alt=\"R_2=(3)\\times(0)+(2)\\times(-1)=-2\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/77839b654a5d343b.svg\" alt=\"Y_{1,3}=(0)+(-2)=-2\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−1) = −1</b></div></div><p class=\"lv-combine\"><b>0 + (−1) = −1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9602643188947584.svg\"><img class=\"math display-math\" src=\"assets/equations/38b1e54a3b119ea9.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(0)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/825cd1ca9fbe27a2.svg\"><img class=\"math display-math\" src=\"assets/equations/ee2b941345fd8cb4.svg\" alt=\"R_2=(2)\\times(0)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74f7aefb8b0d75bd.svg\" alt=\"Y_{2,1}=(0)+(-1)=-1\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>1 + 0 = 1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/50ba62bd05697a22.svg\"><img class=\"math display-math\" src=\"assets/equations/c318e658016b1fbd.svg\" alt=\"R_1=(1)\\times(1)+(3)\\times(0)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f7d66e56559f9de7.svg\"><img class=\"math display-math\" src=\"assets/equations/88c7ac8976f026b8.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(-1)=0\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e353ed5c5344d9f0.svg\" alt=\"Y_{2,2}=(1)+(0)=1\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>2–3</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 = 3</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−1) = −1</b></div></div><p class=\"lv-combine\"><b>3 + (−1) = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/239b4ccf3eb098a0.svg\"><img class=\"math display-math\" src=\"assets/equations/9fed257738d47bdb.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(0)=3\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a91d42dac9ba1633.svg\"><img class=\"math display-math\" src=\"assets/equations/d7380bbaffbc2948.svg\" alt=\"R_2=(0)\\times(0)+(1)\\times(-1)=-1\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc81876afa80a85e.svg\" alt=\"Y_{2,3}=(3)+(-1)=2\" width=\"227.03\" height=\"25.35\" style=\"width:227.03px;height:25.35px;aspect-ratio:227.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>1–2</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 = 0</b></div></div><p class=\"lv-combine\"><b>2 + 0 = 2</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca82f5af7cbb2e71.svg\"><img class=\"math display-math\" src=\"assets/equations/c8ce43d27f6afa3e.svg\" alt=\"R_1=(2)\\times(1)+(1)\\times(0)=2\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f7d66e56559f9de7.svg\"><img class=\"math display-math\" src=\"assets/equations/88c7ac8976f026b8.svg\" alt=\"R_2=(1)\\times(0)+(0)\\times(-1)=0\" width=\"340.12\" height=\"24.43\" style=\"width:340.12px;height:24.43px;aspect-ratio:340.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3322f48fabaf515.svg\" alt=\"Y_{3,1}=(2)+(0)=2\" width=\"208.02\" height=\"25.35\" style=\"width:208.02px;height:25.35px;aspect-ratio:208.02/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>2–3</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −2\">−2</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−2) = −2</b></div></div><p class=\"lv-combine\"><b>1 + (−2) = −1</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b9538ffab8a7d30.svg\"><img class=\"math display-math\" src=\"assets/equations/206ee4c111bd14b3.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(0)=1\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1baae78cba2e069c.svg\"><img class=\"math display-math\" src=\"assets/equations/03bf601080143dcc.svg\" alt=\"R_2=(0)\\times(0)+(2)\\times(-1)=-2\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/43f244bc80788fd1.svg\" alt=\"Y_{3,2}=(1)+(-2)=-1\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<h3>Output position (3, 3)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (3, 3) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–4</b>, columns <b>3–4</b>. The window moves <b>1</b> cell per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>0 + (−3) = −3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: −1\">−1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: −1\">−1</td><td class=\"lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 3, column 3.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9602643188947584.svg\"><img class=\"math display-math\" src=\"assets/equations/38b1e54a3b119ea9.svg\" alt=\"R_1=(0)\\times(1)+(1)\\times(0)=0\" width=\"321.12\" height=\"24.43\" style=\"width:321.12px;height:24.43px;aspect-ratio:321.12/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/04e972a19789fc08.svg\"><img class=\"math display-math\" src=\"assets/equations/4b10b62665a7718a.svg\" alt=\"R_2=(2)\\times(0)+(3)\\times(-1)=-3\" width=\"359.13\" height=\"24.43\" style=\"width:359.13px;height:24.43px;aspect-ratio:359.13/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73f07f2c01400713.svg\" alt=\"Y_{3,3}=(0)+(-3)=-3\" width=\"246.03\" height=\"25.35\" style=\"width:246.03px;height:25.35px;aspect-ratio:246.03/25.35\" loading=\"lazy\"></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/78836b0ad068fd57.svg\" alt=\"\\begin{bmatrix}0 &amp; -1 &amp; -2\\\\-1 &amp; 1 &amp; 2\\\\2 &amp; -1 &amp; -3\\end{bmatrix}\" width=\"136.22\" height=\"72.21\" style=\"width:136.22px;height:72.21px;aspect-ratio:136.22/72.21\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>","<p>ReLU turns negative entries into 0: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5203ca394b677586.svg\" alt=\"\\begin{bmatrix}0 &amp; 0 &amp; 0\\\\0 &amp; 1 &amp; 2\\\\2 &amp; 0 &amp; 0\\end{bmatrix}\" width=\"91.87\" height=\"72.21\" style=\"width:91.87px;height:72.21px;aspect-ratio:91.87/72.21\" loading=\"lazy\"></span>.</p>","<p><strong>Shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/65d999fa66cd37e1.svg\" alt=\"\\left\\lfloor\\frac{3-2}{1}\\right\\rfloor+1\" width=\"105.50\" height=\"45.60\" style=\"width:105.50px;height:45.60px;aspect-ratio:105.50/45.60\" loading=\"lazy\"></span> = 2 on each axis; channels stay unchanged.</p>","<h3>Pooling window (1,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[0, 0, 0, 1]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>0 + 0 + 0 + 1 = 1</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>1/4 = <strong>0.25</strong>. Maximum = <strong>1</strong></p>","<h3>Pooling window (1,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[0, 0, 1, 2]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>0 + 0 + 1 + 2 = 3</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>3/4 = <strong>0.75</strong>. Maximum = <strong>2</strong></p>","<h3>Pooling window (2,1)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[0, 1, 2, 0]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>0 + 1 + 2 + 0 = 3</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>3/4 = <strong>0.75</strong>. Maximum = <strong>2</strong></p>","<h3>Pooling window (2,2)</h3>","<p class=\"worked-step\"><strong>Step 1: select the entries.</strong></p>","<p>[1, 2, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 2: add all selected entries.</strong></p>","<p>1 + 2 + 0 + 0 = 3</p>","<p class=\"worked-step\"><strong>Step 3: divide by the 4 entries in this window.</strong></p>","<p>3/4 = <strong>0.75</strong>. Maximum = <strong>2</strong></p>","<p><strong>Average output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/386a0646a3bb55b5.svg\" alt=\"\\begin{bmatrix}0.25 &amp; 0.75\\\\0.75 &amp; 0.75\\end{bmatrix}\" width=\"106.65\" height=\"45.61\" style=\"width:106.65px;height:45.61px;aspect-ratio:106.65/45.61\" loading=\"lazy\"></span>. <strong>Max output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/4fb14ffabb3fef49.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\2 &amp; 2\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>. Pooling normally has zero trainable parameters and reduces spatial dimensions.</p>","<p>Use MAX output and flatten rowwise: [1, 2, 2, 2]. Dense z = 0.1 × 1 + 0.2 × 2 + 0.3 × 2 + 0.4 × 2 = 1.9. p = σ(1.9) = 0.869891526. BCE = −ln(p) = <strong>0.139386758</strong>. Average pool values were computed for contrast; the question requires max pool.</p>"],"kind":"practice","id":"tee-c17-s46","search":"Drill 46 Mixed convolution pool dense and loss **Question.** A is shown below, kernel Matrix 2 shown below, stride 1, valid. Apply ReLU, then 2 × 2 max pool stride 1. Flatten rowwise, use weight vector [0.1,0.2,0.3,0.4], bias 0, sigmoid output, target 1. Find all stages and BCE.\n\n\n\n\n**Full solution.**\n\n\n\n### Given\n\nInput A and kernel Matrix 2 are printed with the question.\n\nConv: stride 1, valid padding; follow with ReLU.\n\nMax pool: 2 × 2, stride 1; flatten row by row.\n\nDense weights = [0.1,0.2,0.3,0.4]; bias = 0; sigmoid output.\n\nBinary target = 1.\n\n### To find\n\nFind convolution, activated map, pooled map, flattened values, prediction and BCE.\n\n### Formula — which one and why\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n**Pooling.** Max pooling selects the largest window entry. Average pooling adds its entries and divides by their count. Each channel is pooled separately.\n\nV = current pooling window; n = number of entries in that window. Pooling learns no weights or biases.\n\n\n\n\n\n**Yaad rakhne ka cue:** Max mein biggest; average mein total ÷ window ka count.\n\n**Weighted sum and activation.** Each input is multiplied by its connection weight. Add these contributions, add the bias once, then apply the stated activation.\n\nxᵢ = input i; wᵢ = its weight; b = bias; z = sum before activation; a = output after activation; f = the specified activation function.\n\n\n\n\n\n**Yaad rakhne ka cue:** Input × weight, sabka sum, bias once, phir activation.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**Binary cross-entropy.** For a binary target, choose the probability of the correct outcome and take its negative natural log. Sigmoid plus BCE has combined logit derivative p−y.\n\ny is 0 or 1; p is the predicted probability of class 1; z is the sigmoid logit. The p−y derivative already includes the sigmoid derivative.\n\n\n\n\n\n**Yaad rakhne ka cue:** Binary target 1 ho toh −ln(p); target 0 ho toh −ln(1−p).\n\n### Solution — step by step\n\n\n\n\n\n### Formulas and the operation we are performing\nA filter window produces one output value. Multiply entries at matching positions and add the products. In this deep-learning convention, keep the filter in its printed orientation.\n\nHere i and j identify an output position; u and v count positions inside its window. S is stride, and b is the filter bias, zero in this question. The equation uses a padded input if padding is present and zero-based indices; the working below labels output positions from 1 for readability.\n\nN is input width/height, P is padding per side, and K is filter width/height. Floor means take the integer below the result, then add one.\n### Formulas and meaning\nEach 2 × 2 window contains four numbers. Max pooling selects the largest of those four. Average pooling adds all four and divides by 4. Move the window by the g"},{"title":"Drill 47 Mixed backpropagation and L2","question":["<p class=\"inline-question\"><strong>Question.</strong> Single linear neuron ŷ = wx, x = 2, w = 0.4, y = 1. Objective J = ½(ŷ−y)²+(λ/2)w², λ = 0.1, η = 0.2. Find loss, gradient, new weight.</p>"],"answer":["<h3>Given</h3>","<p>Prediction ŷ = wx; x = 2; w = 0.4; target y = 1.</p>","<p>Data loss = ½(ŷ−y)²; penalty = (λ/2)w².</p>","<p>λ = 0.1; η = 0.2.</p>","<h3>To find</h3>","<p>Find total objective, its weight gradient and the new weight.</p>","<h3>Formula — which one and why</h3>","<p><strong>L2 penalty with a factor of one-half.</strong> Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.</p>","<p>λ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/29419cadd5578572.svg\" alt=\"J=J_{\\mathrm{data}}+\\frac\\lambda2\\sum_iw_i^2\" width=\"223.70\" height=\"62.61\" style=\"width:223.70px;height:62.61px;aspect-ratio:223.70/62.61\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79fc02963f72332f.svg\" alt=\"g_i=g_{\\mathrm{data},i}+\\lambda w_i\" width=\"179.88\" height=\"23.98\" style=\"width:179.88px;height:23.98px;aspect-ratio:179.88/23.98\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/616c8cbb90430248.svg\" alt=\"w_i^{\\mathrm{new}}=w_i-\\eta g_i\" width=\"169.00\" height=\"24.06\" style=\"width:169.00px;height:24.06px;aspect-ratio:169.00/24.06\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half wala L2 derivative mein lambda × weight deta hai.</p>","<p><strong>Gradient descent.</strong> Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.</p>","<p>θ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52ef83d9d4ea4381.svg\" alt=\"g_t=J\\prime(\\theta_{t-1})\" width=\"135.51\" height=\"24.43\" style=\"width:135.51px;height:24.43px;aspect-ratio:135.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6df9cee9010e92ee.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta g_t\" width=\"156.05\" height=\"22.51\" style=\"width:156.05px;height:22.51px;aspect-ratio:156.05/22.51\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Naya = purana − learning rate × current gradient.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>This objective contains both prediction error and a weight penalty. Its gradient also has two parts. Compute both at the old weight, add them, then update once.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:237.54px;--narrow-height:90.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9807919ec463b336.svg\"><img class=\"math display-math\" src=\"assets/equations/f7ed754c852735b2.svg\" alt=\"\\hat y=wx,\\qquad J=\\frac12(\\hat y-y)^2+\\frac\\lambda2w^2\" width=\"373.30\" height=\"50.24\" style=\"width:373.30px;height:50.24px;aspect-ratio:373.30/50.24\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.87px;--narrow-height:117.23px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fccbb24d2fd5ed97.svg\"><img class=\"math display-math\" src=\"assets/equations/3a34fcc434834bc2.svg\" alt=\"\\frac{\\partial J}{\\partial w}=(\\hat y-y)x+\\lambda w,\\qquad w_{\\mathrm{new}}=w-\\eta\\frac{\\partial J}{\\partial w}\" width=\"466.25\" height=\"51.29\" style=\"width:466.25px;height:51.29px;aspect-ratio:466.25/51.29\" loading=\"lazy\"></picture></div>","<h3>Step 1: prediction and error</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:242.54px;--narrow-height:66.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3414961b88098bc1.svg\"><img class=\"math display-math\" src=\"assets/equations/2cdfc715227663d5.svg\" alt=\"\\hat y=0.4\\times2=0.8,\\qquad \\hat y-y=0.8-1=-0.2\" width=\"483.95\" height=\"24.80\" style=\"width:483.95px;height:24.80px;aspect-ratio:483.95/24.80\" loading=\"lazy\"></picture></div>","<h3>Step 2: data loss</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:194.03px;--narrow-height:113.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f025cfcfa02c965d.svg\"><img class=\"math display-math\" src=\"assets/equations/5140459142337abc.svg\" alt=\"L_{\\mathrm{data}}=\\frac12(-0.2)^2=\\frac12(0.04)=0.02\" width=\"381.78\" height=\"49.55\" style=\"width:381.78px;height:49.55px;aspect-ratio:381.78/49.55\" loading=\"lazy\"></picture></div>","<h3>Step 3: regularization penalty and total objective</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.72px;--narrow-height:88.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c4fc429067a3f156.svg\"><img class=\"math display-math\" src=\"assets/equations/61163a2b02bc5b66.svg\" alt=\"R=\\frac{0.1}{2}(0.4)^2=0.05(0.16)=0.008\" width=\"380.74\" height=\"49.55\" style=\"width:380.74px;height:49.55px;aspect-ratio:380.74/49.55\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/72c65e08a565a4c1.svg\" alt=\"J=0.02+0.008=0.028\" width=\"265.27\" height=\"18.69\" style=\"width:265.27px;height:18.69px;aspect-ratio:265.27/18.69\" loading=\"lazy\"></div>","<h3>Step 4: calculate the two gradient contributions</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/20e7a6699528fa05.svg\" alt=\"g_{\\mathrm{data}}=(-0.2)\\times2=-0.4\" width=\"274.03\" height=\"24.43\" style=\"width:274.03px;height:24.43px;aspect-ratio:274.03/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ed23175a058690ac.svg\" alt=\"g_{\\mathrm{penalty}}=0.1\\times0.4=0.04\" width=\"270.79\" height=\"23.73\" style=\"width:270.79px;height:23.73px;aspect-ratio:270.79/23.73\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c43044f63438eb7.svg\"><img class=\"math display-math\" src=\"assets/equations/b422d0258ed7d40f.svg\" alt=\"g_{\\mathrm{total}}=-0.4+0.04=-0.36\" width=\"300.38\" height=\"21.55\" style=\"width:300.38px;height:21.55px;aspect-ratio:300.38/21.55\" loading=\"lazy\"></picture></div>","<h3>Step 5: update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:255.65px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93c291aebdd73770.svg\"><img class=\"math display-math\" src=\"assets/equations/f4be65ea94b49c52.svg\" alt=\"w_{\\mathrm{new}}=0.4-0.2(-0.36)=0.4+0.072=0.472\" width=\"493.24\" height=\"24.43\" style=\"width:493.24px;height:24.43px;aspect-ratio:493.24/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> total loss 0.028; gradient −0.36; new weight 0.472.</p>"],"kind":"practice","id":"tee-c17-s47","search":"Drill 47 Mixed backpropagation and L2 **Question.** Single linear neuron ŷ = wx, x = 2, w = 0.4, y = 1. Objective J = ½(ŷ−y)²+(λ/2)w², λ = 0.1, η = 0.2. Find loss, gradient, new weight.\n\n**Full solution.**\n\n\n\n### Given\n\nPrediction ŷ = wx; x = 2; w = 0.4; target y = 1.\n\nData loss = ½(ŷ−y)²; penalty = (λ/2)w².\n\nλ = 0.1; η = 0.2.\n\n### To find\n\nFind total objective, its weight gradient and the new weight.\n\n### Formula — which one and why\n\n**L2 penalty with a factor of one-half.** Square each weight, sum and multiply by λ/2. The one-half cancels the factor 2 when differentiating, so the extra gradient is λw.\n\nλ = penalty strength; w = old weight; J_data and g_data = data loss and its gradient.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Half wala L2 derivative mein lambda × weight deta hai.\n\n**Gradient descent.** Evaluate the gradient at the current parameter, multiply by the learning rate and subtract. If the objective is supplied, differentiate it and recompute the gradient after each update.\n\nθ (theta) = trainable parameter; g = derivative of the stated objective J; η = learning rate; t labels the update number.\n\n\n\n\n\n**Yaad rakhne ka cue:** Naya = purana − learning rate × current gradient.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nThis objective contains both prediction error and a weight penalty. Its gradient also has two parts. Compute both at the old weight, add them, then update once.\n\n\n### Step 1: prediction and error\n\n### Step 2: data loss\n\n### Step 3: regularization penalty and total objective\n\n\n### Step 4: calculate the two gradient contributions\n\n\n\n### Step 5: update\n\n**Final answer:** total loss 0.028; gradient −0.36; new weight 0.472.\n"},{"title":"Drill 48 Mixed dropout and a momentum update","question":["<p class=\"inline-question\"><strong>Question.</strong> Hidden activations [1,2], inverted dropout q = 0.5, mask [1,0]. Linear output weights [0.2,0.3], bias 0, target 1, half squared loss. Update only output weights with momentum β = 0.9, old velocity [0.1,−0.1], η = 0.1.</p>"],"answer":["<h3>Given</h3>","<p>Hidden activations = [1,2]; mask = [1,0]; keep probability q = 0.5.</p>","<p>Linear-output weights = [0.2,0.3]; bias = 0; target = 1.</p>","<p>Half squared loss; update only the output weights.</p>","<p>Old signed velocity = [0.1,−0.1]; β = 0.9; η = 0.1.</p>","<h3>To find</h3>","<p>Find dropped/scaled activations, prediction, gradients, new velocities and new output weights.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inverted dropout.</strong> Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.</p>","<p>aᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/de8c0e93f06e9aa8.svg\" alt=\"a_i^{\\mathrm{test}}=a_i\" width=\"96.38\" height=\"26.95\" style=\"width:96.38px;height:26.95px;aspect-ratio:96.38/26.95\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mask se keep/drop; kept value ko keep probability se divide.</p>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used</h3>","<p>Dropout changes the inputs received by the output neuron. Use those changed inputs in both its forward calculation and its weight gradients.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:179.65px;--narrow-height:165.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0da6165a5d02d6ea.svg\"><img class=\"math display-math\" src=\"assets/equations/efaf3726aa8b79f8.svg\" alt=\"a&#x27;_j=\\frac{m_ja_j}{q},\\quad o=\\sum_jw_ja&#x27;_j+b,\\quad g_j=(o-y)a&#x27;_j\" width=\"509.70\" height=\"61.69\" style=\"width:509.70px;height:61.69px;aspect-ratio:509.70/61.69\" loading=\"lazy\"></picture></div>","<p>The signed-velocity momentum convention is:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.43px;--narrow-height:65.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc93fbe5bcc88056.svg\"><img class=\"math display-math\" src=\"assets/equations/b4d3d4646fcd808d.svg\" alt=\"v_{j,\\mathrm{new}}=\\beta v_{j,\\mathrm{old}}-\\eta g_j,\\qquad w_{j,\\mathrm{new}}=w_j+v_{j,\\mathrm{new}}\" width=\"479.21\" height=\"24.42\" style=\"width:479.21px;height:24.42px;aspect-ratio:479.21/24.42\" loading=\"lazy\"></picture></div>","<h3>Step 1: apply inverted dropout</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.83px;--narrow-height:114.84px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/446657a723f0a489.svg\"><img class=\"math display-math\" src=\"assets/equations/2b32d1a861daf9ff.svg\" alt=\"a&#x27;_1=\\frac{1\\times1}{0.5}=2,\\qquad a&#x27;_2=\\frac{0\\times2}{0.5}=0\" width=\"391.80\" height=\"50.09\" style=\"width:391.80px;height:50.09px;aspect-ratio:391.80/50.09\" loading=\"lazy\"></picture></div>","<h3>Step 2: prediction and error</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a323109c2640591d.svg\"><img class=\"math display-math\" src=\"assets/equations/d947f0c3c40b6311.svg\" alt=\"o=0.2(2)+0.3(0)+0=0.4\" width=\"305.11\" height=\"24.43\" style=\"width:305.11px;height:24.43px;aspect-ratio:305.11/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e63213278aa7de98.svg\" alt=\"o-y=0.4-1=-0.6\" width=\"242.42\" height=\"21.55\" style=\"width:242.42px;height:21.55px;aspect-ratio:242.42/21.55\" loading=\"lazy\"></div>","<h3>Step 3: current weight gradients</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.00px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7f44ece1dbabee9e.svg\"><img class=\"math display-math\" src=\"assets/equations/f17168c45fd84cbe.svg\" alt=\"g_1=(-0.6)(2)=-1.2,\\qquad g_2=(-0.6)(0)=0\" width=\"498.12\" height=\"24.43\" style=\"width:498.12px;height:24.43px;aspect-ratio:498.12/24.43\" loading=\"lazy\"></picture></div>","<h3>Step 4: remembered movement plus new correction</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.38px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6463456a76ac5311.svg\"><img class=\"math display-math\" src=\"assets/equations/afa6505a2a4ce39d.svg\" alt=\"v_{1,\\mathrm{new}}=0.9(0.1)-0.1(-1.2)=0.09+0.12=0.21\" width=\"526.83\" height=\"25.35\" style=\"width:526.83px;height:25.35px;aspect-ratio:526.83/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:190.13px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/66eba48d514886f3.svg\"><img class=\"math display-math\" src=\"assets/equations/896aef66e0912dce.svg\" alt=\"v_{2,\\mathrm{new}}=0.9(-0.1)-0.1(0)=-0.09\" width=\"377.49\" height=\"25.35\" style=\"width:377.49px;height:25.35px;aspect-ratio:377.49/25.35\" loading=\"lazy\"></picture></div>","<h3>Step 5: add velocities to old weights</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ad8445391f1a6df2.svg\" alt=\"w_{1,\\mathrm{new}}=0.2+0.21=0.41\" width=\"275.88\" height=\"23.55\" style=\"width:275.88px;height:23.55px;aspect-ratio:275.88/23.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dc7d2ca77c91e6c.svg\" alt=\"w_{2,\\mathrm{new}}=0.3-0.09=0.21\" width=\"275.88\" height=\"23.30\" style=\"width:275.88px;height:23.30px;aspect-ratio:275.88/23.30\" loading=\"lazy\"></div>","<p><strong>Final answer: [0.41, 0.21].</strong> The second weight moves even with zero current gradient because its old momentum is nonzero.</p>"],"kind":"practice","id":"tee-c17-s48","search":"Drill 48 Mixed dropout and a momentum update **Question.** Hidden activations [1,2], inverted dropout q = 0.5, mask [1,0]. Linear output weights [0.2,0.3], bias 0, target 1, half squared loss. Update only output weights with momentum β = 0.9, old velocity [0.1,−0.1], η = 0.1.\n\n**Full solution.**\n\n\n\n### Given\n\nHidden activations = [1,2]; mask = [1,0]; keep probability q = 0.5.\n\nLinear-output weights = [0.2,0.3]; bias = 0; target = 1.\n\nHalf squared loss; update only the output weights.\n\nOld signed velocity = [0.1,−0.1]; β = 0.9; η = 0.1.\n\n### To find\n\nFind dropped/scaled activations, prediction, gradients, new velocities and new output weights.\n\n### Formula — which one and why\n\n**Inverted dropout.** Multiply by the keep/drop mask, then divide retained activations by the keep probability. This preserves each activation’s expectation over random masks.\n\naᵢ = original activation; mᵢ is 1 to keep or 0 to drop; q = keep probability = 1−dropout rate. Disable this masking/scaling at inference.\n\n\n\n\n\n**Yaad rakhne ka cue:** Mask se keep/drop; kept value ko keep probability se divide.\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used\nDropout changes the inputs received by the output neuron. Use those changed inputs in both its forward calculation and its weight gradients.\n\nThe signed-velocity momentum convention is:\n\n### Step 1: apply inverted dropout\n\n### Step 2: prediction and error\n\n\n### Step 3: current weight gradients\n\n### Step 4: remembered movement plus new correction\n\n\n### Step 5: add velocities to old weights\n\n\n**Final answer: [0.41, 0.21].** The second weight moves even with zero current gradient because its old momentum is nonzero.\n"},{"title":"Drill 49 Mixed CNN dimensions softmax and loss","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 8 × 8 × 3 → Conv 3, stride 1, padding 1, 2 filters → Pool 2, stride 2 → Flatten → Dense 3. Logits [0,1,−1], true class is the second class (one-hot target [0,1,0]). Find shapes, parameters, probabilities and CCE.</p>"],"answer":["<h3>Given</h3>","<p>Input = 8 × 8 × 3.</p>","<p>Conv: kernel 3, stride 1, padding 1, 2 filters.</p>","<p>Pool: kernel 2, stride 2; flatten; dense layer with 3 outputs.</p>","<p>Logits = [0,1,−1]; true class is the second class (one-hot target [0,1,0]).</p>","<h3>To find</h3>","<p>Find shapes, parameter counts, probabilities and CCE.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<p><strong>Stable softmax.</strong> Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.</p>","<p>zⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a279f991a1a98b5.svg\" alt=\"M=\\max_j z_j\" width=\"128.31\" height=\"38.43\" style=\"width:128.31px;height:38.43px;aspect-ratio:128.31/38.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8375be5e6a8189d.svg\" alt=\"p_j=\\frac{e^{z_j-M}}{\\sum_k e^{z_k-M}}\" width=\"166.53\" height=\"62.24\" style=\"width:166.53px;height:62.24px;aspect-ratio:166.53/62.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Largest score ghatao, exp nikalo, total se sabko divide karo.</p>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<h3>Formulas used</h3>","<p>Separate shape from learned parameter count. H, W and C mean height, width and channels. K, P and S mean filter size, padding per side and stride.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4064c7b5aff30cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bf6a8c697b8e11ab.svg\" alt=\"n_{\\mathrm{flat}}=HWC,\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"425.84\" height=\"24.43\" style=\"width:425.84px;height:24.43px;aspect-ratio:425.84/24.43\" loading=\"lazy\"></picture></div>","<p>The +1 counts one bias per receiving filter or neuron. Pooling and flattening add no learned parameters. Softmax converts scores to probabilities; CCE uses the probability of the correct class.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.99px;--narrow-height:157.13px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1ffdc701f4381a15.svg\"><img class=\"math display-math\" src=\"assets/equations/e3c5269ae1be7e5e.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\quad c=\\max_jz_j,\\quad L=-\\ln p_{\\mathrm{correct}}\" width=\"498.29\" height=\"63.31\" style=\"width:498.29px;height:63.31px;aspect-ratio:498.29/63.31\" loading=\"lazy\"></picture></div>","<p>Conv size = (8+2−3)+1 = 8; output 8 × 8 × 2; parameters = (3 × 3 × 3+1) × 2 = 56. Pool 4 × 4 × 2; parameters 0. Flatten 32. Dense 3 parameters = (32+1) × 3 = 99. Total = <strong>155</strong>.</p>","<p class=\"worked-step\"><strong>Step 1 stabilize: </strong> subtract the largest logit 1 from every value: [-1, 0, -2]. This does not change softmax.</p>","<p class=\"worked-step\"><strong>Step 2 exponentiate: </strong> exp values = [0.367879441, 1, 0.135335283].</p>","<p class=\"worked-step\"><strong>Step 3 denominator: </strong> sum = 1.503214724.</p>","<p class=\"worked-step\"><strong>Step 4 divide each value by this same sum: </strong> probabilities = <strong>[0.244728471, 0.665240956, 0.090030573]</strong>. <strong>Check: </strong> all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.</p>","<p>Correct class probability = 0.665240956; CCE = −ln(0.665240956) = <strong>0.407605964</strong>.</p>"],"kind":"practice","id":"tee-c17-s49","search":"Drill 49 Mixed CNN dimensions softmax and loss **Question.** Input 8 × 8 × 3 → Conv 3, stride 1, padding 1, 2 filters → Pool 2, stride 2 → Flatten → Dense 3. Logits [0,1,−1], true class is the second class (one-hot target [0,1,0]). Find shapes, parameters, probabilities and CCE.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 8 × 8 × 3.\n\nConv: kernel 3, stride 1, padding 1, 2 filters.\n\nPool: kernel 2, stride 2; flatten; dense layer with 3 outputs.\n\nLogits = [0,1,−1]; true class is the second class (one-hot target [0,1,0]).\n\n### To find\n\nFind shapes, parameter counts, probabilities and CCE.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n**Stable softmax.** Exponentiate each logit and divide by the sum. Subtracting the largest logit first keeps the exponentials numerically manageable and leaves the probabilities unchanged.\n\nzⱼ = class j score; M = largest score; pⱼ = class j probability. All probabilities sum to 1.\n\n\n\n\n\n**Yaad rakhne ka cue:** Largest score ghatao, exp nikalo, total se sabko divide karo.\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n\n### Formulas used\nSeparate shape from learned parameter count. H, W and C mean height, width and channels. K, P and S mean filter size, padding per side and stride.\n\n\n\nThe +1 counts one bias per receiving filter or neuron. Pooling and flattening add no learned parameters. Softmax converts scores to probabilities; CCE uses the probability of the correct class.\n\n\nConv size = (8+2−3)+1 = 8; output 8 × 8 × 2; parameters = (3 × 3 × 3+1) × 2 = 56. Pool 4 × 4 × 2; parameters 0. Flatten 32. Dense 3 parameters = (32+1) × 3 = 99. Total = **155**.\n**Step 1 stabilize: ** subtract the largest logit 1 from every value: [-1, 0, -2]. This does not change softmax.\n\n**Step 2 exponentiate: ** exp values = [0.367879441, 1, 0.135335283].\n\n**Step 3 denominator: ** sum = 1.503214724.\n\n**Step 4 divide each value by this same sum: ** probabilities = **[0.244728471, 0.665240956, 0.090030573]**. **Check: ** all are positive and their sum is 1 (apart from rounding); the largest logit gets the largest probability.\nCorrect class probability = 0.665240956; CCE = −ln(0.665240956) = **0.407605964**.\n"},{"title":"Drill 50 Three step LSTM retention and replacement","question":["<p class=\"inline-question\"><strong>Question.</strong> C₀ = 0, output gate 0.7 at all steps. Supplied(f, i, candidate) are(1,.5,.8), (.9,0,−.2), (.2,.5,−.6). Find C and h at each step.</p>"],"answer":["<h3>Given</h3>","<p>Initial C₀ = 0; output gate o = 0.7 at all three steps.</p>","<p>Supplied (f,i,candidate): (1,0.5,0.8), (0.9,0,−0.2), (0.2,0.5,−0.6).</p>","<h3>To find</h3>","<p>Calculate C₁,h₁,C₂,h₂,C₃,h₃ in order.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>At each time step use the previous <strong>cell state C</strong>, not the previous visible output h, in the memory equation. The output gate is 0.7 at every step.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.47px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3aff429544aa57f2.svg\"><img class=\"math display-math\" src=\"assets/equations/cec99860eadf260d.svg\" alt=\"C_t=f_tC_{t-1}+i_t\\widetilde C_t,\\qquad h_t=o_t\\tanh(C_t)\" width=\"431.16\" height=\"31.40\" style=\"width:431.16px;height:31.40px;aspect-ratio:431.16/31.40\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 1: Time 1: admit new content.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.09px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/12440f871df30d1a.svg\"><img class=\"math display-math\" src=\"assets/equations/92909a33a68a6d6c.svg\" alt=\"f_1C_0=1(0)=0,\\qquad i_1\\widetilde C_1=0.5(0.8)=0.4\" width=\"456.44\" height=\"31.40\" style=\"width:456.44px;height:31.40px;aspect-ratio:456.44/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7d6404b116e9cbf8.svg\" alt=\"C_1=0+0.4=0.4\" width=\"197.85\" height=\"20.89\" style=\"width:197.85px;height:20.89px;aspect-ratio:197.85/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.79px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bc61a66b7daaff60.svg\"><img class=\"math display-math\" src=\"assets/equations/6ab753ebe65dd463.svg\" alt=\"h_1=0.7\\tanh(0.4)=0.7(0.379948962)=0.265964274\" width=\"565.09\" height=\"24.43\" style=\"width:565.09px;height:24.43px;aspect-ratio:565.09/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Time 2: retain memory and admit no new content.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.64px;--narrow-height:70.49px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/21e9e3dc7975b5fa.svg\"><img class=\"math display-math\" src=\"assets/equations/1604cb4698139943.svg\" alt=\"f_2C_1=0.9(0.4)=0.36,\\qquad i_2\\widetilde C_2=0(-0.2)=0\" width=\"506.67\" height=\"31.40\" style=\"width:506.67px;height:31.40px;aspect-ratio:506.67/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e78e9762a4457abe.svg\" alt=\"C_2=0.36+0=0.36\" width=\"222.29\" height=\"20.89\" style=\"width:222.29px;height:20.89px;aspect-ratio:222.29/20.89\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.79px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36c9d733b0dbfd49.svg\"><img class=\"math display-math\" src=\"assets/equations/bbded31a747f8c6f.svg\" alt=\"h_2=0.7\\tanh(0.36)=0.7(0.345214034)=0.241649824\" width=\"577.30\" height=\"24.43\" style=\"width:577.30px;height:24.43px;aspect-ratio:577.30/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: Time 3: retain a small part and add negative content.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.30px;--narrow-height:148.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/39fc048515ad2602.svg\"><img class=\"math display-math\" src=\"assets/equations/dc1de2dfd9757248.svg\" alt=\"f_3C_2=0.2(0.36)=0.072,\\qquad i_3\\widetilde C_3=0.5(-0.6)=-0.3\" width=\"588.14\" height=\"31.40\" style=\"width:588.14px;height:31.40px;aspect-ratio:588.14/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3e11138e5892ca48.svg\" alt=\"C_3=0.072-0.3=-0.228\" width=\"284.73\" height=\"21.28\" style=\"width:284.73px;height:21.28px;aspect-ratio:284.73/21.28\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.20px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/84a567774fa02539.svg\"><img class=\"math display-math\" src=\"assets/equations/32c2f7dd58700393.svg\" alt=\"h_3=0.7\\tanh(-0.228)=0.7(-0.224129674)=-0.156890772\" width=\"646.55\" height=\"24.43\" style=\"width:646.55px;height:24.43px;aspect-ratio:646.55/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final cell states:</strong> 0.4, 0.36, −0.228. <strong>Final hidden states:</strong> approximately 0.265964274, 0.241649824, −0.156890772. The supplied gate value 1 is an idealized limit, used exactly as given.</p>"],"kind":"practice","id":"tee-c17-s50","search":"Drill 50 Three step LSTM retention and replacement **Question.** C₀ = 0, output gate 0.7 at all steps. Supplied(f, i, candidate) are(1,.5,.8), (.9,0,−.2), (.2,.5,−.6). Find C and h at each step.\n\n**Full solution.**\n\n\n\n### Given\n\nInitial C₀ = 0; output gate o = 0.7 at all three steps.\n\nSupplied (f,i,candidate): (1,0.5,0.8), (0.9,0,−0.2), (0.2,0.5,−0.6).\n\n### To find\n\nCalculate C₁,h₁,C₂,h₂,C₃,h₃ in order.\n\n### Formula — which one and why\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nAt each time step use the previous **cell state C**, not the previous visible output h, in the memory equation. The output gate is 0.7 at every step.\n\n**Step 1: Time 1: admit new content.**\n\n\n\n**Step 2: Time 2: retain memory and admit no new content.**\n\n\n\n**Step 3: Time 3: retain a small part and add negative content.**\n\n\n\n**Final cell states:** 0.4, 0.36, −0.228. **Final hidden states:** approximately 0.265964274, 0.241649824, −0.156890772. The supplied gate value 1 is an idealized limit, used exactly as given.\n"},{"title":"Drill 51 Inception concatenation and parameter count","question":["<p class=\"inline-question\"><strong>Question.</strong> Input 10 × 10 × 8. Parallel branches: A uses 1 × 1 conv 4 filters ; B uses 3 × 3 same Conv 6 filters; C max pool 3 same, stride 1 then 1 × 1 conv 2 filters. Find combined shape and trainable parameters.</p>"],"answer":["<h3>Given</h3>","<p>Input = 10 × 10 × 8.</p>","<p>Branch A: 1 × 1 convolution, 4 filters.</p>","<p>Branch B: 3 × 3 same convolution, 6 filters.</p>","<p>Branch C: 3 × 3 same max pool with stride 1, then 1 × 1 convolution, 2 filters.</p>","<h3>To find</h3>","<p>Find each branch shape and parameters, then the concatenated shape and total parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Inception channel concatenation.</strong> Parallel branches retain their separate features. Add their channel counts while keeping the common height and width. Add trainable parameters across branches.</p>","<p>C₁,C₂,… = branch output channels. Concatenation requires matching spatial dimensions.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5fcf90049e052b72.svg\" alt=\"C_{\\mathrm{out}}=\\sum_k C_k\" width=\"144.90\" height=\"52.91\" style=\"width:144.90px;height:52.91px;aspect-ratio:144.90/52.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c6958d2f8ded49d5.svg\" alt=\"P_{\\mathrm{total}}=\\sum_k P_k\" width=\"151.89\" height=\"52.91\" style=\"width:151.89px;height:52.91px;aspect-ratio:151.89/52.91\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Channels jodo; height-width same rakho.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>Each parallel branch receives the same original 10 × 10 × 8 input. “Same” with stride 1 preserves height and width. Concatenation joins the channel lists without adding the feature values.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2245536fdd10a080.svg\" alt=\"C_{\\mathrm{combined}}=C_A+C_B+C_C\" width=\"281.51\" height=\"21.28\" style=\"width:281.51px;height:21.28px;aspect-ratio:281.51/21.28\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<p>Assume one bias per filter. Pooling has no learned parameters.</p>","<p class=\"worked-step\"><strong>Step 1: Branch A.</strong></p>","<p>Its 4 filters produce shape 10 × 10 × 4.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.74px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff251b0ed25a7ae7.svg\"><img class=\"math display-math\" src=\"assets/equations/baf7f3bc0580d3c4.svg\" alt=\"P_A=(1\\times1\\times8+1)\\times4=9\\times4=36\" width=\"406.74\" height=\"24.43\" style=\"width:406.74px;height:24.43px;aspect-ratio:406.74/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: Branch B.</strong></p>","<p>Its 6 filters produce shape 10 × 10 × 6.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.90px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d6970788f463cb74.svg\"><img class=\"math display-math\" src=\"assets/equations/97eb7526b53ae379.svg\" alt=\"P_B=(3\\times3\\times8+1)\\times6=73\\times6=438\" width=\"431.33\" height=\"24.43\" style=\"width:431.33px;height:24.43px;aspect-ratio:431.33/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: Branch C.</strong></p>","<p>Pooling preserves 10 × 10 × 8 here because stride is 1 and padding is same. Its parameter count is zero. The following 2-filter projection creates 10 × 10 × 2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:229.45px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bdab800ad8bc0347.svg\"><img class=\"math display-math\" src=\"assets/equations/61f74ab4b2624099.svg\" alt=\"P_C=0+(1\\times1\\times8+1)\\times2=18\" width=\"362.11\" height=\"24.43\" style=\"width:362.11px;height:24.43px;aspect-ratio:362.11/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: Join the shapes and add the parameters.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/567c2c4512c2cb27.svg\" alt=\"C_{\\mathrm{combined}}=4+6+2=12\" width=\"277.48\" height=\"21.08\" style=\"width:277.48px;height:21.08px;aspect-ratio:277.48/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.09px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f9a71aaf4ed27273.svg\"><img class=\"math display-math\" src=\"assets/equations/4f06023c81396b20.svg\" alt=\"P_{\\mathrm{total}}=36+438+18=492\" width=\"300.32\" height=\"20.54\" style=\"width:300.32px;height:20.54px;aspect-ratio:300.32/20.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> combined shape 10 × 10 × 12; 492 parameters. Branch B does not take branch A&#x27;s four channels as input: they are parallel branches.</p>"],"kind":"practice","id":"tee-c17-s51","search":"Drill 51 Inception concatenation and parameter count **Question.** Input 10 × 10 × 8. Parallel branches: A uses 1 × 1 conv 4 filters ; B uses 3 × 3 same Conv 6 filters; C max pool 3 same, stride 1 then 1 × 1 conv 2 filters. Find combined shape and trainable parameters.\n\n**Full solution.**\n\n\n\n### Given\n\nInput = 10 × 10 × 8.\n\nBranch A: 1 × 1 convolution, 4 filters.\n\nBranch B: 3 × 3 same convolution, 6 filters.\n\nBranch C: 3 × 3 same max pool with stride 1, then 1 × 1 convolution, 2 filters.\n\n### To find\n\nFind each branch shape and parameters, then the concatenated shape and total parameters.\n\n### Formula — which one and why\n\n**Inception channel concatenation.** Parallel branches retain their separate features. Add their channel counts while keeping the common height and width. Add trainable parameters across branches.\n\nC₁,C₂,… = branch output channels. Concatenation requires matching spatial dimensions.\n\n\n\n\n\n**Yaad rakhne ka cue:** Channels jodo; height-width same rakho.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nEach parallel branch receives the same original 10 × 10 × 8 input. “Same” with stride 1 preserves height and width. Concatenation joins the channel lists without adding the feature values.\n\n\nAssume one bias per filter. Pooling has no learned parameters.\n**Step 1: Branch A.**\nIts 4 filters produce shape 10 × 10 × 4.\n\n**Step 2: Branch B.**\nIts 6 filters produce shape 10 × 10 × 6.\n\n**Step 3: Branch C.**\nPooling preserves 10 × 10 × 8 here because stride is 1 and padding is same. Its parameter count is zero. The following 2-filter projection creates 10 × 10 × 2.\n\n**Step 4: Join the shapes and add the parameters.**\n\n\n**Final answer:** combined shape 10 × 10 × 12; 492 parameters. Branch B does not take branch A's four channels as input: they are parallel branches.\n"},{"title":"Drill 52 Projection shortcut","question":["<p class=\"inline-question\"><strong>Question.</strong> A residual main path outputs 8 × 8 × 16 but input is 16 × 16 × 8. Design a 1 × 1 projection shortcut with stride 2, zero padding. Find its output and parameters.</p>"],"answer":["<h3>Given</h3>","<p>Residual input = 16 × 16 × 8; main-path output = 8 × 8 × 16.</p>","<p>Shortcut kernel = 1 × 1; stride 2; padding 0.</p>","<p>Use one bias per projection filter.</p>","<h3>To find</h3>","<p>Choose the number of filters and find projection output shape and parameters.</p>","<h3>Formula — which one and why</h3>","<p><strong>Convolution/pooling spatial size.</strong> Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.</p>","<p>N = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Input + dono sides ki padding − kernel; stride se divide; floor + 1.</p>","<p><strong>Convolution parameters.</strong> Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.</p>","<p>K_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/74209557d398075e.svg\" alt=\"N_w=K_hK_wC_{\\mathrm{in}}C_{\\mathrm{out}}\" width=\"212.85\" height=\"21.08\" style=\"width:212.85px;height:21.08px;aspect-ratio:212.85/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/614d1f9d70b9928b.svg\" alt=\"N_b=C_{\\mathrm{out}}\" width=\"106.11\" height=\"21.08\" style=\"width:106.11px;height:21.08px;aspect-ratio:106.11/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/61924cb4898d8799.svg\" alt=\"P=N_w+N_b\" width=\"143.89\" height=\"20.54\" style=\"width:143.89px;height:20.54px;aspect-ratio:143.89/20.54\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Filter area × input channels × filters; phir ek bias per filter.</p>","<h3>Solution — step by step</h3>","<h3>Meaning and formulas</h3>","<p>Residual addition needs identical shapes on both paths. The projection must reduce height and width from 16 to 8 and increase channels from 8 to 16.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:205.72px;--narrow-height:67.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8abfcf2c3c8a28be.svg\"><img class=\"math display-math\" src=\"assets/equations/b8afb47cd18fe03e.svg\" alt=\"P_{\\mathrm{projection}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"298.85\" height=\"28.80\" style=\"width:298.85px;height:28.80px;aspect-ratio:298.85/28.80\" loading=\"lazy\"></picture></div>","<h3>Step 1: choose 16 filters</h3>","<p>One filter creates one channel, so 16 filters give the required 16 output channels.</p>","<h3>Step 2: use the specified 1 × 1 kernel and stride 2</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecbcadd42ab07705.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{16+0-1}{2}\\right\\rfloor+1\" width=\"269.14\" height=\"58.62\" style=\"width:269.14px;height:58.62px;aspect-ratio:269.14/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.01px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55b23544c4917d4f.svg\"><img class=\"math display-math\" src=\"assets/equations/c73f4efe4e78e925.svg\" alt=\"N_{\\mathrm{out}}=\\lfloor7.5\\rfloor+1=7+1=8\" width=\"305.90\" height=\"24.43\" style=\"width:305.90px;height:24.43px;aspect-ratio:305.90/24.43\" loading=\"lazy\"></picture></div>","<p>The floor operation drops the fractional part; it does not round 7.5 to 8 before adding 1.</p>","<h3>Step 3: count weights and biases</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.20px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dfae1039bf042104.svg\"><img class=\"math display-math\" src=\"assets/equations/b4a1699aef64acc8.svg\" alt=\"\\text{weights}=1\\times1\\times8\\times16=128\" width=\"332.74\" height=\"21.99\" style=\"width:332.74px;height:21.99px;aspect-ratio:332.74/21.99\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:243.01px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/040d4fe2bfbf253e.svg\"><img class=\"math display-math\" src=\"assets/equations/3c90598459083061.svg\" alt=\"\\text{biases}=16,\\qquad \\text{total}=128+16=144\" width=\"422.46\" height=\"21.70\" style=\"width:422.46px;height:21.70px;aspect-ratio:422.46/21.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> projection output 8 × 8 × 16 and 144 parameters with biases. The projected shortcut now matches the main path, so elementwise addition is valid.</p>"],"kind":"practice","id":"tee-c17-s52","search":"Drill 52 Projection shortcut **Question.** A residual main path outputs 8 × 8 × 16 but input is 16 × 16 × 8. Design a 1 × 1 projection shortcut with stride 2, zero padding. Find its output and parameters.\n\n**Full solution.**\n\n\n\n### Given\n\nResidual input = 16 × 16 × 8; main-path output = 8 × 8 × 16.\n\nShortcut kernel = 1 × 1; stride 2; padding 0.\n\nUse one bias per projection filter.\n\n### To find\n\nChoose the number of filters and find projection output shape and parameters.\n\n### Formula — which one and why\n\n**Convolution/pooling spatial size.** Padding adds P positions at both ends. Subtract kernel width to find the last valid start, divide by stride, take the floor and include the initial placement with +1.\n\nN = current height or width; K = kernel/window size; S = stride; P = padding per side. Apply separately to height and width; dilation is 1 here.\n\n\n\n**Yaad rakhne ka cue:** Input + dono sides ki padding − kernel; stride se divide; floor + 1.\n\n**Convolution parameters.** Every filter spans all input channels. Count its spatial coefficients across those channels, add one bias and multiply by the number of filters.\n\nK_h,K_w = filter height/width; C_in = input channels; C_out = number of filters and output channels. Spatial output positions reuse these weights.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Filter area × input channels × filters; phir ek bias per filter.\n\n### Solution — step by step\n\n\n\n\n\n### Meaning and formulas\nResidual addition needs identical shapes on both paths. The projection must reduce height and width from 16 to 8 and increase channels from 8 to 16.\n\n\n### Step 1: choose 16 filters\nOne filter creates one channel, so 16 filters give the required 16 output channels.\n### Step 2: use the specified 1 × 1 kernel and stride 2\n\n\nThe floor operation drops the fractional part; it does not round 7.5 to 8 before adding 1.\n### Step 3: count weights and biases\n\n\n**Final answer:** projection output 8 × 8 × 16 and 144 parameters with biases. The projected shortcut now matches the main path, so elementwise addition is valid.\n"},{"title":"Revising solved examples","blocks":["<p>Revisit a direct example and then its changed-number version. Write the given values, the formula and the substitutions on separate lines. If an answer differs, compare from the first line until the difference appears. Use the mixed questions after the individual methods make sense.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c17-s53","search":"Revising solved examples Revisit a direct example and then its changed-number version. Write the given values, the formula and the substitutions on separate lines. If an answer differs, compare from the first line until the difference appears. Use the mixed questions after the individual methods make sense.\n\n"}]},{"n":18,"title":"Complete TEE paper rehearsal","sections":[{"title":"Start here","blocks":["<p>Three hours; 100 marks. Answer Q1 and any four of Q2–Q7. Every question below is immediately followed by its full solution. This is the supplied December 2025 historical paper used for a timed rehearsal.</p>","<p>F25 = S12, 3 December 2025, with S13 as a comparison answer key. S18 is another copy of this same paper. All questions are included; its historical choice rule does not remove questions from this practice bank.</p>","<p>Questions below preserve the assessed tasks and numerical data, with wording and diagram layout normalized for readability. Full question statements and their necessary diagrams appear with the solutions. Read the full question, then follow the worked answer line by line. Solutions are independently worked; a historical answer key is not treated as infallible.</p>"],"kind":"read","id":"tee-c18-intro"},{"title":"Rehearsal Q1a","blocks":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Give four ML versus DL differences with examples. Choose and justify ML or DL for (1) 2,000 short product reviews, (2) labeled financial fraud records, (3) captions for 100,000 labeled natural-scene images.</p>","<p><strong>Complete worked answer.</strong></p>","<p>Deep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.</p>","<div class=\"table-scroll\"><table><thead><tr><th>Comparison</th><th>Traditional ML approaches</th><th>Deep learning approaches</th></tr></thead><tbody><tr><td>Features</td><td>Often depend on manually designed features</td><td>Often learn features jointly with the prediction task</td></tr><tr><td>Data</td><td>Often strong baselines for smaller structured datasets</td><td>Training large models from scratch often benefits from abundant data</td></tr><tr><td>Computation</td><td>Many methods can train economically on CPUs</td><td>Large networks often need substantial compute and memory</td></tr><tr><td>Interpretability</td><td>Some models such as small decision trees are easier to inspect</td><td>Large multilayer representations can be harder to explain</td></tr></tbody></table></div>","<p>These are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.</p>","<p>Drivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.</p>","<p><strong>Choices: </strong> (1) Start with traditional ML using text features because the labeled dataset is small; pretrained text models are a viable extension. (2) Start with a tabular ML classifier such as a tree ensemble; labeled structured features do not automatically require DL. (3) DL is appropriate for learning visual features and generating a word sequence; a CNN encoder with a sequence decoder is a syllabus-aligned design. Compare held-out metrics rather than claiming one method must always win.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s0","search":"Rehearsal Q1a **Question (5 marks).** Give four ML versus DL differences with examples. Choose and justify ML or DL for (1) 2,000 short product reviews, (2) labeled financial fraud records, (3) captions for 100,000 labeled natural-scene images.\n\n**Complete worked answer.**\nDeep learning is a branch of machine learning that learns representations using neural networks with multiple processing layers. Machine learning is itself a branch of artificial intelligence. In image recognition, early CNN layers can detect local edges, later layers combine patterns into textures and parts, and deeper layers support object recognition.\n| Comparison | Traditional ML approaches | Deep learning approaches |\n| Features | Often depend on manually designed features | Often learn features jointly with the prediction task |\n| Data | Often strong baselines for smaller structured datasets | Training large models from scratch often benefits from abundant data |\n| Computation | Many methods can train economically on CPUs | Large networks often need substantial compute and memory |\n| Interpretability | Some models such as small decision trees are easier to inspect | Large multilayer representations can be harder to explain |\nThese are tendencies, not rules. A pretrained network can be useful with a small target dataset, and boosted trees can outperform deep networks on some tabular problems. Choose using data type, size, available pretrained models, resources and held-out performance.\nDrivers of deep learning include improved hardware, large datasets, automatic differentiation, improved activations/optimization and useful architectures. Advantages include automatic feature learning and strong modeling of complex image, audio and sequence patterns. Limitations include data and compute requirements, overfitting, sensitivity to training choices, and difficulty explaining decisions. Applications include image classification, speech recognition, translation and medical-image analysis.\n**Choices: ** (1) Start with traditional ML using text features because the labeled dataset is small; pretrained text models are a viable extension. (2) Start with a tabular ML classifier such as a tree ensemble; labeled structured features do not automatically require DL. (3) DL is appropriate for learning visual features and generating a word sequence; a CNN encoder with a sequence decoder is a syllabus-aligned design. Compare held-out metrics rather than claiming one method must always win.\n"},{"title":"Rehearsal Q1b","blocks":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> For automated leaf-disease image classification, discuss factors affecting loss selection. For classes Normal, Mild, Severe with target [0,1,0] and predicted probabilities [0.1,0.8,0.1], compute and interpret categorical cross-entropy.</p>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Classes = Normal,Mild,Severe; target = [0,1,0].</p>","<p>Predicted probabilities = [0.1,0.8,0.1]; use natural logarithms.</p>","<h3>To find</h3>","<p>Calculate categorical cross-entropy and interpret the result.</p>","<h3>Formula — which one and why</h3>","<p><strong>Categorical cross-entropy.</strong> For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.</p>","<p>yⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3b5ae8d980bc0fd4.svg\" alt=\"L=-\\sum_j y_j\\ln p_j\" width=\"182.75\" height=\"55.67\" style=\"width:182.75px;height:55.67px;aspect-ratio:182.75/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/96bd39e07641cf89.svg\" alt=\"L=-\\ln p_c\" width=\"118.56\" height=\"21.70\" style=\"width:118.56px;height:21.70px;aspect-ratio:118.56/21.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One-hot mein sirf correct class ki probability ka minus ln.</p>","<h3>Solution — step by step</h3>","<p>Select a loss according to the task and output meaning: real-valued regression often uses MSE/MAE, binary classification uses binary cross-entropy, and one-of-K classification uses categorical cross-entropy. Consider class imbalance, noisy labels/outliers, whether outputs are calibrated probabilities, and differentiability for optimization.</p>","<p class=\"worked-step\"><strong>Step 1: expand the categorical cross-entropy sum.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6cc766252350138b.svg\" alt=\"L=-[0\\ln(0.1)+1\\ln(0.8)+0\\ln(0.1)]\" width=\"402.28\" height=\"24.43\" style=\"width:402.28px;height:24.43px;aspect-ratio:402.28/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: keep the term for the true class.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17a83c5bb645a7c5.svg\" alt=\"L=-\\ln(0.8)\" width=\"142.93\" height=\"24.43\" style=\"width:142.93px;height:24.43px;aspect-ratio:142.93/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: negate the logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/178c3708a55e1ab7.svg\" alt=\"L\\approx0.223143551\" width=\"178.19\" height=\"17.23\" style=\"width:178.19px;height:17.23px;aspect-ratio:178.19/17.23\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> loss ≈ 0.223144 nats. The true class received probability 0.8, so the loss is relatively small; probability 1 would give loss zero.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s1","search":"Rehearsal Q1b **Question (5 marks).** For automated leaf-disease image classification, discuss factors affecting loss selection. For classes Normal, Mild, Severe with target [0,1,0] and predicted probabilities [0.1,0.8,0.1], compute and interpret categorical cross-entropy.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nClasses = Normal,Mild,Severe; target = [0,1,0].\n\nPredicted probabilities = [0.1,0.8,0.1]; use natural logarithms.\n\n### To find\n\nCalculate categorical cross-entropy and interpret the result.\n\n### Formula — which one and why\n\n**Categorical cross-entropy.** For mutually exclusive classes with a one-hot target, all zero-target terms disappear. The loss is the negative log of the probability assigned to the true class.\n\nyⱼ = target entry; pⱼ = predicted probability; c = index of the true class. Use natural logarithms unless another base is specified.\n\n\n\n\n\n**Yaad rakhne ka cue:** One-hot mein sirf correct class ki probability ka minus ln.\n\n### Solution — step by step\n\n\n\n\n\n\nSelect a loss according to the task and output meaning: real-valued regression often uses MSE/MAE, binary classification uses binary cross-entropy, and one-of-K classification uses categorical cross-entropy. Consider class imbalance, noisy labels/outliers, whether outputs are calibrated probabilities, and differentiability for optimization.\n**Step 1: expand the categorical cross-entropy sum.**\n\n\n\n\n\n\n\n**Step 2: keep the term for the true class.**\n\n\n\n\n\n\n\n**Step 3: calculate its natural logarithm.**\n\n\n\n\n\n\n\n**Step 4: negate the logarithm.**\n\n\n\n\n\n\n\n**Final answer:** loss ≈ 0.223144 nats. The true class received probability 0.8, so the loss is relatively small; probability 1 would give loss zero.\n"},{"title":"Rehearsal Q1c","blocks":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Which regularizer leads to sparsity and why? For an MNIST CNN with high training accuracy and lower validation accuracy, explain how dropout works during training and how it can improve generalization.</p>","<p><strong>Complete worked answer.</strong></p>","<p>Overfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.78px;--narrow-height:136.27px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3eb3323790998696.svg\"><img class=\"math display-math\" src=\"assets/equations/522dfd9873b52e27.svg\" alt=\"J_{L1}=L+\\lambda\\sum_j|w_j|,\\qquad J_{L2}=L+\\frac{\\lambda}{2}\\sum_jw_j^2\" width=\"484.40\" height=\"65.94\" style=\"width:484.40px;height:65.94px;aspect-ratio:484.40/65.94\" loading=\"lazy\"></picture></div>","<p>L1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.</p>","<p>Dropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s2","search":"Rehearsal Q1c **Question (5 marks).** Which regularizer leads to sparsity and why? For an MNIST CNN with high training accuracy and lower validation accuracy, explain how dropout works during training and how it can improve generalization.\n\n**Complete worked answer.**\nOverfitting means learning training-specific patterns that do not generalize well. Very good training results with substantially worse validation results suggest overfitting, provided both sets are comparable and correctly evaluated. Regularization limits this tendency; its strength should be chosen using validation data.\n\nL1 adds a magnitude penalty and can make weights exactly zero at the optimum, encouraging sparsity. Away from zero its added gradient is λ sign(w). L2 adds gradient λw under the displayed convention and smoothly discourages large weights. L2 generally shrinks many weights without making them exactly zero. Some notes omit the half in L2; their added gradient is 2 λw.\nDropout randomly removes selected activations during training, reducing dependence on a particular combination of units. With inverted dropout, retained units are divided by the keep probability q; at inference dropout is disabled and the ordinary network is used. Early stopping monitors validation loss and restores the best validation checkpoint before prolonged fitting to training noise. Data augmentation creates label-preserving input variations. Too much regularization may underfit: both training and validation performance can then worsen.\n"},{"title":"Rehearsal Q1d","blocks":["<p class=\"inline-question\"><strong>Question (5 marks).</strong> Describe sequence processing, context and variable-length sentences in RNNs. Explain their use in language translation, as illustrated by the historical reference to Google Translate.</p>","<p><strong>Complete worked answer.</strong></p>","<p>A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:142.82px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/72d09ad3983b6b52.svg\"><img class=\"math display-math\" src=\"assets/equations/73b94d9abc839fd5.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad p_t=\\operatorname{softmax}(W_{hy}h_t+b_y)\" width=\"670.06\" height=\"25.53\" style=\"width:670.06px;height:25.53px;aspect-ratio:670.06/25.53\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: Current input and previous state jointly determine the new state\"><img src=\"assets/figures/rnn.svg\" alt=\"Current input and previous state jointly determine the new state\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>Current input and previous state jointly determine the new state <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence&#x27;s length to vary while the parameter set stays fixed.</p>","<p>For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.</p>","<p>A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service&#x27;s current architecture.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s3","search":"Rehearsal Q1d **Question (5 marks).** Describe sequence processing, context and variable-length sentences in RNNs. Explain their use in language translation, as illustrated by the historical reference to Google Translate.\n\n**Complete worked answer.**\nA recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.\n\n\nAt each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.\nFor next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.\nA basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.\n"},{"title":"Rehearsal Q2a","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> A 2 → 2 → 1 sigmoid network has all four input-to-hidden weights 0.5, both hidden-to-output weights 0.25, hidden and output biases 0, and target 1. Perform forward and backward passes to update the x₁ → h₁ weight, h₁ → output weight and output bias at η = 0.5. The paper does not state the numerical inputs or loss.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/net_f25.svg\" aria-label=\"Enlarge diagram: F25 Q2a connections with explicitly assumed inputs\"><img src=\"assets/figures/net_f25.svg\" alt=\"F25 Q2a connections with explicitly assumed inputs\" width=\"960\" height=\"601\" loading=\"lazy\"></button><figcaption>F25 Q2a connections with explicitly assumed inputs <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Architecture 2 → 2 → 1; every neuron uses sigmoid.</p>","<p>All four input-to-hidden weights = 0.5; both hidden-to-output weights = 0.25.</p>","<p>All biases = 0; target = 1; η = 0.5.</p>","<p>The paper omits inputs and loss: this worked solution explicitly assumes x = [1,1] and half squared loss.</p>","<h3>To find</h3>","<p>Calculate the forward pass, then gradients and updates for x₁→h₁, h₁→output and the output bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>Half summed squared loss.</strong> This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.</p>","<p>oⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/737ddfb3a05bc433.svg\" alt=\"L=\\frac12\\sum_j(o_j-y_j)^2\" width=\"213.21\" height=\"65.25\" style=\"width:213.21px;height:65.25px;aspect-ratio:213.21/65.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8faacff5464dcaf1.svg\" alt=\"\\frac{\\partial L}{\\partial o_j}=o_j-y_j\" width=\"150.15\" height=\"57.94\" style=\"width:150.15px;height:57.94px;aspect-ratio:150.15/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Half aur square ka 2 cancel: output derivative = prediction − target.</p>","<p><strong>Sigmoid and its slope.</strong> 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).</p>","<p>z = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5dd16ba0b4d79641.svg\" alt=\"p=\\frac{1}{1+e^{-z}}\" width=\"132.60\" height=\"51.56\" style=\"width:132.60px;height:51.56px;aspect-ratio:132.60/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Sigmoid output p; uska slope p × (1−p).</p>","<p><strong>Backpropagation.</strong> 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.</p>","<p>δ (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.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bea7700a623139b7.svg\" alt=\"\\delta_{o_j}=\\frac{\\partial L}{\\partial o_j}f_o\\prime(z_{o_j})\" width=\"182.24\" height=\"57.94\" style=\"width:182.24px;height:57.94px;aspect-ratio:182.24/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b40acc83c437110d.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i\" width=\"136.25\" height=\"57.94\" style=\"width:136.25px;height:57.94px;aspect-ratio:136.25/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a87ae98981ac797.svg\" alt=\"W_{ji,\\mathrm{new}}=W_{ji}-\\eta\\frac{\\partial L}{\\partial W_{ji}}\" width=\"248.26\" height=\"57.94\" style=\"width:248.26px;height:57.94px;aspect-ratio:248.26/57.94\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Receiving delta × sending value = us connection ka gradient.</p>","<h3>Solution — step by step</h3>","<p><strong>Assumptions: </strong> use x = [1,1] and half squared loss. The paper permits suitable assumptions and its key also introduces assumed inputs. There is no unique numerical result without them.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ebc8dda9737caeb3.svg\"><img class=\"math display-math\" src=\"assets/equations/a57d08e71109e92c.svg\" alt=\"z_{h_1} = (0.5 \\times  1) + (0.5 \\times  1) + (0) = 1\" width=\"383.89\" height=\"24.58\" style=\"width:383.89px;height:24.58px;aspect-ratio:383.89/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9d9a8c14314f06ad.svg\"><img class=\"math display-math\" src=\"assets/equations/68fa3eedfd721c67.svg\" alt=\"h_{1}=\\frac{1}{1+e^{-(1)}}=0.731058579\" width=\"320.65\" height=\"53.84\" style=\"width:320.65px;height:53.84px;aspect-ratio:320.65/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.10px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9d50f49ceec1f464.svg\"><img class=\"math display-math\" src=\"assets/equations/74149e3e776dce9d.svg\" alt=\"z_{h_2} = (0.5 \\times  1) + (0.5 \\times  1) + (0) = 1\" width=\"383.89\" height=\"24.58\" style=\"width:383.89px;height:24.58px;aspect-ratio:383.89/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5f1426f29e3d87e6.svg\"><img class=\"math display-math\" src=\"assets/equations/8276b57ee8bf3bfd.svg\" alt=\"h_{2}=\\frac{1}{1+e^{-(1)}}=0.731058579\" width=\"320.65\" height=\"53.84\" style=\"width:320.65px;height:53.84px;aspect-ratio:320.65/53.84\" loading=\"lazy\"></picture></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.88px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c44792db3abbdcd0.svg\"><img class=\"math display-math\" src=\"assets/equations/28292662ef4f2232.svg\" alt=\"z_{o_1} = (0.25 \\times  0.731058579) + (0.25 \\times  0.731058579) + (0) = 0.365529289\" width=\"756.99\" height=\"24.58\" style=\"width:756.99px;height:24.58px;aspect-ratio:756.99/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.44px;--narrow-height:92.93px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/07b12d14b1f2a0ff.svg\"><img class=\"math display-math\" src=\"assets/equations/a199e77a25ea274a.svg\" alt=\"o_{1}=\\frac{1}{1+e^{-(0.365529289)}}=0.590378257\" width=\"400.98\" height=\"53.84\" style=\"width:400.98px;height:53.84px;aspect-ratio:400.98/53.84\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2 loss convention.</strong> This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.</p>","<p>Prediction minus target = [-0.409621743]. Squared errors = [0.167789972]. Half-sum squared loss = 0.083894986; mean squared error = 0.167789972. These are different unless the number of output components makes the scale coincide.</p>","<p><strong>Output delta 1:</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.93px;--narrow-height:141.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b7b0310d2c3be2ab.svg\"><img class=\"math display-math\" src=\"assets/equations/cfa9f3b565ded315.svg\" alt=\"\\delta_{o_1} = 1 \\times  (0.590378257-1) \\times  0.241831771 = -0.099059551\" width=\"632.92\" height=\"24.58\" style=\"width:632.92px;height:24.58px;aspect-ratio:632.92/24.58\" loading=\"lazy\"></picture></div>","<p>The derivative is o(1−o).</p>","<p class=\"worked-step\"><strong>Step 3 output weights.</strong> Gradient = receiving delta × sending activation. An output bias gradient equals its delta.</p>","<p><strong>h1 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h1 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.731058579</strong><span class=\"lv-detail\">h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.099059551</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.072418335</strong><span class=\"lv-detail\">h1 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.286209167</strong></div></div><p>Subtract η × gradient = <b>−0.036209168</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/267f6c273b5a3588.svg\" alt=\"g_{1,1}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,1}}=\\delta_{o_1}h_1\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/30f7bf8aa04d2bf2.svg\"><img class=\"math display-math\" src=\"assets/equations/0995183f490671de.svg\" alt=\"g_{1,1}^{(2)}=(-0.099059551)\\times(0.731058579)\\approx -0.072418335\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/82203dea1f21db8c.svg\"><img class=\"math display-math\" src=\"assets/equations/7a3beb590205510e.svg\" alt=\"W^{(2)}_{1,1,\\mathrm{new}}=0.25-0.5(-0.072418335)\\approx 0.286209167\" width=\"547.39\" height=\"36.54\" style=\"width:547.39px;height:36.54px;aspect-ratio:547.39/36.54\" loading=\"lazy\"></picture></div>","<p><strong>h2 → o1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on h2 → o1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending activation</span><strong class=\"lv-value\">0.731058579</strong><span class=\"lv-detail\">h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.099059551</strong><span class=\"lv-detail\">δ at o1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.072418335</strong><span class=\"lv-detail\">h2 → o1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.286209167</strong></div></div><p>Subtract η × gradient = <b>−0.036209168</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies its activation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2314d47ce6468a48.svg\" alt=\"g_{1,2}^{(2)}=\\frac{\\partial L}{\\partial W^{(2)}_{1,2}}=\\delta_{o_1}h_2\" width=\"230.12\" height=\"69.54\" style=\"width:230.12px;height:69.54px;aspect-ratio:230.12/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.33px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fd02f5bab6bb789a.svg\"><img class=\"math display-math\" src=\"assets/equations/06ed406edd749bf9.svg\" alt=\"g_{1,2}^{(2)}=(-0.099059551)\\times(0.731058579)\\approx -0.072418335\" width=\"593.74\" height=\"36.54\" style=\"width:593.74px;height:36.54px;aspect-ratio:593.74/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/66e7552de1ba0f15.svg\"><img class=\"math display-math\" src=\"assets/equations/fd5e1c3ecdebae0c.svg\" alt=\"W^{(2)}_{1,2,\\mathrm{new}}=0.25-0.5(-0.072418335)\\approx 0.286209167\" width=\"547.39\" height=\"36.54\" style=\"width:547.39px;height:36.54px;aspect-ratio:547.39/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4 hidden deltas.</strong> A hidden unit can influence EVERY connected output, so add those paths BEFORE multiplying by the hidden activation derivative.</p>","<p><strong>Hidden 1 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.099059551</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.024764888</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.024764888</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/486b61a3d9f85a8a.svg\"><img class=\"math display-math\" src=\"assets/equations/b990515cad5dba89.svg\" alt=\"C_1=(0.25)\\times(-0.099059551)\\approx -0.024764888\" width=\"500.59\" height=\"24.43\" style=\"width:500.59px;height:24.43px;aspect-ratio:500.59/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d708f3df447c37c4.svg\"><img class=\"math display-math\" src=\"assets/equations/786870ca2f319d3c.svg\" alt=\"\\text{Sum}=C_1\\approx -0.024764888\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/faa954804a7ac56f.svg\"><img class=\"math display-math\" src=\"assets/equations/efc565ce467804a9.svg\" alt=\"\\delta_{h_1} = -0.024764888 \\times  0.196611933 = -0.004869072\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p><strong>Hidden 2 downstream contribution:</strong></p>","<p>Calculate each outgoing path using the <strong>old</strong> outgoing weight and that output&#x27;s delta.</p>","<figure class=\"learning-visual lv-paths\" data-visual=\"paths\"><figcaption class=\"lv-title\">Several output paths meet at this hidden neuron</figcaption><div class=\"lv-paths\"><div class=\"lv-path\"><span class=\"lv-path-tag\">Output 1</span><div class=\"lv-flow\"><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Output delta</span><strong class=\"lv-value\">−0.099059551</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old outgoing weight</span><strong class=\"lv-value\">0.25</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Path contribution</span><strong class=\"lv-value\">−0.024764888</strong></div></div></div></div><div class=\"lv-merge\"><span aria-hidden=\"true\">↓</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Add every path contribution</span><strong class=\"lv-value\">−0.024764888</strong><span class=\"lv-detail\">Then multiply by the hidden activation derivative.</span></div></div><p class=\"lv-caption\">Multiply within each path. Add the resulting contributions at the shared hidden neuron.</p></figure>","<p><strong>Contribution from output 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.85px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/486b61a3d9f85a8a.svg\"><img class=\"math display-math\" src=\"assets/equations/b990515cad5dba89.svg\" alt=\"C_1=(0.25)\\times(-0.099059551)\\approx -0.024764888\" width=\"500.59\" height=\"24.43\" style=\"width:500.59px;height:24.43px;aspect-ratio:500.59/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Accumulate the contributions, then apply the hidden activation derivative below.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d708f3df447c37c4.svg\"><img class=\"math display-math\" src=\"assets/equations/786870ca2f319d3c.svg\" alt=\"\\text{Sum}=C_1\\approx -0.024764888\" width=\"288.80\" height=\"20.89\" style=\"width:288.80px;height:20.89px;aspect-ratio:288.80/20.89\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:210.93px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c9f11eb5cc7cb0d3.svg\"><img class=\"math display-math\" src=\"assets/equations/569e06b7bb3c113c.svg\" alt=\"\\delta_{h_2} = -0.024764888 \\times  0.196611933 = -0.004869072\" width=\"550.32\" height=\"23.78\" style=\"width:550.32px;height:23.78px;aspect-ratio:550.32/23.78\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5 input weights.</strong> Multiply the hidden delta by the corresponding raw input, not by the hidden output.</p>","<p><strong>x1 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x1 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cb514e27c4d52804.svg\" alt=\"g_{1,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,1}}=\\delta_{h_1}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9759c3655229ab0e.svg\"><img class=\"math display-math\" src=\"assets/equations/e290def3a1c4ea90.svg\" alt=\"g_{1,1}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c3d90c909dab8209.svg\"><img class=\"math display-math\" src=\"assets/equations/a169e16b705d6d2b.svg\" alt=\"W^{(1)}_{1,1,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h1:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h1</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x2 → h1</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a7e2552eb055cb6f.svg\" alt=\"g_{1,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{1,2}}=\\delta_{h_1}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3a5cd9a960e8e0d8.svg\"><img class=\"math display-math\" src=\"assets/equations/ebfca408333d760d.svg\" alt=\"g_{1,2}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/057d087cc10bb2a8.svg\"><img class=\"math display-math\" src=\"assets/equations/da0b9b9064b8dcd6.svg\" alt=\"W^{(1)}_{1,2,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x1 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x1 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x1</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x1 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d8f0b089bd0fe450.svg\" alt=\"g_{2,1}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,1}}=\\delta_{h_2}x_1\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd47a26ddf1d4480.svg\"><img class=\"math display-math\" src=\"assets/equations/e99b8cf0ca1131d6.svg\" alt=\"g_{2,1}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5614079c42cc22b4.svg\"><img class=\"math display-math\" src=\"assets/equations/8fd73e44677515a6.svg\" alt=\"W^{(1)}_{2,1,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p><strong>x2 → h2:</strong></p>","<figure class=\"learning-visual lv-connection\" data-visual=\"connection\"><figcaption class=\"lv-title\">The calculation on x2 → h2</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Sending input</span><strong class=\"lv-value\">1</strong><span class=\"lv-detail\">x2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">×</span><div class=\"lv-card lv-gradient\"><span class=\"lv-label\">Receiving delta</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">δ at h2</span></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Connection gradient</span><strong class=\"lv-value\">−0.004869072</strong><span class=\"lv-detail\">x2 → h2</span></div></div><div class=\"lv-update\"><span class=\"lv-label\">Now update this weight</span><div class=\"lv-update-values\"><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Old weight</span><strong class=\"lv-value\">0.5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">New weight</span><strong class=\"lv-value\">0.502434536</strong></div></div><p>Subtract η × gradient = <b>−0.002434536</b>. This weight <b>increases</b>.</p></div><p class=\"lv-caption\">The sending value and receiving delta have different roles. All deltas still use the original forward-pass weights.</p></figure>","<p>The receiving neuron supplies the delta; the sending neuron supplies the input value.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5ce6325e440d113.svg\" alt=\"g_{2,2}^{(1)}=\\frac{\\partial L}{\\partial W^{(1)}_{2,2}}=\\delta_{h_2}x_2\" width=\"231.60\" height=\"69.54\" style=\"width:231.60px;height:69.54px;aspect-ratio:231.60/69.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:75.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d63a8ff35a6906b2.svg\"><img class=\"math display-math\" src=\"assets/equations/4d0ac3ffd181b903.svg\" alt=\"g_{2,2}^{(1)}=(-0.004869072)\\times(1)\\approx -0.004869072\" width=\"476.99\" height=\"36.54\" style=\"width:476.99px;height:36.54px;aspect-ratio:476.99/36.54\" loading=\"lazy\"></picture></div>","<p>Apply the learning rate to this gradient and subtract the result from the old weight.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:114.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bfabbdcd726cbd9c.svg\"><img class=\"math display-math\" src=\"assets/equations/9733a71bb8ca6e2e.svg\" alt=\"W^{(1)}_{2,2,\\mathrm{new}}=0.5-0.5(-0.004869072)\\approx 0.502434536\" width=\"535.17\" height=\"36.54\" style=\"width:535.17px;height:36.54px;aspect-ratio:535.17/36.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6 bias updates.</strong> 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.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c94badc259c5a62b.svg\"><img class=\"math display-math\" src=\"assets/equations/0aa5e626ccf3c903.svg\" alt=\"b_{h_1,\\mathrm{new}}=0-0.5(-0.004869072)=0.002434536\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2b6bc6b29544f77.svg\"><img class=\"math display-math\" src=\"assets/equations/594dcb090f7d4418.svg\" alt=\"b_{h_2,\\mathrm{new}}=0-0.5(-0.004869072)=0.002434536\" width=\"498.99\" height=\"25.35\" style=\"width:498.99px;height:25.35px;aspect-ratio:498.99/25.35\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:228.09px;--narrow-height:103.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55595ef27eaeb48f.svg\"><img class=\"math display-math\" src=\"assets/equations/8a047fabd725efcd.svg\" alt=\"b_{o_1,\\mathrm{new}}=0-0.5(-0.099059551)=0.049529775\" width=\"497.42\" height=\"25.35\" style=\"width:497.42px;height:25.35px;aspect-ratio:497.42/25.35\" loading=\"lazy\"></picture></div>","<p>These 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.</p>","<p><strong>Requested values: </strong> input weight <strong>0.502434536</strong>, output weight <strong>0.286209167</strong>, output bias <strong>0.049529775</strong>. Other supplied inputs produce different correct conditional results.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s4","search":"Rehearsal Q2a **Question (10 marks).** A 2 → 2 → 1 sigmoid network has all four input-to-hidden weights 0.5, both hidden-to-output weights 0.25, hidden and output biases 0, and target 1. Perform forward and backward passes to update the x₁ → h₁ weight, h₁ → output weight and output bias at η = 0.5. The paper does not state the numerical inputs or loss.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nArchitecture 2 → 2 → 1; every neuron uses sigmoid.\n\nAll four input-to-hidden weights = 0.5; both hidden-to-output weights = 0.25.\n\nAll biases = 0; target = 1; η = 0.5.\n\nThe paper omits inputs and loss: this worked solution explicitly assumes x = [1,1] and half squared loss.\n\n### To find\n\nCalculate the forward pass, then gradients and updates for x₁→h₁, h₁→output and the output bias.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**Half summed squared loss.** This loss convention takes one-half of the sum of squared prediction errors. Use it when the question specifies it, or explicitly state it as an assumption when the paper omits the loss. Differentiating cancels the factor one-half against the square derivative.\n\noⱼ = output j; yⱼ = target j; L = half summed squared loss under the stated or explicitly assumed convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Half aur square ka 2 cancel: output derivative = prediction − target.\n\n**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).\n\nz = preactivation; p = sigmoid output; e is the exponential base, not a prediction error in this formula.\n\n\n\n\n\n**Yaad rakhne ka cue:** Sigmoid output p; uska slope p × (1−p).\n\n**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.\n\nδ (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.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Receiving delta × sending value = us connection ka gradient.\n\n### Solution — step by step\n\n\n\n\n**Assumptions: ** use x = [1,1] and half squared loss. The paper permits suitable assumptions and its key also introduces assumed inputs. There is no unique numerical result without them.\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Step 2 loss convention.** This worked solution uses half summed squared loss, L = ½Σ(o − y)². Follow the loss specified in the question; where none is supplied, this is an explicit assumption.\nPrediction minus target = [-0.409621743]. Squared errors = [0.167789972]. Half-sum squared loss = 0.083894986; mean squared error = 0.167789972. These are different unless the number of output components makes the"},{"title":"Rehearsal Q2b","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain how ResNet skip connections influence gradient flow, feature reuse and vanishing gradients. Compare InceptionNet and AlexNet learning and feature extraction.</p>","<p><strong>Complete worked answer.</strong></p>","<p>A residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The shortcut adds the input to the learned residual before the next stage\"><img src=\"assets/figures/residual.svg\" alt=\"The shortcut adds the input to the learned residual before the next stage\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The shortcut adds the input to the learned residual before the next stage <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/69be13fbc705ad29.svg\" alt=\"\\frac{\\partial L}{\\partial x}=\\frac{\\partial L}{\\partial y}\\left(\\frac{\\partial F}{\\partial x}+I\\right)\" width=\"236.06\" height=\"58.62\" style=\"width:236.06px;height:58.62px;aspect-ratio:236.06/58.62\" loading=\"lazy\"></div>","<p>The identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.</p>","<p>Elementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].</p>","<p>An Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/inception.svg\" aria-label=\"Enlarge diagram: Parallel branches preserve height and width then concatenate channels\"><img src=\"assets/figures/inception.svg\" alt=\"Parallel branches preserve height and width then concatenate channels\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>Parallel branches preserve height and width then concatenate channels <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>A 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.</p>","<p>For H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet&#x27;s sequential kernels, Inception explicitly combines local and larger-scale features within one module.</p>","<p>AlexNet learns features along a mainly sequential stack of convolutional layers. Inception learns several spatial scales in parallel within a module and combines their channels. Both learn filter weights through backpropagation; their structural organization differs.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s5","search":"Rehearsal Q2b **Question (10 marks).** Explain how ResNet skip connections influence gradient flow, feature reuse and vanishing gradients. Compare InceptionNet and AlexNet learning and feature extraction.\n\n**Complete worked answer.**\nA residual block learns a residual mapping F(x) and adds the input through a shortcut: y = F(x)+x, followed by an activation when the block design specifies one. A plain block without the shortcut outputs F(x). If F(x) becomes zero, the residual block can still pass x forward.\n\n\nThe identity term gives a direct gradient path. This helps optimize very deep networks and reduces the burden of learning an identity mapping through many nonlinear layers. Features can be reused or refined instead of being completely reconstructed by every block. Residual connections address optimization degradation and can help gradient flow, although they do not guarantee that vanishing gradients can never occur anywhere in the network.\nElementwise addition requires compatible shapes. If channel counts or spatial sizes differ, use a suitable projection shortcut, often a 1 × 1 convolution with the required stride. A shortcut is an addition, not channel concatenation. Example: x = [2,−1] and F(x) = [0.5,0.2] give y = [2.5,−0.8]; a subsequent ReLU gives [2.5,0]. Without the shortcut the preactivation output would be [0.5,0.2].\nAn Inception module captures features at multiple scales in parallel. A typical module has a 1 × 1 branch, a 1 × 1 reduction followed by 3 × 3 convolution, a 1 × 1 reduction followed by 5 × 5 convolution, and a pooling branch followed by 1 × 1 projection. Padding and strides preserve compatible spatial sizes so branch outputs can be concatenated along the channel axis.\n\nA 1 × 1 convolution mixes input channels at each position. With fewer output channels, it forms a bottleneck before an expensive larger kernel. ReLU following it adds nonlinearity. This reduces the number of input channels processed by 3 × 3 or 5 × 5 kernels while preserving useful learned combinations.\nFor H × W spatial size, Cin input channels and Cout output filters, a K × K convolution uses H × W × Cin × Cout × K² multiply-accumulates when the output spatial size stays H × W. A bottleneck changes the calculation to H × W × Cin × r + H × W × r × Cout × K². A multiply-accumulate is counted as one MAC here; some FLOP conventions count it as two operations. The benefit depends on the selected bottleneck width r. Compared with AlexNet's sequential kernels, Inception explicitly combines local and larger-scale features within one module.\nAlexNet learns features along a mainly sequential stack of convolutional layers. Inception learns several spatial scales in parallel within a module and combines their channels. Both learn filter weights through backpropagation; their structural organization differs.\n"},{"title":"Rehearsal Q3a","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Train one epoch of a single perceptron with η = 1, initial weights and bias 0, threshold 0, on [−1,1,−1] → 0, [−1,1,1] → 1, [1,−1,1] → 1, [−1,1,1] → 1. Then map biological-neuron components to artificial-neuron components.</p>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Initial weights and bias = 0; η = 1; threshold = 0.</p>","<p>Samples in order: [−1,1,−1]→0; [−1,1,1]→1; [1,−1,1]→1; [−1,1,1]→1.</p>","<p>Use output 1 when net &gt; 0 and 0 otherwise, matching the supplied key; one epoch.</p>","<h3>To find</h3>","<p>Process each sample in order, carrying updated weights forward, and report final weights/bias.</p>","<h3>Formula — which one and why</h3>","<p><strong>Perceptron learning rule.</strong> Evaluate the stated threshold, compare the predicted class with its target, then correct weights and bias. The next sample uses the newly updated parameters.</p>","<p>t = target; o = thresholded output; η = learning rate; xᵢ = input i. Binary and bipolar output conventions must follow the question.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1fccc40e029a1d4e.svg\" alt=\"w_i^{\\mathrm{new}}=w_i+\\eta(t-o)x_i\" width=\"240.87\" height=\"24.55\" style=\"width:240.87px;height:24.55px;aspect-ratio:240.87/24.55\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/58dd8fcb5fcd562f.svg\" alt=\"b^{\\mathrm{new}}=b+\\eta(t-o)\" width=\"196.89\" height=\"24.43\" style=\"width:196.89px;height:24.43px;aspect-ratio:196.89/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Prediction nikalo; target−prediction se correction nikalo.</p>","<h3>Solution — step by step</h3>","<p><strong>State the threshold rule.</strong> Use binary output 1 if z&gt;0 and 0 otherwise, matching the associated key. Update Δw = η(t−o)x and Δb = η(t−o), with η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.</p>","<h3>Epoch 1, sample 1</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, -1], target = 0.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (0 × -1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [-1, 1, -1] = [0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 0, 0], new b = 0.</p>","<h3>Epoch 1, sample 2</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (0 × 1) + (0) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [-1, 1, 1] = [-1, 1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [-1, 1, 1], new b = 1.</p>","<h3>Epoch 1, sample 3</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [1, -1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (-1 × 1) + (1 × -1) + (1 × 1) + (1) = 0</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 0.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 1</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 1 × [1, -1, 1] = [1, -1, 1]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 1.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 0, 2], new b = 2.</p>","<h3>Epoch 1, sample 4</h3>","<p class=\"worked-step\"><strong>Step 1: copy this sample and target.</strong></p>","<p>x = [-1, 1, 1], target = 1.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the current net.</strong></p>","<p>z = (0 × -1) + (0 × 1) + (2 × 1) + (2) = 4</p>","<p class=\"worked-step\"><strong>Step 3: apply the threshold.</strong></p>","<p>output = 1.</p>","<p class=\"worked-step\"><strong>Step 4: calculate the update multiplier.</strong></p>","<p>Update multiplier = 0</p>","<p class=\"worked-step\"><strong>Step 5: calculate all weight changes.</strong></p>","<p>Δw = 0 × [-1, 1, 1] = [0, 0, 0]</p>","<p class=\"worked-step\"><strong>Step 6: calculate the bias change.</strong></p>","<p>Δb = 0.</p>","<p class=\"worked-step\"><strong>Step 7: carry the updated parameters forward.</strong></p>","<p>New w = [0, 0, 2], new b = 2.</p>","<p><strong>Final after exactly the requested epochs: </strong> w = <strong>[0, 0, 2]</strong>, b = <strong>2</strong>. A finite number of requested epochs does not itself prove convergence or correct classification of every sample.</p>","<p>Biological dendrites receive signals, synapses influence connection strength, the cell body integrates information, and an axon carries an output signal. In the artificial analogy, inputs represent received signals, weights represent connection strengths, the weighted sum plus bias performs aggregation, and an activation function produces an output. The bias shifts the firing threshold. This is a simplified computational analogy, not a complete biological model.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/neuron.svg\" aria-label=\"Enlarge diagram: The artificial neuron multiplies each input by a weight then adds bias and activates\"><img src=\"assets/figures/neuron.svg\" alt=\"The artificial neuron multiplies each input by a weight then adds bias and activates\" width=\"960\" height=\"365\" loading=\"lazy\"></button><figcaption>The artificial neuron multiplies each input by a weight then adds bias and activates <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s6","search":"Rehearsal Q3a **Question (10 marks).** Train one epoch of a single perceptron with η = 1, initial weights and bias 0, threshold 0, on [−1,1,−1] → 0, [−1,1,1] → 1, [1,−1,1] → 1, [−1,1,1] → 1. Then map biological-neuron components to artificial-neuron components.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInitial weights and bias = 0; η = 1; threshold = 0.\n\nSamples in order: [−1,1,−1]→0; [−1,1,1]→1; [1,−1,1]→1; [−1,1,1]→1.\n\nUse output 1 when net > 0 and 0 otherwise, matching the supplied key; one epoch.\n\n### To find\n\nProcess each sample in order, carrying updated weights forward, and report final weights/bias.\n\n### Formula — which one and why\n\n**Perceptron learning rule.** Evaluate the stated threshold, compare the predicted class with its target, then correct weights and bias. The next sample uses the newly updated parameters.\n\nt = target; o = thresholded output; η = learning rate; xᵢ = input i. Binary and bipolar output conventions must follow the question.\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Prediction nikalo; target−prediction se correction nikalo.\n\n### Solution — step by step\n\n\n\n\n**State the threshold rule.** Use binary output 1 if z>0 and 0 otherwise, matching the associated key. Update Δw = η(t−o)x and Δb = η(t−o), with η = 1. A different rule at zero can change the learning trajectory. Write your convention explicitly.\n### Epoch 1, sample 1\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, -1], target = 0.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (0 × -1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 0\n\n**Step 5: calculate all weight changes.**\n\nΔw = 0 × [-1, 1, -1] = [0, 0, 0]\n\n**Step 6: calculate the bias change.**\n\nΔb = 0.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 0, 0], new b = 0.\n\n\n### Epoch 1, sample 2\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (0 × 1) + (0) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [-1, 1, 1] = [-1, 1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [-1, 1, 1], new b = 1.\n\n\n### Epoch 1, sample 3\n\n**Step 1: copy this sample and target.**\n\nx = [1, -1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (-1 × 1) + (1 × -1) + (1 × 1) + (1) = 0\n\n**Step 3: apply the threshold.**\n\noutput = 0.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 1\n\n**Step 5: calculate all weight changes.**\n\nΔw = 1 × [1, -1, 1] = [1, -1, 1]\n\n**Step 6: calculate the bias change.**\n\nΔb = 1.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 0, 2], new b = 2.\n\n\n### Epoch 1, sample 4\n\n**Step 1: copy this sample and target.**\n\nx = [-1, 1, 1], target = 1.\n\n**Step 2: calculate the current net.**\n\nz = (0 × -1) + (0 × 1) + (2 × 1) + (2) = 4\n\n**Step 3: apply the threshold.**\n\noutput = 1.\n\n**Step 4: calculate the update multiplier.**\n\nUpdate multiplier = 0\n\n**Step 5: calculate all weight changes.**\n\nΔw = 0 × [-1, 1, 1] = [0, 0, 0]\n\n**Step 6: calculate the bias change.**\n\nΔb = 0.\n\n**Step 7: carry the updated parameters forward.**\n\nNew w = [0, 0, 2], new b = 2.\n\n\n**Final after exactly the requested epochs: ** w = **[0, 0, 2]**, b = **2**. A finite number of requested epochs does not itself prove converge"},{"title":"Rehearsal Q3b","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Design face-recognition attendance using a CNN when the supplied dataset is very small. Discuss ways to address the issue and explain transfer learning.</p>","<p><strong>Complete worked answer.</strong></p>","<p>Transfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.</p>","<p>1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.</p>","<p>2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.</p>","<p>3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.</p>","<p>4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.</p>","<p>5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.</p>","<p>6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.</p>","<p>Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s7","search":"Rehearsal Q3b **Question (10 marks).** Design face-recognition attendance using a CNN when the supplied dataset is very small. Discuss ways to address the issue and explain transfer learning.\n\n**Complete worked answer.**\nTransfer learning reuses features learned on a source task to solve a related target task. For a small face-attendance dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.\n1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. For evaluation on enrolled identities, use different capture sessions in each split.\n2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.\n3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.\n4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.\n5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.\n6. Evaluate on held-out sessions, inspect per-class errors, and reject low-confidence/unregistered cases if the attendance design requires that behavior.\nFeature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.\n"},{"title":"Rehearsal Q4a","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> For N = 1,000 samples and batch size 100, count weight updates per epoch for batch GD, SGD and mini-batch GD. For J(θ) = 0.5 θ², η = 0.1, momentum 0.9, v₀ = 0, θ₀ = 1, compute two momentum iterations. List the required momentum-training hyperparameters.</p>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>N = 1,000; mini-batch size = 100.</p>","<p>J(θ) = 0.5θ²; θ₀ = 1; v₀ = 0; η = 0.1; β = 0.9.</p>","<p>Use signed velocity.</p>","<h3>To find</h3>","<p>Count updates per epoch for batch, stochastic and mini-batch GD; then perform two momentum iterations.</p>","<h3>Formula — which one and why</h3>","<p><strong>Number of updates.</strong> An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.</p>","<p>N = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89b7eb4a772465f4.svg\" alt=\"U_{\\mathrm{batch}}=E\" width=\"112.21\" height=\"20.54\" style=\"width:112.21px;height:20.54px;aspect-ratio:112.21/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0eab2be6df842149.svg\" alt=\"U_{\\mathrm{SGD}}=EN\" width=\"128.03\" height=\"20.74\" style=\"width:128.03px;height:20.74px;aspect-ratio:128.03/20.74\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f9d09d1e5734cccd.svg\" alt=\"U_{\\mathrm{keep}}=E\\left\\lceil\\frac NB\\right\\rceil\" width=\"169.05\" height=\"58.62\" style=\"width:169.05px;height:58.62px;aspect-ratio:169.05/58.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf7e65981e0892c7.svg\" alt=\"U_{\\mathrm{drop}}=E\\left\\lfloor\\frac NB\\right\\rfloor\" width=\"169.60\" height=\"58.62\" style=\"width:169.60px;height:58.62px;aspect-ratio:169.60/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Kitne batches process hue, utne updates hue.</p>","<p><strong>Momentum with signed velocity.</strong> Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.</p>","<p>v = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehle velocity banao; phir old parameter mein velocity jodo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count full-batch updates.</strong></p>","<p>All 1,000 samples contribute to one update: 1 per epoch.</p>","<p class=\"worked-step\"><strong>Step 2: count stochastic updates.</strong></p>","<p>One update per sample: 1,000 per epoch.</p>","<p class=\"worked-step\"><strong>Step 3: count mini-batches.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eee877d70ea14115.svg\" alt=\"1000/100=10\" width=\"154.75\" height=\"24.43\" style=\"width:154.75px;height:24.43px;aspect-ratio:154.75/24.43\" loading=\"lazy\"></div>","<p>Use signed velocity vₜ = βvₜ₋₁−ηgₜ and θₜ = θₜ₋₁+vₜ; g(θ) = θ.</p>","<h3>Momentum iteration 1</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the gradient at the current parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/228fc3b3267b30c9.svg\" alt=\"g_1=1\" width=\"67.12\" height=\"21.29\" style=\"width:67.12px;height:21.29px;aspect-ratio:67.12/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the previous displacement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4351a4e3442a023e.svg\" alt=\"0.9(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the current gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7cde65d80bbbce53.svg\" alt=\"0.1(1)=0.1\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: combine to obtain the new signed velocity.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2c6e04e58352c2ce.svg\" alt=\"v_1=0-0.1=-0.1\" width=\"211.24\" height=\"19.94\" style=\"width:211.24px;height:19.94px;aspect-ratio:211.24/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add new velocity to the actual old parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e96386ed9eb17f75.svg\" alt=\"\\theta_1=1+(-0.1)=0.9\" width=\"229.86\" height=\"24.43\" style=\"width:229.86px;height:24.43px;aspect-ratio:229.86/24.43\" loading=\"lazy\"></div>","<h3>Momentum iteration 2</h3>","<p class=\"worked-step\"><strong>Step 1: evaluate the gradient at the current parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc4532aff9a9a2da.svg\" alt=\"g_2=0.9\" width=\"86.13\" height=\"21.29\" style=\"width:86.13px;height:21.29px;aspect-ratio:86.13/21.29\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the previous displacement.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8fd30bce103b617.svg\" alt=\"0.9(-0.1)=-0.09\" width=\"195.51\" height=\"24.43\" style=\"width:195.51px;height:24.43px;aspect-ratio:195.51/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: scale the current gradient.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bf93339d0945c688.svg\" alt=\"0.1(0.9)=0.09\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: combine to obtain the new signed velocity.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f18fc7f5dc715d05.svg\" alt=\"v_2=-0.09-0.09=-0.18\" width=\"285.91\" height=\"19.94\" style=\"width:285.91px;height:19.94px;aspect-ratio:285.91/19.94\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add new velocity to the actual old parameter.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4502fcbdb27f5deb.svg\" alt=\"\\theta_2=0.9+(-0.18)=0.72\" width=\"273.30\" height=\"24.43\" style=\"width:273.30px;height:24.43px;aspect-ratio:273.30/24.43\" loading=\"lazy\"></div>","<p><strong>Hyperparameters: </strong> the basic momentum update has two main tunable coefficients, learning rate η and momentum β. A full training run also requires choices such as epochs and batch size (one for literal SGD), and may include a learning-rate schedule. There is no universal single count for all training configurations; state what is counted. Initial θ and v are initialization values, not learned outputs of the first update.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s8","search":"Rehearsal Q4a **Question (10 marks).** For N = 1,000 samples and batch size 100, count weight updates per epoch for batch GD, SGD and mini-batch GD. For J(θ) = 0.5 θ², η = 0.1, momentum 0.9, v₀ = 0, θ₀ = 1, compute two momentum iterations. List the required momentum-training hyperparameters.\n\n**Complete worked answer.**\n\n\n\n### Given\n\nN = 1,000; mini-batch size = 100.\n\nJ(θ) = 0.5θ²; θ₀ = 1; v₀ = 0; η = 0.1; β = 0.9.\n\nUse signed velocity.\n\n### To find\n\nCount updates per epoch for batch, stochastic and mini-batch GD; then perform two momentum iterations.\n\n### Formula — which one and why\n\n**Number of updates.** An update occurs after one processed batch. Full-batch GD uses one batch per epoch; SGD uses one sample per batch. Mini-batches need a stated remainder policy.\n\nN = dataset size; B = batch size; E = number of epochs. Ceiling rounds upward to include a smaller final batch; floor drops it.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Kitne batches process hue, utne updates hue.\n\n**Momentum with signed velocity.** Combine the retained old displacement with the current downhill correction, then add that signed displacement to the old parameter.\n\nv = signed velocity/displacement; β = momentum coefficient; g = current gradient; η = learning rate. This convention uses +v in the parameter update.\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehle velocity banao; phir old parameter mein velocity jodo.\n\n### Solution — step by step\n\n\n\n\n\n\n**Step 1: count full-batch updates.**\n\nAll 1,000 samples contribute to one update: 1 per epoch.\n\n**Step 2: count stochastic updates.**\n\nOne update per sample: 1,000 per epoch.\n\n**Step 3: count mini-batches.**\n\n\n\n\n\n\n\n\nUse signed velocity vₜ = βvₜ₋₁−ηgₜ and θₜ = θₜ₋₁+vₜ; g(θ) = θ.\n### Momentum iteration 1\n\n**Step 1: evaluate the gradient at the current parameter.**\n\n\n\n\n\n\n\n**Step 2: retain the previous displacement.**\n\n\n\n\n\n\n\n**Step 3: scale the current gradient.**\n\n\n\n\n\n\n\n**Step 4: combine to obtain the new signed velocity.**\n\n\n\n\n\n\n\n**Step 5: add new velocity to the actual old parameter.**\n\n\n\n\n\n\n\n\n### Momentum iteration 2\n\n**Step 1: evaluate the gradient at the current parameter.**\n\n\n\n\n\n\n\n**Step 2: retain the previous displacement.**\n\n\n\n\n\n\n\n**Step 3: scale the current gradient.**\n\n\n\n\n\n\n\n**Step 4: combine to obtain the new signed velocity.**\n\n\n\n\n\n\n\n**Step 5: add new velocity to the actual old parameter.**\n\n\n\n\n\n\n\n\n**Hyperparameters: ** the basic momentum update has two main tunable coefficients, learning rate η and momentum β. A full training run also requires choices such as epochs and batch size (one for literal SGD), and may include a learning-rate schedule. There is no universal single count for all training configurations; state what is counted. Initial θ and v are initialization values, not learned outputs of the first update.\n"},{"title":"Rehearsal Q4b","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Define vanishing gradients in RNNs and explain why they occur. Use “The dogs barked at the thief and … were appreciated” to discuss long context. Explain LSTM forgetting/retention, then compute the retained contribution for f = [0.1,0.9], Cprevious = [2,1].</p>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Forget-gate outputs f = [0.1,0.9]; old cell = [2,1].</p>","<p>No input gate or candidate is supplied.</p>","<h3>To find</h3>","<p>Explain forgetting/retention and calculate the retained old-cell part only.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM retained old memory.</strong> Multiply each old cell value by its corresponding forget-gate value. This gives only the old contribution, not the complete new cell.</p>","<p>f = activated forget gate; C_old = previous cell state; ⊙ means multiply matching entries.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/35cedc4f6bc20c8a.svg\" alt=\"C_{\\mathrm{retained}}=f\\odot C_{\\mathrm{old}}\" width=\"199.43\" height=\"22.24\" style=\"width:199.43px;height:22.24px;aspect-ratio:199.43/22.24\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Forget gate × old cell = bacha hua purana hissa.</p>","<h3>Solution — step by step</h3>","<p>Backpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.</p>","<p>1. Initialize the hidden state and run the forward recurrence from the first input to the last.</p>","<p>2. Compute the specified output loss, at the final step or across several steps.</p>","<p>3. Start from the last loss and propagate derivatives backwards through output and hidden operations.</p>","<p>4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.</p>","<p>5. Sum all uses of each shared weight before applying the optimizer update.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:371.04px;--narrow-height:147.90px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fdf1ee48fdcfd79f.svg\"><img class=\"math display-math\" src=\"assets/equations/43466db031266f9c.svg\" alt=\"\\delta_t=(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1})\\odot(1-h_t^2),\\quad \\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T}\" width=\"623.72\" height=\"62.51\" style=\"width:623.72px;height:62.51px;aspect-ratio:623.72/62.51\" loading=\"lazy\"></picture></div>","<p>The tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/rnn.svg\" aria-label=\"Enlarge diagram: BPTT follows this unrolled network backwards and sums gradients of shared weights\"><img src=\"assets/figures/rnn.svg\" alt=\"BPTT follows this unrolled network backwards and sums gradients of shared weights\" width=\"1060\" height=\"475\" loading=\"lazy\"></button><figcaption>BPTT follows this unrolled network backwards and sums gradients of shared weights <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The plural subject “dogs” must remain represented across intervening words. A vanilla RNN may fail to learn that dependency when early gradients are weak; it is not guaranteed to fail on every such sentence. In an LSTM, forget components close to 1 retain relevant subject information along the cell path.</p>","<p class=\"worked-step\"><strong>Step 1: retain the first old-cell component.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/687125898d5f60b7.svg\" alt=\"0.1(2)=0.2\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: retain the second old-cell component.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ba3003dba6d22d16.svg\" alt=\"0.9(1)=0.9\" width=\"126.26\" height=\"24.43\" style=\"width:126.26px;height:24.43px;aspect-ratio:126.26/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: assemble the retained old-cell contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/813a6e1d025fa14c.svg\" alt=\"f\\odot C_{\\mathrm{old}}=[0.2,0.9]\" width=\"205.34\" height=\"24.43\" style=\"width:205.34px;height:24.43px;aspect-ratio:205.34/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> [0.2,0.9] is only retained old content. The input gate and candidate are missing, so the complete updated cell cannot be calculated.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s9","search":"Rehearsal Q4b **Question (10 marks).** Define vanishing gradients in RNNs and explain why they occur. Use “The dogs barked at the thief and … were appreciated” to discuss long context. Explain LSTM forgetting/retention, then compute the retained contribution for f = [0.1,0.9], Cprevious = [2,1].\n\n**Complete worked answer.**\n\n\n\n### Given\n\nForget-gate outputs f = [0.1,0.9]; old cell = [2,1].\n\nNo input gate or candidate is supplied.\n\n### To find\n\nExplain forgetting/retention and calculate the retained old-cell part only.\n\n### Formula — which one and why\n\n**LSTM retained old memory.** Multiply each old cell value by its corresponding forget-gate value. This gives only the old contribution, not the complete new cell.\n\nf = activated forget gate; C_old = previous cell state; ⊙ means multiply matching entries.\n\n\n\n**Yaad rakhne ka cue:** Forget gate × old cell = bacha hua purana hissa.\n\n### Solution — step by step\n\n\n\n\nBackpropagation through time trains an RNN by treating its time-unrolled computations as a deep computational graph.\n1. Initialize the hidden state and run the forward recurrence from the first input to the last.\n2. Compute the specified output loss, at the final step or across several steps.\n3. Start from the last loss and propagate derivatives backwards through output and hidden operations.\n4. At each earlier state, add the direct output-loss contribution and the contribution arriving from future states.\n5. Sum all uses of each shared weight before applying the optimizer update.\n\nThe tanh derivative is 1−h². Repeated multiplication by recurrent weights and activation derivatives may shrink gradients toward zero or amplify them greatly. Early words then receive a weak learning signal or updates become unstable. Gated architectures help long-context learning; suitable initialization and learning rates help training; clipping limits exploding gradients. Truncated BPTT restricts the backward time window to reduce computation and memory. It does not mean creating independent weights for each time step.\n\nThe plural subject “dogs” must remain represented across intervening words. A vanilla RNN may fail to learn that dependency when early gradients are weak; it is not guaranteed to fail on every such sentence. In an LSTM, forget components close to 1 retain relevant subject information along the cell path.\n**Step 1: retain the first old-cell component.**\n\n\n\n\n\n\n\n**Step 2: retain the second old-cell component.**\n\n\n\n\n\n\n\n**Step 3: assemble the retained old-cell contribution.**\n\n\n\n\n\n\n\n**Final answer:** [0.2,0.9] is only retained old content. The input gate and candidate are missing, so the complete updated cell cannot be calculated.\n"},{"title":"Rehearsal Q5a","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> State the purpose of each LSTM gate. For “Artificial Intelligence has revolutionized every domain. The work force will have to update themselves to remain relevant,” explain a context change. Calculate C and h given i = 0.7, f = 0.4, o = 0.8, candidate = 0.9, Cprevious = 0.5. Why is LSTM more effective than a simple RNN for language modeling?</p>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Activated gate values: i = 0.7,f = 0.4,o = 0.8.</p>","<p>Candidate = 0.9; old cell = 0.5.</p>","<h3>To find</h3>","<p>Explain the context change in the question; calculate the new cell and hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>LSTM cell and hidden state.</strong> Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.</p>","<p>f,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/baccbadbb58af40d.svg\" alt=\"C=f\\odot C_{\\mathrm{old}}+i\\odot\\widetilde C\" width=\"223.75\" height=\"30.29\" style=\"width:223.75px;height:30.29px;aspect-ratio:223.75/30.29\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2bb414a00be2c088.svg\" alt=\"h=o\\odot\\tanh C\" width=\"159.92\" height=\"19.26\" style=\"width:159.92px;height:19.26px;aspect-ratio:159.92/19.26\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Purana rakho + naya lo; phir tanh aur output gate.</p>","<h3>Solution — step by step</h3>","<p>An LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:280.83px;--narrow-height:155.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31dbb5df72a8ba34.svg\"><img class=\"math display-math\" src=\"assets/equations/555b66da5e34fae2.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c),\\quad C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"593.49\" height=\"31.40\" style=\"width:593.49px;height:31.40px;aspect-ratio:593.49/31.40\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/1081d04f622a619e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"494.86\" height=\"24.43\" style=\"width:494.86px;height:24.43px;aspect-ratio:494.86/24.43\" loading=\"lazy\"></picture></div>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: The cell path retains selected old content and adds selected new content\"><img src=\"assets/figures/lstm.svg\" alt=\"The cell path retains selected old content and adds selected new content\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>The cell path retains selected old content and adds selected new content <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>The forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.</p>","<p>In language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.</p>","<p>The second sentence shifts attention toward the workforce while retaining useful prior AI context. Input gates can admit the new subject; forget gates can reduce obsolete details.</p>","<p class=\"worked-step\"><strong>Step 1: retain old memory.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8f3bf24a2e1d90a0.svg\" alt=\"fC_{old}=0.4(0.5)=0.2\" width=\"233.31\" height=\"24.43\" style=\"width:233.31px;height:24.43px;aspect-ratio:233.31/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: admit candidate content.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a48bf51c7d9b9c7.svg\" alt=\"i\\widetilde C=0.7(0.9)=0.63\" width=\"217.08\" height=\"31.40\" style=\"width:217.08px;height:31.40px;aspect-ratio:217.08/31.40\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add the two contributions.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b89883a392a4e3ec.svg\" alt=\"C=0.2+0.63=0.83\" width=\"231.72\" height=\"19.23\" style=\"width:231.72px;height:19.23px;aspect-ratio:231.72/19.23\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: apply tanh to the updated cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6aee7e26a8e96885.svg\" alt=\"\\tanh(0.83)\\approx0.680476006\" width=\"272.89\" height=\"24.43\" style=\"width:272.89px;height:24.43px;aspect-ratio:272.89/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: multiply by the output gate.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.86px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c85eca49bc37b1e7.svg\"><img class=\"math display-math\" src=\"assets/equations/6ea5c9d366d636a3.svg\" alt=\"h=0.8(0.680476006)\\approx0.544380805\" width=\"387.41\" height=\"24.43\" style=\"width:387.41px;height:24.43px;aspect-ratio:387.41/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> C = 0.83 and h ≈ 0.544380805. The supplied gates are already activated; do not apply sigmoid again.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s10","search":"Rehearsal Q5a **Question (10 marks).** State the purpose of each LSTM gate. For “Artificial Intelligence has revolutionized every domain. The work force will have to update themselves to remain relevant,” explain a context change. Calculate C and h given i = 0.7, f = 0.4, o = 0.8, candidate = 0.9, Cprevious = 0.5. Why is LSTM more effective than a simple RNN for language modeling?\n\n**Complete worked answer.**\n\n\n\n### Given\n\nActivated gate values: i = 0.7,f = 0.4,o = 0.8.\n\nCandidate = 0.9; old cell = 0.5.\n\n### To find\n\nExplain the context change in the question; calculate the new cell and hidden state.\n\n### Formula — which one and why\n\n**LSTM cell and hidden state.** Multiply old memory by the forget gate; multiply candidate content by the input gate; add those two contributions. Apply tanh to the new cell and multiply by the output gate.\n\nf,i,o = activated forget/input/output gates; C_old = previous cell; C_tilde = candidate content; C = new cell; h = visible hidden state. ⊙ means elementwise multiplication.\n\n\n\n\n\n**Yaad rakhne ka cue:** Purana rakho + naya lo; phir tanh aur output gate.\n\n### Solution — step by step\n\n\n\n\nAn LSTM contains a cell state C and hidden state h. Sigmoid gates control the fractions of information retained, admitted and exposed; a tanh transform proposes new content.\n\n\n\n\nThe forget gate f near 1 retains old content; near 0 removes it. The input gate i controls candidate admission. The output gate o selects the visible state. The additive cell path helps useful information and training signals travel over longer intervals, especially when forget gates retain relevant components.\nIn language modeling, the cell can retain an earlier subject while intervening words modify other features. When the topic changes, a learned forget gate can reduce obsolete information while the input gate admits new context. These are intuitive interpretations, not numeric gate values derivable from words alone. Exact values require weights, inputs and previous states. LSTMs often learn longer dependencies more effectively than vanilla RNNs, but do not guarantee perfect indefinite memory.\nThe second sentence shifts attention toward the workforce while retaining useful prior AI context. Input gates can admit the new subject; forget gates can reduce obsolete details.\n**Step 1: retain old memory.**\n\n\n\n\n\n\n\n**Step 2: admit candidate content.**\n\n\n\n\n\n\n\n**Step 3: add the two contributions.**\n\n\n\n\n\n\n\n**Step 4: apply tanh to the updated cell.**\n\n\n\n\n\n\n\n**Step 5: multiply by the output gate.**\n\n\n\n\n\n\n\n**Final answer:** C = 0.83 and h ≈ 0.544380805. The supplied gates are already activated; do not apply sigmoid again.\n"},{"title":"Rehearsal Q5b","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain AdaGrad, give its update rule and discuss advantages and disadvantages compared with standard SGD.</p>","<p><strong>Complete worked answer.</strong></p>","<p>AdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p>Frequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.</p>","<p>Example with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.</p>","<p>Advantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s11","search":"Rehearsal Q5b **Question (10 marks).** Explain AdaGrad, give its update rule and discuss advantages and disadvantages compared with standard SGD.\n\n**Complete worked answer.**\nAdaGrad gives each parameter its own effective learning rate based on the sum of its past squared gradients. Start G₀ = 0, choose η and a small positive ε, then apply elementwise:\n\nFrequently updated coordinates accumulate a larger G and take smaller steps. Rarely active coordinates keep a relatively larger effective learning rate, which can be useful for sparse features. The square removes the sign in the accumulator; the unsquared current gradient still determines the direction of the parameter change.\nExample with θ₀ = 1, η = 0.1, gradients 2 then 1 and negligible ε: first G = 4, denominator = 2, change = 0.1 × 2/2 = 0.1, θ₁ = 0.9. Next G = 5, denominator = √5 = 2.236068, change = 0.1/2.236068 = 0.04472136, θ₂ = 0.85527864.\nAdvantages over ordinary SGD include coordinatewise adaptation and usefulness for sparse gradients. Disadvantages include extra accumulator memory and continuously shrinking effective learning rates: G never decreases, so learning may become too slow. AdaGrad still requires a base learning rate and does not guarantee a global minimum. RMSProp addresses indefinite accumulation by replacing the sum with an exponentially weighted average.\n"},{"title":"Rehearsal Q6a","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Calculate every activation shape and trainable-parameter count for: Input 128 × 128 × 3. → Conv K = 3, filters = 16, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 3, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 240 units. → Dense 120 units. → Dense 5 units. Also convolve the input A with the kernel K shown below, valid padding and stride 2.</p>","<figure class=\"learning-visual lv-given\" data-visual=\"given\"><figcaption class=\"lv-title\">Given matrices</figcaption><div class=\"lv-matrix-panels lv-two-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Input A</div><table class=\"lv-matrix\" aria-label=\"Input A\"><caption>Input A</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">Kernel K</div><table class=\"lv-matrix\" aria-label=\"Kernel K\"><caption>Kernel K</caption><tbody><tr><td class=\"\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table></div></div><p class=\"lv-caption\">Stride 2; P = 0 (no padding).</p></figure>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Input 128 × 128 × 3.</p>","<p>Conv K = 3, filters = 16, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Conv K = 3, filters = 32, stride = 1, padding = 0.</p>","<p>Pool K = 2, stride = 2, padding = 0.</p>","<p>Dense 240 units.</p>","<p>Dense 120 units.</p>","<p>Dense 5 units.</p>","<p>Also convolve the input A with the kernel K shown below, valid padding and stride 2.</p>","<h3>To find</h3>","<p>Find every layer shape, its parameter count and the network total. Find every convolution output cell.</p>","<h3>Formula — which one and why</h3>","<p><strong>Complete CNN calculation.</strong> Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.</p>","<p>H,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:232.77px;--narrow-height:136.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cb685a42551287a1.svg\"><img class=\"math display-math\" src=\"assets/equations/ef936ccc7475be1a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P_{\\mathrm{pad}}-K}{S}\\right\\rfloor+1\" width=\"321.47\" height=\"58.62\" style=\"width:321.47px;height:58.62px;aspect-ratio:321.47/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3eea0634c9f3976.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"258.47\" height=\"27.70\" style=\"width:258.47px;height:27.70px;aspect-ratio:258.47/27.70\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c0e2ff46bbfc4867.svg\" alt=\"P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"225.51\" height=\"24.43\" style=\"width:225.51px;height:24.43px;aspect-ratio:225.51/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cd31b9774832f122.svg\" alt=\"P_{\\mathrm{pool}}=P_{\\mathrm{flatten}}=0\" width=\"193.96\" height=\"23.71\" style=\"width:193.96px;height:23.71px;aspect-ratio:193.96/23.71\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Ek layer ka output, next layer ka input; shape aur parameters alag count.</p>","<p><strong>Convolution values.</strong> At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.</p>","<p>X = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Matching cells multiply; sab products add; bias sirf ek baar.</p>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<p>Use output size <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span>, Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.</p>","<h3>Layer-by-layer calculation</h3>","<p>Carry the complete output shape of one layer into the next. Spatial size determines the number of activations; it does not multiply the number of shared convolution parameters.</p>","<h3>Layer 1 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 1: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">128 × 128 × 3</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">16 filters · 3 × 3 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">126 × 126 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">432</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">16</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">448</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>128 × 128 × 3</strong>. Use 16 filters of spatial size 3 × 3, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:223.88px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60bad070a07deb57.svg\"><img class=\"math display-math\" src=\"assets/equations/32d2786097210b6e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{128+2(0)-3}{1}\\right\\rfloor+1=126\" width=\"381.81\" height=\"58.87\" style=\"width:381.81px;height:58.87px;aspect-ratio:381.81/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>126 × 126 × 16</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 3 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd36df36d5f6f027.svg\"><img class=\"math display-math\" src=\"assets/equations/2eb50e4698b8f7ed.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times3\\times16=432\" width=\"330.89\" height=\"23.91\" style=\"width:330.89px;height:23.91px;aspect-ratio:330.89/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc0c940eb69b41c0.svg\" alt=\"N_{\\mathrm{biases}}=16\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe2e71f3a8efffa4.svg\" alt=\"P_1=432+16=448\" width=\"219.13\" height=\"20.36\" style=\"width:219.13px;height:20.36px;aspect-ratio:219.13/20.36\" loading=\"lazy\"></div>","<h3>Layer 2 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 2: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">126 × 126 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">63 × 63 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>126 × 126 × 16</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.26px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/31d9e5cfd413812f.svg\"><img class=\"math display-math\" src=\"assets/equations/3c15021631c4c384.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1=63\" width=\"296.29\" height=\"58.62\" style=\"width:296.29px;height:58.62px;aspect-ratio:296.29/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling acts independently on each channel. The output is <strong>63 × 63 × 16</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<h3>Layer 3 — convolution</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 3: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">63 × 63 × 16</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Convolution</span><strong class=\"lv-value\">32 filters · 3 × 3 · S = 1 · P = 0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">61 × 61 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">4,608</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">32</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">4,640</strong></div></div><p class=\"lv-caption\">Spatial positions share the filter weights. Output depth equals the number of filters.</p></figure>","<p>Input: <strong>63 × 63 × 16</strong>. Use 32 filters of spatial size 3 × 3, stride 1, and padding 0 on each side.</p>","<p><strong>1. Calculate height and width.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.75px;--narrow-height:137.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d1b1c42ec3b8b44b.svg\"><img class=\"math display-math\" src=\"assets/equations/a0caa4135f45ed9c.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{63+2(0)-3}{1}\\right\\rfloor+1=61\" width=\"357.38\" height=\"58.87\" style=\"width:357.38px;height:58.87px;aspect-ratio:357.38/58.87\" loading=\"lazy\"></picture></div>","<p><strong>2. Determine output channels.</strong> Each filter produces one feature map. Therefore the output is <strong>61 × 61 × 32</strong>.</p>","<p><strong>3. Count trainable values.</strong> Each filter receives all 16 input channels. Its weights are reused at every spatial position.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.56px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fcf6aecafd4a3651.svg\"><img class=\"math display-math\" src=\"assets/equations/767ba18d56e40888.svg\" alt=\"N_{\\mathrm{weights}}=3\\times3\\times16\\times32=4{,}608\" width=\"362.11\" height=\"23.91\" style=\"width:362.11px;height:23.91px;aspect-ratio:362.11/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1cbdbfdd12c82e10.svg\" alt=\"N_{\\mathrm{biases}}=32\" width=\"123.00\" height=\"20.54\" style=\"width:123.00px;height:20.54px;aspect-ratio:123.00/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebc484850d4827e3.svg\" alt=\"P_3=4{,}608+32=4{,}640\" width=\"257.15\" height=\"21.43\" style=\"width:257.15px;height:21.43px;aspect-ratio:257.15/21.43\" loading=\"lazy\"></div>","<h3>Layer 4 — pooling</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 4: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">61 × 61 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Pooling</span><strong class=\"lv-value\">2 × 2 window · S = 2</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">30 × 30 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">Spatial dimensions change; the channel count stays the same. Pooling learns no weights.</p></figure>","<p>Input: <strong>61 × 61 × 32</strong>. Use a 2 × 2 window, stride 2, and zero padding.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2fa03284017c373e.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1=30\" width=\"284.07\" height=\"58.62\" style=\"width:284.07px;height:58.62px;aspect-ratio:284.07/58.62\" loading=\"lazy\"></div>","<p>Pooling acts independently on each channel. The output is <strong>30 × 30 × 32</strong>.</p>","<p><strong>Trainable parameters: 0.</strong> Max/average pooling has no learned filter weights or biases.</p>","<p>The division gives 29.5; take its floor before adding 1. A partial window outside the unpadded input is not included.</p>","<h3>Layer 5 — flatten</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 5: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">30 × 30 × 32</strong><span class=\"lv-detail\">height × width × channels</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Flatten</span><strong class=\"lv-value\">Rearrange activations</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">28,800</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">0</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">0</strong></div></div><p class=\"lv-caption\">The same activation values are rearranged into one vector. No parameter is learned.</p></figure>","<p>Input: <strong>30 × 30 × 32</strong>. Rearrange all activation values into one vector.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.77px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f8d6a23f5595005e.svg\"><img class=\"math display-math\" src=\"assets/equations/9fedbcb21e866a38.svg\" alt=\"n_{\\mathrm{flat}}=30\\times30\\times32=28{,}800\" width=\"308.23\" height=\"21.02\" style=\"width:308.23px;height:21.02px;aspect-ratio:308.23/21.02\" loading=\"lazy\"></picture></div>","<p>Output: a vector with <strong>28,800 entries</strong>. Flattening changes the arrangement, so it adds <strong>0 trainable parameters</strong>.</p>","<h3>Layer 6 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 6: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">28,800</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">240 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">240</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">6,912,000</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">240</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">6,912,240</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>28,800 features</strong>. Output: <strong>240 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:245.35px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e815f655162e42b.svg\"><img class=\"math display-math\" src=\"assets/equations/24e6116ce6d82f93.svg\" alt=\"N_{\\mathrm{weights}}=28{,}800\\times240=6{,}912{,}000\" width=\"377.05\" height=\"23.91\" style=\"width:377.05px;height:23.91px;aspect-ratio:377.05/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/237f8d226a0fb66a.svg\" alt=\"N_{\\mathrm{biases}}=240\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.56px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a36eb80ee2f332fd.svg\"><img class=\"math display-math\" src=\"assets/equations/a4474a3c31a68206.svg\" alt=\"P_6=6{,}912{,}000+240=6{,}912{,}240\" width=\"356.26\" height=\"21.43\" style=\"width:356.26px;height:21.43px;aspect-ratio:356.26/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 7 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 7: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">240</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">120 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">28,800</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">120</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">28,920</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>240 features</strong>. Output: <strong>120 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:214.13px;--narrow-height:64.65px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55419bb786cbe655.svg\"><img class=\"math display-math\" src=\"assets/equations/67cf05b2fc828555.svg\" alt=\"N_{\\mathrm{weights}}=240\\times120=28{,}800\" width=\"314.59\" height=\"23.91\" style=\"width:314.59px;height:23.91px;aspect-ratio:314.59/23.91\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dde36966a653a38.svg\" alt=\"N_{\\mathrm{biases}}=120\" width=\"135.22\" height=\"20.54\" style=\"width:135.22px;height:20.54px;aspect-ratio:135.22/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.34px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/780340973d3c0ce4.svg\"><img class=\"math display-math\" src=\"assets/equations/056fc82ce0b81134.svg\" alt=\"P_7=28{,}800+120=28{,}920\" width=\"293.80\" height=\"21.43\" style=\"width:293.80px;height:21.43px;aspect-ratio:293.80/21.43\" loading=\"lazy\"></picture></div>","<h3>Layer 8 — fully connected layer</h3>","<figure class=\"learning-visual lv-layer\" data-visual=\"layer\"><figcaption class=\"lv-title\">Layer 8: what changes and what is learned</figcaption><div class=\"lv-flow\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Input shape</span><strong class=\"lv-value\">120</strong><span class=\"lv-detail\">input features</span></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Dense layer</span><strong class=\"lv-value\">5 neurons</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">→</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Output shape</span><strong class=\"lv-value\">5</strong><span class=\"lv-detail\">output features</span></div></div><div class=\"lv-parameter-count\"><div class=\"lv-card lv-input\"><span class=\"lv-label\">Weights</span><strong class=\"lv-value\">600</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">+</span><div class=\"lv-card lv-weight\"><span class=\"lv-label\">Biases</span><strong class=\"lv-value\">5</strong></div><span class=\"lv-operator\" aria-hidden=\"true\">=</span><div class=\"lv-card lv-result\"><span class=\"lv-label\">Trainable parameters</span><strong class=\"lv-value\">605</strong></div></div><p class=\"lv-caption\">Every output neuron receives every input feature, with one bias per output neuron.</p></figure>","<p>Input: <strong>120 features</strong>. Output: <strong>5 neurons</strong>. Every output neuron connects to every input feature and has one bias.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/26857a3f5e70fd9d.svg\" alt=\"N_{\\mathrm{weights}}=120\\times5=600\" width=\"258.93\" height=\"23.91\" style=\"width:258.93px;height:23.91px;aspect-ratio:258.93/23.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8917be67939f2d89.svg\" alt=\"N_{\\mathrm{biases}}=5\" width=\"110.79\" height=\"20.54\" style=\"width:110.79px;height:20.54px;aspect-ratio:110.79/20.54\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b4289ff8bd02992b.svg\" alt=\"P_8=600+5=605\" width=\"206.92\" height=\"20.74\" style=\"width:206.92px;height:20.74px;aspect-ratio:206.92/20.74\" loading=\"lazy\"></div>","<h3>Summary of the complete network</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Layer</th><th>Spatial or flatten calculation</th><th>Output</th><th>Weights</th><th>Biases</th><th>Total</th></tr></thead><tbody><tr><td>1 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/dbb0832b53a96b49.svg\" alt=\"\\left\\lfloor\\frac{128+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"189.97\" height=\"45.60\" style=\"width:189.97px;height:45.60px;aspect-ratio:189.97/45.60\" loading=\"lazy\"></span></td><td>126 x 126 x 16</td><td>432</td><td>16</td><td>448</td></tr><tr><td>2 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/a6979fd0d1f6b483.svg\" alt=\"\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1\" width=\"124.50\" height=\"45.60\" style=\"width:124.50px;height:45.60px;aspect-ratio:124.50/45.60\" loading=\"lazy\"></span></td><td>63 x 63 x 16</td><td>0</td><td>0</td><td>0</td></tr><tr><td>3 conv</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f9e5ee2c7c7e1bbb.svg\" alt=\"\\left\\lfloor\\frac{63+2 \\times  0-3}{1}\\right\\rfloor+1\" width=\"180.47\" height=\"45.60\" style=\"width:180.47px;height:45.60px;aspect-ratio:180.47/45.60\" loading=\"lazy\"></span></td><td>61 x 61 x 32</td><td>4,608</td><td>32</td><td>4,640</td></tr><tr><td>4 pool</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/1ac02853de1445dd.svg\" alt=\"\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1\" width=\"115.00\" height=\"45.60\" style=\"width:115.00px;height:45.60px;aspect-ratio:115.00/45.60\" loading=\"lazy\"></span></td><td>30 x 30 x 32</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5 flat</td><td>30 × 30 × 32</td><td>28800</td><td>0</td><td>0</td><td>0</td></tr><tr><td>6 dense</td><td>28800 → 240</td><td>240</td><td>6,912,000</td><td>240</td><td>6,912,240</td></tr><tr><td>7 dense</td><td>240 → 120</td><td>120</td><td>28,800</td><td>120</td><td>28,920</td></tr><tr><td>8 dense</td><td>120 → 5</td><td>5</td><td>600</td><td>5</td><td>605</td></tr></tbody></table></div>","<p><strong>Parameter substitutions, in layer order: </strong></p>","<p>Layer 1: (3 x 3 x 3 + 1) x 16 = 448.</p>","<p>Layer 3: (3 x 3 x 16 + 1) x 32 = 4,640.</p>","<p>Layer 6: (28800 + 1) x 240 = 6,912,240.</p>","<p>Layer 7: (240 + 1) x 120 = 28,920.</p>","<p>Layer 8: (120 + 1) x 5 = 605.</p>","<p><strong>Total: </strong> 448 + 4,640 + 6,912,240 + 28,920 + 605 = <strong>6,946,853 trainable parameters</strong>. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.</p>","<p><strong>Separate convolution calculation: </strong></p>","<p class=\"worked-step\"><strong>Step 1 shape: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/966c8fb493880239.svg\" alt=\"\\left\\lfloor\\frac{5+2 \\times  0-3}{2}\\right\\rfloor+1\" width=\"170.96\" height=\"45.60\" style=\"width:170.96px;height:45.60px;aspect-ratio:170.96/45.60\" loading=\"lazy\"></span> = 2 along each axis. Use the deep-learning cross-correlation convention: do not flip the printed kernel.</p>","<h3>Output position (1, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −4\">−4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 + (−2) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>4 + 0 + (−4) = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>3 + 0 + (−1) = 2</b></div></div><p class=\"lv-combine\"><b>1 + 0 + 2 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-selected\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a7b5121489bd31f6.svg\"><img class=\"math display-math\" src=\"assets/equations/a9fce55fa8f0fbec.svg\" alt=\"R_1=(3)\\times(1)+(1)\\times(0)+(2)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2be91abc57b10ecb.svg\"><img class=\"math display-math\" src=\"assets/equations/b71bdd3aed98c346.svg\" alt=\"R_2=(2)\\times(2)+(1)\\times(0)+(2)\\times(-2)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e404b4617ef0e7d0.svg\"><img class=\"math display-math\" src=\"assets/equations/19fc18a5d8a877eb.svg\" alt=\"R_3=(3)\\times(1)+(2)\\times(0)+(1)\\times(-1)=2\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b108d091066c8f7c.svg\" alt=\"Y_{1,1}=(1)+(0)+(2)=3\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (1, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (1, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>1–3</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-row-2 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 2\">2</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 4\">4</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0\">0</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>2 + 0 + (−1) = 1</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>4 + 0 + 0 = 4</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>1 + 0 + (−1) = 0</b></div></div><p class=\"lv-combine\"><b>1 + 4 + 0 = 5</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-selected\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 1, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aa4766cd874d5e7f.svg\"><img class=\"math display-math\" src=\"assets/equations/eaf8c509090f51f1.svg\" alt=\"R_1=(2)\\times(1)+(2)\\times(0)+(1)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/93a6f5b5b20f2f23.svg\"><img class=\"math display-math\" src=\"assets/equations/47348f4aaa64e235.svg\" alt=\"R_2=(2)\\times(2)+(1)\\times(0)+(0)\\times(-2)=4\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5f03457a49dcba68.svg\"><img class=\"math display-math\" src=\"assets/equations/91d68511c5df7991.svg\" alt=\"R_3=(1)\\times(1)+(0)\\times(0)+(1)\\times(-1)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dd6e5a7547d2ee64.svg\" alt=\"Y_{1,2}=(1)+(4)+(0)=5\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 1)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 1) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>1–3</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 0\">0</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 0\">0</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>3 + 0 + (−1) = 2</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 + 0 = 0</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>1 + 0 + 0 = 1</b></div></div><p class=\"lv-combine\"><b>2 + 0 + 1 = 3</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-selected\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 1.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3a3d0394f9567ec.svg\"><img class=\"math display-math\" src=\"assets/equations/1f506dd6c963dbdb.svg\" alt=\"R_1=(3)\\times(1)+(2)\\times(0)+(1)\\times(-1)=2\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4ab2e486b72e8236.svg\"><img class=\"math display-math\" src=\"assets/equations/7737415f7a101340.svg\" alt=\"R_2=(0)\\times(2)+(3)\\times(0)+(0)\\times(-2)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c2dca2b82f9aac21.svg\"><img class=\"math display-math\" src=\"assets/equations/dbc9736155e0a1ec.svg\" alt=\"R_3=(1)\\times(1)+(1)\\times(0)+(0)\\times(-1)=1\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f077b3678b0e1f35.svg\" alt=\"Y_{2,1}=(2)+(0)+(1)=3\" width=\"269.11\" height=\"25.35\" style=\"width:269.11px;height:25.35px;aspect-ratio:269.11/25.35\" loading=\"lazy\"></div>","<h3>Output position (2, 2)</h3>","<p>Use this position&#x27;s input window. Multiply corresponding entries row by row; then add all row totals.</p>","<figure class=\"learning-visual lv-convolution\" data-visual=\"convolution\"><figcaption class=\"lv-title\">Follow window (2, 2) into one output cell</figcaption><p class=\"lv-instruction\">Input rows <b>3–5</b>, columns <b>3–5</b>. The window moves <b>2</b> cells per output step.</p><div class=\"lv-matrix-panels\"><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">1. Select the input window</div><table class=\"lv-matrix\" aria-label=\"1. Select the input window\"><caption>1. Select the input window</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"4\" aria-label=\"Row 1, column 4: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"5\" aria-label=\"Row 1, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: 2\">2</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"4\" aria-label=\"Row 2, column 4: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"5\" aria-label=\"Row 2, column 5: 0\">0</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 2\">2</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: 1\">1</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"4\" aria-label=\"Row 3, column 4: 0\">0</td><td class=\"lv-row-0 lv-selected\" data-row=\"3\" data-col=\"5\" aria-label=\"Row 3, column 5: 1\">1</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"1\" aria-label=\"Row 4, column 1: 0\">0</td><td class=\"lv-muted-cell\" data-row=\"4\" data-col=\"2\" aria-label=\"Row 4, column 2: 3\">3</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"3\" aria-label=\"Row 4, column 3: 0\">0</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"4\" aria-label=\"Row 4, column 4: 1\">1</td><td class=\"lv-row-1 lv-selected\" data-row=\"4\" data-col=\"5\" aria-label=\"Row 4, column 5: 2\">2</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"1\" aria-label=\"Row 5, column 1: 1\">1</td><td class=\"lv-muted-cell\" data-row=\"5\" data-col=\"2\" aria-label=\"Row 5, column 2: 1\">1</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"3\" aria-label=\"Row 5, column 3: 0\">0</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"4\" aria-label=\"Row 5, column 4: 2\">2</td><td class=\"lv-row-2 lv-selected\" data-row=\"5\" data-col=\"5\" aria-label=\"Row 5, column 5: 3\">3</td></tr></tbody></table><p class=\"lv-matrix-note\">Only the outlined cells belong to this output.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">2. Match the kernel</div><table class=\"lv-matrix\" aria-label=\"2. Match the kernel\"><caption>2. Match the kernel</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 2\">2</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −2\">−2</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 1\">1</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −1\">−1</td></tr></tbody></table><p class=\"lv-matrix-note\">Same row and column positions; no matrix multiplication.</p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">3. Multiply cell by cell</div><table class=\"lv-matrix\" aria-label=\"3. Multiply cell by cell\"><caption>3. Multiply cell by cell</caption><tbody><tr><td class=\"lv-row-0\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 1\">1</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 0\">0</td><td class=\"lv-row-0\" data-row=\"1\" data-col=\"3\" aria-label=\"Row 1, column 3: −1\">−1</td></tr><tr><td class=\"lv-row-1\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: 0\">0</td><td class=\"lv-row-1\" data-row=\"2\" data-col=\"3\" aria-label=\"Row 2, column 3: −4\">−4</td></tr><tr><td class=\"lv-row-2\" data-row=\"3\" data-col=\"1\" aria-label=\"Row 3, column 1: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"2\" aria-label=\"Row 3, column 2: 0\">0</td><td class=\"lv-row-2\" data-row=\"3\" data-col=\"3\" aria-label=\"Row 3, column 3: −3\">−3</td></tr></tbody></table><p class=\"lv-matrix-note\">Each cell is input × matching kernel coefficient.</p></div></div><div class=\"lv-result-flow\"><div><span class=\"lv-label\">4. Add the products row by row</span><div class=\"lv-row-sums\"><div class=\"lv-sum-line lv-row-0\"><span>Row 1</span><b>1 + 0 + (−1) = 0</b></div><div class=\"lv-sum-line lv-row-1\"><span>Row 2</span><b>0 + 0 + (−4) = −4</b></div><div class=\"lv-sum-line lv-row-2\"><span>Row 3</span><b>0 + 0 + (−3) = −3</b></div></div><p class=\"lv-combine\"><b>0 + (−4) + (−3) = −7</b></p></div><div class=\"lv-matrix-panel\"><div class=\"lv-matrix-label\" aria-hidden=\"true\">5. Place it in the output</div><table class=\"lv-matrix\" aria-label=\"5. Place it in the output\"><caption>5. Place it in the output</caption><tbody><tr><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"1\" aria-label=\"Row 1, column 1: 3\">3</td><td class=\"lv-muted-cell\" data-row=\"1\" data-col=\"2\" aria-label=\"Row 1, column 2: 5\">5</td></tr><tr><td class=\"lv-muted-cell\" data-row=\"2\" data-col=\"1\" aria-label=\"Row 2, column 1: 3\">3</td><td class=\"lv-selected\" data-row=\"2\" data-col=\"2\" aria-label=\"Row 2, column 2: −7\">−7</td></tr></tbody></table><p class=\"lv-matrix-note\">Output row 2, column 2.</p></div></div></figure>","<p><strong>Window row 1.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.10px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8247d99177a36658.svg\"><img class=\"math display-math\" src=\"assets/equations/bbe676b3e02a351a.svg\" alt=\"R_1=(1)\\times(1)+(0)\\times(0)+(1)\\times(-1)=0\" width=\"462.32\" height=\"24.43\" style=\"width:462.32px;height:24.43px;aspect-ratio:462.32/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 2.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/959c04625a9a0df4.svg\"><img class=\"math display-math\" src=\"assets/equations/b50d1e82d7e6e8b7.svg\" alt=\"R_2=(0)\\times(2)+(1)\\times(0)+(2)\\times(-2)=-4\" width=\"481.33\" height=\"24.43\" style=\"width:481.33px;height:24.43px;aspect-ratio:481.33/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Window row 3.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/20986846d13e4484.svg\"><img class=\"math display-math\" src=\"assets/equations/369116c3da370aea.svg\" alt=\"R_3=(0)\\times(1)+(2)\\times(0)+(3)\\times(-1)=-3\" width=\"481.33\" height=\"24.43\" style=\"width:481.33px;height:24.43px;aspect-ratio:481.33/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Add the rows to obtain one output cell.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:182.23px;--narrow-height:64.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/aec0342788a9224e.svg\"><img class=\"math display-math\" src=\"assets/equations/0984e17e87f9bbc9.svg\" alt=\"Y_{2,2}=(0)+(-4)+(-3)=-7\" width=\"326.14\" height=\"25.35\" style=\"width:326.14px;height:25.35px;aspect-ratio:326.14/25.35\" loading=\"lazy\"></picture></div>","<p><strong>Final output: </strong> <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/3797d8870cefe33e.svg\" alt=\"\\begin{bmatrix}3 &amp; 5\\\\3 &amp; -7\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>. Each output came from its own complete window; stride changes the next window position, not the multiplication rule.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s12","search":"Rehearsal Q6a **Question (10 marks).** Calculate every activation shape and trainable-parameter count for: Input 128 × 128 × 3. → Conv K = 3, filters = 16, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Conv K = 3, filters = 32, stride = 1, padding = 0. → Pool K = 2, stride = 2, padding = 0. → Flatten. → Dense 240 units. → Dense 120 units. → Dense 5 units. Also convolve the input A with the kernel K shown below, valid padding and stride 2.\n\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput 128 × 128 × 3.\n\nConv K = 3, filters = 16, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nConv K = 3, filters = 32, stride = 1, padding = 0.\n\nPool K = 2, stride = 2, padding = 0.\n\nDense 240 units.\n\nDense 120 units.\n\nDense 5 units.\n\nAlso convolve the input A with the kernel K shown below, valid padding and stride 2.\n\n### To find\n\nFind every layer shape, its parameter count and the network total. Find every convolution output cell.\n\n### Formula — which one and why\n\n**Complete CNN calculation.** Carry each output shape into the next layer. Convolution changes spatial size and channel count; pooling changes spatial size; flattening converts all activations into dense-layer inputs.\n\nH,W,C = feature-map height, width and channels; K = kernel size; S = stride; P_pad = padding. One bias is assumed for each learned filter or dense neuron unless specified otherwise.\n\n\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Ek layer ka output, next layer ka input; shape aur parameters alag count.\n\n**Convolution values.** At each valid location, multiply corresponding window and kernel entries, add all products and add the filter bias once. Move by the stated stride and repeat.\n\nX = input; K = kernel; S = stride; b = filter bias; u,v locate a kernel entry. Use the printed kernel without flipping under the stated deep-learning convention.\n\n\n\n**Yaad rakhne ka cue:** Matching cells multiply; sab products add; bias sirf ek baar.\n\n### Solution — step by step\n\n\n\n\n\n\n\n\nUse output size \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\), Conv weights K² × Cin × Cout and biases Cout, Dense weights Nin × Nout and biases Nout. Assume a bias per learned filter/unit, full input-channel connectivity and no trainable pooling parameters. ReLU and softmax activations themselves add no trainable parameters.\n| Layer | Spatial or flatten calculation | Output | Weights | Biases | Total |\n| 1 conv | \\(\\left\\lfloor\\frac{128+2 \\times  0-3}{1}\\right\\rfloor+1\\) | 126 x 126 x 16 | 432 | 16 | 448 |\n| 2 pool | \\(\\left\\lfloor\\frac{126-2}{2}\\right\\rfloor+1\\) | 63 x 63 x 16 | 0 | 0 | 0 |\n| 3 conv | \\(\\left\\lfloor\\frac{63+2 \\times  0-3}{1}\\right\\rfloor+1\\) | 61 x 61 x 32 | 4,608 | 32 | 4,640 |\n| 4 pool | \\(\\left\\lfloor\\frac{61-2}{2}\\right\\rfloor+1\\) | 30 x 30 x 32 | 0 | 0 | 0 |\n| 5 flat | 30 × 30 × 32 | 28800 | 0 | 0 | 0 |\n| 6 dense | 28800 → 240 | 240 | 6,912,000 | 240 | 6,912,240 |\n| 7 dense | 240 → 120 | 120 | 28,800 | 120 | 28,920 |\n| 8 dense | 120 → 5 | 5 | 600 | 5 | 605 |\n**Parameter substitutions, in layer order: **\nLayer 1: (3 x 3 x 3 + 1) x 16 = 448.\nLayer 3: (3 x 3 x 16 + 1) x 32 = 4,640.\nLayer 6: (28800 + 1) x 240 = 6,912,240.\nLayer 7: (240 + 1) x 120 = 28,920.\nLayer 8: (120 + 1) x 5 = 605.\n**Total: ** 448 + 4,640 + 6,912,240 + 28,920 + 605 = **6,946,853 trainable parameters**. Pooling changes activation size; it does not itself add learned weights. Always floor noninteger spatial dimensions.\n**Separate convolution calculation: **\n**Step 1 shape: ** \\(\\left\\lfloor\\frac{5+2 \\ti"},{"title":"Rehearsal Q6b","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain activations and the role of nonlinearity. Compare sigmoid, tanh, ReLU and Leaky ReLU including advantages and disadvantages.</p>","<p><strong>Complete worked answer.</strong></p>","<p>An activation function transforms a neuron&#x27;s weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.</p>","<p><strong>Sigmoid</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.43px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/36359a5421bdb1af.svg\"><img class=\"math display-math\" src=\"assets/equations/15f8d84de53f52c0.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\qquad 0&lt;\\sigma(z)&lt;1\" width=\"358.30\" height=\"51.56\" style=\"width:358.30px;height:51.56px;aspect-ratio:358.30/51.56\" loading=\"lazy\"></picture></div>","<p>Here z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.</p>","<p><strong>Hyperbolic tangent</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:215.60px;--narrow-height:93.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/369af2e85f2204d4.svg\"><img class=\"math display-math\" src=\"assets/equations/4a9360ff9640949f.svg\" alt=\"\\tanh(z)=\\frac{e^z-e^{-z}}{e^z+e^{-z}},\\qquad -1&lt;\\tanh(z)&lt;1\" width=\"456.42\" height=\"54.23\" style=\"width:456.42px;height:54.23px;aspect-ratio:456.42/54.23\" loading=\"lazy\"></picture></div>","<p>The numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.</p>","<p><strong>ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f3a2f94af1e35f2f.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)=\\begin{cases}z&amp;z\\geq0\\\\0&amp;z&lt;0\\end{cases}\" width=\"368.04\" height=\"58.62\" style=\"width:368.04px;height:58.62px;aspect-ratio:368.04/58.62\" loading=\"lazy\"></div>","<p>The output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.</p>","<p><strong>Leaky ReLU</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fa7213ea51b43af7.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\geq0\\\\\\alpha z&amp;z&lt;0\\end{cases},\\qquad 0&lt;\\alpha&lt;1\" width=\"480.43\" height=\"58.62\" style=\"width:480.43px;height:58.62px;aspect-ratio:480.43/58.62\" loading=\"lazy\"></div>","<p>Alpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.</p>","<p>Sigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s13","search":"Rehearsal Q6b **Question (10 marks).** Explain activations and the role of nonlinearity. Compare sigmoid, tanh, ReLU and Leaky ReLU including advantages and disadvantages.\n\n**Complete worked answer.**\nAn activation function transforms a neuron's weighted sum. Hidden-layer nonlinearity allows a network to represent nonlinear decision boundaries. Without it, composing affine layers gives another affine map: W₂(W₁x+b₁)+b₂ = (W₂W₁)x+(W₂b₁+b₂). More linear layers alone therefore do not solve XOR.\n**Sigmoid**\n\nHere z is the weighted sum and e is the exponential base. The whole expression 1 + e raised to minus z belongs below the fraction bar. Advantage: smooth probability-like output for binary classification. Limitation: saturation makes gradients small; the derivative never exceeds 0.25.\n**Hyperbolic tangent**\n\nThe numerator subtracts the exponentials; the denominator adds them. Advantage: zero-centered signed outputs, useful in recurrent states and candidates. Limitation: large positive or negative inputs still saturate.\n**ReLU**\n\nThe output range is zero to positive infinity. Advantage: inexpensive and derivative 1 on the positive side. Limitation: the negative side has zero gradient and a unit can become inactive.\n**Leaky ReLU**\n\nAlpha is a small chosen slope on the negative side. Advantage: negative inputs retain a small gradient. Limitation: alpha must be chosen; a fixed slope is not automatically optimal. At zero the two branches agree on output zero, but the derivative is convention-dependent.\nSigmoid derivative is a(1−a), tanh derivative is 1−a², and ReLU derivative is 1 for positive preactivation and 0 for negative preactivation. At zero ReLU is nondifferentiable; a common implementation selects zero. Strong saturation can slow learning by shrinking gradients. ReLU avoids positive-side saturation but cannot guarantee convergence. For mutually exclusive classes, use softmax at the output; for real-valued regression, a linear output is often suitable.\n"},{"title":"Rehearsal Q7a","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain feedforward information flow, weights, biases and activations, then calculate the output. Input x = [1, 0]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/given_412d332265.svg\" aria-label=\"Enlarge diagram: Given matrices for this question\"><img src=\"assets/figures/given_412d332265.svg\" alt=\"Given matrices for this question\" width=\"1100\" height=\"275\" loading=\"lazy\"></button><figcaption>Given matrices for this question <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Complete worked answer.</strong></p>","<h3>Given</h3>","<p>Input x = [1, 0].</p>","<p>W₁ is printed with the question.</p>","<p>b₁ = [0.1, 0.2].</p>","<p>W₂ is printed with the question.</p>","<p>b₂ = [0.1].</p>","<p>Hidden and output activations are ReLU.</p>","<h3>To find</h3>","<p>Find all preactivations, hidden activations and final outputs. Find the requested activation values and slopes.</p>","<h3>Formula — which one and why</h3>","<p><strong>Forward propagation.</strong> Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.</p>","<p>x = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3929c1e524affa01.svg\" alt=\"z_h=W_1x+b_1\" width=\"154.66\" height=\"20.81\" style=\"width:154.66px;height:20.81px;aspect-ratio:154.66/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a067fbd2b571e3c.svg\" alt=\"h=f_1(z_h)\" width=\"111.65\" height=\"24.43\" style=\"width:111.65px;height:24.43px;aspect-ratio:111.65/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/02e0daad7201e074.svg\" alt=\"z_o=W_2h+b_2\" width=\"153.18\" height=\"20.81\" style=\"width:153.18px;height:20.81px;aspect-ratio:153.18/20.81\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0badfa3430a92383.svg\" alt=\"o=f_2(z_o)\" width=\"107.86\" height=\"24.43\" style=\"width:107.86px;height:24.43px;aspect-ratio:107.86/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Pehli layer ka activated output hi agli layer ka input hai.</p>","<p><strong>ReLU and Leaky ReLU.</strong> ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.</p>","<p>z = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4edc237fa121ff9b.svg\" alt=\"\\operatorname{LeakyReLU}(z)=\\begin{cases}z&amp;z\\ge0\\\\\\alpha z&amp;z&lt;0\\end{cases}\" width=\"315.45\" height=\"58.62\" style=\"width:315.45px;height:58.62px;aspect-ratio:315.45/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.</p>","<h3>Solution — step by step</h3>","<p>A feedforward network transforms inputs layer by layer with no recurrent feedback. Weights scale contributions; bias shifts the preactivation; activation supplies the nonlinear transformation.</p>","<p class=\"worked-step\"><strong>Step 1 map the arrows.</strong> 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.</p>","<p><strong>Hidden neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cd4f127dab262e74.svg\"><img class=\"math display-math\" src=\"assets/equations/dc2c7898e4942415.svg\" alt=\"z_{h_1} = (0.2 \\times  1) + (0.4 \\times  0) + (0.1) = 0.3\" width=\"421.90\" height=\"24.58\" style=\"width:421.90px;height:24.58px;aspect-ratio:421.90/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2b99f7dd17297569.svg\" alt=\"h_{1} = \\max(0,0.3) = 0.3\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Hidden neuron 2: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:266.11px;--narrow-height:63.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6bf10ef9c5abf8e9.svg\"><img class=\"math display-math\" src=\"assets/equations/f8a809dfb5349555.svg\" alt=\"z_{h_2} = (0.3 \\times  1) + (0.7 \\times  0) + (0.2) = 0.5\" width=\"421.90\" height=\"24.58\" style=\"width:421.90px;height:24.58px;aspect-ratio:421.90/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ac1a985150f1b35b.svg\" alt=\"h_{2} = \\max(0,0.5) = 0.5\" width=\"239.93\" height=\"24.43\" style=\"width:239.93px;height:24.43px;aspect-ratio:239.93/24.43\" loading=\"lazy\"></div>","<p><strong>Output neuron 1: </strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.31px;--narrow-height:102.77px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/725a43999780ebd1.svg\"><img class=\"math display-math\" src=\"assets/equations/e22a0b62445991e6.svg\" alt=\"z_{o_1} = (0.5 \\times  0.3) + (0.6 \\times  0.5) + (0.1) = 0.55\" width=\"470.57\" height=\"24.58\" style=\"width:470.57px;height:24.58px;aspect-ratio:470.57/24.58\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d22e4c171ba2abbb.svg\" alt=\"o_{1} = \\max(0,0.55) = 0.55\" width=\"262.14\" height=\"24.43\" style=\"width:262.14px;height:24.43px;aspect-ratio:262.14/24.43\" loading=\"lazy\"></div>","<p><strong>Matrix-orientation note: </strong> this solution uses column input and rows as receiving neurons, giving <strong>0.55</strong>. The historical key uses the transpose interpretation for W₁ and obtains 0.61. If the problem does not define its orientation, state your convention; do not silently swap it during calculation. Under the alternative: hidden values = [0.3,0.6], output = 0.5 × 0.3+0.6 × 0.6+0.1 = 0.61.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s14","search":"Rehearsal Q7a **Question (10 marks).** Explain feedforward information flow, weights, biases and activations, then calculate the output. Input x = [1, 0]. Each row below lists the incoming weights of one receiving neuron. W₁ is shown below; b₁ = [0.1, 0.2]; W₂ is shown below; b₂ = [0.1]. Hidden and output activations are ReLU.\n\n\n\n**Complete worked answer.**\n\n\n\n### Given\n\nInput x = [1, 0].\n\nW₁ is printed with the question.\n\nb₁ = [0.1, 0.2].\n\nW₂ is printed with the question.\n\nb₂ = [0.1].\n\nHidden and output activations are ReLU.\n\n### To find\n\nFind all preactivations, hidden activations and final outputs. Find the requested activation values and slopes.\n\n### Formula — which one and why\n\n**Forward propagation.** Evaluate one layer completely before supplying its activated outputs to the next layer. Each layer has its own weights and biases.\n\nx = input vector; h = hidden outputs; W₁,b₁ = hidden parameters; W₂,b₂ = output parameters; f₁,f₂ = the stated activations.\n\n\n\n\n\n\n\n\n\n**Yaad rakhne ka cue:** Pehli layer ka activated output hi agli layer ka input hai.\n\n**ReLU and Leaky ReLU.** ReLU returns zero for negative input and retains positive input. Leaky ReLU instead multiplies a negative input by its supplied slope.\n\nz = preactivation; α (alpha) = supplied negative-side slope for Leaky ReLU. The derivative at zero needs an explicit convention.\n\n\n\n\n\n**Yaad rakhne ka cue:** Positive ko rehne do; negative ko zero. Leaky mein chhota negative rehne do.\n\n### Solution — step by step\n\n\n\n\nA feedforward network transforms inputs layer by layer with no recurrent feedback. Weights scale contributions; bias shifts the preactivation; activation supplies the nonlinear transformation.\n**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.\n**Hidden neuron 1: **\n\n\n**Hidden neuron 2: **\n\n\n**Output neuron 1: **\n\n\n**Matrix-orientation note: ** this solution uses column input and rows as receiving neurons, giving **0.55**. The historical key uses the transpose interpretation for W₁ and obtains 0.61. If the problem does not define its orientation, state your convention; do not silently swap it during calculation. Under the alternative: hidden values = [0.3,0.6], output = 0.5 × 0.3+0.6 × 0.6+0.1 = 0.61.\n"},{"title":"Rehearsal Q7b","blocks":["<p class=\"inline-question\"><strong>Question (10 marks).</strong> Explain hierarchical CNN feature extraction and the roles of convolution, pooling and fully connected layers. Why prefer CNNs over fully connected ANNs for images? Give medical-image and autonomous-vehicle applications and advantages.</p>","<p><strong>Complete worked answer.</strong></p>","<p>A convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/convolution.svg\" aria-label=\"Enlarge diagram: One filter is reused at successive spatial positions\"><img src=\"assets/figures/convolution.svg\" alt=\"One filter is reused at successive spatial positions\" width=\"960\" height=\"630\" loading=\"lazy\"></button><figcaption>One filter is reused at successive spatial positions <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p>Convolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.</p>","<p>Compared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.</p>","<p>For medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c18-s15","search":"Rehearsal Q7b **Question (10 marks).** Explain hierarchical CNN feature extraction and the roles of convolution, pooling and fully connected layers. Why prefer CNNs over fully connected ANNs for images? Give medical-image and autonomous-vehicle applications and advantages.\n\n**Complete worked answer.**\nA convolutional neural network processes local spatial neighborhoods using learnable filters. A filter slides across the image; the same weights are reused at different locations. Each filter produces one output channel. Early features often respond to edges, subsequent layers combine local patterns into textures or parts, and deeper features support object-level classification.\n\nConvolution extracts local patterns, a nonlinear activation lets the network combine them nonlinearly, and pooling reduces spatial resolution and sensitivity to small local shifts. Flattening or global pooling converts feature maps into a classification representation; a dense output layer produces class scores or probabilities.\nCompared with a fully connected image network, CNNs exploit locality and weight sharing, often requiring far fewer parameters for early image processing. An RGB filter extends through all input channels. Pooling does not change the number of channels and normally has no trainable parameters. A CNN is not automatically invariant to every transformation.\nFor medical-image analysis, a CNN can classify a chest X-ray or identify suspicious regions from labeled scans, learning useful spatial patterns. For autonomous vehicles, CNN-based perception can detect road signs, pedestrians or lanes from camera images. Benefits include learned hierarchical visual features and reuse across image positions; both applications require held-out evaluation under relevant acquisition conditions.\n\n"}]},{"n":19,"title":"Formula reference and exam revision","sections":[{"title":"The one page method map","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Question clue</th><th>First action</th><th>Core formula or check</th></tr></thead><tbody><tr><td>Neuron output</td><td>Multiply each input by its matching weight</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/23c659c8111d9781.svg\" alt=\"z=\\sum_iw_ix_i+b\" width=\"133.08\" height=\"40.71\" style=\"width:133.08px;height:40.71px;aspect-ratio:133.08/40.71\" loading=\"lazy\"></span>, then activate</td></tr><tr><td>Network prediction</td><td>Finish one whole layer before the next</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/5c938cf38724d627.svg\" alt=\"h=f(Wx+b)\" width=\"123.70\" height=\"19.00\" style=\"width:123.70px;height:19.00px;aspect-ratio:123.70/19.00\" loading=\"lazy\"></span></td></tr><tr><td>Backpropagation</td><td>State loss then prediction-minus-target</td><td>delta times sending activation</td></tr><tr><td>Optimizer update</td><td>Identify current gradient and stored state</td><td>old parameter minus update</td></tr><tr><td>CNN dimensions</td><td>Write N K S P and channels</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/c0351298d1be04e6.svg\" alt=\"\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"167.27\" height=\"45.60\" style=\"width:167.27px;height:45.60px;aspect-ratio:167.27/45.60\" loading=\"lazy\"></span></td></tr><tr><td>CNN parameters</td><td>Count one filter then all filters</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/cfa2f04f36764d25.svg\" alt=\"(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"134.66\" height=\"21.55\" style=\"width:134.66px;height:21.55px;aspect-ratio:134.66/21.55\" loading=\"lazy\"></span></td></tr><tr><td>Pooling</td><td>Draw every valid window</td><td>Maximum, or mean of the window</td></tr><tr><td>Dense parameters</td><td>Count connections and receiving biases</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/641d99b5a929f5f6.svg\" alt=\"(N_{\\mathrm{in}}+1)N_{\\mathrm{out}}\" width=\"111.82\" height=\"19.00\" style=\"width:111.82px;height:19.00px;aspect-ratio:111.82/19.00\" loading=\"lazy\"></span></td></tr><tr><td>RNN hidden state</td><td>Add new-input and old-state transforms</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/99df7aa8ced09e2c.svg\" alt=\"\\tanh(W_{xh}x+W_{hh}h_{t-1}+b)\" width=\"222.79\" height=\"19.00\" style=\"width:222.79px;height:19.00px;aspect-ratio:222.79/19.00\" loading=\"lazy\"></span></td></tr><tr><td>LSTM</td><td>Retain old add new then expose</td><td>Retain old cell, add admitted candidate, then apply output gate</td></tr><tr><td>GRU</td><td>Check the stated z convention</td><td><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/9abbc158fb98ec74.svg\" alt=\"h=(1-z)h_{t-1}+z\\widetilde h\" width=\"170.21\" height=\"24.21\" style=\"width:170.21px;height:24.21px;aspect-ratio:170.21/24.21\" loading=\"lazy\"></span></td></tr></tbody></table></div>"],"question":[],"answer":[],"kind":"read","id":"tee-c19-s0","search":"The one page method map | Question clue | First action | Core formula or check |\n| Neuron output | Multiply each input by its matching weight | \\(z=\\sum_iw_ix_i+b\\), then activate |\n| Network prediction | Finish one whole layer before the next | \\(h=f(Wx+b)\\) |\n| Backpropagation | State loss then prediction-minus-target | delta times sending activation |\n| Optimizer update | Identify current gradient and stored state | old parameter minus update |\n| CNN dimensions | Write N K S P and channels | \\(\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\\) |\n| CNN parameters | Count one filter then all filters | \\((K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}}\\) |\n| Pooling | Draw every valid window | Maximum, or mean of the window |\n| Dense parameters | Count connections and receiving biases | \\((N_{\\mathrm{in}}+1)N_{\\mathrm{out}}\\) |\n| RNN hidden state | Add new-input and old-state transforms | \\(\\tanh(W_{xh}x+W_{hh}h_{t-1}+b)\\) |\n| LSTM | Retain old add new then expose | Retain old cell, add admitted candidate, then apply output gate |\n| GRU | Check the stated z convention | \\(h=(1-z)h_{t-1}+z\\widetilde h\\) |"},{"title":"All formulas: meanings, use and substitution","blocks":["<p>These are the formulas used by this course. Each entry names its symbols and the type of calculation it serves. Numerical practice in the teaching chapters shows the longer working. Follow any different convention explicitly stated in the examination.</p>","<h3>Formula 1: Mean, variance and standard deviation</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.24px;--narrow-height:181.05px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7bccad9589b45084.svg\"><img class=\"math display-math\" src=\"assets/equations/ba649f65f75f4057.svg\" alt=\"\\mu=\\frac{1}{n}\\sum_i x_i,\\quad v=\\frac{1}{n}\\sum_i(x_i-\\mu)^2,\\quad s=\\sqrt{v}\" width=\"490.91\" height=\"61.92\" style=\"width:490.91px;height:61.92px;aspect-ratio:490.91/61.92\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> n is the count; mu is the mean; v is the population variance; s is the standard deviation.</p>","<p><strong>Use:</strong> Use when calculating a population mean/variance or standardization. Sample-variance estimates may use n−1 when explicitly requested.</p>","<p><strong>Substitution example:</strong> For [2,4]: mean = 3; deviations = −1,1; squares = 1,1; variance = 1; standard deviation = 1.</p>","<h3>Formula 2: Standardization</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a0a4f4a38fa7007.svg\" alt=\"x_{scaled}=\\frac{x-\\mu_{train}}{s_{train}}\" width=\"206.36\" height=\"51.38\" style=\"width:206.36px;height:51.38px;aspect-ratio:206.36/51.38\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> Use the mean and standard deviation estimated from training data.</p>","<p><strong>Use:</strong> Use to express a value relative to the training distribution. The standard deviation must be nonzero.</p>","<p><strong>Substitution example:</strong> For x = 7, mean = 5, standard deviation = 2: (7−5)/2 = 1.</p>","<h3>Formula 3: Power, constant and sum derivatives</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:206.46px;--narrow-height:154.76px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dffe83aa3b00d40c.svg\"><img class=\"math display-math\" src=\"assets/equations/0d7c48cb1d9b9e1f.svg\" alt=\"\\frac{d}{dx}(cx^n)=cnx^{n-1},\\quad\\frac{d}{dx}c=0,\\quad (f+g)\\prime=f\\prime+g\\prime\" width=\"544.76\" height=\"50.50\" style=\"width:544.76px;height:50.50px;aspect-ratio:544.76/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> c is a constant, x is the changing variable and n is the power.</p>","<p><strong>Use:</strong> Use to differentiate the loss supplied in a gradient-descent question.</p>","<p><strong>Substitution example:</strong> For 0.7x³: derivative = 0.7 × 3 × x² = 2.1x².</p>","<h3>Formula 4: Chain rule</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/434e48fc84f871b4.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}\" width=\"154.58\" height=\"50.50\" style=\"width:154.58px;height:50.50px;aspect-ratio:154.58/50.50\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> z is the intermediate value linking w to L.</p>","<p><strong>Use:</strong> Multiply derivatives along a path; add contributions from distinct paths that meet.</p>","<p><strong>Substitution example:</strong> For z = 3w+1 and L = z² at w = 1: z = 4; derivative = (2×4)×3 = 24.</p>","<h3>Formula 5: Dot product and a neuron</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.90px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e4620ff07e410bce.svg\"><img class=\"math display-math\" src=\"assets/equations/8316d459b29940dc.svg\" alt=\"z=\\sum_i w_i x_i+b,\\qquad a=f(z)\" width=\"320.16\" height=\"52.35\" style=\"width:320.16px;height:52.35px;aspect-ratio:320.16/52.35\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> x is the input; w is its matching weight; b is one bias; z is the weighted sum; a is the activated output.</p>","<p><strong>Use:</strong> Multiply each matching pair, add the products, add bias once, then activate.</p>","<p><strong>Substitution example:</strong> x = [2,1], w = [0.5,−0.2], b = 0.1: z = 1−0.2+0.1 = 0.9.</p>","<h3>Formula 6: Matrix multiplication</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47f627ca6464a106.svg\" alt=\"(AB)_{ij}=\\sum_k A_{ik}B_{kj}\" width=\"214.94\" height=\"52.91\" style=\"width:214.94px;height:52.91px;aspect-ratio:214.94/52.91\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> i selects a row of A; j selects a column of B; k runs along the matching entries.</p>","<p><strong>Use:</strong> Use row-times-column sums. A with shape m×n and B with n×p produces m×p.</p>","<p><strong>Substitution example:</strong> Row [1,2] times column [3,4] gives 1×3+2×4 = 11.</p>","<h3>Formula 7: Layer forward pass</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.53px;--narrow-height:72.98px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2845b5af7a9f9056.svg\"><img class=\"math display-math\" src=\"assets/equations/4698521353358290.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)},\\qquad a^{(l)}=f(z^{(l)})\" width=\"419.03\" height=\"29.16\" style=\"width:419.03px;height:29.16px;aspect-ratio:419.03/29.16\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> l labels the layer; the previous layer activations become inputs to the next layer.</p>","<p><strong>Use:</strong> For receiving-neuron rows, compute each row dot product and add that receiving neuron’s bias. Finish the whole layer before moving on.</p>","<h3>Formula 8: Sigmoid and its derivative</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.94px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e03a4bc95b918203.svg\"><img class=\"math display-math\" src=\"assets/equations/11660565b2daac98.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}},\\quad \\sigma\\prime(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"427.89\" height=\"51.56\" style=\"width:427.89px;height:51.56px;aspect-ratio:427.89/51.56\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> e is approximately 2.71828; sigma is the output.</p>","<p><strong>Use:</strong> Use for a sigmoid forward pass and for its local backpropagation derivative.</p>","<p><strong>Substitution example:</strong> At z = 0: output = 1/(1+1) = 0.5; derivative = 0.5×0.5 = 0.25.</p>","<h3>Formula 9: Tanh and its derivative</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.66px;--narrow-height:99.06px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e538ee72147c838.svg\"><img class=\"math display-math\" src=\"assets/equations/210ffd0354b9c9a9.svg\" alt=\"\\tanh(z)=\\frac{e^{2z}-1}{e^{2z}+1},\\quad \\tanh\\prime(z)=1-\\tanh^2(z)\" width=\"484.74\" height=\"56.48\" style=\"width:484.74px;height:56.48px;aspect-ratio:484.74/56.48\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> Tanh gives an output between −1 and 1.</p>","<p><strong>Use:</strong> Use for a stated tanh activation, commonly an RNN hidden state or recurrent candidate.</p>","<p><strong>Substitution example:</strong> At z = 0: numerator = 0, denominator = 2; output = 0; derivative = 1.</p>","<h3>Formula 10: ReLU and its derivative</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3bc788a99b96d468.svg\" alt=\"f(z)=\\max(0,z),\\quad f\\prime(z)=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z&lt;0\\end{cases}\" width=\"404.88\" height=\"58.62\" style=\"width:404.88px;height:58.62px;aspect-ratio:404.88/58.62\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> max means choose the larger value.</p>","<p><strong>Use:</strong> Use for ReLU. At zero the derivative is mathematically undefined; use the convention stated by the question or implementation.</p>","<p><strong>Substitution example:</strong> For −2, output = 0 and derivative = 0. For 3, output = 3 and derivative = 1.</p>","<h3>Formula 11: Leaky ReLU</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3faffb967fafdf3.svg\" alt=\"f(z)=\\begin{cases}z&amp;z\\geq0\\\\az&amp;z&lt;0\\end{cases}\" width=\"199.61\" height=\"58.62\" style=\"width:199.61px;height:58.62px;aspect-ratio:199.61/58.62\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> a is the small negative-side slope, commonly 0.01 unless specified.</p>","<p><strong>Use:</strong> For negative z multiply by a; the output remains negative.</p>","<p><strong>Substitution example:</strong> For z = −2 and a = 0.01: output = −0.02; derivative on this side is 0.01.</p>","<h3>Formula 12: Stable softmax</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.27px;--narrow-height:118.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c492ec558e0b1e23.svg\"><img class=\"math display-math\" src=\"assets/equations/4f5f1a315cf3ec0f.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_j z_j\" width=\"324.43\" height=\"63.31\" style=\"width:324.43px;height:63.31px;aspect-ratio:324.43/63.31\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> z values are class scores; p values are probabilities.</p>","<p><strong>Use:</strong> Subtract the same maximum from every score, exponentiate, add, divide each by that total.</p>","<p><strong>Substitution example:</strong> For [0,0]: exponentials = [1,1]; total = 2; probabilities = [0.5,0.5].</p>","<h3>Formula 13: Squared and absolute losses</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a288e1ba23bc9347.svg\" alt=\"\\mathrm{SSE}=\\sum_i(o_i-y_i)^2\" width=\"211.02\" height=\"52.35\" style=\"width:211.02px;height:52.35px;aspect-ratio:211.02/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1bdd5bbb9ca64f61.svg\" alt=\"L_{\\mathrm{half}}=\\frac{\\mathrm{SSE}}2\" width=\"135.29\" height=\"50.50\" style=\"width:135.29px;height:50.50px;aspect-ratio:135.29/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bdee7885d635e78c.svg\" alt=\"L_{\\mathrm{MSE}}=\\frac{\\mathrm{SSE}}n\" width=\"143.04\" height=\"50.77\" style=\"width:143.04px;height:50.77px;aspect-ratio:143.04/50.77\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42ae3654ddbdf33e.svg\" alt=\"L_{\\mathrm{MAE}}=\\frac1n\\sum_i|o_i-y_i|\" width=\"243.92\" height=\"61.92\" style=\"width:243.92px;height:61.92px;aspect-ratio:243.92/61.92\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> o is prediction; y is target; n is the number of averaged terms.</p>","<p><strong>Use:</strong> Read whether the question uses a half sum, a mean, or an unhalved sum. The scaling changes gradients.</p>","<p><strong>Substitution example:</strong> For errors [−1,2]: half sum = (1+4)/2 = 2.5; MSE = 2.5; MAE = (1+2)/2 = 1.5. The first two coincide only because n = 2.</p>","<h3>Formula 14: Binary cross entropy</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> y is 0 or 1; p is the predicted probability for class 1; ln is the natural logarithm.</p>","<p><strong>Use:</strong> Use for a sigmoid binary prediction. If y = 1 use −ln(p); if y = 0 use −ln(1−p).</p>","<p><strong>Substitution example:</strong> For y = 1 and p = 0.8: loss = 0.223144.</p>","<h3>Formula 15: Categorical cross entropy</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.61px;--narrow-height:117.24px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4be60e1a1e5d9ec8.svg\"><img class=\"math display-math\" src=\"assets/equations/d607248d18cc3f42.svg\" alt=\"H(p,q)=-\\sum_i p_i\\ln q_i,\\qquad\\log_2q=\\frac{\\ln q}{\\ln2}\" width=\"434.75\" height=\"62.61\" style=\"width:434.75px;height:62.61px;aspect-ratio:434.75/62.61\" loading=\"lazy\"></picture></div>","<p>For a soft target distribution, retain every nonzero target-weighted term. Natural logs give nats; base-2 logs give bits.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.42px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea93bf47748eb958.svg\"><img class=\"math display-math\" src=\"assets/equations/abecd65b7d7b5753.svg\" alt=\"L=-\\sum_i y_i\\ln p_i=-\\ln p_{true}\" width=\"306.83\" height=\"52.35\" style=\"width:306.83px;height:52.35px;aspect-ratio:306.83/52.35\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The final equality assumes one-hot labels, with exactly one y equal to 1.</p>","<p><strong>Use:</strong> Use for mutually exclusive multiclass labels. Select the probability of the true class.</p>","<p><strong>Substitution example:</strong> True class 2 and probabilities [0.1,0.8,0.1]: loss = −ln(0.8) = 0.223144.</p>","<h3>Formula 16: Output delta for half squared loss</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc1948e719d0e70b.svg\" alt=\"\\delta^{out}=(o-y)f\\prime(z)\" width=\"193.19\" height=\"27.01\" style=\"width:193.19px;height:27.01px;aspect-ratio:193.19/27.01\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> Delta is the loss derivative with respect to the preactivation z.</p>","<p><strong>Use:</strong> Use with half squared loss. For unhalved one-output MSE multiply by 2; for an MSE averaged over m outputs multiply the half-sum delta by 2/m.</p>","<p><strong>Substitution example:</strong> Sigmoid output 0.5 and target 1: delta = (−0.5)×0.25 = −0.125.</p>","<h3>Formula 17: Sigmoid plus BCE; softmax plus CCE</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/154ed49b87099426.svg\" alt=\"\\delta^{out}=p-y\" width=\"124.09\" height=\"25.92\" style=\"width:124.09px;height:25.92px;aspect-ratio:124.09/25.92\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> p and y can be vectors for softmax.</p>","<p><strong>Use:</strong> This is the combined derivative with respect to the logits. Do not multiply by the activation derivative again.</p>","<p><strong>Substitution example:</strong> Binary p = 0.8, y = 1: delta = −0.2.</p>","<h3>Formula 18: Hidden delta, weight gradient and bias gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.54px;--narrow-height:198.12px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f960780a672401ea.svg\"><img class=\"math display-math\" src=\"assets/equations/4cb07890e7ce7a95.svg\" alt=\"\\delta_j^h=f\\prime(z_j^h)\\sum_k w_{kj}^{out}\\delta_k^{out},\\quad\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i,\\quad\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"540.82\" height=\"63.69\" style=\"width:540.82px;height:63.69px;aspect-ratio:540.82/63.69\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> a_i is the activation sending a signal along the weight; delta_j belongs to the receiving neuron.</p>","<p><strong>Use:</strong> Use OLD downstream weights throughout one backward pass. Add all outgoing-path contributions.</p>","<p><strong>Substitution example:</strong> If receiving delta = −0.2 and sending activation = 3: weight gradient = −0.6; bias gradient = −0.2.</p>","<h3>Formula 19: Gradient descent</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d35498ffd4122e2.svg\" alt=\"\\theta_{new}=\\theta-\\eta g,\\qquad g=\\frac{\\partial J}{\\partial\\theta}\" width=\"286.02\" height=\"51.29\" style=\"width:286.02px;height:51.29px;aspect-ratio:286.02/51.29\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> theta is the parameter; eta is learning rate; g is the current gradient.</p>","<p><strong>Use:</strong> Recalculate g at the current parameter unless the question supplies gradients directly.</p>","<p><strong>Substitution example:</strong> theta = 1, eta = 0.1, g = −2 gives 1−0.1(−2) = 1.2.</p>","<h3>Formula 20: Batch and mini-batch gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.65px;--narrow-height:146.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/01bdd22eb4365aa9.svg\"><img class=\"math display-math\" src=\"assets/equations/60db920018eb907a.svg\" alt=\"g_{batch}=\\frac1B\\sum_{i=1}^{B}g_i,\\quad U_{epoch}=\\left\\lceil\\frac NB\\right\\rceil\" width=\"368.95\" height=\"72.79\" style=\"width:368.95px;height:72.79px;aspect-ratio:368.95/72.79\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> B is batch size; N is sample count; U is updates per epoch when the final incomplete batch is retained.</p>","<p><strong>Use:</strong> SGD uses B = 1. Full batch uses B = N. Average only when the stated objective is a mean.</p>","<p><strong>Substitution example:</strong> N = 105, B = 20: six updates, with five samples in the last batch.</p>","<h3>Formula 21: Momentum: signed velocity</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/d6d609593a44d53f.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\qquad\\theta_t=\\theta_{t-1}+v_t\" width=\"374.50\" height=\"22.51\" style=\"width:374.50px;height:22.51px;aspect-ratio:374.50/22.51\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> v stores signed movement; beta retains part of old movement.</p>","<p><strong>Use:</strong> Use this convention consistently. Other textbooks may define an unsigned gradient accumulator and subtract it instead.</p>","<p><strong>Substitution example:</strong> beta = 0.8, old v = −0.2, eta = 0.1, g = 1.8 gives v = −0.34.</p>","<h3>Formula 22: Nesterov: look-ahead gradient</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:226.80px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/29d3ddbf9730bc3a.svg\"><img class=\"math display-math\" src=\"assets/equations/ba02f58e5e55b487.svg\" alt=\"\\theta_{look}=\\theta+\\beta v,\\quad v_{new}=\\beta v-\\eta g(\\theta_{look}),\\quad\\theta_{new}=\\theta+v_{new}\" width=\"597.46\" height=\"24.43\" style=\"width:597.46px;height:24.43px;aspect-ratio:597.46/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The look-ahead point is temporary; the update is added to the original theta.</p>","<p><strong>Use:</strong> Evaluate the gradient at the look-ahead point, not at the old theta.</p>","<p><strong>Substitution example:</strong> theta = 1.8, beta = 0.8 and v = −0.2 gives look-ahead = 1.64.</p>","<h3>Formula 23: AdaGrad</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.84px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3060020ef7a35ed4.svg\"><img class=\"math display-math\" src=\"assets/equations/fe45aacbe9d8627a.svg\" alt=\"G_t=G_{t-1}+g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"419.94\" height=\"52.24\" style=\"width:419.94px;height:52.24px;aspect-ratio:419.94/52.24\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> G is accumulated squared gradient; epsilon prevents division by zero.</p>","<p><strong>Use:</strong> Accumulate every squared gradient, separately for each parameter. Use the epsilon placement stated by the problem.</p>","<p><strong>Substitution example:</strong> Old G = 4 and g = −3 gives G = 13.</p>","<h3>Formula 24: RMSProp</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.46px;--narrow-height:94.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/459c86785f7d6c4f.svg\"><img class=\"math display-math\" src=\"assets/equations/914e44e2b8e8e8f9.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2,\\quad\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"483.06\" height=\"52.24\" style=\"width:483.06px;height:52.24px;aspect-ratio:483.06/52.24\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> rho is the decay; s is a decaying mean of squared gradients.</p>","<p><strong>Use:</strong> Calculate the new square memory first, then update the parameter.</p>","<p><strong>Substitution example:</strong> rho = 0.9, old s = 4, g = −3 gives s = 3.6+0.9 = 4.5.</p>","<h3>Formula 25: Adam: both memories</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> m remembers signed gradients; v remembers squared gradients.</p>","<p><strong>Use:</strong> Start with the initial states specified. Common defaults are beta1 = 0.9 and beta2 = 0.999.</p>","<h3>Formula 26: Adam: correction and update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:231.71px;--narrow-height:202.71px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/92678247acd594b0.svg\"><img class=\"math display-math\" src=\"assets/equations/c443fc0367c152b1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\widehat v_t=\\frac{v_t}{1-\\beta_2^t},\\quad\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"571.98\" height=\"66.85\" style=\"width:571.98px;height:66.85px;aspect-ratio:571.98/66.85\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> t counts updates starting at 1, not 0.</p>","<p><strong>Use:</strong> Correct both zero-initialized memories before the update; do not multiply by the gradient a second time.</p>","<p><strong>Substitution example:</strong> At t = 1, m = 0.2 and beta1 = 0.9: corrected m = 0.2/0.1 = 2.</p>","<h3>Formula 27: L1 penalty and update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:283.85px;--narrow-height:133.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f35555b2b4b6691c.svg\"><img class=\"math display-math\" src=\"assets/equations/fd296afd4f88edb6.svg\" alt=\"J=L+\\lambda\\sum_j|w_j|,\\quad w_{new}=w-\\eta\\left[g_{data}+\\lambda\\operatorname{sign}(w)\\right]\" width=\"561.92\" height=\"55.67\" style=\"width:561.92px;height:55.67px;aspect-ratio:561.92/55.67\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> lambda is regularization strength; sign(w) is +1 for positive w and −1 for negative w.</p>","<p><strong>Use:</strong> At zero, L1 has a subgradient rather than a unique derivative; use the specified convention. Include only parameters named in the penalty.</p>","<p><strong>Substitution example:</strong> w = −2, lambda = 0.1, data gradient = 0 gives penalty gradient = −0.1.</p>","<h3>Formula 28: L2 penalty and update with a half</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.90px;--narrow-height:144.13px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a21ef40f9211941d.svg\"><img class=\"math display-math\" src=\"assets/equations/e0797baa70350e25.svg\" alt=\"J=L+\\frac\\lambda2\\sum_jw_j^2,\\quad w_{new}=w-\\eta(g_{data}+\\lambda w)\" width=\"496.66\" height=\"65.94\" style=\"width:496.66px;height:65.94px;aspect-ratio:496.66/65.94\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The half cancels the 2 produced by differentiating a square.</p>","<p><strong>Use:</strong> If the objective uses lambda times the sum of squares WITHOUT a half, use 2 lambda w instead.</p>","<p><strong>Substitution example:</strong> w = 2, lambda = 0.1, data gradient = 0.3 gives total gradient = 0.5.</p>","<h3>Formula 29: Inverted dropout</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:168.83px;--narrow-height:130.45px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4fe7ae66a3ded01.svg\"><img class=\"math display-math\" src=\"assets/equations/455d85a70cf8258a.svg\" alt=\"q=1-p,\\quad a_{train}=\\frac{m\\odot a}{q},\\quad a_{test}=a\" width=\"419.93\" height=\"52.26\" style=\"width:419.93px;height:52.26px;aspect-ratio:419.93/52.26\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> p is drop probability; q is keep probability; mask m contains zeros and ones; the circled dot means elementwise multiplication.</p>","<p><strong>Use:</strong> During training, zero dropped entries and divide kept entries by q. Disable dropout at inference.</p>","<p><strong>Substitution example:</strong> a = 3, q = 0.5, mask = 1 gives 3/0.5 = 6.</p>","<h3>Formula 30: Convolution output dimensions</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.70px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f467d926f905df6d.svg\"><img class=\"math display-math\" src=\"assets/equations/b7c680fad37aede4.svg\" alt=\"N_{out}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"293.79\" height=\"58.62\" style=\"width:293.79px;height:58.62px;aspect-ratio:293.79/58.62\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> N is input height or width; P is padding on each side; K is kernel size; S is stride; floor rounds down.</p>","<p><strong>Use:</strong> Apply separately to height and width. Output channels equal the number of filters. This formula assumes dilation 1.</p>","<p><strong>Substitution example:</strong> N = 7, P = 1, K = 3, S = 2 gives floor(6/2)+1 = 4.</p>","<h3>Formula 31: Convolution value</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:380.25px;--narrow-height:130.78px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5afb61a6d5f3879.svg\"><img class=\"math display-math\" src=\"assets/equations/0fcf0c4134fa9fe3.svg\" alt=\"Y_{ij,o}=\\sum_c\\sum_u\\sum_v K_{uvco}X_{iS+u-P,jS+v-P,c}+b_o\" width=\"473.49\" height=\"51.51\" style=\"width:473.49px;height:51.51px;aspect-ratio:473.49/51.51\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> c runs over input channels; u,v run over kernel positions; o selects one filter.</p>","<p><strong>Use:</strong> This is the usual deep-learning cross-correlation operation. Use zeros outside the padded image. Multiply matching cells, add all channels, then add the filter bias once.</p>","<h3>Formula 32: Max, min and average pooling</h3>","<p>Min pooling keeps the smallest entry in each window. For a four-entry window:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/619bb1c028de4233.svg\" alt=\"y_{\\min}=\\min(x_1,x_2,x_3,x_4)\" width=\"266.30\" height=\"24.43\" style=\"width:266.30px;height:24.43px;aspect-ratio:266.30/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:220.47px;--narrow-height:124.64px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/edf81d51873a0dfc.svg\"><img class=\"math display-math\" src=\"assets/equations/5d156947c613cf69.svg\" alt=\"y_{max}=\\max_{(i,j)\\in W}x_{ij},\\quad y_{avg}=\\frac1{|W|}\\sum_{(i,j)\\in W}x_{ij}\" width=\"430.66\" height=\"67.59\" style=\"width:430.66px;height:67.59px;aspect-ratio:430.66/67.59\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> W is one pooling window; its size is the number of included cells.</p>","<p><strong>Use:</strong> Move the window by the stated stride; process channels separately. For padding, follow the stated average-pooling denominator convention.</p>","<p><strong>Substitution example:</strong> For [1,4,2,3]: maximum = 4; average = 10/4 = 2.5.</p>","<h3>Formula 33: Convolution parameter count</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.37px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8a253f24fdf99d8e.svg\"><img class=\"math display-math\" src=\"assets/equations/bd7e05cdd2c763eb.svg\" alt=\"P_{conv}=(K_hK_wC_{in}+1)C_{out}\" width=\"293.70\" height=\"24.43\" style=\"width:293.70px;height:24.43px;aspect-ratio:293.70/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> Kernel height and width times input channels gives weights per filter; +1 is one bias; Cout is filter count.</p>","<p><strong>Use:</strong> Use for a fully connected, ungrouped convolution with bias. Output height and width do not multiply the parameter count.</p>","<p><strong>Substitution example:</strong> 3×3 kernel, 3 input channels, 2 filters: (27+1)×2 = 56.</p>","<h3>Formula 34: Flatten and dense parameter count</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.08px;--narrow-height:64.63px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/56dad01ac3222ddd.svg\"><img class=\"math display-math\" src=\"assets/equations/33a05d43681713eb.svg\" alt=\"N_{flat}=HWC,\\qquad P_{dense}=(N_{in}+1)N_{out}\" width=\"448.95\" height=\"25.53\" style=\"width:448.95px;height:25.53px;aspect-ratio:448.95/25.53\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> H,W,C are activation dimensions; Nin and Nout are dense-layer input and output counts.</p>","<p><strong>Use:</strong> Flatten has no trainable parameters. Dense biases belong to receiving neurons.</p>","<p><strong>Substitution example:</strong> 2×2×2 flattens to 8; dense 3 then has (8+1)×3 = 27 parameters.</p>","<h3>Formula 35: Convolution multiply-accumulate count</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:276.71px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d20bfcc57cb122e.svg\"><img class=\"math display-math\" src=\"assets/equations/86ffc171b254aab9.svg\" alt=\"MAC=H_{out}W_{out}K_hK_wC_{in}C_{out}\" width=\"339.28\" height=\"21.35\" style=\"width:339.28px;height:21.35px;aspect-ratio:339.28/21.35\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> Each output value uses kernel area times input-channel count multiplications.</p>","<p><strong>Use:</strong> Used for Inception bottleneck comparisons. This counts one multiply-accumulate as one MAC and ignores bias additions. Some FLOP conventions count multiply and add separately.</p>","<h3>Formula 36: Concatenation and residual addition</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:174.23px;--narrow-height:92.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/588297b667afd636.svg\"><img class=\"math display-math\" src=\"assets/equations/8b8cdd9b96177407.svg\" alt=\"C_{concat}=\\sum_b C_b,\\qquad y_{res}=F(x)+x\" width=\"392.84\" height=\"52.91\" style=\"width:392.84px;height:52.91px;aspect-ratio:392.84/52.91\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> b labels branches with matching spatial dimensions.</p>","<p><strong>Use:</strong> Inception concatenates channels; residual addition requires matching full shapes. Use a projection when needed.</p>","<p><strong>Substitution example:</strong> Channels 16+32+8+8 give 64. Adding two 14×14×64 tensors keeps 14×14×64.</p>","<h3>Formula 37: Vanilla RNN</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:346.08px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2d32a1185192d80.svg\"><img class=\"math display-math\" src=\"assets/equations/77145310b191a975.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\\quad o_t=W_{hy}h_t+b_y\" width=\"566.32\" height=\"25.53\" style=\"width:566.32px;height:25.53px;aspect-ratio:566.32/25.53\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> x_t is current input; h_previous is previous state; the same matrices are reused at every time step.</p>","<p><strong>Use:</strong> Calculate the two matrix-vector products, add bias, then tanh. Apply the stated output activation to o_t when required.</p>","<h3>Formula 38: Perceptron update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.00px;--narrow-height:109.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2fd235815e859770.svg\"><img class=\"math display-math\" src=\"assets/equations/e3355300bf932c93.svg\" alt=\"\\widehat y=\\operatorname{step}(w^Tx+b),\\quad w_{new}=w+\\eta(y-\\widehat y)x,\\quad b_{new}=b+\\eta(y-\\widehat y)\" width=\"694.16\" height=\"27.90\" style=\"width:694.16px;height:27.90px;aspect-ratio:694.16/27.90\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The step threshold and label encoding must match the question.</p>","<p><strong>Use:</strong> Use for a stated perceptron learning rule; this is not the sigmoid derivative rule.</p>","<h3>Formula 39: BPTT hidden delta</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/77be07478b9cbea0.svg\" alt=\"\\delta_t=\\left[W_{hy}^T(p_t-y_t)+W_{hh}^T\\delta_{t+1}\\right]\\odot(1-h_t^2)\" width=\"437.03\" height=\"31.63\" style=\"width:437.03px;height:31.63px;aspect-ratio:437.03/31.63\" loading=\"lazy\"></div>","<p><strong>Symbols:</strong> Here p_t is the softmax probability vector. The output term assumes softmax plus cross entropy at each stated output step; omit it at steps with no direct loss.</p>","<p><strong>Use:</strong> Backpropagate from the last time step. Shared-weight gradients sum contributions across time.</p>","<h3>Formula 40: BPTT recurrent-weight gradient</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc3f87fdb9a197b4.svg\" alt=\"g_{\\mathrm{clipped}}=g\\min\\left(1,\\frac{\\tau}{\\lVert g\\rVert_2}\\right)\" width=\"277.13\" height=\"58.87\" style=\"width:277.13px;height:58.87px;aspect-ratio:277.13/58.87\" loading=\"lazy\"></div>","<p>For gradient norm clipping, τ &gt; 0 is the maximum norm. Leave a zero gradient unchanged. This is a remedy for exploding gradients; it is distinct from the shared-weight gradient formula below.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.84px;--narrow-height:139.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9aa073a86bb67d16.svg\"><img class=\"math display-math\" src=\"assets/equations/c9fa6409d743c860.svg\" alt=\"\\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^T,\\quad\\frac{\\partial L}{\\partial W_{xh}}=\\sum_t\\delta_t x_t^T\" width=\"429.08\" height=\"62.51\" style=\"width:429.08px;height:62.51px;aspect-ratio:429.08/62.51\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> These are outer products, not scalar dot products.</p>","<p><strong>Use:</strong> Sum each occurrence of a shared weight. Apply the learning-rate update after accumulating the required contributions.</p>","<h3>Formula 41: LSTM gates and candidate</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> f is forget gate; i is input gate; [h,x] means concatenation.</p>","<p><strong>Use:</strong> Compute each gate from its own weights and bias. Gate values lie between 0 and 1.</p>","<h3>Formula 42: LSTM candidate and output gate</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:292.13px;--narrow-height:148.68px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ffe858586bf2d707.svg\"><img class=\"math display-math\" src=\"assets/equations/a90c778fa86aa08a.svg\" alt=\"\\widetilde C_t=\\tanh(W_C[h_{t-1},x_t]+b_C),\\quad o_t=\\sigma(W_o[h_{t-1},x_t]+b_o)\" width=\"607.38\" height=\"31.40\" style=\"width:607.38px;height:31.40px;aspect-ratio:607.38/31.40\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> The candidate can be negative; the gates are sigmoid outputs.</p>","<p><strong>Use:</strong> Do not confuse the candidate value with its input gate.</p>","<h3>Formula 43: LSTM cell and hidden state</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.55px;--narrow-height:109.59px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e295aa726de62b85.svg\"><img class=\"math display-math\" src=\"assets/equations/758fd5519435e456.svg\" alt=\"C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t,\\quad h_t=o_t\\odot\\tanh(C_t)\" width=\"492.26\" height=\"31.40\" style=\"width:492.26px;height:31.40px;aspect-ratio:492.26/31.40\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> C is the cell state; h is the exposed hidden state.</p>","<p><strong>Use:</strong> Calculate old retained part, new admitted part, sum them, apply tanh, then multiply by output gate.</p>","<h3>Formula 44: GRU gates, candidate and update</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:279.17px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/552178cdb39642a9.svg\"><img class=\"math display-math\" src=\"assets/equations/4c9f5914ab749b31.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z),\\quad r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"618.24\" height=\"24.43\" style=\"width:618.24px;height:24.43px;aspect-ratio:618.24/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> z is update gate; r is reset gate.</p>","<p><strong>Use:</strong> Use the exact gate and reset placement convention in the question.</p>","<h3>Formula 45: GRU state under the retain-old convention</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:388.02px;--narrow-height:155.11px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/3206de1fb9907f41.svg\"><img class=\"math display-math\" src=\"assets/equations/50489aea6d050084.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h),\\quad h_t=z_t\\odot h_{t-1}+(1-z_t)\\odot\\widetilde h_t\" width=\"750.51\" height=\"31.13\" style=\"width:750.51px;height:31.13px;aspect-ratio:750.51/31.13\" loading=\"lazy\"></picture></div>","<p><strong>Symbols:</strong> In THIS convention, z weights the old state. Some sources reverse the two coefficients.</p>","<p><strong>Use:</strong> Read the stated update equation before substituting. For vector states, all gate products here are elementwise.</p>","<h3>Formula 46: Batch normalization and learned scale/shift</h3>","<p>Use during training to normalize intermediate activations before a learned scale and shift. m is the number of values; μ_B and σ²_B are the batch mean and population variance; γ and β are learned. Epsilon is inside the square root. Ordinary inference uses stored running statistics. The linked full lesson calculates every stage for [2,4].</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a91b1c9216cbd799.svg\" alt=\"\\mu_B=\\frac{1}{m}\\sum_{i=1}^{m}x_i\" width=\"160.06\" height=\"68.62\" style=\"width:160.06px;height:68.62px;aspect-ratio:160.06/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcfc8cc5fd3adc8.svg\" alt=\"\\sigma_B^2=\\frac{1}{m}\\sum_{i=1}^{m}(x_i-\\mu_B)^2\" width=\"244.63\" height=\"68.62\" style=\"width:244.63px;height:68.62px;aspect-ratio:244.63/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13126b94bcd9d415.svg\" alt=\"\\hat{x}_i=\\frac{x_i-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\" width=\"159.11\" height=\"75.23\" style=\"width:159.11px;height:75.23px;aspect-ratio:159.11/75.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7fd3e426f48f08b9.svg\" alt=\"y_i=\\gamma\\hat{x}_i+\\beta\" width=\"131.48\" height=\"25.07\" style=\"width:131.48px;height:25.07px;aspect-ratio:131.48/25.07\" loading=\"lazy\"></div>","<h3>Formula 47: Global average pooling</h3>","<p>Take a separate average for each full spatial feature map. H and W count rows and columns; c selects one of C channels; a is an activation value. Output has C values. The linked lesson computes two channel averages and the following dense-layer parameters.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/002749b4b374cf54.svg\" alt=\"g_c=\\frac{1}{HW}\\sum_{i=1}^{H}\\sum_{j=1}^{W}a_{i,j,c}\" width=\"239.71\" height=\"74.90\" style=\"width:239.71px;height:74.90px;aspect-ratio:239.71/74.90\" loading=\"lazy\"></div>","<h3>Formula 48: Top-k error percentage</h3>","<p>N is the total number of evaluated examples. C_k counts those whose true class is among the k highest-scoring predictions. Count failures, divide by total, then convert to percent. The worked lesson contrasts top-1 and top-5 using the same 100 images.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fb17785121a672d.svg\" alt=\"E_k=\\frac{N-C_k}{N}\\times100\\%\" width=\"239.34\" height=\"50.50\" style=\"width:239.34px;height:50.50px;aspect-ratio:239.34/50.50\" loading=\"lazy\"></div>"],"question":[],"answer":[],"kind":"read","id":"tee-c19-s1","search":"All formulas: meanings, use and substitution These are the formulas used by this guide. Each entry names its symbols and the type of calculation it serves. Numerical practice in the teaching chapters shows the longer working. Follow any different convention explicitly stated in the examination.\n\n### Formula 1: Mean, variance and standard deviation\n\n**Symbols:** n is the count; mu is the mean; v is the population variance; s is the standard deviation.\n**Use:** Use when calculating a population mean/variance or standardization. Sample-variance estimates may use n−1 when explicitly requested.\n**Substitution example:** For [2,4]: mean = 3; deviations = −1,1; squares = 1,1; variance = 1; standard deviation = 1.\n\n### Formula 2: Standardization\n\n**Symbols:** Use the mean and standard deviation estimated from training data.\n**Use:** Use to express a value relative to the training distribution. The standard deviation must be nonzero.\n**Substitution example:** For x = 7, mean = 5, standard deviation = 2: (7−5)/2 = 1.\n\n### Formula 3: Power, constant and sum derivatives\n\n**Symbols:** c is a constant, x is the changing variable and n is the power.\n**Use:** Use to differentiate the loss supplied in a gradient-descent question.\n**Substitution example:** For 0.7x³: derivative = 0.7 × 3 × x² = 2.1x².\n\n### Formula 4: Chain rule\n\n**Symbols:** z is the intermediate value linking w to L.\n**Use:** Multiply derivatives along a path; add contributions from distinct paths that meet.\n**Substitution example:** For z = 3w+1 and L = z² at w = 1: z = 4; derivative = (2×4)×3 = 24.\n\n### Formula 5: Dot product and a neuron\n\n**Symbols:** x is the input; w is its matching weight; b is one bias; z is the weighted sum; a is the activated output.\n**Use:** Multiply each matching pair, add the products, add bias once, then activate.\n**Substitution example:** x = [2,1], w = [0.5,−0.2], b = 0.1: z = 1−0.2+0.1 = 0.9.\n\n### Formula 6: Matrix multiplication\n\n**Symbols:** i selects a row of A; j selects a column of B; k runs along the matching entries.\n**Use:** Use row-times-column sums. A with shape m×n and B with n×p produces m×p.\n**Substitution example:** Row [1,2] times column [3,4] gives 1×3+2×4 = 11.\n\n### Formula 7: Layer forward pass\n\n**Symbols:** l labels the layer; the previous layer activations become inputs to the next layer.\n**Use:** For receiving-neuron rows, compute each row dot product and add that receiving neuron’s bias. Finish the whole layer before moving on.\n\n### Formula 8: Sigmoid and its derivative\n\n**Symbols:** e is approximately 2.71828; sigma is the output.\n**Use:** Use for a sigmoid forward pass and for its local backpropagation derivative.\n**Substitution example:** At z = 0: output = 1/(1+1) = 0.5; derivative = 0.5×0.5 = 0.25.\n\n### Formula 9: Tanh and its derivative\n\n**Symbols:** Tanh gives an output between −1 and 1.\n**Use:** Use for a stated tanh activation, commonly an RNN hidden state or recurrent candidate.\n**Substitution example:** At z = 0: numerator = 0, denominator = 2; output = 0; derivative = 1.\n\n### Formula 10: ReLU and its derivative\n\n**Symbols:** max means choose the larger value.\n**Use:** Use for ReLU. At zero the derivative is mathematically undefined; use the convention stated by the question or implementation.\n**Substitution example:** For −2, output = 0 and derivative = 0. For 3, output = 3 and derivative = 1.\n\n### Formula 11: Leaky ReLU\n\n**Symbols:** a is the small negative-side slope, commonly 0.01 unless specified.\n**Use:** For negati"},{"title":"Calculator sequence without model guesswork","blocks":["<p>The reported model name is “Casio FX ES 990”; the exact model is not confirmed. Use your calculator’s actual function labels. On common ES/ES Plus models, exp(x) is usually the shifted ln key, while the EXP/ × 10ˣ key enters scientific notation and is NOT the same as exp(x). Check the exact key labeling on your device.</p>","<p>For sigmoid at 2.2, type 1÷(1+exp(−2.2)). Keep the negative sign inside the exponential. Expected 0.900249511. For a negative gradient update, type old−rate × (negative gradient); use parentheses around the negative value. For cross-entropy, use −ln(probability), not log 10. For tanh, use the hyperbolic function or its exponential fraction if that function is difficult to find.</p>","<p>Retain 6–9 digits in intermediate results or use stored values; round final answers to 4–6 decimal places unless the paper says otherwise. Work line by line on paper even if the calculator can evaluate the whole expression. Check exp(0) = 1, ln(1) = 0, sigmoid(0) = 0.5, tanh(0) = 0 before relying on the chosen key sequence.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c19-s2","search":"Calculator sequence without model guesswork The reported model name is “Casio FX ES 990”; the exact model is not confirmed. Use your calculator’s actual function labels. On common ES/ES Plus models, exp(x) is usually the shifted ln key, while the EXP/ × 10ˣ key enters scientific notation and is NOT the same as exp(x). Check the exact key labeling on your device.\nFor sigmoid at 2.2, type 1÷(1+exp(−2.2)). Keep the negative sign inside the exponential. Expected 0.900249511. For a negative gradient update, type old−rate × (negative gradient); use parentheses around the negative value. For cross-entropy, use −ln(probability), not log 10. For tanh, use the hyperbolic function or its exponential fraction if that function is difficult to find.\nRetain 6–9 digits in intermediate results or use stored values; round final answers to 4–6 decimal places unless the paper says otherwise. Work line by line on paper even if the calculator can evaluate the whole expression. Check exp(0) = 1, ln(1) = 0, sigmoid(0) = 0.5, tanh(0) = 0 before relying on the chosen key sequence."},{"title":"What to write if the exam page feels blank","blocks":["<p>Pause briefly, put both feet down and take one slow breath. Then write only the GIVEN values and what is ASKED. Classify the question using the method map. Write its general formula before inserting numbers. One correct first line is a smaller task than “solve the whole question”.</p>","<p>For CNN, draw the shape chain. For back prop, draw arrows and label the loss. For an optimizer, draw columns for step, gradient, state, new parameter. For LSTM, write old part, new part, cell, hidden. If you remain stuck after a short attempt, leave visible working space and move to a question you can start. Return after collecting those marks.</p>","<p>The goal is to reduce the next action to something concrete and familiar. Practice it during mocks so it is available under time pressure.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c19-s3","search":"What to write if the exam page feels blank Pause briefly, put both feet down and take one slow breath. Then write only the GIVEN values and what is ASKED. Classify the question using the method map. Write its general formula before inserting numbers. One correct first line is a smaller task than “solve the whole question”.\nFor CNN, draw the shape chain. For back prop, draw arrows and label the loss. For an optimizer, draw columns for step, gradient, state, new parameter. For LSTM, write old part, new part, cell, hidden. If you remain stuck after a short attempt, leave visible working space and move to a question you can start. Return after collecting those marks.\nThe goal is to reduce the next action to something concrete and familiar. Practice it during mocks so it is available under time pressure."},{"title":"Answer lengths and partial credit habits","blocks":["<p>For 2 marks, give a precise definition plus the key distinction/example. For 5 marks, give the definition, a labeled diagram or formula, working/principle and a relevant implication. For 10 marks, answer every subpart: architecture or setup, main equations, stepwise explanation, required numerical working, and limitations or justification where asked. Do not pad a numerical with unrelated theory.</p>","<p>Always label assumptions when inputs, loss, threshold or matrix orientation are missing. Box the requested final result, include shapes or units, and retain working. An unsupported final number makes it harder to award method credit. Never say an optimizer guarantees global convergence or an architecture always outperforms another unless a specific theorem and its conditions actually apply.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c19-s4","search":"Answer lengths and partial credit habits For 2 marks, give a precise definition plus the key distinction/example. For 5 marks, give the definition, a labeled diagram or formula, working/principle and a relevant implication. For 10 marks, answer every subpart: architecture or setup, main equations, stepwise explanation, required numerical working, and limitations or justification where asked. Do not pad a numerical with unrelated theory.\nAlways label assumptions when inputs, loss, threshold or matrix orientation are missing. Box the requested final result, include shapes or units, and retain working. An unsupported final number makes it harder to award method credit. Never say an optimizer guarantees global convergence or an architecture always outperforms another unless a specific theorem and its conditions actually apply."},{"title":"Methods to revise before the examination","blocks":["<h3>Last-day revision: read in this order</h3>","<p>This is a revision digest after studying the lessons. Full solutions remain beside each topic and under Solved Questions. If a step here is unclear, return to that worked example; the final day is for recovering the method, not memorizing unexplained final numbers.</p>","<h3>1. Learning and the neuron</h3>","<p>Machine learning estimates a model from data. Deep learning uses multiple trainable layers to learn successive representations. Inputs describe a sample; targets are the required answers; predictions are the model&#x27;s answers. Weights and biases are learned parameters. Learning rate, batch size and architecture are chosen hyperparameters.</p>","<p>Training changes parameters using training examples. Validation selects settings/stopping time. Testing evaluates the final choice on held-out data. Overfitting means strong training performance with weak generalization; underfitting means the model has not captured enough of the relationship.</p>","<p>For one neuron, multiply each input by its own weight, add all products, add the bias once and apply the activation. A layer repeats this for several receiving neurons. Each weight-matrix row belongs to one receiving neuron. Transpose swaps rows and columns; it does not change signs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.90px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1489ef71177ccc4a.svg\"><img class=\"math display-math\" src=\"assets/equations/2beefda557917f96.svg\" alt=\"z=\\sum_iw_ix_i+b,\\qquad a=f(z)\" width=\"320.16\" height=\"52.35\" style=\"width:320.16px;height:52.35px;aspect-ratio:320.16/52.35\" loading=\"lazy\"></picture></div>","<p><strong>Memory cue:</strong> multiply → sum → bias → activate. In a full network, finish one complete layer before the next.</p>","<h3>2. Activation and loss choices</h3>","<p>Sigmoid maps to (0,1) and is used for binary-class probabilities. Tanh maps to (−1,1), centred on zero. Both can saturate, producing small derivatives. ReLU retains positive values and returns zero on the negative side; its negative-side gradient is zero. Leaky ReLU retains a specified small negative-side slope. Softmax normalizes a complete list of logits into mutually exclusive class probabilities.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.94px;--narrow-height:90.66px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fc390cc0a677c2cc.svg\"><img class=\"math display-math\" src=\"assets/equations/afe493539b707a8a.svg\" alt=\"\\sigma(z)=\\frac1{1+e^{-z}},\\qquad\\sigma\\prime(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"452.31\" height=\"51.56\" style=\"width:452.31px;height:51.56px;aspect-ratio:452.31/51.56\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc7dbcac123b9229.svg\" alt=\"\\tanh\\prime(z)=1-\\tanh^2(z)\" width=\"254.66\" height=\"27.91\" style=\"width:254.66px;height:27.91px;aspect-ratio:254.66/27.91\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:158.27px;--narrow-height:118.03px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd0c8ddf71d7e5e7.svg\"><img class=\"math display-math\" src=\"assets/equations/b901ae0600ed0d36.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}},\\qquad c=\\max_jz_j\" width=\"324.43\" height=\"63.31\" style=\"width:324.43px;height:63.31px;aspect-ratio:324.43/63.31\" loading=\"lazy\"></picture></div>","<p>For squared errors, SSE sums squares, half SSE divides that sum by 2, and MSE divides it by the number of scalar predictions. Their derivatives differ. For one-hot categorical cross-entropy, only the correct-class probability contributes. For binary cross-entropy, p means probability of class 1, not automatically the true class.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/38b125f3e664a9e5.svg\" alt=\"L_{\\mathrm{half}}=\\frac12\\sum_i(\\hat y_i-y_i)^2\" width=\"242.52\" height=\"61.92\" style=\"width:242.52px;height:61.92px;aspect-ratio:242.52/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52c8252c5d3ef107.svg\" alt=\"\\mathrm{MSE}=\\frac1n\\sum_i(\\hat y_i-y_i)^2\" width=\"249.46\" height=\"61.92\" style=\"width:249.46px;height:61.92px;aspect-ratio:249.46/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/519958f461b019f9.svg\" alt=\"L_{\\mathrm{BCE}}=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"373.89\" height=\"24.43\" style=\"width:373.89px;height:24.43px;aspect-ratio:373.89/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/266c4f8c9aa94e08.svg\" alt=\"L_{\\mathrm{CCE}}=-\\ln p_{\\mathrm{correct}}\" width=\"201.74\" height=\"21.70\" style=\"width:201.74px;height:21.70px;aspect-ratio:201.74/21.70\" loading=\"lazy\"></div>","<p><strong>Memory cue:</strong> loss ka denominator dekho before differentiating. Sigmoid output is not its derivative.</p>","<h3>3. Backpropagation: the repeatable method</h3>","<p>Write the given loss and activation first. Compute all forward sums/activations with the original parameters. Differentiate loss with respect to each output, multiply by the output activation derivative, and call the result the output delta.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0f696548e5b34122.svg\" alt=\"\\delta_o=\\frac{\\partial L}{\\partial o}f_o\\prime(z_o)\" width=\"164.94\" height=\"51.29\" style=\"width:164.94px;height:51.29px;aspect-ratio:164.94/51.29\" loading=\"lazy\"></div>","<p>For a hidden neuron, add the outgoing weighted deltas first and then multiply by the hidden activation derivative. Each connection gradient is receiving delta × sending activation. The bias gradient is the receiving delta. Use old weights for all gradients before making the simultaneous update.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea9470bc5f0a15d2.svg\" alt=\"\\delta_{h_i}=f_h\\prime(z_{h_i})\\sum_jW_{ji}^{(2)}\\delta_{o_j}\" width=\"261.95\" height=\"58.38\" style=\"width:261.95px;height:58.38px;aspect-ratio:261.95/58.38\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:143.05px;--narrow-height:130.54px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c82c3235c49eee6f.svg\"><img class=\"math display-math\" src=\"assets/equations/5e2e128efb837fa9.svg\" alt=\"\\frac{\\partial L}{\\partial W_{ji}}=\\delta_ja_i,\\qquad\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"292.78\" height=\"57.94\" style=\"width:292.78px;height:57.94px;aspect-ratio:292.78/57.94\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a5c419cc72b98572.svg\" alt=\"\\theta_{\\mathrm{new}}=\\theta-\\eta\\frac{\\partial L}{\\partial\\theta}\" width=\"170.52\" height=\"51.29\" style=\"width:170.52px;height:51.29px;aspect-ratio:170.52/51.29\" loading=\"lazy\"></div>","<p><strong>Memory cue:</strong> path mein multiply; paths milne par add; update sab gradients ke baad. For sigmoid+BCE or softmax+CCE, the logit delta simplifies to prediction−target for the stated single-example sum convention.</p>","<h3>4. Optimizers: identify the stored state</h3>","<p>Full-batch GD uses the entire dataset for one update; SGD uses one sample; mini-batch uses a subset. An epoch is one pass through the data. With a final incomplete batch included, updates per epoch are ceiling(N/B).</p>","<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>State and calculation order</th><th>Detail that changes the answer</th></tr></thead><tbody><tr><td>GD</td><td>Current gradient → subtract ηg</td><td>Recompute at the new parameter unless gradients are explicitly supplied</td></tr><tr><td>Momentum</td><td>Retain βv → subtract ηg → add new velocity to parameter</td><td>Signed velocity and gradient-average conventions must not be mixed</td></tr><tr><td>Nesterov</td><td>Compute lookahead θ+βv → gradient there → new velocity → update actual θ</td><td>Do not add new velocity to the lookahead point</td></tr><tr><td>AdaGrad</td><td>Add g² to all-past sum G → divide gradient by √G+ε</td><td>G never decreases</td></tr><tr><td>RMSProp</td><td>Decay old squared state → add recent g² → normalize</td><td>Use the specified decay factor</td></tr><tr><td>Adam</td><td>Update signed mean m and squared mean v → correct both → normalize</td><td>Carry raw states forward; correction powers use iteration t</td></tr></tbody></table></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.45px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/cfd2c8e117828e21.svg\"><img class=\"math display-math\" src=\"assets/equations/d6d609593a44d53f.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t,\\qquad\\theta_t=\\theta_{t-1}+v_t\" width=\"374.50\" height=\"22.51\" style=\"width:374.50px;height:22.51px;aspect-ratio:374.50/22.51\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/a5e0dae9a0fb7261.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\qquad\\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"329.41\" height=\"53.28\" style=\"width:329.41px;height:53.28px;aspect-ratio:329.41/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>Here v means signed velocity in momentum and squared-gradient state in Adam; the method defines the symbol. <strong>Memory cue:</strong> AdaGrad sab squares; RMSProp recent squares; Adam direction + squares + correction.</p>","<h3>5. Regularization and generalization</h3>","<p>L1 adds λΣ|w| and a nonzero-weight derivative λsign(w), encouraging sparsity. L2 with the half convention adds (λ/2)Σw² and derivative λw. Without that half, the derivative is 2λw. Regularization gradients add to data gradients before updating the weight.</p>","<p>Inverted dropout uses keep probability q: retain a sampled activation with scale 1/q, or replace it by zero. Inference uses the full activation without that training-time rescaling. Drop probability p gives q = 1−p. Early stopping tracks validation performance and restores the best checkpoint under the stated patience rule.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:121.40px;--narrow-height:87.91px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6e936750aa2b4998.svg\"><img class=\"math display-math\" src=\"assets/equations/3e23910228005a23.svg\" alt=\"a&#x27;_i=\\frac{m_i a_i}{q},\\qquad m_i\\in\\{0,1\\}\" width=\"293.39\" height=\"48.82\" style=\"width:293.39px;height:48.82px;aspect-ratio:293.39/48.82\" loading=\"lazy\"></picture></div>","<p><strong>Memory cue:</strong> dropout probability aur keep probability alag; L2 mein half hai ya nahi, pehle dekho.</p>","<h3>6. CNN calculation sequence</h3>","<p>Use the deep-learning cross-correlation convention unless the question explicitly requires kernel flipping. At each output position, multiply matching input-window and kernel entries, sum over spatial entries and all input channels, and add that filter&#x27;s bias once. A new filter creates a new output channel.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.92px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/859b60e888192c5a.svg\"><img class=\"math display-math\" src=\"assets/equations/e06cb7b0e9f45658.svg\" alt=\"P_{\\mathrm{conv}}=(K_hK_wC_{\\mathrm{in}}+1)C_{\\mathrm{out}}\" width=\"292.68\" height=\"24.43\" style=\"width:292.68px;height:24.43px;aspect-ratio:292.68/24.43\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d4064c7b5aff30cf.svg\"><img class=\"math display-math\" src=\"assets/equations/bf6a8c697b8e11ab.svg\" alt=\"n_{\\mathrm{flat}}=HWC,\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"425.84\" height=\"24.43\" style=\"width:425.84px;height:24.43px;aspect-ratio:425.84/24.43\" loading=\"lazy\"></picture></div>","<p>Apply the shape formula separately to height and width. Pooling changes spatial dimensions but preserves channels; ordinary pooling and flattening have zero learned parameters. Maximum pooling chooses the largest window value; average pooling adds its values and divides by the number of entries. A filter&#x27;s spatial reuse changes computation, not its parameter count.</p>","<p>For a complete architecture, make one row per layer: input shape → operation → output shape → weights → biases → total. Flatten uses the size after the final convolution/pool. <strong>Memory cue:</strong> shape count aur parameter count ko kabhi mix mat karo.</p>","<h3>7. CNN theory and architectures</h3>","<p>CNNs use local connectivity and weight sharing, reducing parameters compared with unrestricted dense image mappings. Convolution learns features; activations introduce nonlinearity; pooling summarizes local responses; dense or global-pooling/output stages make the final task prediction.</p>","<p>AlexNet: stacked convolutions with ReLU, pooling and dense classification; dropout in dense layers and data augmentation help control overfitting. Inception: parallel spatial scales, 1 × 1 reductions and channel concatenation. ResNet: learns a residual F(x) and adds a shortcut x; use projection when shapes differ. Concatenation adds channels; residual addition requires equal shapes and retains their count.</p>","<p>Transfer learning reuses a pretrained feature extractor, replaces the task head, trains the head and optionally fine-tunes selected pretrained layers at a suitable smaller learning rate. Explain classification, detection and segmentation as different outputs, with an appropriate concrete application.</p>","<h3>8. Recurrent models</h3>","<p>An RNN combines the current input with the previous activated hidden state using weights shared across time. Unroll the sequence and calculate one step at a time.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9dd7210eacaa003c.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b)\" width=\"349.64\" height=\"24.43\" style=\"width:349.64px;height:24.43px;aspect-ratio:349.64/24.43\" loading=\"lazy\"></div>","<p>For TEE, revise every recurrent-model item below. The faculty MT2 update received on 12 October focuses MT2 on Units 3 and 4; these Unit 5 RNN topics belong to the complete TEE preparation route.</p>","<p>BPTT applies the chain rule backward through the unrolled network. A shared weight receives contributions from all relevant time steps; sum them before the update. Repeated small derivative products can vanish; repeated large products can explode. Gradient clipping limits large updates; gated memory helps preserve useful long-range dependencies.</p>","<p>LSTM has a cell memory C and hidden state h. Sigmoid gates control retain/write/read proportions; the candidate uses tanh. Calculate activated gates first when raw gate scores are supplied.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8751dee634f91753.svg\" alt=\"C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"258.41\" height=\"30.37\" style=\"width:258.41px;height:30.37px;aspect-ratio:258.41/30.37\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a01a031c432f962.svg\" alt=\"h_t=o_t\\odot\\tanh(C_t)\" width=\"198.55\" height=\"24.43\" style=\"width:198.55px;height:24.43px;aspect-ratio:198.55/24.43\" loading=\"lazy\"></div>","<p>GRU uses reset and update gates with one hidden state. In the candidate-weighting convention used here:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/37663e895cb447b3.svg\" alt=\"\\widetilde h_t=\\tanh(Wx_t+U(r_t\\odot h_{t-1})+b)\" width=\"372.22\" height=\"31.13\" style=\"width:372.22px;height:31.13px;aspect-ratio:372.22/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.94px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/949c126edafa8f0a.svg\"><img class=\"math display-math\" src=\"assets/equations/40cc13a7254b2881.svg\" alt=\"h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"311.64\" height=\"31.13\" style=\"width:311.64px;height:31.13px;aspect-ratio:311.64/31.13\" loading=\"lazy\"></picture></div>","<p>If the question instead uses z to retain the old state, follow its reversed mixing convention. <strong>Memory cue:</strong> LSTM = old memory retain + new content write, then output gate. GRU = reset for candidate, update for final mixture.</p>","<h3>The final answer-writing routine</h3>","<p>For every numerical: full question → Given → To find → governing formula and why → separate numbered steps → final answer. Carry extra calculator precision; round at the end. Label each layer, iteration and connection so the examiner can follow the calculation.</p>","<p>For a definition question, state the technical meaning and the requested distinction/example. For a longer mechanism question, include a labelled diagram or equations, explain their sequence, then give the relevant benefits, limitations or comparison. Marks printed beside a historical question are its actual marks; individual steps here are not assigned invented official marks.</p>","<p>For a 180-minute TEE, a workable allocation is 10 minutes to read/select, about 30 minutes per attempted 20-mark main question, and 20 minutes to complete or review. Adjust to the paper. If stuck, write the givens and governing formula first, complete the solvable parts, then return to the unfinished calculation.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c19-s5","search":"Methods to revise before the examination \n### Last-day revision: read in this order\nThis is a revision digest after studying the lessons. Full solutions remain beside each topic and under Solved Questions. If a step here is unclear, return to that worked example; the final day is for recovering the method, not memorizing unexplained final numbers.\n\n### 1. Learning and the neuron\nMachine learning estimates a model from data. Deep learning uses multiple trainable layers to learn successive representations. Inputs describe a sample; targets are the required answers; predictions are the model's answers. Weights and biases are learned parameters. Learning rate, batch size and architecture are chosen hyperparameters.\n\nTraining changes parameters using training examples. Validation selects settings/stopping time. Testing evaluates the final choice on held-out data. Overfitting means strong training performance with weak generalization; underfitting means the model has not captured enough of the relationship.\n\nFor one neuron, multiply each input by its own weight, add all products, add the bias once and apply the activation. A layer repeats this for several receiving neurons. Each weight-matrix row belongs to one receiving neuron. Transpose swaps rows and columns; it does not change signs.\n\n**Memory cue:** multiply → sum → bias → activate. In a full network, finish one complete layer before the next.\n\n### 2. Activation and loss choices\nSigmoid maps to (0,1) and is used for binary-class probabilities. Tanh maps to (−1,1), centred on zero. Both can saturate, producing small derivatives. ReLU retains positive values and returns zero on the negative side; its negative-side gradient is zero. Leaky ReLU retains a specified small negative-side slope. Softmax normalizes a complete list of logits into mutually exclusive class probabilities.\n\n\n\nFor squared errors, SSE sums squares, half SSE divides that sum by 2, and MSE divides it by the number of scalar predictions. Their derivatives differ. For one-hot categorical cross-entropy, only the correct-class probability contributes. For binary cross-entropy, p means probability of class 1, not automatically the true class.\n\n\n\n\n**Memory cue:** loss ka denominator dekho before differentiating. Sigmoid output is not its derivative.\n\n### 3. Backpropagation: the repeatable method\nWrite the given loss and activation first. Compute all forward sums/activations with the original parameters. Differentiate loss with respect to each output, multiply by the output activation derivative, and call the result the output delta.\n\nFor a hidden neuron, add the outgoing weighted deltas first and then multiply by the hidden activation derivative. Each connection gradient is receiving delta × sending activation. The bias gradient is the receiving delta. Use old weights for all gradients before making the simultaneous update.\n\n\n\n**Memory cue:** path mein multiply; paths milne par add; update sab gradients ke baad. For sigmoid+BCE or softmax+CCE, the logit delta simplifies to prediction−target for the stated single-example sum convention.\n\n### 4. Optimizers: identify the stored state\nFull-batch GD uses the entire dataset for one update; SGD uses one sample; mini-batch uses a subset. An epoch is one pass through the data. With a final incomplete batch included, updates per epoch are ceiling(N/B).\n\n| Method | State and calculation order | Detail that changes the answer |\n| GD | Current gradient → subtract ηg | Recompute at the new pa"}]},{"n":20,"title":"Course vocabulary in plain words","sections":[{"title":"Learning and the numbers we adjust","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Term</th><th>Meaning</th><th>Tiny example</th></tr></thead><tbody><tr><td>Input / feature</td><td>A number given to the model</td><td>Image pixel intensity</td></tr><tr><td>Sample</td><td>One example processed by the model</td><td>One labeled image</td></tr><tr><td>Dataset</td><td>A collection of examples</td><td>1,000 training images</td></tr><tr><td>Target / label</td><td>Correct answer supplied for training</td><td>Class 2 is correct</td></tr><tr><td>Prediction</td><td>Model&#x27;s current answer</td><td>Class probabilities</td></tr><tr><td>Weight</td><td>Learned multiplier on a connection</td><td>0.4 multiplying an input</td></tr><tr><td>Bias</td><td>Learned value added to a weighted sum</td><td>z = wx + b</td></tr><tr><td>Parameter</td><td>A value learned during training</td><td>Weight or bias</td></tr><tr><td>Hyperparameter</td><td>A setting chosen for training</td><td>Learning rate or batch size</td></tr><tr><td>Activation</td><td>Transformation of a neuron&#x27;s raw score</td><td>ReLU or sigmoid</td></tr><tr><td>Loss</td><td>Numerical measure of prediction error</td><td>Mean squared error</td></tr><tr><td>Gradient</td><td>Local rate of loss change for parameters</td><td>Positive g means locally uphill</td></tr><tr><td>Optimizer</td><td>Rule using gradients to update parameters</td><td>Momentum or Adam</td></tr><tr><td>Epoch</td><td>One pass through the training dataset</td><td>All 100 samples processed</td></tr><tr><td>Iteration</td><td>One parameter update in these exercises</td><td>One mini-batch update</td></tr><tr><td>Inference</td><td>Applying the trained model</td><td>Predicting a new image&#x27;s class</td></tr></tbody></table></div>"],"question":[],"answer":[],"kind":"read","id":"tee-c20-s0","search":"Learning and the numbers we adjust | Term | Meaning | Tiny example |\n| Input / feature | A number given to the model | Image pixel intensity |\n| Sample | One example processed by the model | One labeled image |\n| Dataset | A collection of examples | 1,000 training images |\n| Target / label | Correct answer supplied for training | Class 2 is correct |\n| Prediction | Model's current answer | Class probabilities |\n| Weight | Learned multiplier on a connection | 0.4 multiplying an input |\n| Bias | Learned value added to a weighted sum | z = wx + b |\n| Parameter | A value learned during training | Weight or bias |\n| Hyperparameter | A setting chosen for training | Learning rate or batch size |\n| Activation | Transformation of a neuron's raw score | ReLU or sigmoid |\n| Loss | Numerical measure of prediction error | Mean squared error |\n| Gradient | Local rate of loss change for parameters | Positive g means locally uphill |\n| Optimizer | Rule using gradients to update parameters | Momentum or Adam |\n| Epoch | One pass through the training dataset | All 100 samples processed |\n| Iteration | One parameter update in these exercises | One mini-batch update |\n| Inference | Applying the trained model | Predicting a new image's class |"},{"title":"Images and sequences","blocks":["<div class=\"table-scroll\"><table><thead><tr><th>Term</th><th>Meaning</th><th>What to keep separate</th></tr></thead><tbody><tr><td>Tensor</td><td>Array of numbers with one or more axes</td><td>Its shape and its values</td></tr><tr><td>Channel</td><td>One feature map within an image-like tensor</td><td>Channels versus spatial size</td></tr><tr><td>Kernel / filter</td><td>Learned weights sliding over a map</td><td>Kernel size versus filter count</td></tr><tr><td>Stride</td><td>Step between adjacent window positions</td><td>Stride versus kernel width</td></tr><tr><td>Padding</td><td>Extra border cells around an input</td><td>Per-side P versus total 2P</td></tr><tr><td>Feature map</td><td>Responses from a filter across positions</td><td>Activations versus parameters</td></tr><tr><td>Pooling</td><td>Window-based reduction of feature maps</td><td>Maximum versus average</td></tr><tr><td>Flatten</td><td>Rearrange H × W × C entries as a vector</td><td>Rearrangement has no parameters</td></tr><tr><td>Logit</td><td>Raw score before an output activation</td><td>Score versus probability</td></tr><tr><td>Hidden state</td><td>Recurrent features carried through time</td><td>Previous state versus current input</td></tr><tr><td>Shared weights</td><td>One learned rule reused at many positions/times</td><td>Reuse versus extra parameters</td></tr></tbody></table></div>"],"question":[],"answer":[],"kind":"read","id":"tee-c20-s1","search":"Images and sequences | Term | Meaning | What to keep separate |\n| Tensor | Array of numbers with one or more axes | Its shape and its values |\n| Channel | One feature map within an image-like tensor | Channels versus spatial size |\n| Kernel / filter | Learned weights sliding over a map | Kernel size versus filter count |\n| Stride | Step between adjacent window positions | Stride versus kernel width |\n| Padding | Extra border cells around an input | Per-side P versus total 2P |\n| Feature map | Responses from a filter across positions | Activations versus parameters |\n| Pooling | Window-based reduction of feature maps | Maximum versus average |\n| Flatten | Rearrange H × W × C entries as a vector | Rearrangement has no parameters |\n| Logit | Raw score before an output activation | Score versus probability |\n| Hidden state | Recurrent features carried through time | Previous state versus current input |\n| Shared weights | One learned rule reused at many positions/times | Reuse versus extra parameters |"},{"title":"Reading a question precisely","blocks":["<p>“Calculate” asks for arithmetic and a result. Write the formula and substitutions before the final number.</p>","<p>“Explain” asks how and why a method works. Give its definition, describe the steps, and connect each step to its purpose.</p>","<p>“Compare” asks for matched differences. Discuss the same attributes for both methods, such as stored state, update rule, benefit and limitation.</p>","<p>“Draw” asks for a labeled structure. Label inputs, layers or time steps, arrows, activations and the output. A diagram and explanation should describe the same computation.</p>","<p>“Design” asks for a justified arrangement. State the task, input and output, chosen layers, activation/loss pair and training procedure. State any assumption needed because the question leaves a value unspecified.</p>"],"question":[],"answer":[],"kind":"read","id":"tee-c20-s2","search":"Reading a question precisely “Calculate” asks for arithmetic and a result. Write the formula and substitutions before the final number.\n“Explain” asks how and why a method works. Give its definition, describe the steps, and connect each step to its purpose.\n“Compare” asks for matched differences. Discuss the same attributes for both methods, such as stored state, update rule, benefit and limitation.\n“Draw” asks for a labeled structure. Label inputs, layers or time steps, arrows, activations and the output. A diagram and explanation should describe the same computation.\n“Design” asks for a justified arrangement. State the task, input and output, chosen layers, activation/loss pair and training procedure. State any assumption needed because the question leaves a value unspecified."}]},{"n":21,"title":"February 2025 re-exam · complete solved paper","sourceKind":"actual-paper","sections":[{"id":"tee-c21-s0","title":"R25 Q1a · ML versus DL and architecture choice","kind":"practice","question":["<p><strong>Question. Compare ML and DL. Choose architectures for five-class diabetic-retinopathy retinal images, alphabet-image recognition, and weather prediction from N days of history.</strong> (5 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> Deep learning is a subfield of machine learning that learns representations through multiple trainable processing layers. Each layer transforms the preceding representation, allowing the complete model to learn a composition of functions from data.</p><h3>Position within artificial intelligence</h3><p>Artificial intelligence studies systems that perform tasks such as perception, reasoning and decision-making. Machine learning develops models whose parameters or behavior are estimated from data. Deep learning uses layered neural models within machine learning.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/862fde9ce2f6cd54.svg\" alt=\"\\text{Deep learning}\\subset\\text{Machine learning}\\subset\\text{Artificial intelligence}\" width=\"613.55\" height=\"22.53\" style=\"width:613.55px;height:22.53px;aspect-ratio:613.55/22.53\" loading=\"lazy\"></div><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_ai_ml_dl.svg\" aria-label=\"Enlarge diagram: AI is the broad field. Machine learning learns from data; deep learning learns through multiple representation layers.\"><img src=\"assets/figures/v_ai_ml_dl.svg\" alt=\"AI is the broad field. Machine learning learns from data; deep learning learns through multiple representation layers.\" width=\"1080\" height=\"590\" loading=\"lazy\"></button><figcaption>AI is the broad field. Machine learning learns from data; deep learning learns through multiple representation layers. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><h3>Motivation: why use multiple learned layers?</h3><p><strong>Representation learning.</strong> Hand-designing every useful image or speech feature is difficult. A deep model can learn intermediate representations together with the final prediction objective. In a CNN, early layers may respond to local edges, while later layers combine information over larger regions. These patterns depend on training and are not guaranteed to have a particular human meaning.</p><p><strong>Nonlinear relationships.</strong> Real tasks often depend on combinations of input variables. Composing affine transformations with nonlinear activations can represent interactions that a single linear decision boundary cannot. Depth supplies repeated transformations; increasing only the number of neurons in one layer changes width instead.</p><p><strong>End-to-end optimization.</strong> The final task loss supplies gradients to the preceding trainable layers. The feature extractor and prediction head can therefore be adjusted for the same task. Preprocessing and human decisions about architecture, data and evaluation still remain necessary.</p><h3>Factors that made deep learning practical</h3><div class=\"table-scroll\"><table><thead><tr><th>Factor</th><th>How it contributes</th></tr></thead><tbody><tr><td>Larger datasets</td><td>Provide more examples of the variations a complex model must learn</td></tr><tr><td>GPUs and parallel computation</td><td>Accelerate the large matrix and convolution operations used in training</td></tr><tr><td>Improved training methods</td><td>Backpropagation, suitable activations, initialization and optimizers make fitting deep models more practical</td></tr><tr><td>Pretrained models</td><td>Reuse learned features so a new task may require less labeled data and training effort</td></tr></tbody></table></div><h3>Applications in different domains</h3><p>An application answer should identify the input, the prediction and the role of the learned representation.</p><div class=\"table-scroll\"><table><thead><tr><th>Domain</th><th>Example input</th><th>Required output</th><th>Role of deep learning</th></tr></thead><tbody><tr><td>Computer vision</td><td>Photograph or video frame</td><td>Image class, object locations or pixel labels</td><td>Learn visual features with a CNN and an appropriate task head</td></tr><tr><td>Language</td><td>Review, sentence or conversation</td><td>Sentiment label, translated words or a response</td><td>Learn representations of text and its context</td></tr><tr><td>Speech</td><td>Audio sequence</td><td>Words or a speaker label</td><td>Model patterns in acoustic features over time</td></tr><tr><td>Healthcare</td><td>Medical image or patient measurements</td><td>A task-specific class or numerical estimate</td><td>Learn associations from labeled examples; assess results on suitable held-out data</td></tr><tr><td>Autonomous systems and robotics</td><td>Camera and other sensor measurements</td><td>Perception estimates used by a larger control system</td><td>Recognize objects and relevant environmental features</td></tr><tr><td>Financial services</td><td>Transaction features or a time-ordered record</td><td>Fraud score, risk estimate or forecast</td><td>Model patterns and interactions among observations</td></tr></tbody></table></div><h3>Advantages, limitations and comparison with traditional ML</h3><div class=\"table-scroll\"><table><thead><tr><th>Aspect</th><th>Traditional machine learning often uses</th><th>Deep learning often uses</th></tr></thead><tbody><tr><td>Representation</td><td>Selected or engineered input features</td><td>Features learned jointly across layers</td></tr><tr><td>Useful architectures</td><td>Linear models, decision trees, SVMs</td><td>MLPs, CNNs, RNNs and gated recurrent models</td></tr><tr><td>Training from scratch</td><td>Can be effective with modest structured datasets</td><td>Large models often need substantial data and computation</td></tr><tr><td>Interpretation</td><td>Some models have directly inspectable rules or coefficients</td><td>Learned internal representations can be harder to interpret</td></tr></tbody></table></div><p>Feature learning, flexible nonlinear modeling and reuse of pretrained representations are major advantages. Limitations include computation and memory costs, overfitting with insufficient representative data, difficulty interpreting predictions, and reduced reliability when deployment data differs from training data. High training accuracy does not establish generalization.</p><p>These are tendencies, not absolute divisions. Traditional ML can also learn representations; deep models can process tabular data. A pretrained deep model may be useful even with a small target dataset. Select the model according to the task, available data, resources and validation results.</p><p class=\"inline-question\"><strong>Question. Explain the motivation for deep learning and describe applications in at least three domains.</strong></p><p><strong>Answer.</strong> Deep learning is motivated by the need to learn useful hierarchical representations and nonlinear relationships directly from complex data. Multiple trainable layers compose feature transformations, and the task loss can train those transformations jointly with the predictor. Larger datasets, GPU computation and improved optimization methods have made this practical. In computer vision, CNNs learn visual features for image classification and object localization. In language processing, neural sequence models use word representations and context for sentiment analysis or translation. In speech processing, neural models map acoustic patterns to words. The benefits must be balanced against data requirements, computation, overfitting and interpretability limitations.</p><div class=\"table-wrap\"><table><thead><tr><th>Task</th><th>Suitable architecture</th><th>Why / output</th></tr></thead><tbody><tr><td>Retinal images,5classes</td><td>CNN</td><td>Spatial image features;5-way softmax for exclusive classes</td></tr><tr><td>Alphabet images</td><td>CNN</td><td>Edges/shapes compose into characters; class-count softmax</td></tr><tr><td>Weather from a temporal history</td><td>RNN/LSTM or GRU</td><td>Ordered history; regression output for numeric weather quantities, suitable classification head for categorical weather</td></tr></tbody></table></div><p>Architecture choice is justified by data structure. A fully connected model can technically take flattened images, but ignores spatial locality; sequential models preserve temporal order.</p>"],"search":"ML versus DL and architecture choice Compare ML and DL. Choose architectures for five-class diabetic-retinopathy retinal images, alphabet-image recognition, and weather prediction from N days of history.","units":[1,4,5],"marks":5,"sourcePages":[1],"sourceKind":"actual-paper"},{"id":"tee-c21-s1","title":"R25 Q1b · Training and validation errors","kind":"practice","question":["<p><strong>Question. Choose best and worst models from training/validation errors: M1=0.9/1.2; M2=0.3/0.6; M3=1.5/0.5; M4=1.2/1.1. Explain the reasoning and remedies.</strong> (5 marks)</p>"],"answer":["<div class=\"table-wrap\"><table><thead><tr><th>Model</th><th>Train</th><th>Validation</th></tr></thead><tbody><tr><td>1</td><td>0.9</td><td>1.2</td></tr><tr><td>2</td><td>0.3</td><td>0.6</td></tr><tr><td>3</td><td>1.5</td><td>0.5</td></tr><tr><td>4</td><td>1.2</td><td>1.1</td></tr></tbody></table></div><p><strong>For the same validation set and same loss definition, M3 is best (0.5) and M1 is worst (1.2).</strong> Choose by validation performance, not the smallest training loss. M2 has the smallest training error but a larger validation error than M3.</p><p>M3’s validation loss below training loss is unusual but not logically impossible: training-only dropout/augmentation, different regularization inclusion or an easier validation sample can cause this. First verify comparable evaluation conditions and leakage-free splits. Error values alone do not prove overfitting or underfitting without baselines and learning curves.</p><p>For poor generalization, inspect data quality/splits and learning curves; if overfitting is established, use regularization, dropout, more suitable data or early stopping; if underfitting is established, improve model capacity/features or training. Do not prescribe a larger network solely from these four numbers.</p>"],"search":"Training and validation errors Choose best and worst models from training/validation errors: M1=0.9/1.2; M2=0.3/0.6; M3=1.5/0.5; M4=1.2/1.1. Explain the reasoning and remedies.","units":[3],"marks":5,"sourcePages":[1],"sourceKind":"actual-paper"},{"id":"tee-c21-s2","title":"R25 Q1c · CNN hierarchy and stride-two convolution","kind":"practice","question":["<p><strong>Question. Explain why CNNs use a hierarchy of convolutional layers. Apply the printed3×3kernel to the5×5input with stride2.</strong> (5 marks)</p>"],"answer":["<p>Early layers learn local edge/texture patterns; deeper layers combine them into parts and class-relevant configurations, with a growing receptive field. Nonlinearities make stacked layers more expressive than one linear convolution.</p><h3>Given</h3><p>Input:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-26a644e9131b783f.svg\" alt=\"\\begin{bmatrix}2&amp;3&amp;8&amp;2&amp;3\\\\2&amp;2&amp;4&amp;4&amp;6\\\\1&amp;2&amp;1&amp;2&amp;9\\\\7&amp;5&amp;3&amp;3&amp;2\\\\2&amp;4&amp;3&amp;5&amp;4\\end{bmatrix}\" style=\"width:17.724ex;height:14.932ex\" loading=\"lazy\"></div><p>Kernel:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-dfae566e77e4351c.svg\" alt=\"\\begin{bmatrix}1&amp;0&amp;1\\\\2&amp;4&amp;0\\\\6&amp;4&amp;2\\end{bmatrix}\" style=\"width:10.937ex;height:8.597ex\" loading=\"lazy\"></div><p>Stride=2, zero padding=0, no bias supplied.</p><h3>To find</h3><p>Valid cross-correlation output (CNN convention, no kernel flip).</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-cbf0b1f38ebaaccb.svg\" alt=\"O=\\left\\lfloor\\frac{N+2P-F}{S}\\right\\rfloor+1\" style=\"width:24.339ex;height:5.428ex\" loading=\"lazy\"></div><p>Multiply corresponding cells and sum. Here O=⌊(5−3)/2⌋+1=2 in each direction.</p><h3>Step 1. Output (1,1) from input top-left (1,1)</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-217f7d6e6c6e566c.svg\" alt=\"\\begin{bmatrix}2&amp;3&amp;8\\\\2&amp;2&amp;4\\\\1&amp;2&amp;1\\end{bmatrix}\" style=\"width:10.937ex;height:8.597ex\" loading=\"lazy\"></div><p>2×1 + 3×0 + 8×1 + 2×2 + 2×4 + 4×0 + 1×6 + 2×4 + 1×2 = 2 + 0 + 8 + 4 + 8 + 0 + 6 + 8 + 2 = 38</p><h3>Step 2. Output (1,2) from input top-left (1,3)</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-fd5db35a9f88c331.svg\" alt=\"\\begin{bmatrix}8&amp;2&amp;3\\\\4&amp;4&amp;6\\\\1&amp;2&amp;9\\end{bmatrix}\" style=\"width:10.937ex;height:8.597ex\" loading=\"lazy\"></div><p>8×1 + 2×0 + 3×1 + 4×2 + 4×4 + 6×0 + 1×6 + 2×4 + 9×2 = 8 + 0 + 3 + 8 + 16 + 0 + 6 + 8 + 18 = 67</p><h3>Step 3. Output (2,1) from input top-left (3,1)</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-c03180114d7dc748.svg\" alt=\"\\begin{bmatrix}1&amp;2&amp;1\\\\7&amp;5&amp;3\\\\2&amp;4&amp;3\\end{bmatrix}\" style=\"width:10.937ex;height:8.597ex\" loading=\"lazy\"></div><p>1×1 + 2×0 + 1×1 + 7×2 + 5×4 + 3×0 + 2×6 + 4×4 + 3×2 = 1 + 0 + 1 + 14 + 20 + 0 + 12 + 16 + 6 = 70</p><h3>Step 4. Output (2,2) from input top-left (3,3)</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-99c4e3c248d2285d.svg\" alt=\"\\begin{bmatrix}1&amp;2&amp;9\\\\3&amp;3&amp;2\\\\3&amp;5&amp;4\\end{bmatrix}\" style=\"width:10.937ex;height:8.597ex\" loading=\"lazy\"></div><p>1×1 + 2×0 + 9×1 + 3×2 + 3×4 + 2×0 + 3×6 + 5×4 + 4×2 = 1 + 0 + 9 + 6 + 12 + 0 + 18 + 20 + 8 = 74</p><h3>Final answer</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-58e9e7ec888c133f.svg\" alt=\"\\begin{bmatrix}38&amp;67\\\\70&amp;74\\end{bmatrix}\" style=\"width:9.176ex;height:5.43ex\" loading=\"lazy\"></div><p><strong>Source / convention note.</strong> Padding is not specified; valid/no-padding is declared. CNN cross-correlation convention is used without kernel reversal.</p>"],"search":"CNN hierarchy and stride-two convolution Explain why CNNs use a hierarchy of convolutional layers. Apply the printed3×3kernel to the5×5input with stride2.","units":[4],"marks":5,"sourcePages":[1],"sourceKind":"actual-paper"},{"id":"tee-c21-s3","title":"R25 Q1d · BPTT and recurrent strengths","kind":"practice","question":["<p><strong>Question. Compare BPTT with feedforward backpropagation and state the strengths of RNNs.</strong> (5 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> Backpropagation through time (BPTT) differentiates the loss of an RNN by applying backpropagation to its temporally unrolled computational graph and summing contributions to shared parameters.</p><h3>Explanation and working</h3><p>Unroll the recurrent network for the sequence length. Run the forward calculation in time order. Calculate the specified loss. Differentiate backwards through the unrolled graph. Add contributions to each shared weight from every time it was used. Update each shared weight once for the selected sequence or batch. This is backpropagation through time, or BPTT.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bptt.svg\" aria-label=\"Enlarge diagram: Unroll forward through time, then accumulate backward contributions for the shared parameters.\"><img src=\"assets/figures/v_bptt.svg\" alt=\"Unroll forward through time, then accumulate backward contributions for the shared parameters.\" width=\"1080\" height=\"670\" loading=\"lazy\"></button><figcaption>Unroll forward through time, then accumulate backward contributions for the shared parameters. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><p>For tanh, let δₜ mean the gradient with respect to the hidden preactivation. The following form allows losses at several time steps; a missing output loss contributes zero.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/05416576e2064832.svg\" alt=\"\\delta_t=\\left(W_{hy}^{T}\\delta_t^{out}+W_{hh}^{T}\\delta_{t+1}\\right)\\odot(1-h_t^2)\" width=\"386.74\" height=\"31.63\" style=\"width:386.74px;height:31.63px;aspect-ratio:386.74/31.63\" loading=\"lazy\"></div><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:211.84px;--narrow-height:216.86px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1b44f91dfbf3ef75.svg\"><img class=\"math display-math\" src=\"assets/equations/dc28790fa408d967.svg\" alt=\"\\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^{T},\\quad \\frac{\\partial L}{\\partial W_{xh}}=\\sum_t\\delta_t x_t^{T},\\quad \\frac{\\partial L}{\\partial b_h}=\\sum_t\\delta_t\" width=\"602.48\" height=\"62.51\" style=\"width:602.48px;height:62.51px;aspect-ratio:602.48/62.51\" loading=\"lazy\"></picture></div><p>The symbol ⊙ means pairwise multiplication. The transpose T turns a column into a row. δnext carries the effect of future time steps. The summation is essential because these are shared parameters.</p><h3>One BPTT delta at h = 0.5</h3><p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, h_t = 0.5, current output-path derivative = 0.2, next-step delta = 0.3 and recurrent weight = 0.4. Find the current preactivation delta.</strong></p><h3>Given</h3><p>Activated h_t = 0.5; q_t = 0.2; δ_(t+1) = 0.3; recurrent weight u = 0.4.</p><h3>To find</h3><p>Current preactivation delta δ_t.</p><h3>Formula — which one and why</h3><p>Two paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.</p><p>q_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Future aur current dono add; tanh slope uske baad.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: calculate the future path contribution.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bb48ef38d6d22273.svg\" alt=\"0.4(0.3)=0.12\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: add the current output contribution.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fdbe3cda286c3c16.svg\" alt=\"0.2+0.12=0.32\" width=\"180.57\" height=\"18.27\" style=\"width:180.57px;height:18.27px;aspect-ratio:180.57/18.27\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: calculate the current tanh slope.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f60b4793b26f591.svg\" alt=\"1-(0.5)^2=0.75\" width=\"179.02\" height=\"27.70\" style=\"width:179.02px;height:27.70px;aspect-ratio:179.02/27.70\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: multiply by that slope.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e726c1bb32ed233e.svg\" alt=\"\\delta_t=(0.32)(0.75)=0.24\" width=\"252.63\" height=\"24.43\" style=\"width:252.63px;height:24.43px;aspect-ratio:252.63/24.43\" loading=\"lazy\"></div><p><strong>Final answer:</strong> δ_t = 0.24.</p><h3>One BPTT delta at h = -0.2</h3><p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, h_t = -0.2, current output-path derivative = 0.1, next-step delta = 0 and recurrent weight = 0.5. Find the current preactivation delta.</strong></p><h3>Given</h3><p>Activated h_t = -0.2; q_t = 0.1; δ_(t+1) = 0; recurrent weight u = 0.5.</p><h3>To find</h3><p>Current preactivation delta δ_t.</p><h3>Formula — which one and why</h3><p>Two paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.</p><p>q_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Future aur current dono add; tanh slope uske baad.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: calculate the future path contribution.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ad7c98370e2604f.svg\" alt=\"0.5(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: add the current output contribution.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d31df4938e5db9a.svg\" alt=\"0.1+0=0.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: calculate the current tanh slope.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb671dc68ac70d16.svg\" alt=\"1-(-0.2)^2=0.96\" width=\"198.03\" height=\"27.70\" style=\"width:198.03px;height:27.70px;aspect-ratio:198.03/27.70\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: multiply by that slope.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c494eb0b53453545.svg\" alt=\"\\delta_t=(0.1)(0.96)=0.096\" width=\"252.63\" height=\"24.43\" style=\"width:252.63px;height:24.43px;aspect-ratio:252.63/24.43\" loading=\"lazy\"></div><p><strong>Final answer:</strong> δ_t = 0.096.</p><div class=\"table-wrap\"><table><thead><tr><th>Feedforward backprop</th><th>BPTT</th></tr></thead><tbody><tr><td>Propagate through layers in one acyclic graph</td><td>Unroll recurrence through time, then propagate through the resulting acyclic graph</td></tr><tr><td>Layer-specific parameters usually distinct</td><td>Recurrent parameters shared across time; sum gradient contributions over all uses</td></tr><tr><td>No persistent temporal state by default</td><td>Hidden state connects earlier and later steps</td></tr><tr><td>Depth-related gradient issues</td><td>Long time paths add vanishing/exploding difficulty; truncation limits path length</td></tr></tbody></table></div><p>RNN strengths: variable-length sequences, shared parameters and order-dependent context; applications include language, speech and time series. Memory is not perfect and vanilla RNNs struggle with long dependencies.</p>"],"search":"BPTT and recurrent strengths Compare BPTT with feedforward backpropagation and state the strengths of RNNs.","units":[5],"marks":5,"sourcePages":[1,2],"sourceKind":"actual-paper"},{"id":"tee-c21-s4","title":"R25 Q2a · Activation, ReLU and numeric outputs","kind":"practice","question":["<p><strong>Question. Explain why activation functions are needed and sketch ReLU. Is sigmoid appropriate for an unscaled house-price output? Compute softmax([1.2,3.4,0.9]) and sigmoid(2.5).</strong> (10 marks)</p>"],"answer":["<p>An activation function transforms a neuron&#x27;s weighted sum into its output. Nonlinear activations allow successive layers to represent nonlinear relationships. If every layer is only linear or affine, composing those layers still gives one affine transformation; depth alone does not create a nonlinear decision boundary.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_nonlinear.svg\" aria-label=\"Enlarge diagram: Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation.\"><img src=\"assets/figures/v_nonlinear.svg\" alt=\"Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Substituting one affine rule into another still gives a single affine rule. A nonlinear activation changes this limitation. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><h3>Why two linear layers are still linear in the input</h3><p>For the first layer let h = 2x + 1. Let the second output be y = 3h + 4. Substitute the first rule into the second:</p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.93px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f54676c512498a38.svg\"><img class=\"math display-math\" src=\"assets/equations/0da4ca75660c25f8.svg\" alt=\"y=3(2x+1)+4=6x+3+4=6x+7\" width=\"429.97\" height=\"24.43\" style=\"width:429.97px;height:24.43px;aspect-ratio:429.97/24.43\" loading=\"lazy\"></picture></div><p>This is one straight-line rule. A nonlinear activation between the two calculations changes what the combined model can represent.</p><div class=\"table-scroll\"><table><thead><tr><th>Activation</th><th>Output range</th><th>Useful property</th><th>Main limitation</th></tr></thead><tbody><tr><td>Sigmoid</td><td>Strictly between 0 and 1</td><td>Useful as a binary-class probability output</td><td>Saturates at large positive or negative inputs; gradients become small</td></tr><tr><td>Tanh</td><td>Strictly between −1 and 1</td><td>Can represent signed, zero-centered activations</td><td>Also saturates and can contribute to vanishing gradients</td></tr><tr><td>ReLU</td><td>From 0 upward</td><td>Simple; derivative is 1 for positive inputs</td><td>A unit that stays on the negative side receives zero local gradient</td></tr></tbody></table></div><p>Sigmoid and tanh do not return negative and positive versions of the same scale: their ranges differ. ReLU is not restricted to values below 1. For multiclass output, softmax normalizes a group of class scores so the probabilities sum to 1; it acts on the score vector rather than independently applying sigmoid to each score.</p><p><strong>Exam conclusion:</strong> select the activation according to the layer&#x27;s job and task. Hidden layers need useful nonlinear transformations; the output activation must match the meaning of the desired prediction.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-1c6ec1b1ec321f01.svg\" alt=\"\\mathrm{ReLU}(z)=\\max(0,z)\" style=\"width:20.77ex;height:2.262ex\" loading=\"lazy\"></div><svg style=\"width:100%;height:auto;max-width:100%\" viewBox=\"0 0 360 220\" role=\"img\" aria-label=\"ReLU: zero for negative input, line y=x for positive input\"><path d=\"M20 180H330M160 205V20\" fill=\"none\" stroke=\"#777\"/><path d=\"M20 180H160L310 30\" fill=\"none\" stroke=\"#176950\" stroke-width=\"4\"/><text x=\"320\" y=\"200\">z</text><text x=\"170\" y=\"25\">a</text></svg><p>Unscaled house prices are not restricted to(0,1), so a sigmoid cannot directly represent them. Use a linear regression output (or a justified positive-valued transform). A sigmoid could be used only with a deliberately bounded/normalized target and inverse transformation.</p><h3>Given</h3><p>Logits=[1.2,3.4,0.9]; separate sigmoid input=2.5.</p><h3>To find</h3><p>Normalized class probabilities and sigmoid value.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-051b60342e33ce99.svg\" alt=\"p_i=\\frac{e^{z_i-m}}{\\sum_je^{z_j-m}},\\quad m=\\max_j z_j;\\qquad\\sigma(z)=\\frac1{1+e^{-z}}\" style=\"width:50.271ex;height:5.862ex\" loading=\"lazy\"></div><h3>Step 1. Subtract the maximum for stable softmax</h3><p>[−2.2,0,−2.5]. This common shift leaves softmax unchanged.</p><h3>Step 2. Exponentiate then sum</h3><p>[0.11080315836233387, 1.0, 0.0820849986238988]; sum=1.192888156986.</p><h3>Step 3. Divide each by the same sum</h3><div class=\"table-wrap\"><table><thead><tr><th>Logit</th><th>Exponential / sum</th><th>Probability</th></tr></thead><tbody><tr><td>1.2</td><td>0.110803158362/1.192888156986</td><td>0.092886460</td></tr><tr><td>3.4</td><td>1.000000000000/1.192888156986</td><td>0.838301558</td></tr><tr><td>0.9</td><td>0.082084998624/1.192888156986</td><td>0.068811982</td></tr></tbody></table></div><h3>Step 4. Compute sigmoid separately</h3><p>e^(−2.5)=0.082084998624;1+e^(−2.5)=1.082084998624; reciprocal=0.924141820.</p><h3>Final answer</h3><p>Softmax=[0.09288646, 0.838301558, 0.068811982], sum=1.000000000; sigmoid(2.5)=0.924141820.</p>"],"search":"Activation, ReLU and numeric outputs Explain why activation functions are needed and sketch ReLU. Is sigmoid appropriate for an unscaled house-price output? Compute softmax([1.2,3.4,0.9]) and sigmoid(2.5).","units":[2],"marks":10,"sourcePages":[2],"sourceKind":"actual-paper"},{"id":"tee-c21-s5","title":"R25 Q2b · Vanishing/exploding gradients and GRU","kind":"practice","question":["<p><strong>Question. Explain vanishing/exploding gradients in RNNs and the gates of a GRU.</strong> (10 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> Vanishing and exploding gradients describe the attenuation or amplification of backward derivatives through repeated Jacobian products. In recurrent networks, these products extend across time and affect long-range credit assignment.</p><h3>Explanation and working</h3><p>In BPTT, the gradient repeatedly multiplies recurrent weights and activation derivatives. Products of many small factors can approach zero; early information then receives very little learning signal. Large repeated factors can make the gradient explode. These are about training signals, not an instruction that every hidden-state value must become zero or infinity.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_vanishing.svg\" aria-label=\"Enlarge diagram: Follow the repeated products. Small factors can weaken the learning signal; large products can destabilize updates.\"><img src=\"assets/figures/v_vanishing.svg\" alt=\"Follow the repeated products. Small factors can weaken the learning signal; large products can destabilize updates.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Follow the repeated products. Small factors can weaken the learning signal; large products can destabilize updates. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><p><strong>Numerical intuition: </strong> 0.5¹⁰ = 0.0009765625, whereas 2¹⁰ = 1,024. Sigmoid&#x27;s derivative is at most 0.25 and becomes even smaller in saturation. Tanh also saturates for large magnitude inputs.</p><p>Useful remedies include LSTM or GRU gates and cell paths, suitable initialization and learning rate, and gradient clipping for explosion. Clipping does not by itself solve vanishing gradients. LSTM makes long-range learning easier; it does not guarantee perfect unlimited memory.</p><h3>Why the effect grows with sequence length</h3><p>For a vanilla tanh RNN, each hidden-state transition contributes a Jacobian. The derivative through several transitions contains a product of these Jacobians:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/78674f482f3097e9.svg\" alt=\"\\frac{\\partial h_t}{\\partial h_{t-1}}=\\operatorname{diag}(1-h_t^2)W_{hh}\" width=\"277.24\" height=\"55.84\" style=\"width:277.24px;height:55.84px;aspect-ratio:277.24/55.84\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/382feba776054adf.svg\" alt=\"\\frac{\\partial h_T}{\\partial h_t}=\\prod_{k=T}^{t+1}\\frac{\\partial h_k}{\\partial h_{k-1}}\" width=\"195.88\" height=\"72.98\" style=\"width:195.88px;height:72.98px;aspect-ratio:195.88/72.98\" loading=\"lazy\"></div><p>The product is ordered from the latest transition toward the earliest. Small activation derivatives and recurrent transformations can attenuate the signal; repeated amplification can make it grow. A one-dimensional product illustrates the issue, but a vector RNN depends on the full matrix products, not one weight alone.</p><h3>Gradient norm clipping: a complete numerical</h3><p>Norm clipping rescales an oversized gradient while retaining its direction. It limits the update size caused by an exploding gradient.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc3f87fdb9a197b4.svg\" alt=\"g_{\\mathrm{clipped}}=g\\min\\left(1,\\frac{\\tau}{\\lVert g\\rVert_2}\\right)\" width=\"277.13\" height=\"58.87\" style=\"width:277.13px;height:58.87px;aspect-ratio:277.13/58.87\" loading=\"lazy\"></div><p>If g is the zero vector, leave it unchanged. The threshold τ is positive. This is global norm clipping for the vector being considered; elementwise clipping is a different operation.</p><p class=\"inline-question\"><strong>Question. A gradient is g = [6, 8]ᵀ. Clip its Euclidean norm to at most τ = 5, then update w = [1, 1]ᵀ with learning rate η = 0.1.</strong></p><h3>Given</h3><p>Gradient g = [6,8]ᵀ; norm threshold τ = 5.</p><p>Old weights w = [1,1]ᵀ; η = 0.1.</p><h3>To find</h3><p>Find the clipped gradient and updated weights.</p><h3>Formula — which one and why</h3><p><strong>Gradient norm clipping.</strong> If the vector norm exceeds the allowed threshold, multiply every component by the same scale. This changes magnitude while preserving direction.</p><p>g = gradient vector; τ (tau) = maximum norm; ||g||₂ = square root of the sum of squared components; η = learning rate.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f0dbe784a7be0b2f.svg\" alt=\"\\lVert g\\rVert_2=\\sqrt{\\sum_i g_i^2}\" width=\"165.94\" height=\"60.11\" style=\"width:165.94px;height:60.11px;aspect-ratio:165.94/60.11\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dbdee9367720972d.svg\" alt=\"g_{\\mathrm{clip}}=g\\min\\left(1,\\frac\\tau{\\lVert g\\rVert_2}\\right)\" width=\"250.25\" height=\"58.87\" style=\"width:250.25px;height:58.87px;aspect-ratio:250.25/58.87\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b334e0c9202e5b4.svg\" alt=\"w_{\\mathrm{new}}=w-\\eta g_{\\mathrm{clip}}\" width=\"181.94\" height=\"21.27\" style=\"width:181.94px;height:21.27px;aspect-ratio:181.94/21.27\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Bada gradient? Sab components ko ek hi factor se chhota karo.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: calculate the original norm.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.18px;--narrow-height:77.87px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5cf7611fc86c5694.svg\"><img class=\"math display-math\" src=\"assets/equations/92ed9c7434bcec37.svg\" alt=\"\\lVert g\\rVert_2=\\sqrt{6^2+8^2}=\\sqrt{36+64}=10\" width=\"369.09\" height=\"33.33\" style=\"width:369.09px;height:33.33px;aspect-ratio:369.09/33.33\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 2: find the scale.</strong> Since 10 &gt; 5, scale the vector by 5/10 = 0.5.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55639775a78bd93d.svg\" alt=\"g_{\\mathrm{clipped}}=0.5\\begin{bmatrix}6\\\\8\\end{bmatrix}=\\begin{bmatrix}3\\\\4\\end{bmatrix}\" width=\"243.96\" height=\"58.64\" style=\"width:243.96px;height:58.64px;aspect-ratio:243.96/58.64\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: verify the clipped norm.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4cd7b08ae98b6682.svg\" alt=\"\\sqrt{3^2+4^2}=\\sqrt{9+16}=5\" width=\"265.31\" height=\"30.79\" style=\"width:265.31px;height:30.79px;aspect-ratio:265.31/30.79\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: update each parameter with the clipped gradient.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/22080c63aaa74ec0.svg\" alt=\"w_{1,\\mathrm{new}}=1-0.1(3)=0.7\" width=\"263.65\" height=\"25.35\" style=\"width:263.65px;height:25.35px;aspect-ratio:263.65/25.35\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1268aa744d549860.svg\" alt=\"w_{2,\\mathrm{new}}=1-0.1(4)=0.6\" width=\"263.65\" height=\"25.35\" style=\"width:263.65px;height:25.35px;aspect-ratio:263.65/25.35\" loading=\"lazy\"></div><p><strong>Final answer:</strong> clipped gradient [3, 4]ᵀ and new weights [0.7, 0.6]ᵀ. Clipping does not increase a vanishing gradient and does not replace the need for an appropriate recurrent architecture.</p><h3>Gradient norm clipping: [3, 4]</h3><p class=\"inline-question\"><strong>Question. Clip gradient g = [3, 4] to maximum L2 norm 10. Use global norm clipping.</strong></p><h3>Given</h3><p>g = [3, 4]; threshold τ = 10.</p><h3>To find</h3><p>The norm, scaling factor and clipped gradient.</p><h3>Formula — which one and why</h3><p>Global norm clipping scales the entire list by one common factor only if its norm exceeds the threshold.</p><p>τ is the maximum permitted norm, not a per-entry bound.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c087afaaeb69ebf5.svg\" alt=\"\\|g\\|_2=\\sqrt{\\sum_i g_i^2}\" width=\"165.94\" height=\"60.11\" style=\"width:165.94px;height:60.11px;aspect-ratio:165.94/60.11\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbf72036323a5940.svg\" alt=\"g_{\\mathrm{clip}}=g\\min(1,\\tau/\\|g\\|_2)\" width=\"243.31\" height=\"25.35\" style=\"width:243.31px;height:25.35px;aspect-ratio:243.31/25.35\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Norm bada ho tab sab entries ko same ratio se chhota karo.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: calculate the squared norm.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9e1425dca608e703.svg\" alt=\"3^2+4^2=25\" width=\"132.66\" height=\"23.60\" style=\"width:132.66px;height:23.60px;aspect-ratio:132.66/23.60\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: take the square root.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31e01f04f62bf975.svg\" alt=\"\\|g\\|_2=\\sqrt{25}=5\" width=\"169.42\" height=\"30.48\" style=\"width:169.42px;height:30.48px;aspect-ratio:169.42/30.48\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: choose the shared scale.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93428ecf1a9721ce.svg\" alt=\"c=\\min(1,10/5)=1\" width=\"219.66\" height=\"24.43\" style=\"width:219.66px;height:24.43px;aspect-ratio:219.66/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: scale every entry.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/af049506394d9137.svg\" alt=\"g_1^{\\mathrm{clip}}=3(1)=3\" width=\"161.40\" height=\"31.24\" style=\"width:161.40px;height:31.24px;aspect-ratio:161.40/31.24\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c36bcaa7f2c9e3b.svg\" alt=\"g_2^{\\mathrm{clip}}=4(1)=4\" width=\"161.40\" height=\"31.24\" style=\"width:161.40px;height:31.24px;aspect-ratio:161.40/31.24\" loading=\"lazy\"></div><p><strong>Final answer:</strong> Clipped gradient = [3, 4].</p><h3>Gradient norm clipping: [0, 12]</h3><p class=\"inline-question\"><strong>Question. Clip gradient g = [0, 12] to maximum L2 norm 3. Use global norm clipping.</strong></p><h3>Given</h3><p>g = [0, 12]; threshold τ = 3.</p><h3>To find</h3><p>The norm, scaling factor and clipped gradient.</p><h3>Formula — which one and why</h3><p>Global norm clipping scales the entire list by one common factor only if its norm exceeds the threshold.</p><p>τ is the maximum permitted norm, not a per-entry bound.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c087afaaeb69ebf5.svg\" alt=\"\\|g\\|_2=\\sqrt{\\sum_i g_i^2}\" width=\"165.94\" height=\"60.11\" style=\"width:165.94px;height:60.11px;aspect-ratio:165.94/60.11\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbf72036323a5940.svg\" alt=\"g_{\\mathrm{clip}}=g\\min(1,\\tau/\\|g\\|_2)\" width=\"243.31\" height=\"25.35\" style=\"width:243.31px;height:25.35px;aspect-ratio:243.31/25.35\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Norm bada ho tab sab entries ko same ratio se chhota karo.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: calculate the squared norm.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d5fe5de098f7a47.svg\" alt=\"0^2+12^2=144\" width=\"157.09\" height=\"23.60\" style=\"width:157.09px;height:23.60px;aspect-ratio:157.09/23.60\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: take the square root.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/723310d10d7d6089.svg\" alt=\"\\|g\\|_2=\\sqrt{144}=12\" width=\"193.85\" height=\"30.88\" style=\"width:193.85px;height:30.88px;aspect-ratio:193.85/30.88\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: choose the shared scale.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/185f7122d90f817c.svg\" alt=\"c=\\min(1,3/12)=0.25\" width=\"250.88\" height=\"24.43\" style=\"width:250.88px;height:24.43px;aspect-ratio:250.88/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: scale every entry.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d479ef7213e9c007.svg\" alt=\"g_1^{\\mathrm{clip}}=0(0.25)=0\" width=\"192.63\" height=\"31.24\" style=\"width:192.63px;height:31.24px;aspect-ratio:192.63/31.24\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/451a7aae4fe2ab76.svg\" alt=\"g_2^{\\mathrm{clip}}=12(0.25)=3\" width=\"204.84\" height=\"31.24\" style=\"width:204.84px;height:31.24px;aspect-ratio:204.84/31.24\" loading=\"lazy\"></div><p><strong>Final answer:</strong> Clipped gradient = [0.0, 3.0].</p><p class=\"definition\"><strong>Definition.</strong> A gated recurrent unit (GRU) is a recurrent architecture that uses reset and update gates to control its hidden-state transition. Unlike a standard LSTM, it does not carry a separate cell state alongside the hidden state.</p><h3>Gate equations and the convention used here</h3><p>The reset gate r controls how the previous hidden state enters candidate formation. The update gate z controls the mixture of the old state and the candidate. Both are calculated from the current input and previous hidden state:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/70d5c123a1a8d5b7.svg\" alt=\"r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"290.93\" height=\"24.43\" style=\"width:290.93px;height:24.43px;aspect-ratio:290.93/24.43\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/facdae4e8c80fb1f.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z)\" width=\"292.00\" height=\"24.43\" style=\"width:292.00px;height:24.43px;aspect-ratio:292.00/24.43\" loading=\"lazy\"></div><p>The candidate equation used in these notes applies reset before the recurrent candidate transformation:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cb42e5f674e4241.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h)\" width=\"403.57\" height=\"31.13\" style=\"width:403.57px;height:31.13px;aspect-ratio:403.57/31.13\" loading=\"lazy\"></div><p>These notes define z as the fraction of <strong>new candidate</strong> admitted:</p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:209.94px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/949c126edafa8f0a.svg\"><img class=\"math display-math\" src=\"assets/equations/40cc13a7254b2881.svg\" alt=\"h_t=(1-z_t)\\odot h_{t-1}+z_t\\odot\\widetilde h_t\" width=\"311.64\" height=\"31.13\" style=\"width:311.64px;height:31.13px;aspect-ratio:311.64/31.13\" loading=\"lazy\"></picture></div><p>Thus z near 0 favors retention of the old hidden state, while z near 1 favors the candidate. The reset gate affects the candidate calculation; it does not directly multiply the retained old-state term in the final mixture.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/gru.svg\" aria-label=\"Enlarge diagram: First calculate the reset-dependent candidate. Then combine the old hidden state and the candidate using the stated update-gate convention.\"><img src=\"assets/figures/gru.svg\" alt=\"First calculate the reset-dependent candidate. Then combine the old hidden state and the candidate using the stated update-gate convention.\" width=\"960\" height=\"510\" loading=\"lazy\"></button><figcaption>First calculate the reset-dependent candidate. Then combine the old hidden state and the candidate using the stated update-gate convention. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><h3>Complete numerical with supplied gate values</h3><p class=\"inline-question\"><strong>Question.</strong> A scalar GRU has hₜ₋₁ = 0.4, reset gate rₜ = 0.5, update gate zₜ = 0.25, xₜ = 1, Wₕ = 0.2, Uₕ = 0.5 and bₕ = 0. Calculate the candidate and new hidden state using hₜ = (1−zₜ)hₜ₋₁ + zₜh̃ₜ.</p><h3>Given</h3><p>Old hidden state = 0.4; r = 0.5; z = 0.25.</p><p>x = 1; W = 0.2; U = 0.5; b = 0.</p><p>Here z weights the candidate in the final mixture.</p><h3>To find</h3><p>Find candidate and new hidden state.</p><h3>Formula — which one and why</h3><p><strong>GRU reset and state mixture.</strong> The reset gate controls old-state information entering the candidate. The stated update convention then mixes the original old state and the candidate.</p><p>r = reset gate; z = update gate; h_old = previous state; h_tilde = candidate. Here z weights the candidate; some questions instead define z to weight the old state.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0823781665f17f77.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(r\\odot h_{\\mathrm{old}})+b)\" width=\"342.15\" height=\"31.13\" style=\"width:342.15px;height:31.13px;aspect-ratio:342.15/31.13\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/27ea37a678ab26e6.svg\" alt=\"h=(1-z)\\odot h_{\\mathrm{old}}+z\\odot\\widetilde h\" width=\"273.32\" height=\"31.13\" style=\"width:273.32px;height:31.13px;aspect-ratio:273.32/31.13\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Reset candidate ko control; update gate old-new mixture ko control.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: apply the reset gate to the previous hidden state.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1a4ee6cc7b942d74.svg\" alt=\"r_th_{t-1}=0.5(0.4)=0.2\" width=\"241.56\" height=\"24.43\" style=\"width:241.56px;height:24.43px;aspect-ratio:241.56/24.43\" loading=\"lazy\"></div><p>The gates are already supplied as outputs, so no further sigmoid calculation is needed.</p><p class=\"worked-step\"><strong>Step 2: calculate the candidate preactivation.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:193.59px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ca995973009650d3.svg\"><img class=\"math display-math\" src=\"assets/equations/f549a71ed6a573d3.svg\" alt=\"a_{\\mathrm{candidate}}=W_hx_t+U_h(r_th_{t-1})+b_h\" width=\"371.38\" height=\"24.43\" style=\"width:371.38px;height:24.43px;aspect-ratio:371.38/24.43\" loading=\"lazy\"></picture></div><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:217.23px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2f40a657a883a8d8.svg\"><img class=\"math display-math\" src=\"assets/equations/05a1713a2609d0e7.svg\" alt=\"a_{\\mathrm{candidate}}=0.2(1)+0.5(0.2)+0=0.3\" width=\"400.19\" height=\"24.43\" style=\"width:400.19px;height:24.43px;aspect-ratio:400.19/24.43\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 3: apply tanh to obtain the candidate.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2e3e84d154de9f24.svg\"><img class=\"math display-math\" src=\"assets/equations/a1e77c483544b002.svg\" alt=\"\\widetilde h_t=\\tanh(0.3)\\approx0.291312612\" width=\"315.61\" height=\"31.13\" style=\"width:315.61px;height:31.13px;aspect-ratio:315.61/31.13\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 4: calculate the two mixture contributions.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.18px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/56b9a2466f5d57e7.svg\"><img class=\"math display-math\" src=\"assets/equations/b3f54d1f31eaa225.svg\" alt=\" (1-z_t)h_{t-1}=(1-0.25)(0.4)=0.3\" width=\"376.32\" height=\"24.43\" style=\"width:376.32px;height:24.43px;aspect-ratio:376.32/24.43\" loading=\"lazy\"></picture></div><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.19px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8512106d268f635a.svg\"><img class=\"math display-math\" src=\"assets/equations/4cab7af53e3adf95.svg\" alt=\"z_t\\widetilde h_t=0.25\\tanh(0.3)\\approx0.072828153\" width=\"382.75\" height=\"31.13\" style=\"width:382.75px;height:31.13px;aspect-ratio:382.75/31.13\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 5: add the contributions.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.52px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/14fb84144802870c.svg\"><img class=\"math display-math\" src=\"assets/equations/99c980a8ec789fec.svg\" alt=\"h_t=0.3+0.25\\tanh(0.3)\\approx0.372828153\" width=\"424.21\" height=\"24.43\" style=\"width:424.21px;height:24.43px;aspect-ratio:424.21/24.43\" loading=\"lazy\"></picture></div><p><strong>Final answer:</strong> candidate ≈ 0.291313 and new hidden state ≈ 0.372828. The new scalar state lies between the old state 0.4 and the candidate 0.291313, as expected for this convex mixture.</p><h3>If the question uses the other update-gate convention</h3><p>Some texts define z as the fraction of the <strong>old state retained</strong>:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/360ddf17a95ce9ee.svg\" alt=\"h_t=z_th_{t-1}+(1-z_t)\\widetilde h_t\" width=\"251.91\" height=\"31.13\" style=\"width:251.91px;height:31.13px;aspect-ratio:251.91/31.13\" loading=\"lazy\"></div><p>Under that explicitly different convention, the same numerical value z = 0.25 gives:</p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:176.52px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e8fba95c9469ec76.svg\"><img class=\"math display-math\" src=\"assets/equations/d0cde1d1f4ff9640.svg\" alt=\"h_t=0.25(0.4)+0.75\\tanh(0.3)\\approx0.318484459\" width=\"486.67\" height=\"24.43\" style=\"width:486.67px;height:24.43px;aspect-ratio:486.67/24.43\" loading=\"lazy\"></picture></div><p>This is not the answer to the worked question above, which states the first convention. To represent an identical mixture while switching conventions, the gate values must be complemented as well. Always identify the final mixture equation before substituting values.</p><h3>Relationship to LSTM</h3><p>A basic GRU has three affine transformations: reset, update and candidate. A standard LSTM has four: forget, input, output and candidate. With equal input and hidden dimensions and the same bias convention, GRU therefore has fewer recurrent parameters. This is a parameter-count comparison, not a guarantee of higher accuracy or faster execution for every task.</p><h3>Retain-old GRU with gate 0</h3><p class=\"inline-question\"><strong>Question. Use h_new = z h_old+(1−z) candidate. Given h_old = 0.4, z = 0, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new state.</strong></p><h3>Given</h3><p>h_old = 0.4; z = 0; r = 0.5; x = 1.</p><p>W = 0.2; U = 0.5; b = 0; z is the retain-old gate.</p><h3>To find</h3><p>Candidate and final hidden state.</p><h3>Formula — which one and why</h3><p>The reset gate changes old-state input to the candidate. The update gate separately mixes the original old state and candidate.</p><p>The question explicitly makes z multiply the old state. r and z do different jobs.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Reset sirf candidate mein; update mix mein original old state.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/298840de1c01f101.svg\" alt=\"rh_{\\mathrm{old}}=0.5(0.4)=0.2\" width=\"228.03\" height=\"24.43\" style=\"width:228.03px;height:24.43px;aspect-ratio:228.03/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: calculate the candidate raw sum.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/708a856537eccf89.svg\"><img class=\"math display-math\" src=\"assets/equations/f6b1201a9f34684a.svg\" alt=\"a=0.2(1)+0.5(0.2)+0=0.3\" width=\"325.20\" height=\"24.43\" style=\"width:325.20px;height:24.43px;aspect-ratio:325.20/24.43\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 3: apply tanh.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5d5bc478f8a3566.svg\"><img class=\"math display-math\" src=\"assets/equations/8ef1fca1e3e9a662.svg\" alt=\"\\widetilde h=\\tanh(0.3)\\approx0.291312612\" width=\"307.34\" height=\"31.13\" style=\"width:307.34px;height:31.13px;aspect-ratio:307.34/31.13\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 4: retain the old-state fraction.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/81c714ea0d0f3d30.svg\" alt=\"0(0.4)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 5: calculate the candidate fraction.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b85f83251c9025c.svg\"><img class=\"math display-math\" src=\"assets/equations/fb448a828d5eb818.svg\" alt=\"(1-0)(0.291312612)\\approx0.291312612\" width=\"382.84\" height=\"24.43\" style=\"width:382.84px;height:24.43px;aspect-ratio:382.84/24.43\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 6: add the two fractions.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb12f65fb3a6f99d.svg\"><img class=\"math display-math\" src=\"assets/equations/05b6b2f57ab16b9a.svg\" alt=\"h_{\\mathrm{new}}=0+(0.291312612)\\approx0.291312612\" width=\"430.05\" height=\"24.43\" style=\"width:430.05px;height:24.43px;aspect-ratio:430.05/24.43\" loading=\"lazy\"></picture></div><p><strong>Final answer:</strong> Candidate ≈ 0.291312612; new state ≈ 0.291312612.</p><h3>Retain-old GRU with gate 0.8</h3><p class=\"inline-question\"><strong>Question. Use h_new = z h_old+(1−z) candidate. Given h_old = -0.2, z = 0.8, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new state.</strong></p><h3>Given</h3><p>h_old = -0.2; z = 0.8; r = 0.5; x = 1.</p><p>W = 0.2; U = 0.5; b = 0; z is the retain-old gate.</p><h3>To find</h3><p>Candidate and final hidden state.</p><h3>Formula — which one and why</h3><p>The reset gate changes old-state input to the candidate. The update gate separately mixes the original old state and candidate.</p><p>The question explicitly makes z multiply the old state. r and z do different jobs.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Reset sirf candidate mein; update mix mein original old state.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c07f11824db74c75.svg\" alt=\"rh_{\\mathrm{old}}=0.5(-0.2)=-0.1\" width=\"266.05\" height=\"24.43\" style=\"width:266.05px;height:24.43px;aspect-ratio:266.05/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: calculate the candidate raw sum.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/177d51be8807173f.svg\"><img class=\"math display-math\" src=\"assets/equations/ba304bd37c97d1fe.svg\" alt=\"a=0.2(1)+0.5(-0.1)+0=0.15\" width=\"356.42\" height=\"24.43\" style=\"width:356.42px;height:24.43px;aspect-ratio:356.42/24.43\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 3: apply tanh.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22b0ab9fe31c5dbb.svg\"><img class=\"math display-math\" src=\"assets/equations/89f3eabbc08b8f86.svg\" alt=\"\\widetilde h=\\tanh(0.15)\\approx0.148885034\" width=\"319.55\" height=\"31.13\" style=\"width:319.55px;height:31.13px;aspect-ratio:319.55/31.13\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 4: retain the old-state fraction.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d5d62808c22a4a6.svg\" alt=\"0.8(-0.2)=-0.16\" width=\"195.51\" height=\"24.43\" style=\"width:195.51px;height:24.43px;aspect-ratio:195.51/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 5: calculate the candidate fraction.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/47661b22efc0daeb.svg\"><img class=\"math display-math\" src=\"assets/equations/349c3a8b18523729.svg\" alt=\"(1-0.8)(0.148885034)\\approx0.029777007\" width=\"401.85\" height=\"24.43\" style=\"width:401.85px;height:24.43px;aspect-ratio:401.85/24.43\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 6: add the two fractions.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a559a88735fecf3e.svg\"><img class=\"math display-math\" src=\"assets/equations/78f9973806e42ffa.svg\" alt=\"h_{\\mathrm{new}}=-0.16+(0.029777007)\\approx-0.130222993\" width=\"499.29\" height=\"24.43\" style=\"width:499.29px;height:24.43px;aspect-ratio:499.29/24.43\" loading=\"lazy\"></picture></div><p><strong>Final answer:</strong> Candidate ≈ 0.148885034; new state ≈ -0.130222993.</p>"],"search":"Vanishing/exploding gradients and GRU Explain vanishing/exploding gradients in RNNs and the gates of a GRU.","units":[5],"marks":10,"sourcePages":[2],"sourceKind":"actual-paper"},{"id":"tee-c21-s6","title":"R25 Q3a · 4–3–2 forward pass and dropout","kind":"practice","question":["<p><strong>Question. For the printed network, inputs=[0.1,0.2,0.3,0.4], targets=[0.01,0.99], w1…w18=[0.10,0.15,…,0.95] and both layer biases=0.60. Find total forward error, then drop hidden neuron H12 and compare errors.</strong> (10 marks)</p>"],"answer":["<h3>Given</h3><p>Input→hidden rows (destinations H11,H12,H13):</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-4cd053daebb13329.svg\" alt=\"\\begin{bmatrix}0.1&amp;0.25&amp;0.4&amp;0.55\\\\0.15&amp;0.3&amp;0.45&amp;0.6\\\\0.2&amp;0.35&amp;0.5&amp;0.65\\end{bmatrix}\" style=\"width:25.896ex;height:8.597ex\" loading=\"lazy\"></div><p>Hidden→output rows (destinations O1,O2):</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-327612e026ce8f89.svg\" alt=\"\\begin{bmatrix}0.7&amp;0.8&amp;0.9\\\\0.75&amp;0.85&amp;0.95\\end{bmatrix}\" style=\"width:18.982ex;height:5.43ex\" loading=\"lazy\"></div><div class=\"flow\"><span class=\"flow-box\">4inputs</span> → <span class=\"flow-box\">3sigmoid hidden units</span> → <span class=\"flow-box\">2sigmoid outputs</span> → <span class=\"flow-box\">Half sum of squared errors</span></div><h3>To find</h3><p>Original and dropped forward outputs and loss.</p><h3>Formula: which one and why</h3><p>The paper omits activation and error convention. Declare sigmoid at both layers and half-SSE. For the given single dropped unit use an ordinary binary mask, no additional inverted-dropout scaling because no keep probability is supplied.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-356678101dc6b13b.svg\" alt=\"h_j=\\sigma(\\sum_iW_{ji}x_i+0.6),\\quad o_k=\\sigma(\\sum_jV_{kj}h_j+0.6),\\quad E=\\frac12\\sum_k(o_k-t_k)^2\" style=\"width:72.25ex;height:6.042ex\" loading=\"lazy\"></div><h3>Step 1. Multiply and add each hidden neuron</h3><div class=\"table-wrap\"><table><thead><tr><th>Neuron</th><th>Products + bias</th><th>Net</th><th>Sigmoid</th></tr></thead><tbody><tr><td>1</td><td>0.1×0.1 + 0.2×0.25 + 0.3×0.4 + 0.4×0.55 +0.6</td><td>1.000000000</td><td>0.731058578630</td></tr><tr><td>2</td><td>0.1×0.15 + 0.2×0.3 + 0.3×0.45 + 0.4×0.6 +0.6</td><td>1.050000000</td><td>0.740774899182</td></tr><tr><td>3</td><td>0.1×0.2 + 0.2×0.35 + 0.3×0.5 + 0.4×0.65 +0.6</td><td>1.100000000</td><td>0.750260105595</td></tr></tbody></table></div><h3>Step 2. Compute original output nets and activations</h3><div class=\"table-wrap\"><table><thead><tr><th>Output</th><th>Full substitution</th><th>Net</th><th>Output</th></tr></thead><tbody><tr><td>1</td><td>0.731058578630×0.7 + 0.740774899182×0.8 + 0.750260105595×0.9 +0.6</td><td>2.379595019422</td><td>0.915258028946</td></tr><tr><td>2</td><td>0.731058578630×0.75 + 0.740774899182×0.85 + 0.750260105595×0.95 +0.6</td><td>2.490699698593</td><td>0.923487256983</td></tr></tbody></table></div><h3>Step 3. Square both output errors and halve their sum</h3><div class=\"table-wrap\"><table><thead><tr><th>Output</th><th>Prediction−target</th><th>Square</th><th>Half square</th></tr></thead><tbody><tr><td>1</td><td>0.9152580289459775−0.01=0.905258028946</td><td>0.819492098971</td><td>0.409746049486</td></tr><tr><td>2</td><td>0.9234872569833742−0.99=-0.066512743017</td><td>0.004423944984</td><td>0.002211972492</td></tr></tbody></table></div><p>Total=0.411958021977.</p><h3>Step 4. Drop H12 only and recompute both outputs</h3><p>Masked hidden activations=[0.7310585786300049, 0, 0.7502601055951177]. Other hidden activations and all weights are unchanged.</p><div class=\"table-wrap\"><table><thead><tr><th>Output</th><th>Net with H12 term zero</th><th>Sigmoid</th></tr></thead><tbody><tr><td>1</td><td>0.731058578630×0.7+0×0.8+0.750260105595×0.9+0.6=1.786975100077</td><td>0.856556014402</td></tr><tr><td>2</td><td>0.731058578630×0.75+0×0.85+0.750260105595×0.95+0.6=1.861041034288</td><td>0.865418242930</td></tr></tbody></table></div><h3>Step 5. Compute dropped loss and compare</h3><p>Half squares: 0.5×(0.856556014402−0.01)² + 0.5×(0.865418242930−0.99)² = 0.366088849857. Difference dropped−original=-0.045869172120.</p><h3>Final answer</h3><p><strong>Original E=0.411958021977; dropped E=0.366088849857.</strong> A lower single-example masked loss is not evidence that dropout always lowers training or test loss.</p><p><strong>Source / convention note.</strong> Activation/loss/dropout scaling missing from original; result is conditional on explicit standard classroom assumptions.</p>"],"search":"4–3–2 forward pass and dropout For the printed network, inputs=[0.1,0.2,0.3,0.4], targets=[0.01,0.99], w1…w18=[0.10,0.15,…,0.95] and both layer biases=0.60. Find total forward error, then drop hidden neuron H12 and compare errors.","units":[2,3],"marks":10,"sourcePages":[3],"sourceKind":"actual-paper"},{"id":"tee-c21-s7","title":"R25 Q3b · Four CNN design explanations","kind":"practice","question":["<p><strong>Question. Explain(i)parameter sharing and sparse connections,(ii)5×5versus3×3kernel trade-offs,(iii)ReLU’s effect on learning,(iv)whether CNNs can work without pooling.</strong> (10 marks)</p>"],"answer":["<div class=\"table-wrap\"><table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody><tr><td>i</td><td>Local receptive fields create sparse connectivity. The same filter weights are reused across spatial positions, reducing parameters and recognizing a feature in different positions. This gives translation equivariance under appropriate boundary/stride conditions, not automatic complete invariance.</td></tr><tr><td>ii</td><td>At fixed channel counts,5×5uses25weights per channel-pair,3×3uses9. Two stride1 3×3layers yield an effective5×5receptive field with an extra nonlinearity and18C²weights when all channel widths equalC, versus25C². Intermediate channels, biases and compute/memory can change the comparison.</td></tr><tr><td>iii</td><td>ReLU passes positive values/gradient1 and zeros negative values/gradient0. It introduces nonlinearity and avoids positive-side sigmoid saturation, but can produce inactive/dead units. It does not eliminate all gradient problems.</td></tr><tr><td>iv</td><td>Yes. Strided convolutions can downsample; global pooling or other aggregation may form the head. Removing pooling without another reduction can increase feature-map sizes/compute. Pooling is a design choice, not a mathematical necessity.</td></tr></tbody></table></div>"],"search":"Four CNN design explanations Explain(i)parameter sharing and sparse connections,(ii)5×5versus3×3kernel trade-offs,(iii)ReLU’s effect on learning,(iv)whether CNNs can work without pooling.","units":[4],"marks":10,"sourcePages":[3],"sourceKind":"actual-paper"},{"id":"tee-c21-s8","title":"R25 Q4a · 64×64 CNN shape and parameter table","kind":"practice","question":["<p><strong>Question. For input64×64×3: conv3×3,32filters,P1,S1; maxpool2×2,S2; conv3×3,64,P1,S1; pool2,S2; conv3×3,128,P1,S1; pool2,S2; FC256; softmax43. Find each shape and all weights/biases.</strong> (10 marks)</p>"],"answer":["<h3>Given</h3><p>Input=[64, 64, 3]</p><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Kernel</th><th>Stride</th><th>Padding</th><th>Filters / units</th></tr></thead><tbody><tr><td>Conv</td><td>3</td><td>1</td><td>1</td><td>32</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Conv</td><td>3</td><td>1</td><td>1</td><td>64</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Conv</td><td>3</td><td>1</td><td>1</td><td>128</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>256</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>43</td></tr></tbody></table></div><h3>To find</h3><p>Each output shape and all trainable weights plus biases.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-cbf0b1f38ebaaccb.svg\" alt=\"O=\\left\\lfloor\\frac{N+2P-F}{S}\\right\\rfloor+1\" style=\"width:24.339ex;height:5.428ex\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-69756abf2018c02c.svg\" alt=\"P_{conv}=(F_hF_wC_{in}+1)C_{out},\\quad P_{dense}=(n_{in}+1)n_{out}\" style=\"width:50.749ex;height:2.262ex\" loading=\"lazy\"></div><p>Each filter/unit has one bias. Pooling has zero learned parameters. Flatten preserves the number of values, then a dense layer connects every input value to every output unit.</p><h3>Step 1. Work layer by layer</h3><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Input</th><th>Full substitution and reason</th><th>Output</th><th>Parameters</th></tr></thead><tbody><tr><td>Conv</td><td>64×64×3</td><td>⌊(64+2×1−3)/1⌋+1=64; parameters=(3×3×3+1)×32=896</td><td>64×64×32</td><td>896</td></tr><tr><td>Pool</td><td>64×64×32</td><td>⌊(64−2)/2⌋+1=32; channels stay 32; no trainable weights</td><td>32×32×32</td><td>0</td></tr><tr><td>Conv</td><td>32×32×32</td><td>⌊(32+2×1−3)/1⌋+1=32; parameters=(3×3×32+1)×64=18496</td><td>32×32×64</td><td>18496</td></tr><tr><td>Pool</td><td>32×32×64</td><td>⌊(32−2)/2⌋+1=16; channels stay 64; no trainable weights</td><td>16×16×64</td><td>0</td></tr><tr><td>Conv</td><td>16×16×64</td><td>⌊(16+2×1−3)/1⌋+1=16; parameters=(3×3×64+1)×128=73856</td><td>16×16×128</td><td>73856</td></tr><tr><td>Pool</td><td>16×16×128</td><td>⌊(16−2)/2⌋+1=8; channels stay 128; no trainable weights</td><td>8×8×128</td><td>0</td></tr><tr><td>Dense</td><td>8×8×128</td><td>Flatten/input length=8×8×128=8192; parameters=(8192+1)×256=2097408</td><td>256</td><td>2097408</td></tr><tr><td>Dense</td><td>1×1×256</td><td>Flatten/input length=1×1×256=256; parameters=(256+1)×43=11051</td><td>43</td><td>11051</td></tr></tbody></table></div><h3>Step 2. Sum only trainable parameters</h3><p>896 + 18496 + 73856 + 2097408 + 11051 = 2201707</p><h3>Final answer</h3><p><strong>Total parameters=2201707.</strong> Shape and parameter count are separate results.</p>"],"search":"64×64 CNN shape and parameter table For input64×64×3: conv3×3,32filters,P1,S1; maxpool2×2,S2; conv3×3,64,P1,S1; pool2,S2; conv3×3,128,P1,S1; pool2,S2; FC256; softmax43. Find each shape and all weights/biases.","units":[4],"marks":10,"sourcePages":[4],"sourceKind":"actual-paper"},{"id":"tee-c21-s9","title":"R25 Q4b · Bipolar AND perceptron","kind":"practice","question":["<p><strong>Question. Implement AND with bipolar inputs/targets and learning rate1.</strong> (10 marks)</p>"],"answer":["<h3>Given</h3><p>Truth table: (−1,−1)→−1;(−1,+1)→−1;(+1,−1)→−1;(+1,+1)→+1. η=1.</p><h3>To find</h3><p>A trained separating perceptron.</p><h3>Formula: which one and why</h3><p>Initial weights/bias and zero-threshold tie rule are unspecified. Choose w=(0,0),b=0; output+1ifnet≥0,else−1. Use error update w←w+η(t−y)x,b←b+η(t−y). A sign-only misclassification update differs by a factor2 but can also learn the gate.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-31e9ee08177b99d9.svg\" alt=\"z=w^Tx+b,\\quad w\\leftarrow w+(t-y)x,\\quad b\\leftarrow b+(t-y)\" style=\"width:50.518ex;height:2.583ex\" loading=\"lazy\"></div><h3>Step 1. Run all examples in the declared order</h3><div class=\"table-wrap\"><table><thead><tr><th>Epoch</th><th>x</th><th>Target</th><th>Old parameters</th><th>Net</th><th>Output</th><th>t−y</th><th>New parameters</th></tr></thead><tbody><tr><td>1</td><td>[-1, -1]</td><td>-1</td><td>[0, 0]; b=0</td><td>0</td><td>1</td><td>-2</td><td>[2, 2]; b=-2</td></tr><tr><td>1</td><td>[-1, 1]</td><td>-1</td><td>[2, 2]; b=-2</td><td>-2</td><td>-1</td><td>0</td><td>[2, 2]; b=-2</td></tr><tr><td>1</td><td>[1, -1]</td><td>-1</td><td>[2, 2]; b=-2</td><td>-2</td><td>-1</td><td>0</td><td>[2, 2]; b=-2</td></tr><tr><td>1</td><td>[1, 1]</td><td>1</td><td>[2, 2]; b=-2</td><td>2</td><td>1</td><td>0</td><td>[2, 2]; b=-2</td></tr><tr><td>2</td><td>[-1, -1]</td><td>-1</td><td>[2, 2]; b=-2</td><td>-6</td><td>-1</td><td>0</td><td>[2, 2]; b=-2</td></tr><tr><td>2</td><td>[-1, 1]</td><td>-1</td><td>[2, 2]; b=-2</td><td>-2</td><td>-1</td><td>0</td><td>[2, 2]; b=-2</td></tr><tr><td>2</td><td>[1, -1]</td><td>-1</td><td>[2, 2]; b=-2</td><td>-2</td><td>-1</td><td>0</td><td>[2, 2]; b=-2</td></tr><tr><td>2</td><td>[1, 1]</td><td>1</td><td>[2, 2]; b=-2</td><td>2</td><td>1</td><td>0</td><td>[2, 2]; b=-2</td></tr></tbody></table></div><h3>Step 2. Verify every truth-table row with final parameters</h3><div class=\"table-wrap\"><table><thead><tr><th>x</th><th>Net</th><th>Output</th><th>Target</th></tr></thead><tbody><tr><td>[-1, -1]</td><td>-6</td><td>-1</td><td>-1</td></tr><tr><td>[-1, 1]</td><td>-2</td><td>-1</td><td>-1</td></tr><tr><td>[1, -1]</td><td>-2</td><td>-1</td><td>-1</td></tr><tr><td>[1, 1]</td><td>2</td><td>1</td><td>1</td></tr></tbody></table></div><h3>Final answer</h3><p><strong>One valid learned solution: w=[2, 2], b=-2.</strong> Last full epoch makes no changes; all four rows are correct.</p><p><strong>Source / convention note.</strong> Initialization, order and threshold convention explicitly supplied as assumptions; multiple equivalent separating weights exist.</p>"],"search":"Bipolar AND perceptron Implement AND with bipolar inputs/targets and learning rate1.","units":[2],"marks":10,"sourcePages":[4],"sourceKind":"actual-paper"},{"id":"tee-c21-s10","title":"R25 Q5a · ResNet shortcut and Inception1×1","kind":"practice","question":["<p><strong>Question. Describe skip connections and their benefit in ResNet. Explain a1×1convolution’s role in Inception with an example.</strong> (10 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> A residual network uses shortcut connections to learn a residual mapping relative to a block&#x27;s input. A basic residual block adds the block transformation F(x) to a shortcut representation of x.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0d9d34020eaab826.svg\" alt=\"y=F(x)+x\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div><p>If the desired mapping is H(x), the residual branch represents F(x) = H(x) − x. When the useful mapping is close to identity, a small residual can be easier to optimize than reconstructing identity through the entire branch.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/residual.svg\" aria-label=\"Enlarge diagram: The two paths must have equal output shape before elementwise addition.\"><img src=\"assets/figures/residual.svg\" alt=\"The two paths must have equal output shape before elementwise addition.\" width=\"960\" height=\"475\" loading=\"lazy\"></button><figcaption>The two paths must have equal output shape before elementwise addition. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><h3>Effect on gradient propagation</h3><p>For the identity-shortcut formulation, the derivative includes a direct identity contribution.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/505f1041667e53bb.svg\" alt=\"\\frac{\\partial y}{\\partial x}=\\frac{\\partial F}{\\partial x}+I\" width=\"156.21\" height=\"51.29\" style=\"width:156.21px;height:51.29px;aspect-ratio:156.21/51.29\" loading=\"lazy\"></div><p>This provides a path for information and derivatives that does not require passing through every weight layer in the residual branch. It helps optimize deep networks and addresses the degradation problem. It does not imply that every possible ResNet is immune to vanishing gradients.</p><h3>Projection when dimensions differ</h3><p>If channels or spatial dimensions change, use a projection shortcut, often a 1 × 1 convolution with suitable stride.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9ffeadda67cc02f9.svg\" alt=\"y=F(x)+W_sx\" width=\"172.89\" height=\"24.43\" style=\"width:172.89px;height:24.43px;aspect-ratio:172.89/24.43\" loading=\"lazy\"></div><p>An identity shortcut has no learned parameters. A projection does. For Cᵢ input channels and Cₒ output channels, a biased 1 × 1 projection has CᵢCₒ + Cₒ parameters. The residual branch&#x27;s output must match the projection output for addition.</p><p class=\"inline-question\"><strong>Question.</strong> Let x = [1, 2, 3] and F(x) = [0.1, −0.2, 0.3]. Find the residual sum.</p><h3>Given</h3><p>x = [1,2,3]; residual branch F(x) = [0.1,−0.2,0.3].</p><h3>To find</h3><p>Find the three components of x+F(x).</p><h3>Formula — which one and why</h3><p><strong>Residual addition.</strong> Add corresponding components of the input shortcut and learned branch. Apply the output activation afterward if requested.</p><p>x = shortcut/input; F(x) = residual branch output. Both arrays must have matching shapes before addition.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ec48bb473e2d7934.svg\" alt=\"y=x+F(x)\" width=\"139.69\" height=\"24.43\" style=\"width:139.69px;height:24.43px;aspect-ratio:139.69/24.43\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Same position ke numbers add; shape same rehni chahiye.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: add the first matching pair.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/db025849e060d366.svg\" alt=\"1+0.1=1.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: add the second matching pair.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ab49a448719b780e.svg\" alt=\"2+(-0.2)=1.8\" width=\"175.14\" height=\"24.43\" style=\"width:175.14px;height:24.43px;aspect-ratio:175.14/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: add the third matching pair.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d117d7aaf6f65395.svg\" alt=\"3+0.3=3.3\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: assemble in the original order.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f3d1f51931e7a8d.svg\" alt=\"y=[1.1,1.8,3.3]\" width=\"173.56\" height=\"24.43\" style=\"width:173.56px;height:24.43px;aspect-ratio:173.56/24.43\" loading=\"lazy\"></div><p>The vector length remains 3. Concatenating these vectors would give length 6 and would implement a different operation. Any post-addition activation specified in the architecture is applied after this sum.</p><p class=\"definition\"><strong>Definition.</strong> A 1 × 1 convolution combines the input channels independently at each spatial location. A bottleneck uses fewer output channels before a larger spatial convolution, reducing its parameter and multiplication counts.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_bottleneck.svg\" aria-label=\"Enlarge diagram: Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size.\"><img src=\"assets/figures/v_bottleneck.svg\" alt=\"Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size.\" width=\"1080\" height=\"790\" loading=\"lazy\"></button><figcaption>Compare the direct path with both stages of the bottleneck. The reduction changes channel depth, not spatial size. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><p class=\"inline-question\"><strong>Question. Input is 28 × 28 × 192. Compare a direct same-padded 5 × 5 convolution with 32 filters against a 1 × 1 reduction to 16 channels followed by the same 5 × 5 convolution. Count MACs and ignore bias additions.</strong></p><h3>Given</h3><p>Both paths produce 28 × 28 × 32. The direct layer receives 192 channels; the bottleneck&#x27;s spatial layer receives 16 channels. Stride is 1 and padding preserves spatial size.</p><h3>To find</h3><p>Direct MACs, total two-stage bottleneck MACs and percentage saved.</p><h3>Formula — which one and why</h3><p>Each output scalar uses one product per input-channel kernel entry. Multiply that cost by the number of output positions and channels. The two bottleneck layers require separate counts, which are added.</p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div><p>One MAC counts one multiply–accumulate pair. A convention counting multiplication and addition separately gives approximately twice as many FLOPs.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: direct layer.</strong> Each output uses 5 × 5 × 192 = 4,800 products. There are 28 × 28 × 32 = 25,088 outputs.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f08b61aa51f8fc4.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=25088(4800)=120422400\" width=\"417.37\" height=\"24.43\" style=\"width:417.37px;height:24.43px;aspect-ratio:417.37/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: 1 × 1 reduction.</strong> There are 16 receiving filters, each spanning all 192 original channels.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/aaefb7a933a188a0.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=28(28)(16)(192)=2408448\" width=\"418.42\" height=\"24.43\" style=\"width:418.42px;height:24.43px;aspect-ratio:418.42/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: reduced-depth spatial layer.</strong> Its 32 filters now span 16 channels.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b6f81bb572b38322.svg\" alt=\"\\mathrm{MACs}_{5\\times5}=28(28)(32)(25)(16)=10035200\" width=\"461.86\" height=\"24.43\" style=\"width:461.86px;height:24.43px;aspect-ratio:461.86/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: add the two bottleneck costs.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3917ad1b6a4cc0eb.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=2408448+10035200=12443648\" width=\"524.30\" height=\"21.35\" style=\"width:524.30px;height:21.35px;aspect-ratio:524.30/21.35\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 5: calculate the saving.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fe529a7c8d14263e.svg\" alt=\"\\mathrm{saving}=120422400-12443648=107978752\" width=\"480.03\" height=\"21.58\" style=\"width:480.03px;height:21.58px;aspect-ratio:480.03/21.58\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e22e38a0d749a968.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{107978752}{120422400}\\approx89.666667\\%\" width=\"534.95\" height=\"50.34\" style=\"width:534.95px;height:50.34px;aspect-ratio:534.95/50.34\" loading=\"lazy\"></div><p><strong>Final answer:</strong> direct = 120,422,400 MACs; bottleneck = 12,443,648 MACs, saving about 89.67%. Spatial size is unchanged; the saving comes from reducing the channels entering the expensive 5 × 5 layer. If the reduction width is not supplied, use a symbol for it and label any numerical choice as an assumption.</p><h3>A second bottleneck with different dimensions</h3><p class=\"inline-question\"><strong>Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with a 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.</strong></p><h3>Given</h3><p>Spatial output = 8 × 8; original channels = 16; final filters = 8; bottleneck channels = 4; stride = 1.</p><h3>To find</h3><p>Direct MACs, bottleneck MACs and saving.</p><h3>Formula — which one and why</h3><p>Use the same MAC formula above once for the direct path and once for each bottleneck stage. Every branch must include all of its layers.</p><h3>Solution — step by step</h3><p class=\"worked-step\"><strong>Step 1: direct spatial convolution.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dffc8608ebe7e697.svg\" alt=\"8(8)(8)(3)(3)(16)=73728\" width=\"274.24\" height=\"24.43\" style=\"width:274.24px;height:24.43px;aspect-ratio:274.24/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: 1 × 1 reduction.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbfbed2568dc51ee.svg\" alt=\"8(8)(4)(1)(1)(16)=4096\" width=\"262.02\" height=\"24.43\" style=\"width:262.02px;height:24.43px;aspect-ratio:262.02/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: reduced-depth 3 × 3 convolution.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/60dc7f05c85051f9.svg\" alt=\"8(8)(8)(3)(3)(4)=18432\" width=\"262.02\" height=\"24.43\" style=\"width:262.02px;height:24.43px;aspect-ratio:262.02/24.43\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 4: add the stages and subtract from the direct cost.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4821e959cb7a516.svg\" alt=\"4096+18432=22528\" width=\"233.50\" height=\"18.54\" style=\"width:233.50px;height:18.54px;aspect-ratio:233.50/18.54\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be3a4d13f46b02ba.svg\" alt=\"73728-22528=51200\" width=\"245.71\" height=\"18.52\" style=\"width:245.71px;height:18.52px;aspect-ratio:245.71/18.52\" loading=\"lazy\"></div><p><strong>Final answer:</strong> direct = 73,728 MACs; bottleneck = 22,528 MACs; saving = 51,200 MACs, about 69.44%. Both paths produce 8 × 8 × 8, but they are different learned transformations and need not produce identical feature values.</p>"],"search":"ResNet shortcut and Inception1×1 Describe skip connections and their benefit in ResNet. Explain a1×1convolution’s role in Inception with an example.","units":[4],"marks":10,"sourcePages":[4],"sourceKind":"actual-paper"},{"id":"tee-c21-s11","title":"R25 Q5b · ReLU RNN state with declared orientation","kind":"practice","question":["<p><strong>Question. Sketch a one-hidden-layer RNN and state its hidden-state formula. Compute hₜ for Wxh=[[0.2,0.4],[0.1,0.3]], Whh=[[0.5,0.6],[0.3,0.4]], b=[0.1,0.2], x=[1,0], previoush=[0,1], ReLU.</strong> (10 marks)</p>"],"answer":["<h3>Given</h3><p><strong>Input-to-hidden weight matrix Wₓₕ:</strong> transforms the two current input values into contributions to the two hidden units.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-a3abd76a293a016b.svg\" alt=\"W_{xh}=\\begin{bmatrix}0.2&amp;0.4\\\\0.1&amp;0.3\\end{bmatrix}\" style=\"width:17.612ex;height:5.43ex\" loading=\"lazy\"></div><p><strong>Hidden-to-hidden weight matrix Wₕₕ:</strong> transforms the two previous hidden activations into recurrent contributions.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-c38f9bda7b0fbd25.svg\" alt=\"W_{hh}=\\begin{bmatrix}0.5&amp;0.6\\\\0.3&amp;0.4\\end{bmatrix}\" style=\"width:17.618ex;height:5.43ex\" loading=\"lazy\"></div><div class=\"table-wrap\"><table><thead><tr><th>Quantity</th><th>Given value</th><th>Meaning</th></tr></thead><tbody><tr><td>xₜ</td><td>[1, 0]</td><td>Current input row: two input values</td></tr><tr><td>hₜ₋₁</td><td>[0, 1]</td><td>Previous hidden-state row: two stored activations</td></tr><tr><td>b</td><td>[0.1, 0.2]</td><td>One bias for each hidden unit</td></tr><tr><td>Activation</td><td>ReLU(z) = max(0, z)</td><td>Apply separately to each hidden weighted sum</td></tr></tbody></table></div><h3>To find</h3><p>Sketch the one-hidden-layer RNN, state its recurrence, and calculate the two components of hₜ.</p><h3>Formula: which one and why</h3><figure class=\"diagram\"><svg style=\"width:100%;height:auto;max-width:100%\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 960 440\" width=\"960\" height=\"440\" role=\"img\" aria-labelledby=\"r25-rnn-title r25-rnn-desc\">\n<title id=\"r25-rnn-title\">One-hidden-layer recurrent neural network with a one-step recurrent connection</title>\n<desc id=\"r25-rnn-desc\">Input x at time t passes through input-to-hidden weights W x h. The hidden layer adds that input contribution, the previous hidden state through recurrent weights W h h, and bias b, then applies ReLU to produce two hidden activations h at time t. The recurrent arrow passes through a one-step delay: the current hidden state becomes the previous hidden state for the next input. An optional output head maps the hidden state through W h y, output bias and an output activation to prediction y hat. Output-head parameters are illustrative and are not supplied or needed for this question.</desc>\n<defs><marker id=\"r25-rnn-arrow\" markerWidth=\"8\" markerHeight=\"8\" refX=\"7\" refY=\"4\" orient=\"auto\"><path d=\"M0 0L8 4L0 8Z\" fill=\"#176950\"/></marker></defs>\n<rect width=\"960\" height=\"440\" rx=\"16\" fill=\"#f6faf7\"/>\n<g fill=\"#fff\" stroke=\"#176950\" stroke-width=\"2\"><rect x=\"35\" y=\"185\" width=\"155\" height=\"105\" rx=\"12\"/><rect x=\"340\" y=\"165\" width=\"270\" height=\"145\" rx=\"12\"/><rect x=\"765\" y=\"185\" width=\"165\" height=\"105\" rx=\"12\"/><rect x=\"420\" y=\"55\" width=\"110\" height=\"50\" rx=\"10\"/></g>\n<g fill=\"none\" stroke=\"#176950\" stroke-width=\"3\" marker-end=\"url(#r25-rnn-arrow)\"><path d=\"M190 237H340\"/><path d=\"M610 237H765\"/><path d=\"M475 105V165\"/><path d=\"M475 310V380H265V270H340\"/></g>\n<g font-family=\"Arial,sans-serif\" text-anchor=\"middle\" fill=\"#183e35\"><text x=\"112\" y=\"219\" font-size=\"21\">Input xₜ</text><text x=\"112\" y=\"248\" font-size=\"19\">[1, 0]</text><text x=\"112\" y=\"274\" font-size=\"16\">two input values</text><text x=\"262\" y=\"214\" font-size=\"21\">Wₓₕ</text><text x=\"475\" y=\"87\" font-size=\"21\">+ bias b</text><text x=\"475\" y=\"198\" font-size=\"21\" font-weight=\"bold\">One hidden layer</text><text x=\"475\" y=\"230\" font-size=\"18\">zₜ = input + history + bias</text><text x=\"475\" y=\"260\" font-size=\"21\">hₜ = ReLU(zₜ)</text><text x=\"475\" y=\"288\" font-size=\"17\">two hidden activations</text><text x=\"689\" y=\"214\" font-size=\"21\">Wₕᵧ</text><text x=\"848\" y=\"216\" font-size=\"20\">Output head</text><text x=\"848\" y=\"247\" font-size=\"21\">ŷₜ</text><text x=\"848\" y=\"274\" font-size=\"15\">illustrative only</text><text x=\"303\" y=\"250\" font-size=\"20\">Wₕₕ</text></g>\n<rect x=\"305\" y=\"354\" width=\"145\" height=\"50\" rx=\"8\" fill=\"#e5f0e9\" stroke=\"#176950\"/><g font-family=\"Arial,sans-serif\" text-anchor=\"middle\" fill=\"#183e35\"><text x=\"377\" y=\"375\" font-size=\"18\">One-step delay</text><text x=\"377\" y=\"395\" font-size=\"15\">previous state hₜ₋₁</text><text x=\"689\" y=\"270\" font-size=\"14\">+ output bias</text><text x=\"689\" y=\"290\" font-size=\"14\">then output activation</text><text x=\"480\" y=\"425\" font-size=\"17\">The same hidden layer and recurrent weights are reused at each time step.</text></g></svg><figcaption><strong>Sketch to draw in the exam:</strong> input → one hidden layer → output, with a recurrent arrow through a one-step delay back to the hidden layer. Wₓₕ connects input to hidden; Wₕₕ carries the previous hidden state. Wₕᵧ denotes a possible hidden-to-output mapping. The paper asks for hₜ only, so no output weights or output prediction are required.</figcaption></figure><p>The printed vectors are horizontal and the weight-index convention is not specified. Adopt row vectors multiplied on the right:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-88904d5970c9803f.svg\" alt=\"h_t=\\operatorname{ReLU}(x_tW_{xh}+h_{t-1}W_{hh}+b)\" style=\"width:33.627ex;height:2.262ex\" loading=\"lazy\"></div><h3>Step 1. Multiply the input row</h3><p>[1,0]Wxh=[1×0.2+0×0.1,1×0.4+0×0.3]=[0.2,0.4].</p><h3>Step 2. Multiply the previous-state row</h3><p>[0,1]Whh=[0×0.5+1×0.3,0×0.6+1×0.4]=[0.3,0.4].</p><h3>Step 3. Add componentwise including bias</h3><p>[0.2+0.3+0.1,0.4+0.4+0.2]=[0.6,1.0].</p><h3>Step 4. Apply ReLU separately</h3><p>[max(0,0.6),max(0,1.0)]=[0.6,1.0].</p><h3>Final answer</h3><p><strong>Row-vector convention: hₜ=[0.6,1.0].</strong> If the supplied matrices instead map column inputs by Wxh x + Whh h +b, the untransposed arrays give[0.9,0.7]. That is a different orientation; explicitly state the formula. Transposing the matrices when switching convention preserves the same network.</p><p><strong>Source / convention note.</strong> Square matrices and printed horizontal vectors leave orientation ambiguous; both possible readings are explained, main answer follows row-vector form.</p>"],"search":"ReLU RNN state with declared orientation Sketch a one-hidden-layer RNN and state its hidden-state formula. Compute hₜ for Wxh=[[0.2,0.4],[0.1,0.3]], Whh=[[0.5,0.6],[0.3,0.4]], b=[0.1,0.2], x=[1,0], previoush=[0,1], ReLU.","units":[5],"marks":10,"sourcePages":[4],"sourceKind":"actual-paper"},{"id":"tee-c21-s12","title":"R25 Q6a · 3–2–1 forward pass and update w7,w8","kind":"practice","question":["<p><strong>Question. For inputs[1,0,1], weights w1…w8=[0.2,−0.3,0.4,0.1,−0.5,0.2,−0.3,−0.2], biases[−0.4,0.2,0.1], target1 and sigmoid at all neurons: find prediction,error,and update w7,w8 with η=0.9.</strong> (10 marks)</p>"],"answer":["<h3>Given</h3><p>Diagram edge mapping: x1→h1=w1,x1→h2=w2;x2→h1=w3,x2→h2=w4;x3→h1=w5,x3→h2=w6;h1→out=w7,h2→out=w8.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-af190f1cb4fd05fd.svg\" alt=\"\\begin{bmatrix}0.2&amp;0.4&amp;-0.5\\\\-0.3&amp;0.1&amp;0.2\\end{bmatrix}\" style=\"width:19.109ex;height:5.43ex\" loading=\"lazy\"></div><div class=\"flow\"><span class=\"flow-box\">[1,0,1]</span> → <span class=\"flow-box\">Two sigmoid hidden units</span> → <span class=\"flow-box\">One sigmoid output</span> → <span class=\"flow-box\">Target1</span></div><h3>To find</h3><p>Prediction, explicit error convention, two simultaneous output-weight updates.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-bca4073f798d2cce.svg\" alt=\"E=\\frac12(o-t)^2,\\quad\\delta_o=(o-t)o(1-o),\\quad\\frac{\\partial E}{\\partial w_k}=\\delta_o h_j,\\quad w_k^{new}=w_k-\\eta\\frac{\\partial E}{\\partial w_k}\" style=\"width:74.559ex;height:5.056ex\" loading=\"lazy\"></div><p>The paper says error without naming its scaling. Use half squared error and also report residual/SSE, so the gradient convention is clear.</p><h3>Step 1. Calculate each hidden weighted sum then sigmoid</h3><div class=\"table-wrap\"><table><thead><tr><th>Unit</th><th>Products +bias</th><th>Net</th><th>Activation</th></tr></thead><tbody><tr><td>1</td><td>1×(0.2) + 0×(0.4) + 1×(-0.5) +(-0.4)</td><td>-0.7</td><td>0.331812227832</td></tr><tr><td>2</td><td>1×(-0.3) + 0×(0.1) + 1×(0.2) +(0.2)</td><td>0.10000000000000003</td><td>0.524979187479</td></tr></tbody></table></div><h3>Step 2. Output weighted sum and sigmoid</h3><p>z=0.331812227832×(−0.3)+0.524979187479×(−0.2)+0.1=-0.104539505845; o=1/(1+e^(−z))=0.473888898824.</p><h3>Step 3. State error and loss</h3><p>Residual o−t=-0.526111101176; SSE=0.276792890781; halfSSE=0.138396445390.</p><h3>Step 4. Multiply the output chain-rule factors</h3><p>δ=(0.473888898824−1)×0.473888898824×(1−0.473888898824)=-0.131169078214.</p><h3>Step 5. Gradient for each edge</h3><div class=\"table-wrap\"><table><thead><tr><th>Weight</th><th>δ × its source activation</th><th>Gradient</th></tr></thead><tbody><tr><td>w7</td><td>-0.131169078214×0.331812227832</td><td>-0.043523504065</td></tr><tr><td>w8</td><td>-0.131169078214×0.524979187479</td><td>-0.068861036103</td></tr></tbody></table></div><h3>Step 6. Update from the old weights</h3><div class=\"table-wrap\"><table><thead><tr><th>Weight</th><th>Old − learning rate × gradient</th><th>New</th></tr></thead><tbody><tr><td>w7</td><td>-0.3−0.9×(-0.043523504065)</td><td>-0.260828846342</td></tr><tr><td>w8</td><td>-0.2−0.9×(-0.068861036103)</td><td>-0.138025067507</td></tr></tbody></table></div><h3>Final answer</h3><p><strong>w7′=-0.260828846342; w8′=-0.138025067507.</strong> Only the requested two weights are updated; use the same old forward pass for both gradients. With unhalved SSE the gradients double, so numerical updates would differ.</p><p><strong>Source / convention note.</strong> Original does not specify loss scaling; half-SSE is declared and alternatives distinguished.</p>"],"search":"3–2–1 forward pass and update w7,w8 For inputs[1,0,1], weights w1…w8=[0.2,−0.3,0.4,0.1,−0.5,0.2,−0.3,−0.2], biases[−0.4,0.2,0.1], target1 and sigmoid at all neurons: find prediction,error,and update w7,w8 with η=0.9.","units":[2],"marks":10,"sourcePages":[5],"sourceKind":"actual-paper"},{"id":"tee-c21-s13","title":"R25 Q6b · AdaGrad stagnation versus RMSProp","kind":"practice","question":["<p><strong>Question. A healthcare model trained with AdaGrad becomes stagnant after many epochs. Discuss AdaGrad and RMSProp in detail and their fundamental differences.</strong> (10 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> AdaGrad is an adaptive first-order optimizer that scales each parameter&#x27;s update using the inverse square root of the sum of its previous and current squared gradients. Each parameter maintains its own accumulator.</p><h3>State, effective learning rate and update</h3><p>For one parameter θ, let gₜ be its current gradient and s₀ = 0:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/32f05266b341eaa2.svg\" alt=\"s_t=s_{t-1}+g_t^2\" width=\"146.31\" height=\"27.82\" style=\"width:146.31px;height:27.82px;aspect-ratio:146.31/27.82\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5cf38c4d809aeefb.svg\" alt=\"\\eta_{\\mathrm{effective},t}=\\frac{\\eta}{\\sqrt{s_t}+\\varepsilon}\" width=\"212.27\" height=\"52.24\" style=\"width:212.27px;height:52.24px;aspect-ratio:212.27/52.24\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/52438222ad8d94df.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta_{\\mathrm{effective},t}g_t\" width=\"231.02\" height=\"24.25\" style=\"width:231.02px;height:24.25px;aspect-ratio:231.02/24.25\" loading=\"lazy\"></div><p>s stores squared-gradient history. Both positive and negative gradients increase this nonnegative sum after squaring. The effective learning rate is the coefficient multiplying the signed gradient; the actual displacement also depends on that gradient&#x27;s magnitude and sign.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_adagrad.svg\" aria-label=\"Enlarge diagram: The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients.\"><img src=\"assets/figures/v_adagrad.svg\" alt=\"The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>The accumulator retains every squared gradient. A larger accumulator reduces the coefficient applied to subsequent gradients. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><h3>Complete numerical: supplied gradients</h3><p class=\"inline-question\"><strong>Question.</strong> Start θ₀ = 1, s₀ = 0, η = 0.1. Given gradients g₁ = 2 and g₂ = 1, perform two AdaGrad updates. Ignore epsilon only for this hand calculation because neither denominator is zero.</p><h3>Given</h3><p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p><p>Supplied gradients g₁ = 2, g₂ = 1.</p><p>ε = 0 for this hand calculation.</p><h3>To find</h3><p>Calculate all required states and the parameter after each of two updates.</p><h3>Formula — which one and why</h3><p><strong>AdaGrad.</strong> Add the new squared gradient to all previous squares. Divide the signed current gradient by the square root of that accumulated magnitude.</p><p>G = accumulated squared gradients (also denoted s in some lessons); g = current gradient; η = base learning rate; ε = small stabilizer, set to zero only where the question says so.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Square karo, purane sum mein jodo, root se scale karo.</p><h3>Solution — step by step</h3><p>The gradients are supplied by the question. They are not computed from an assumed objective, and g₂ is not replaced by the updated parameter.</p><p><strong>Iteration 1 — step 1: update the accumulator.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/18b84cdbfe918936.svg\" alt=\"s_1=0+2^2=4\" width=\"164.48\" height=\"25.26\" style=\"width:164.48px;height:25.26px;aspect-ratio:164.48/25.26\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: calculate the effective learning rate.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8acc57815fd4951a.svg\" alt=\"\\eta_{\\mathrm{effective},1}=\\frac{0.1}{\\sqrt4}=0.05\" width=\"241.94\" height=\"57.72\" style=\"width:241.94px;height:57.72px;aspect-ratio:241.94/57.72\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 3: apply the signed gradient.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8aa23a9e3a9c5875.svg\" alt=\"\\theta_1=1-0.05(2)=0.9\" width=\"235.28\" height=\"24.43\" style=\"width:235.28px;height:24.43px;aspect-ratio:235.28/24.43\" loading=\"lazy\"></div><p><strong>Iteration 2 — step 1: retain s₁ and add the new squared gradient.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1e29c54438050499.svg\" alt=\"s_2=4+1^2=5\" width=\"164.48\" height=\"25.26\" style=\"width:164.48px;height:25.26px;aspect-ratio:164.48/25.26\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: calculate the new coefficient.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:165.92px;--narrow-height:96.81px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4d33a28de17065dc.svg\"><img class=\"math display-math\" src=\"assets/equations/3d6533ca9b2ac114.svg\" alt=\"\\eta_{\\mathrm{effective},2}=\\frac{0.1}{\\sqrt5}\\approx0.044721360\" width=\"327.47\" height=\"57.72\" style=\"width:327.47px;height:57.72px;aspect-ratio:327.47/57.72\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 3: update from θ₁.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:189.01px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/81f6101b82b353cb.svg\"><img class=\"math display-math\" src=\"assets/equations/f835d09c27f0313a.svg\" alt=\"\\theta_2=0.9-\\frac{0.1(1)}{\\sqrt5}\\approx0.855278640\" width=\"350.57\" height=\"60.60\" style=\"width:350.57px;height:60.60px;aspect-ratio:350.57/60.60\" loading=\"lazy\"></picture></div><p><strong>Final answer:</strong> θ₁ = 0.9 and θ₂ ≈ 0.855279, with accumulators s₁ = 4 and s₂ = 5.</p><h3>Advantage, limitation and epsilon convention</h3><p>Coordinate-specific scaling can be useful when some features or gradients occur infrequently. Because s never decreases, its effective learning rate is nonincreasing when η and ε are fixed, and can become too small during prolonged training. The actual displacement magnitude need not decrease monotonically because gₜ also changes.</p><p>ε is normally a small positive stabilizer. These notes place it outside the square root. If a question places it inside, use that specified denominator consistently; the two placements are not numerically identical.</p><p class=\"definition\"><strong>Definition.</strong> RMSProp is an adaptive optimizer that normalizes the current gradient by the root of an exponentially weighted moving average of squared gradients. Its decaying history addresses AdaGrad&#x27;s permanently growing accumulator.</p><h3>Recurrence and interpretation</h3><p>Using decay β and zero initial state:</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b2de5dc1fbe8c99.svg\" alt=\"s_t=\\beta s_{t-1}+(1-\\beta)g_t^2\" width=\"235.06\" height=\"27.82\" style=\"width:235.06px;height:27.82px;aspect-ratio:235.06/27.82\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/03fd4ff4e7ab2e6e.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\varepsilon}\" width=\"216.56\" height=\"52.24\" style=\"width:216.56px;height:52.24px;aspect-ratio:216.56/52.24\" loading=\"lazy\"></div><p>β is the fraction of the previous squared-gradient average retained, not a signed velocity. Some papers use ρ for this same decay. The square is applied to the gradient before averaging; the square root is applied to the resulting average in the update.</p><p>If recent squared gradients are smaller than the old average, s can decrease. Thus older large gradients do not remain in the denominator with their original weight forever.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_rmsprop.svg\" aria-label=\"Enlarge diagram: Retain part of the old squared-gradient average and add the weighted square of the current gradient.\"><img src=\"assets/figures/v_rmsprop.svg\" alt=\"Retain part of the old squared-gradient average and add the weighted square of the current gradient.\" width=\"1080\" height=\"510\" loading=\"lazy\"></button><figcaption>Retain part of the old squared-gradient average and add the weighted square of the current gradient. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><h3>Complete numerical: two iterations</h3><p class=\"inline-question\"><strong>Question.</strong> θ₀ = 1, s₀ = 0, η = 0.1, β = 0.9; supplied gradients are 2 then 1. Perform two RMSProp updates, with ε = 0 for this hand calculation.</p><h3>Given</h3><p>θ₀ = 1; initial state(s) = 0; η = 0.1.</p><p>Supplied gradients g₁ = 2, g₂ = 1.</p><p>ε = 0 for this hand calculation.</p><p>β = 0.9.</p><h3>To find</h3><p>Calculate all required states and the parameter after each of two updates.</p><h3>Formula — which one and why</h3><p><strong>RMSProp.</strong> Use a decaying average of squared gradients, then scale the current gradient by its square root. Old contributions gradually lose influence.</p><p>s = squared-gradient average; ρ (rho), sometimes written β, = retained fraction; g = current gradient; η = learning rate; ε = denominator stabilizer.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div><p><strong>Yaad rakhne ka cue:</strong> Saare purane squares nahi—unki fading average.</p><h3>Solution — step by step</h3><p><strong>Iteration 1 — step 1: calculate the squared-gradient average.</strong></p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ea96f08ec1d03a73.svg\" alt=\"s_1=0.9(0)+0.1(2^2)=0.4\" width=\"283.96\" height=\"27.70\" style=\"width:283.96px;height:27.70px;aspect-ratio:283.96/27.70\" loading=\"lazy\"></div><p class=\"worked-step\"><strong>Step 2: calculate the denominator and signed correction.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d388f002971175a6.svg\"><img class=\"math display-math\" src=\"assets/equations/73269d6fb6447a99.svg\" alt=\"\\sqrt{s_1}=\\sqrt{0.4}\\approx0.632455532\" width=\"289.17\" height=\"30.34\" style=\"width:289.17px;height:30.34px;aspect-ratio:289.17/30.34\" loading=\"lazy\"></picture></div><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/91debda43e9c7015.svg\"><img class=\"math display-math\" src=\"assets/equations/918a6ff758f0307c.svg\" alt=\"\\frac{\\eta g_1}{\\sqrt{s_1}}=\\frac{0.1(2)}{\\sqrt{0.4}}\\approx0.316227766\" width=\"321.06\" height=\"60.60\" style=\"width:321.06px;height:60.60px;aspect-ratio:321.06/60.60\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 3: update the parameter.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.76px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/46ce5315f0e4b144.svg\"><img class=\"math display-math\" src=\"assets/equations/67ba0f8d71ab9792.svg\" alt=\"\\theta_1=1-0.316227766\\approx0.683772234\" width=\"387.31\" height=\"20.89\" style=\"width:387.31px;height:20.89px;aspect-ratio:387.31/20.89\" loading=\"lazy\"></picture></div><p><strong>Iteration 2 — step 1: use s₁, not the original zero state.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:239.17px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a780b29bab6859eb.svg\"><img class=\"math display-math\" src=\"assets/equations/e9da8c8b2ad0696a.svg\" alt=\"s_2=0.9(0.4)+0.1(1^2)=0.46\" width=\"315.20\" height=\"27.70\" style=\"width:315.20px;height:27.70px;aspect-ratio:315.20/27.70\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 2: calculate the denominator and signed correction.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:69.70px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/10263e4a8476b1fa.svg\"><img class=\"math display-math\" src=\"assets/equations/ae7e6b23e0aacbac.svg\" alt=\"\\sqrt{s_2}=\\sqrt{0.46}\\approx0.678232998\" width=\"301.38\" height=\"30.34\" style=\"width:301.38px;height:30.34px;aspect-ratio:301.38/30.34\" loading=\"lazy\"></picture></div><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:99.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ce8864a56ffdc251.svg\"><img class=\"math display-math\" src=\"assets/equations/8d403055f469e062.svg\" alt=\"\\frac{\\eta g_2}{\\sqrt{s_2}}=\\frac{0.1(1)}{\\sqrt{0.46}}\\approx0.147441956\" width=\"322.89\" height=\"60.60\" style=\"width:322.89px;height:60.60px;aspect-ratio:322.89/60.60\" loading=\"lazy\"></picture></div><p class=\"worked-step\"><strong>Step 3: update from θ₁, retaining calculator precision.</strong></p><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.68px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd5064d2dd1b316c.svg\"><img class=\"math display-math\" src=\"assets/equations/7aa9a16e4306403f.svg\" alt=\"\\theta_2\\approx0.683772234-0.147441956\\approx0.536330278\" width=\"504.06\" height=\"20.89\" style=\"width:504.06px;height:20.89px;aspect-ratio:504.06/20.89\" loading=\"lazy\"></picture></div><p><strong>Final answer:</strong> θ₁ ≈ 0.683772 and θ₂ ≈ 0.536330; s₁ = 0.4 and s₂ = 0.46.</p><h3>Comparison with AdaGrad and Adam</h3><p>AdaGrad stores an unweighted cumulative sum; RMSProp stores a decaying average. Basic RMSProp has no separate first-moment average and no Adam-style bias correction. With zero initialization, the early RMSProp state can therefore be much smaller than the first squared gradient, which explains the relatively large first correction in this example. The method still requires appropriate learning-rate and decay choices; adaptive scaling does not guarantee convergence to a global optimum.</p><p>AdaGrad’s nondecreasing squared-gradient sum can shrink its effective step excessively. RMSProp’s exponential average discounts older squared gradients, so it avoids that permanent accumulation. Both adapt rates coordinatewise and use ε for numerical stability. Switching is a plausible remedy, not a guarantee: inspect learning rate, gradient scale, data and convergence before attributing every plateau to the optimizer.</p>"],"search":"AdaGrad stagnation versus RMSProp A healthcare model trained with AdaGrad becomes stagnant after many epochs. Discuss AdaGrad and RMSProp in detail and their fundamental differences.","units":[3],"marks":10,"sourcePages":[5],"sourceKind":"actual-paper"},{"id":"tee-c21-s14","title":"R25 Q7a · Long-text sentiment architecture","kind":"practice","question":["<p><strong>Question. Choose a deep architecture for long social-media/customer-review sequences classified positive,negative or neutral. Explain its operation with equations.</strong> (10 marks)</p>"],"answer":["<p>An LSTM is a suitable syllabus-aligned choice for long dependencies. Tokenize and embed the text, process the sequence through LSTM states, form a sequence representation and use a three-class softmax. Padding/masking must prevent padded tokens from being treated as content.</p><div class=\"flow\"><span class=\"flow-box\">Text tokens</span> → <span class=\"flow-box\">Embedding sequence</span> → <span class=\"flow-box\">LSTM hidden/cell recurrence</span> → <span class=\"flow-box\">Final or pooled representation</span> → <span class=\"flow-box\">Dense3 +softmax</span> → <span class=\"flow-box\">Positive / negative / neutral</span></div><p class=\"definition\"><strong>Definition.</strong> Long short-term memory (LSTM) is a gated recurrent architecture with a cell state and hidden state. Forget, input and output gates regulate state retention, incorporation of candidate information and exposure of the updated cell.</p><h3>Explanation and working</h3><p>Long short-term memory, or LSTM, keeps a cell state Cₜ and a hidden state hₜ. A sigmoid gate produces values from 0 to 1: approximately 0 blocks a component, approximately 1 passes it. Intermediate values pass a fraction. Gates are learned from the previous hidden state and current input, not manually assigned by the user during normal inference.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/lstm.svg\" aria-label=\"Enlarge diagram: Follow the cell state from left to right then identify forget input and output gates\"><img src=\"assets/figures/lstm.svg\" alt=\"Follow the cell state from left to right then identify forget input and output gates\" width=\"960\" height=\"555\" loading=\"lazy\"></button><figcaption>Follow the cell state from left to right then identify forget input and output gates <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.75px;--narrow-height:103.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c991bf8824254bc.svg\"><img class=\"math display-math\" src=\"assets/equations/dc6d5a7033a71923.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f),\\quad i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"551.43\" height=\"25.53\" style=\"width:551.43px;height:25.53px;aspect-ratio:551.43/25.53\" loading=\"lazy\"></picture></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c08c8ddc953628c6.svg\" alt=\"\\widetilde C_t=\\tanh(W_c[h_{t-1},x_t]+b_c)\" width=\"299.78\" height=\"31.40\" style=\"width:299.78px;height:31.40px;aspect-ratio:299.78/31.40\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8751dee634f91753.svg\" alt=\"C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"258.41\" height=\"30.37\" style=\"width:258.41px;height:30.37px;aspect-ratio:258.41/30.37\" loading=\"lazy\"></div><div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.69px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/932f49e3f8a32474.svg\"><img class=\"math display-math\" src=\"assets/equations/d1817c5fc6ff06c8.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o),\\qquad h_t=o_t\\odot\\tanh(C_t)\" width=\"519.30\" height=\"24.43\" style=\"width:519.30px;height:24.43px;aspect-ratio:519.30/24.43\" loading=\"lazy\"></picture></div><p>The brackets [h, x] concatenate two vectors: [a, b] joined with [c, d] gives [a, b, c, d]. Concatenation is not addition. f is the forget gate: how much old cell content remains. i is the input gate: how much new candidate enters. The candidate is proposed content. o is the output gate: how much of the activated cell becomes visible as the hidden state.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-ce62d9e3abab42e3.svg\" alt=\"p=\\operatorname{softmax}(Wh+b),\\qquad L=-\\sum_{k=1}^3y_k\\log p_k\" style=\"width:44.936ex;height:6.756ex\" loading=\"lazy\"></div><p>Train on labelled examples with cross-entropy and BPTT; evaluate on held-out reviews with class-wise precision/recall/F1. LSTM gates reduce long-path gradient decay but do not guarantee perfect memory. The three outputs are mutually exclusive classes for this question.</p>"],"search":"Long-text sentiment architecture Choose a deep architecture for long social-media/customer-review sequences classified positive,negative or neutral. Explain its operation with equations.","units":[5],"marks":10,"sourcePages":[5,6],"sourceKind":"actual-paper"},{"id":"tee-c21-s15","title":"R25 Q7b · Transfer learning","kind":"practice","question":["<p><strong>Question. Explain transfer learning and its benefits with suitable examples.</strong> (5 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> Transfer learning reuses representations or parameters learned on a source task to support a target task. With a pretrained neural network, common strategies are fixed feature extraction and fine-tuning selected pretrained layers.</p><h3>Explanation and working</h3><p>Transfer learning reuses a model or representation learned on one task for a related new task. A pretrained CNN may already detect useful edges, textures and shapes, saving data and training effort.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Start with learned image features. Replace the task-specific head, then choose which pretrained layers may change. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><p><strong>Full scenario.</strong> Build a face-attendance model with few images per student. Explain a training plan.</p><p class=\"worked-step\"><strong>Step 1. Define and split the data.</strong> Collect varied, permitted images and separate training/validation/test by suitable independent captures. Keep duplicates out of different splits. Apply the pretrained model’s required input size and normalization.</p><p class=\"worked-step\"><strong>Step 2. Choose a suitable pretrained backbone.</strong> For a course example, use VGG 16 or ResNet as an image-feature extractor. ImageNet-pretrained VGG 16 was trained on ImageNet, not automatically on a face-specific dataset. A face-trained model can be a more task-specific choice if available.</p><p class=\"worked-step\"><strong>Step 3. Replace the classifier.</strong> Remove the original class head. Add a new classifier matching the required student classes, or an appropriate embedding-based recognition system if that is the chosen formulation. For the exam classification example, use a softmax head and cross-entropy.</p><p class=\"worked-step\"><strong>Step 4. Freeze and train.</strong> Freeze the base weights and train the new head first. Use suitable augmentation, regularization and validation monitoring.</p><p class=\"worked-step\"><strong>Step 5. Fine-tune if justified.</strong> Unfreeze selected later layers and train at a smaller learning rate. Early layers may remain frozen. Compare validation performance and restore the best checkpoint.</p><p class=\"worked-step\"><strong>Step 6. Evaluate.</strong> Use the held-out test set once for the final estimate. Include unfamiliar faces and a rejection rule if describing a real attendance system; a closed-set classroom example alone does not solve unknown-person recognition.</p><p>Feature extraction keeps the backbone fixed. Fine-tuning changes some pretrained weights. Training the entire model from scratch is a third option when enough representative data and compute are available, but it is usually harder for the stated small-dataset scenario.</p><p>Early image layers commonly learn reusable edges and textures. Later layers become more specialized to source-task categories. “Earlier” means closer to the input, regardless of whether a drawing places those layers at the top or bottom.</p><div class=\"table-scroll\"><table><thead><tr><th>Target dataset</th><th>Sensible starting choice</th><th>Reason</th></tr></thead><tbody><tr><td>Small and similar</td><td>Freeze the backbone; train a new head first</td><td>Useful features already exist, while few examples make overfitting likely</td></tr><tr><td>Large and similar</td><td>Train a new head, then fine-tune more layers if validation improves</td><td>More data can support more trainable parameters</td></tr><tr><td>Small and different</td><td>Try a more relevant pretrained model or fixed earlier/intermediate features; tune cautiously</td><td>Later source features may be unsuitable, but small data still makes extensive tuning risky</td></tr><tr><td>Large and different</td><td>Compare broad fine-tuning with training from scratch</td><td>Sufficient data permits stronger adaptation; the value of source features must be tested</td></tr></tbody></table></div><p>These are starting strategies, not universal rules. Fine-tuning an early layer means updating its pretrained weights, not automatically learning it “from scratch”. With very little data, simply unfreezing early layers because the task differs can overfit. Choose changes using validation performance and apply the required preprocessing consistently.</p><p><strong>Example.</strong> With 100 labelled microscopic images, an ImageNet model may provide reusable low-level patterns, but its animal/object classifier is inappropriate. Replace the head, test fixed representations and monitor validation before increasing the number of trainable layers. With a large representative image dataset, broader fine-tuning becomes a more reasonable candidate.</p><p><strong>Yaad rakho:</strong> data kam toh kam weights hilao; task alag toh features ki suitability pehle dekho.</p>"],"search":"Transfer learning Explain transfer learning and its benefits with suitable examples.","units":[4],"marks":5,"sourcePages":[6],"sourceKind":"actual-paper"},{"id":"tee-c21-s16","title":"R25 Q7c · Learning rate and two losses","kind":"practice","question":["<p><strong>Question. Explain the importance of learning rate. Give and explain one classification loss and one regression loss.</strong> (5 marks)</p>"],"answer":["<p class=\"definition\"><strong>Definition.</strong> The learning rate is a hyperparameter controlling the scale of a gradient-based update. It affects convergence speed and stability; it is not the gradient and is not the magnitude of the loss.</p><h3>Explanation and working</h3><p>A very small rate can make progress slow. A very large rate can overshoot, oscillate or diverge. A suitable rate permits progress without uncontrolled jumps. Feature scaling can reduce long zig-zag paths. A noisy curve alone is not proof of failure; individual mini-batch losses fluctuate.</p><figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/optimizers.svg\" aria-label=\"Enlarge diagram: Illustrative loss traces show why smoothness and progress are different\"><img src=\"assets/figures/optimizers.svg\" alt=\"Illustrative loss traces show why smoothness and progress are different\" width=\"960\" height=\"450\" loading=\"lazy\"></button><figcaption>Illustrative loss traces show why smoothness and progress are different <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure><div class=\"table-scroll\"><table><thead><tr><th>Observation</th><th>Possible reason</th><th>Sensible first action</th></tr></thead><tbody><tr><td>Loss barely changes</td><td>Very small rate, saturated/dead units, wrong implementation</td><td>Check gradients and data; then tune rate or activation</td></tr><tr><td>Loss jumps wildly</td><td>Rate too high or exploding gradients</td><td>Reduce rate; inspect gradient size; clip if appropriate</td></tr><tr><td>Noisy but decreasing loss</td><td>Small-batch sampling noise</td><td>Compare a smoothed trend; consider larger batches or momentum</td></tr><tr><td>Training improves but validation worsens</td><td>Overfitting</td><td>Use regularization, augmentation or early stopping</td></tr><tr><td>All identical hidden neurons learn alike</td><td>Symmetric initialization</td><td>Use suitable nonidentical initial weights</td></tr></tbody></table></div><p>Convergence means updates or the objective are settling under a criterion. A zero gradient can also occur at a saddle point or in a saturated region; it is not proof of a global optimum.</p><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-bb4226c392bbf68f.svg\" alt=\"L_{class}=-\\sum_ky_k\\log p_k,\\qquad L_{reg}=\\frac1n\\sum_i(\\hat y_i-y_i)^2\" style=\"width:49.692ex;height:5.786ex\" loading=\"lazy\"></div><p>Categorical cross-entropy penalizes low assigned probability to the true class; for a one-hot target and true-class probability0.8, L=−ln0.8≈0.223144. MSE measures average squared numeric prediction error; errors1and−2give(1²+(-2)²)/2=2.5. These are illustrative examples; their output interpretation and loss scaling must match the model.</p>"],"search":"Learning rate and two losses Explain the importance of learning rate. Give and explain one classification loss and one regression loss.","units":[2,3],"marks":5,"sourcePages":[6],"sourceKind":"actual-paper"}]},{"n":22,"title":"Faculty Assignment 2 · worked practice","sourceKind":"faculty-assignment","sections":[{"id":"tee-c22-s0","title":"Faculty Assignment2 Q1 · One momentum update with an omitted coefficient","kind":"practice","question":["<p><strong>Question. For J(w)=½(w−3)²,w₀=5,learning rate0.1,perform one SGD-with-momentum iteration.</strong> (Faculty assignment: no marks printed)</p>"],"answer":["<h3>Given</h3><p>w₀=5,η=0.1. βandinitialvelocityare not supplied.</p><h3>To find</h3><p>One update conditional on zero initial velocity.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-d398e0121f17d787.svg\" alt=\"g=w-3,\\quad v_1=\\beta v_0+\\eta g,\\quad w_1=w_0-v_1\" style=\"width:42.67ex;height:2.084ex\" loading=\"lazy\"></div><p>Choose displacement convention and v₀=0; then the first step is independent of β.</p><h3>Step 1. Differentiate and evaluate</h3><p>g₀=5−3=2.</p><h3>Step 2. Calculate momentum displacement</h3><p>v₁=β×0+0.1×2=0.2.</p><h3>Step 3. Subtract the displacement</h3><p>w₁=5−0.2=4.8.</p><h3>Final answer</h3><p><strong>w₁=4.8 if v₀=0.</strong> For a nonzero initial velocity, w₁=4.8−βv₀; no unique numerical value follows without those givens.</p><p><strong>Source / convention note.</strong> Authentic faculty Assignment2; no marks printed. β/v₀ omission explicitly identified.</p>"],"search":"One momentum update with an omitted coefficient For J(w)=½(w−3)²,w₀=5,learning rate0.1,perform one SGD-with-momentum iteration.","units":[3],"marks":null,"sourcePages":[],"sourceKind":"faculty-assignment"},{"id":"tee-c22-s1","title":"Faculty Assignment2 Q2 · Specified momentum update","kind":"practice","question":["<p><strong>Question. For J(w)=½(w+2)²,η=0.2,β=0.8,w₀=4,v₀=0,perform one momentum step.</strong> (Faculty assignment: no marks printed)</p>"],"answer":["<h3>Given</h3><p>All givens above.</p><h3>To find</h3><p>v₁andw₁.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-5b00da4482787868.svg\" alt=\"g=w+2,\\quad v_1=\\beta v_0+\\eta g,\\quad w_1=w_0-v_1\" style=\"width:42.67ex;height:2.084ex\" loading=\"lazy\"></div><h3>Step 1. Gradient</h3><p>g₀=4+2=6.</p><h3>Step 2. Momentum displacement</h3><p>v₁=0.8×0+0.2×6=1.2.</p><h3>Step 3. Weight</h3><p>w₁=4−1.2=2.8.</p><h3>Final answer</h3><p><strong>v₁=1.2,w₁=2.8.</strong> A signed-velocity convention givesv₁=−1.2andw₁=w₀+v₁; the final weight is the same.</p>"],"search":"Specified momentum update For J(w)=½(w+2)²,η=0.2,β=0.8,w₀=4,v₀=0,perform one momentum step.","units":[3],"marks":null,"sourcePages":[],"sourceKind":"faculty-assignment"},{"id":"tee-c22-s2","title":"Faculty Assignment2 Q3 · 28×28 CNN","kind":"practice","question":["<p><strong>Question. Input28×28×1; conv5,6valid; pool2stride2; conv5,16valid; pool2stride2; dense120,dense84,dense10. Find layer dimensions and parameters.</strong> (Faculty assignment: no marks printed)</p>"],"answer":["<h3>Given</h3><p>Input=[28, 28, 1]</p><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Kernel</th><th>Stride</th><th>Padding</th><th>Filters / units</th></tr></thead><tbody><tr><td>Conv</td><td>5</td><td>1</td><td>0</td><td>6</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Conv</td><td>5</td><td>1</td><td>0</td><td>16</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>120</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>84</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>10</td></tr></tbody></table></div><h3>To find</h3><p>Each output shape and all trainable weights plus biases.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-cbf0b1f38ebaaccb.svg\" alt=\"O=\\left\\lfloor\\frac{N+2P-F}{S}\\right\\rfloor+1\" style=\"width:24.339ex;height:5.428ex\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-69756abf2018c02c.svg\" alt=\"P_{conv}=(F_hF_wC_{in}+1)C_{out},\\quad P_{dense}=(n_{in}+1)n_{out}\" style=\"width:50.749ex;height:2.262ex\" loading=\"lazy\"></div><p>Each filter/unit has one bias. Pooling has zero learned parameters. Flatten preserves the number of values, then a dense layer connects every input value to every output unit.</p><h3>Step 1. Work layer by layer</h3><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Input</th><th>Full substitution and reason</th><th>Output</th><th>Parameters</th></tr></thead><tbody><tr><td>Conv</td><td>28×28×1</td><td>⌊(28+2×0−5)/1⌋+1=24; parameters=(5×5×1+1)×6=156</td><td>24×24×6</td><td>156</td></tr><tr><td>Pool</td><td>24×24×6</td><td>⌊(24−2)/2⌋+1=12; channels stay 6; no trainable weights</td><td>12×12×6</td><td>0</td></tr><tr><td>Conv</td><td>12×12×6</td><td>⌊(12+2×0−5)/1⌋+1=8; parameters=(5×5×6+1)×16=2416</td><td>8×8×16</td><td>2416</td></tr><tr><td>Pool</td><td>8×8×16</td><td>⌊(8−2)/2⌋+1=4; channels stay 16; no trainable weights</td><td>4×4×16</td><td>0</td></tr><tr><td>Dense</td><td>4×4×16</td><td>Flatten/input length=4×4×16=256; parameters=(256+1)×120=30840</td><td>120</td><td>30840</td></tr><tr><td>Dense</td><td>1×1×120</td><td>Flatten/input length=1×1×120=120; parameters=(120+1)×84=10164</td><td>84</td><td>10164</td></tr><tr><td>Dense</td><td>1×1×84</td><td>Flatten/input length=1×1×84=84; parameters=(84+1)×10=850</td><td>10</td><td>850</td></tr></tbody></table></div><h3>Step 2. Sum only trainable parameters</h3><p>156 + 2416 + 30840 + 10164 + 850 = 44426</p><h3>Final answer</h3><p><strong>Total parameters=44426.</strong> Shape and parameter count are separate results.</p>"],"search":"28×28 CNN Input28×28×1; conv5,6valid; pool2stride2; conv5,16valid; pool2stride2; dense120,dense84,dense10. Find layer dimensions and parameters.","units":[4],"marks":null,"sourcePages":[],"sourceKind":"faculty-assignment"},{"id":"tee-c22-s3","title":"Faculty Assignment2 Q4 · Batch linear regression update","kind":"practice","question":["<p><strong>Question. x=[1,2],y=[3,5],w=b=0,η=0.1;J=(1/(2m))Σ(wxᵢ+b−yᵢ)²,m=2. Compute both gradients and update.</strong> (Faculty assignment: no marks printed)</p>"],"answer":["<h3>Given</h3><p>Two examples, shared w,b, m=2.</p><h3>To find</h3><p>One simultaneous batch update.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-4886822a6f85a414.svg\" alt=\"\\frac{\\partial J}{\\partial w}=\\frac1m\\sum_ie_ix_i,\\quad\\frac{\\partial J}{\\partial b}=\\frac1m\\sum_ie_i,\\quad e_i=wx_i+b-y_i\" style=\"width:56.618ex;height:5.844ex\" loading=\"lazy\"></div><h3>Step 1. Predict and subtract targets</h3><div class=\"table-wrap\"><table><thead><tr><th>x</th><th>y</th><th>wx+b</th><th>e</th><th>e×x</th></tr></thead><tbody><tr><td>1</td><td>3</td><td>0</td><td>-3</td><td>-3</td></tr><tr><td>2</td><td>5</td><td>0</td><td>-5</td><td>-10</td></tr></tbody></table></div><h3>Step 2. Average each gradient sum</h3><p>dw=(−3−10)/2=−6.5;db=(−3−5)/2=−4.</p><h3>Step 3. Update both from old parameters</h3><p>w′=0−0.1×(−6.5)=0.65;b′=0−0.1×(−4)=0.4.</p><h3>Final answer</h3><p><strong>w′=0.65,b′=0.4.</strong> New predictions1.05and1.7; do not updatew before computing theoldbgradient.</p>"],"search":"Batch linear regression update x=[1,2],y=[3,5],w=b=0,η=0.1;J=(1/(2m))Σ(wxᵢ+b−yᵢ)²,m=2. Compute both gradients and update.","units":[2,3],"marks":null,"sourcePages":[],"sourceKind":"faculty-assignment"},{"id":"tee-c22-s4","title":"Faculty Assignment2 Q5 · 32×32 three-convolution CNN","kind":"practice","question":["<p><strong>Question. Input32×32×1; conv3,8same; pool2stride2; conv5,16valid; pool2stride2; conv3,32same; dense64; output5. Find shapes and parameters.</strong> (Faculty assignment: no marks printed)</p>"],"answer":["<h3>Given</h3><p>Input=[32, 32, 1]</p><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Kernel</th><th>Stride</th><th>Padding</th><th>Filters / units</th></tr></thead><tbody><tr><td>Conv</td><td>3</td><td>1</td><td>1</td><td>8</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Conv</td><td>5</td><td>1</td><td>0</td><td>16</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Conv</td><td>3</td><td>1</td><td>1</td><td>32</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>64</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>5</td></tr></tbody></table></div><h3>To find</h3><p>Each output shape and all trainable weights plus biases.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-cbf0b1f38ebaaccb.svg\" alt=\"O=\\left\\lfloor\\frac{N+2P-F}{S}\\right\\rfloor+1\" style=\"width:24.339ex;height:5.428ex\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-69756abf2018c02c.svg\" alt=\"P_{conv}=(F_hF_wC_{in}+1)C_{out},\\quad P_{dense}=(n_{in}+1)n_{out}\" style=\"width:50.749ex;height:2.262ex\" loading=\"lazy\"></div><p>Each filter/unit has one bias. Pooling has zero learned parameters. Flatten preserves the number of values, then a dense layer connects every input value to every output unit.</p><h3>Step 1. Work layer by layer</h3><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Input</th><th>Full substitution and reason</th><th>Output</th><th>Parameters</th></tr></thead><tbody><tr><td>Conv</td><td>32×32×1</td><td>⌊(32+2×1−3)/1⌋+1=32; parameters=(3×3×1+1)×8=80</td><td>32×32×8</td><td>80</td></tr><tr><td>Pool</td><td>32×32×8</td><td>⌊(32−2)/2⌋+1=16; channels stay 8; no trainable weights</td><td>16×16×8</td><td>0</td></tr><tr><td>Conv</td><td>16×16×8</td><td>⌊(16+2×0−5)/1⌋+1=12; parameters=(5×5×8+1)×16=3216</td><td>12×12×16</td><td>3216</td></tr><tr><td>Pool</td><td>12×12×16</td><td>⌊(12−2)/2⌋+1=6; channels stay 16; no trainable weights</td><td>6×6×16</td><td>0</td></tr><tr><td>Conv</td><td>6×6×16</td><td>⌊(6+2×1−3)/1⌋+1=6; parameters=(3×3×16+1)×32=4640</td><td>6×6×32</td><td>4640</td></tr><tr><td>Dense</td><td>6×6×32</td><td>Flatten/input length=6×6×32=1152; parameters=(1152+1)×64=73792</td><td>64</td><td>73792</td></tr><tr><td>Dense</td><td>1×1×64</td><td>Flatten/input length=1×1×64=64; parameters=(64+1)×5=325</td><td>5</td><td>325</td></tr></tbody></table></div><h3>Step 2. Sum only trainable parameters</h3><p>80 + 3216 + 4640 + 73792 + 325 = 82053</p><h3>Final answer</h3><p><strong>Total parameters=82053.</strong> Shape and parameter count are separate results.</p>"],"search":"32×32 three-convolution CNN Input32×32×1; conv3,8same; pool2stride2; conv5,16valid; pool2stride2; conv3,32same; dense64; output5. Find shapes and parameters.","units":[4],"marks":null,"sourcePages":[],"sourceKind":"faculty-assignment"},{"id":"tee-c22-s5","title":"Faculty Assignment2 Q6 · 64×64 two-convolution CNN","kind":"practice","question":["<p><strong>Question. Input64×64×3; conv5,16valid; pool2stride2; conv3,32same; pool2stride2; dense128; output10. Find shapes and parameters.</strong> (Faculty assignment: no marks printed)</p>"],"answer":["<h3>Given</h3><p>Input=[64, 64, 3]</p><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Kernel</th><th>Stride</th><th>Padding</th><th>Filters / units</th></tr></thead><tbody><tr><td>Conv</td><td>5</td><td>1</td><td>0</td><td>16</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Conv</td><td>3</td><td>1</td><td>1</td><td>32</td></tr><tr><td>Pool</td><td>2</td><td>2</td><td>0</td><td>0</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>128</td></tr><tr><td>Dense</td><td>0</td><td>0</td><td>0</td><td>10</td></tr></tbody></table></div><h3>To find</h3><p>Each output shape and all trainable weights plus biases.</p><h3>Formula: which one and why</h3><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-cbf0b1f38ebaaccb.svg\" alt=\"O=\\left\\lfloor\\frac{N+2P-F}{S}\\right\\rfloor+1\" style=\"width:24.339ex;height:5.428ex\" loading=\"lazy\"></div><div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/recovered-69756abf2018c02c.svg\" alt=\"P_{conv}=(F_hF_wC_{in}+1)C_{out},\\quad P_{dense}=(n_{in}+1)n_{out}\" style=\"width:50.749ex;height:2.262ex\" loading=\"lazy\"></div><p>Each filter/unit has one bias. Pooling has zero learned parameters. Flatten preserves the number of values, then a dense layer connects every input value to every output unit.</p><h3>Step 1. Work layer by layer</h3><div class=\"table-wrap\"><table><thead><tr><th>Layer</th><th>Input</th><th>Full substitution and reason</th><th>Output</th><th>Parameters</th></tr></thead><tbody><tr><td>Conv</td><td>64×64×3</td><td>⌊(64+2×0−5)/1⌋+1=60; parameters=(5×5×3+1)×16=1216</td><td>60×60×16</td><td>1216</td></tr><tr><td>Pool</td><td>60×60×16</td><td>⌊(60−2)/2⌋+1=30; channels stay 16; no trainable weights</td><td>30×30×16</td><td>0</td></tr><tr><td>Conv</td><td>30×30×16</td><td>⌊(30+2×1−3)/1⌋+1=30; parameters=(3×3×16+1)×32=4640</td><td>30×30×32</td><td>4640</td></tr><tr><td>Pool</td><td>30×30×32</td><td>⌊(30−2)/2⌋+1=15; channels stay 32; no trainable weights</td><td>15×15×32</td><td>0</td></tr><tr><td>Dense</td><td>15×15×32</td><td>Flatten/input length=15×15×32=7200; parameters=(7200+1)×128=921728</td><td>128</td><td>921728</td></tr><tr><td>Dense</td><td>1×1×128</td><td>Flatten/input length=1×1×128=128; parameters=(128+1)×10=1290</td><td>10</td><td>1290</td></tr></tbody></table></div><h3>Step 2. Sum only trainable parameters</h3><p>1216 + 4640 + 921728 + 1290 = 928874</p><h3>Final answer</h3><p><strong>Total parameters=928874.</strong> Shape and parameter count are separate results.</p>"],"search":"64×64 two-convolution CNN Input64×64×3; conv5,16valid; pool2stride2; conv3,32same; pool2stride2; dense128; output10. Find shapes and parameters.","units":[4],"marks":null,"sourcePages":[],"sourceKind":"faculty-assignment"}]}]},"meta":{"mt2":{"questions":[{"paper":"MT1A","q":"Q2","marks":3,"unit":"2","page":1,"status":"Retain"},{"paper":"MT1A","q":"Q3","marks":3,"unit":"2","page":1,"status":"Retain"},{"paper":"MT1A","q":"Q4","marks":3,"unit":"2","page":1,"status":"Retain"},{"paper":"MT1B","q":"Q3","marks":3,"unit":"2","page":2,"status":"Retain"},{"paper":"MT1B","q":"Q4","marks":3,"unit":"2","page":2,"status":"Retain"},{"paper":"F25","q":"Q1c","marks":5,"unit":"3","page":1,"status":"Retain"},{"paper":"F25","q":"Q1d","marks":5,"unit":"5","page":"1–2","status":"Retain"},{"paper":"F25","q":"Q2b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"F25","q":"Q3b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"F25","q":"Q4a","marks":10,"unit":"3","page":"2–3","status":"Retain"},{"paper":"F25","q":"Q5b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"F25","q":"Q6a","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"F25","q":"Q7b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R26","q":"Q1c","marks":5,"unit":"3","page":1,"status":"Retain"},{"paper":"R26","q":"Q1d","marks":5,"unit":"5","page":1,"status":"Retain"},{"paper":"R26","q":"Q2b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"R26","q":"Q3b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"R26","q":"Q4a","marks":10,"unit":"3","page":2,"status":"Retain"},{"paper":"R26","q":"Q5a","marks":10,"unit":"5","page":3,"status":"Retain"},{"paper":"R26","q":"Q5b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"R26","q":"Q6a","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"R26","q":"Q7b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F23","q":"Q1b","marks":5,"unit":"2–3","page":1,"status":"Retain"},{"paper":"F23","q":"Q1d","marks":5,"unit":"4","page":1,"status":"Retain"},{"paper":"F23","q":"Q3b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"F23","q":"Q4a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F23","q":"Q5a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F23","q":"Q6b","marks":10,"unit":"4","page":5,"status":"Retain"},{"paper":"F23","q":"Q7a","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"F23","q":"Q7b","marks":10,"unit":"3","page":5,"status":"Retain"},{"paper":"R24","q":"Q1c","marks":5,"unit":"3","page":1,"status":"Retain"},{"paper":"R24","q":"Q1d","marks":5,"unit":"4","page":2,"status":"Retain"},{"paper":"R24","q":"Q2b","marks":10,"unit":"3","page":3,"status":"Retain comparison and ii; exclude formal rate bounds"},{"paper":"R24","q":"Q3b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"R24","q":"Q4b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R24","q":"Q5a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R24","q":"Q6b","marks":10,"unit":"4","page":5,"status":"Retain"},{"paper":"R24","q":"Q7b","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"F22","q":"Q1a","marks":4,"unit":"4","page":1,"status":"Retain"},{"paper":"F22","q":"Q1b","marks":4,"unit":"3","page":1,"status":"Retain"},{"paper":"F22","q":"Q1e","marks":4,"unit":"5","page":2,"status":"Retain"},{"paper":"F22","q":"Q3a","marks":10,"unit":"2–3","page":3,"status":"Retain"},{"paper":"F22","q":"Q3b","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"F22","q":"Q4a","marks":10,"unit":"4","page":"3–4","status":"Retain"},{"paper":"F22","q":"Q4b","marks":10,"unit":"2–3","page":4,"status":"Retain"},{"paper":"F22","q":"Q5b","marks":10,"unit":"3","page":4,"status":"Retain"},{"paper":"F22","q":"Q6a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F22","q":"Q6b","marks":10,"unit":"2–3","page":"4–5","status":"Retain"},{"paper":"R23","q":"Q1a","marks":4,"unit":"5","page":1,"status":"Retain"},{"paper":"R23","q":"Q1b","marks":4,"unit":"4","page":1,"status":"Retain"},{"paper":"R23","q":"Q1d","marks":4,"unit":"3","page":1,"status":"Retain"},{"paper":"R23","q":"Q2a","marks":10,"unit":"2–4","page":2,"status":"Retain"},{"paper":"R23","q":"Q2b","marks":10,"unit":"2–3","page":2,"status":"Retain"},{"paper":"R23","q":"Q4a","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"R23","q":"Q4b","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"R23","q":"Q6a","marks":10,"unit":"3","page":4,"status":"Retain"},{"paper":"R23","q":"Q6b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R23","q":"Q7b","marks":10,"unit":"3","page":4,"status":"Retain"}],"drill_mapping":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"13":11,"14":12,"15":13,"16":14,"17":15,"18":16,"19":17,"20":18,"21":19,"22":20,"23":21,"24":22,"25":23,"26":24,"27":25,"28":26,"29":27,"30":28,"31":29,"32":30,"33":31,"34":32,"35":33,"36":34,"37":35,"38":36,"39":37,"40":38,"41":39,"46":40,"47":41,"48":42,"49":43,"51":44,"52":45},"drills":45,"source_pages":7},"tee":{"questions":[{"paper":"MT1A","q":"Q1a","marks":2,"unit":"1","page":1,"status":"Retain"},{"paper":"MT1A","q":"Q1b","marks":2,"unit":"1","page":1,"status":"Retain"},{"paper":"MT1A","q":"Q2","marks":3,"unit":"2","page":1,"status":"Retain"},{"paper":"MT1A","q":"Q3","marks":3,"unit":"2","page":1,"status":"Retain"},{"paper":"MT1A","q":"Q4","marks":3,"unit":"2","page":1,"status":"Retain"},{"paper":"MT1B","q":"Q1a","marks":2,"unit":"1","page":2,"status":"Retain"},{"paper":"MT1B","q":"Q1b","marks":2,"unit":"1","page":2,"status":"Retain"},{"paper":"MT1B","q":"Q2","marks":3,"unit":"2","page":2,"status":"Retain"},{"paper":"MT1B","q":"Q3","marks":3,"unit":"2","page":2,"status":"Retain"},{"paper":"MT1B","q":"Q4","marks":3,"unit":"2","page":2,"status":"Retain"},{"paper":"F25","q":"Q1a","marks":5,"unit":"1","page":1,"status":"Retain"},{"paper":"F25","q":"Q1b","marks":5,"unit":"2","page":1,"status":"Retain"},{"paper":"F25","q":"Q1c","marks":5,"unit":"3","page":1,"status":"Retain"},{"paper":"F25","q":"Q1d","marks":5,"unit":"5","page":"1–2","status":"Retain"},{"paper":"F25","q":"Q2a","marks":10,"unit":"2","page":2,"status":"Retain"},{"paper":"F25","q":"Q2b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"F25","q":"Q3a","marks":10,"unit":"2","page":2,"status":"Retain"},{"paper":"F25","q":"Q3b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"F25","q":"Q4a","marks":10,"unit":"3","page":"2–3","status":"Retain"},{"paper":"F25","q":"Q4b","marks":10,"unit":"5","page":3,"status":"Retain"},{"paper":"F25","q":"Q5a","marks":10,"unit":"5","page":3,"status":"Retain"},{"paper":"F25","q":"Q5b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"F25","q":"Q6a","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"F25","q":"Q6b","marks":10,"unit":"2","page":3,"status":"Retain"},{"paper":"F25","q":"Q7a","marks":10,"unit":"2","page":"3–4","status":"Retain"},{"paper":"F25","q":"Q7b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R26","q":"Q1a","marks":5,"unit":"1","page":1,"status":"Retain"},{"paper":"R26","q":"Q1b","marks":5,"unit":"2","page":1,"status":"Retain"},{"paper":"R26","q":"Q1c","marks":5,"unit":"3","page":1,"status":"Retain"},{"paper":"R26","q":"Q1d","marks":5,"unit":"5","page":1,"status":"Retain"},{"paper":"R26","q":"Q2a","marks":10,"unit":"2","page":2,"status":"Retain"},{"paper":"R26","q":"Q2b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"R26","q":"Q3a","marks":10,"unit":"2","page":2,"status":"Retain"},{"paper":"R26","q":"Q3b","marks":10,"unit":"4","page":2,"status":"Retain"},{"paper":"R26","q":"Q4a","marks":10,"unit":"3","page":2,"status":"Retain"},{"paper":"R26","q":"Q4b","marks":10,"unit":"5","page":"2–3","status":"Retain i–iii; exclude iv beyond explicit syllabus"},{"paper":"R26","q":"Q5a","marks":10,"unit":"5","page":3,"status":"Retain"},{"paper":"R26","q":"Q5b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"R26","q":"Q6a","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"R26","q":"Q6b","marks":10,"unit":"2","page":4,"status":"Retain"},{"paper":"R26","q":"Q7a","marks":10,"unit":"2","page":4,"status":"Retain"},{"paper":"R26","q":"Q7b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F23","q":"Q1a","marks":5,"unit":"1","page":1,"status":"Retain"},{"paper":"F23","q":"Q1b","marks":5,"unit":"2–3","page":1,"status":"Retain"},{"paper":"F23","q":"Q1c","marks":5,"unit":"5","page":1,"status":"Retain"},{"paper":"F23","q":"Q1d","marks":5,"unit":"4","page":1,"status":"Retain"},{"paper":"F23","q":"Q2a","marks":10,"unit":"2","page":2,"status":"Retain"},{"paper":"F23","q":"Q2b","marks":10,"unit":"1–2","page":3,"status":"Retain"},{"paper":"F23","q":"Q3a","marks":10,"unit":"2","page":3,"status":"Retain"},{"paper":"F23","q":"Q3b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"F23","q":"Q4a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F23","q":"Q4b","marks":10,"unit":"5","page":4,"status":"Retain"},{"paper":"F23","q":"Q5a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F23","q":"Q5b","marks":10,"unit":"2","page":4,"status":"Retain"},{"paper":"F23","q":"Q6a","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"F23","q":"Q6b","marks":10,"unit":"4","page":5,"status":"Retain"},{"paper":"F23","q":"Q7a","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"F23","q":"Q7b","marks":10,"unit":"3","page":5,"status":"Retain"},{"paper":"R24","q":"Q1a","marks":5,"unit":"1","page":1,"status":"Retain"},{"paper":"R24","q":"Q1b","marks":5,"unit":"2","page":1,"status":"Retain"},{"paper":"R24","q":"Q1c","marks":5,"unit":"3","page":1,"status":"Retain"},{"paper":"R24","q":"Q1d","marks":5,"unit":"4","page":2,"status":"Retain"},{"paper":"R24","q":"Q2a","marks":10,"unit":"2","page":"2–3","status":"Retain"},{"paper":"R24","q":"Q2b","marks":10,"unit":"3","page":3,"status":"Retain comparison and ii; exclude formal rate bounds"},{"paper":"R24","q":"Q3a","marks":10,"unit":"2","page":3,"status":"Retain"},{"paper":"R24","q":"Q3b","marks":10,"unit":"3","page":3,"status":"Retain"},{"paper":"R24","q":"Q4a","marks":10,"unit":"2","page":3,"status":"Retain"},{"paper":"R24","q":"Q4b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R24","q":"Q5a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R24","q":"Q5b","marks":10,"unit":"1,4,5","page":4,"status":"Retain"},{"paper":"R24","q":"Q6a","marks":10,"unit":"5","page":"4–5","status":"Retain"},{"paper":"R24","q":"Q6b","marks":10,"unit":"4","page":5,"status":"Retain"},{"paper":"R24","q":"Q7a","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"R24","q":"Q7b","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"F22","q":"Q1a","marks":4,"unit":"4","page":1,"status":"Retain"},{"paper":"F22","q":"Q1b","marks":4,"unit":"3","page":1,"status":"Retain"},{"paper":"F22","q":"Q1c","marks":4,"unit":"1","page":2,"status":"Retain"},{"paper":"F22","q":"Q1d","marks":4,"unit":"2","page":2,"status":"Retain"},{"paper":"F22","q":"Q1e","marks":4,"unit":"5","page":2,"status":"Retain"},{"paper":"F22","q":"Q2a","marks":10,"unit":"5","page":2,"status":"Retain"},{"paper":"F22","q":"Q2b","marks":10,"unit":"2","page":2,"status":"Retain"},{"paper":"F22","q":"Q3a","marks":10,"unit":"2–3","page":3,"status":"Retain"},{"paper":"F22","q":"Q3b","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"F22","q":"Q4a","marks":10,"unit":"4","page":"3–4","status":"Retain"},{"paper":"F22","q":"Q4b","marks":10,"unit":"2–3","page":4,"status":"Retain"},{"paper":"F22","q":"Q5a","marks":10,"unit":"5","page":4,"status":"Retain"},{"paper":"F22","q":"Q5b","marks":10,"unit":"3","page":4,"status":"Retain"},{"paper":"F22","q":"Q6a","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"F22","q":"Q6b","marks":10,"unit":"2–3","page":"4–5","status":"Retain"},{"paper":"F22","q":"Q7a","marks":10,"unit":"5","page":5,"status":"Retain"},{"paper":"F22","q":"Q7b","marks":10,"unit":"2","page":5,"status":"Retain"},{"paper":"R23","q":"Q1a","marks":4,"unit":"5","page":1,"status":"Retain"},{"paper":"R23","q":"Q1b","marks":4,"unit":"4","page":1,"status":"Retain"},{"paper":"R23","q":"Q1c","marks":4,"unit":"1","page":1,"status":"Retain"},{"paper":"R23","q":"Q1d","marks":4,"unit":"3","page":1,"status":"Retain"},{"paper":"R23","q":"Q1e","marks":4,"unit":"2","page":2,"status":"Retain"},{"paper":"R23","q":"Q2a","marks":10,"unit":"2–4","page":2,"status":"Retain"},{"paper":"R23","q":"Q2b","marks":10,"unit":"2–3","page":2,"status":"Retain"},{"paper":"R23","q":"Q3a","marks":10,"unit":"5","page":2,"status":"Retain"},{"paper":"R23","q":"Q3b","marks":10,"unit":"2","page":3,"status":"Retain"},{"paper":"R23","q":"Q4a","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"R23","q":"Q4b","marks":10,"unit":"4","page":3,"status":"Retain"},{"paper":"R23","q":"Q5a","marks":10,"unit":"5","page":4,"status":"Retain"},{"paper":"R23","q":"Q5b","marks":10,"unit":"2","page":4,"status":"Retain"},{"paper":"R23","q":"Q6a","marks":10,"unit":"3","page":4,"status":"Retain"},{"paper":"R23","q":"Q6b","marks":10,"unit":"4","page":4,"status":"Retain"},{"paper":"R23","q":"Q7a","marks":10,"unit":"5","page":4,"status":"Retain"},{"paper":"R23","q":"Q7b","marks":10,"unit":"3","page":4,"status":"Retain"}],"drills":52,"source_pages":34}},"titles":{"Variables functions and symbols":"Notation and numerical conventions","Matrix multiplication: every row has a job":"Linear algebra revision: vectors, matrices and affine layers","Derivatives without a calculus course":"Differentiation revision: derivatives, partial derivatives and gradients","The chain rule is multiplying linked effects":"Chain rule revision and a complete loss derivative","Probability mean and variance in plain language":"Probability and statistics revision","Exponentials and natural logarithms":"Exponential, logarithmic and related calculus identities","What does learning from data mean":"Machine learning, deep learning and the training objective","What one artificial neuron does":"Artificial neuron: mathematical model and working","What an optimizer is trying to do":"Optimization: objective, gradient and descent direction","A moving average remembers the recent past":"Exponentially weighted moving averages","Recognizing overfitting and underfitting":"Generalization, underfitting and overfitting","AlexNet and the reason for its components":"AlexNet: architecture, contributions and limitations","Inception examines several spatial scales":"Inception: parallel multi-scale feature extraction","ResNet adds a shortcut":"Residual networks: identity mapping and projection shortcuts","What makes a sequence different":"Sequence modeling and recurrent neural networks","The ordinary gradient descent update":"Gradient descent: algorithm and numerical","Batch stochastic and mini batch gradient descent":"Batch GD, stochastic GD and mini-batch GD","A tiny dataset shows why the methods differ":"Batch update versus sequential SGD: worked comparison","Learning rate and common training problems":"Learning rate, convergence and optimization difficulties","Momentum remembers movement":"Momentum: velocity, update rule and working","Nesterov looks before correcting":"Nesterov accelerated gradient (NAG)","AdaGrad adds every squared gradient":"AdaGrad: adaptive per-parameter learning rates","RMSProp remembers recent squared gradients":"RMSProp: decaying squared-gradient average","Adam remembers both direction and squared size":"Adam: moment estimates and parameter updates","Adam bias correction: why the denominator is one minus beta to a power":"Adam bias correction: derivation","One comparison to rebuild all optimizer formulas":"Optimizer comparison and update conventions","L1 and L2 add a cost for large weights":"L1 and L2 regularization: objectives and derivatives","Dropout removes activations during training":"Dropout: stochastic regularization","Early stopping uses the best validation point":"Early stopping and checkpoint selection","Choosing a remedy":"Selecting a remedy from training behavior","Inverted dropout during training and inference":"Inverted dropout: expectation and inference","Reading image shapes before doing CNN arithmetic":"CNN tensor notation and layer dimensions","A computer sees an image as numbers":"Image tensors and learned feature maps","The convolution calculation":"Convolution: operation and complete numerical","Stride padding and floor":"Stride, padding and output-size equations","Convolution over several channels":"Convolution across input channels","One filter over multiple channels: all contributions go into one cell":"Multi-channel convolution: worked numerical","Choosing more or fewer filters":"Filter count and output-channel depth","Pooling needs comparisons or averages":"Max pooling and average pooling","Parameters are different from activation values":"Trainable parameters versus activations","One complete CNN pipeline":"Complete CNN: output shapes and parameter counts","Why one by one convolution saves work":"1 × 1 convolutions and bottleneck calculations","Transfer learning from a small dataset":"Transfer learning: feature extraction and fine-tuning","The vanilla RNN equations from scratch":"Vanilla RNN: state and output equations","Your first complete training step":"Training a linear neuron: two complete updates","Activation functions and how to calculate them":"Activation functions: definitions, derivatives and limitations","Choosing a loss":"Loss functions: regression and classification","What you should understand before optimization":"Training procedure: forward pass, backward pass and update","LSTM a memory path with three gates":"LSTM: architecture and gate equations","GRU two gates and one state":"GRU: architecture and update conventions","Mean, variance and standard deviation from ordinary arithmetic":"Mean, variance and standard deviation","Standardization: what the answer 1 actually means":"Feature standardization: definition and calculation","Loss: how one wrong prediction becomes a number":"Squared-error objectives and their derivatives","Classification regression and learning types":"Learning tasks and supervision types","Training validation and test data":"Training, validation and test sets","Parameters and hyperparameters":"Parameters, hyperparameters and optimizer states","Complete sigmoid training example":"Sigmoid neuron: complete forward and backward pass","Backpropagation with one hidden neuron":"Backpropagation: chain rule through a hidden layer","More outputs and vectorized backpropagation":"Multi-output and vectorized backpropagation","Forward propagation through multiple neurons":"Forward propagation through a multilayer network","BPTT with every arithmetic step visible":"BPTT: complete two-step gradient calculation","Reading an LSTM equation one operation at a time":"LSTM state update: mathematical interpretation"},"chapterMeta":{"2":{"title":"Mathematics revision","label":"REFERENCE","description":"Notation, linear algebra, differentiation, probability and logarithms. Use this short refresher when required; elementary arithmetic is assumed."},"4":{"title":"Neural-network foundations","label":"UNITS 1–2 · PREREQUISITES","description":"Technical definitions, neuron models, activations, losses, forward propagation and backpropagation. These foundations support the MT2 calculations."},"5":{"title":"Optimization algorithms","label":"UNIT 3","description":"Gradient descent, batch variants, momentum, Nesterov, AdaGrad, RMSProp and Adam. Definitions and derivations lead into complete worked updates."},"6":{"title":"Regularization and generalization","label":"UNIT 3","description":"Overfitting, L1/L2 penalties, dropout and early stopping: mechanisms, equations, comparisons and numerical applications."},"7":{"title":"Convolutional neural networks","label":"UNIT 4","description":"Convolution, pooling, output dimensions and parameter counts, including full network calculations."},"8":{"title":"CNN architectures and transfer learning","label":"UNIT 4","description":"AlexNet, Inception, ResNet, bottlenecks and transfer learning. Study their structure, design purpose and calculations."},"9":{"title":"Recurrent neural networks","label":"UNIT 5","description":"State equations, parameter sharing and sequence mappings. The MT2 route covers introductory RNNs; TEE adds recurrent training and gated architectures."},"19":{"title":"Formula reference and exam revision","label":"REVISION","description":"Core formulas, their conditions and the complete worked applications."},"21":{"title":"February 2025 re-exam · complete solved paper","label":"Actual historical paper","description":"22 February 2025 re-examination; full original marks and explicit source conventions."},"22":{"title":"Faculty Assignment 2 · worked practice","label":"Faculty practice, not a PYQ","description":"Assignment 2 from faculty Teams; not counted as an examination paper."}},"edition":"faculty-mt2-pattern-2026-10-12","mt2Exam":{"received":"2026-10-12","source":"Faculty message relayed directly by the user in this chat","message":"There can be numericals from unit 3\nAnd 2 numericals from unit 4\n2mk can be a theory numerical combo or only theory\n3mk is 2 numericals and theory or 1 numerical and theory question with all theory of unit 3 and 4","clarification":"Either 2 numerical and theory or 1 theory 1 numerical combo with 1 numerical and 1 theory","threeMarkCombinations":[["numerical","numerical","theory"],["theory + numerical","numerical","theory"]],"focusUnits":[3,4],"marks":10,"durationMinutes":60,"readingSummary":"Faculty update, 12 October: prepare Unit 3 and Unit 4 theory and numericals. Give extra practice to two Unit 4 numerical questions. ANN and maths remain prerequisites; RNN is available in TEE.","mockInstructions":"60 minutes · 10 marks. Q1(a,b): 2 marks each, compulsory; attempt any two of Q2–Q4: 3 marks each. This uses the shared M2 choice pattern already supplied. The latest faculty message guides the Unit 3–4 theory/numerical mix; it does not fix individual question numbers or numerical topics.","mockDescriptions":{"A":"Q1 theory · two Unit 4 numericals + Unit 3 theory among the 3-mark choices","B":"Q1 theory/numerical combination · Unit 3 theory + numerical mixed question, Unit 4 numerical, Unit 4 theory"},"qualifications":["Both Unit 3 and Unit 4 theory must be prepared; numerical-heavy guidance is not permission to skip theory.","Two Unit 4 numericals are highlighted in the message, but their exact location among compulsory and optional parts is not given.","The user's clarification identifies N + N + T or mixed theory/numerical + N + T among the three 3-mark choices. It does not specify their order or exact topics.","RNN is not named in this update, so it is removed from the focused MT2 path and retained in TEE."],"excludedSectionIds":["mt2-c11-s1","mt2-c12-s1","mt2-c12-s5","mt2-c13-s6","mt2-c14-s7","mt2-c15-s2","mt2-c16-s0","mt2-c17-s39","mt2-c9-intro","mt2-c9-s0","mt2-c9-s1","mt2-c9-s2","mt2-c9-s3","mt2-c9-s4","mt2-c9-s5"]},"examSchedule":{"subject":"Deep Learning","date":"2026-10-13","day":"Tuesday","start":"15:00","end":"16:00","timezone":"Asia/Calcutta","duration_minutes":60,"marks":10,"marks_confirmed":true,"choice_pattern_confirmed":false,"exact_portion_confirmed":false,"source":"User-supplied Class Test II timetable; S02 course policy section 4"},"courses":{"mt2":[{"id":"mt2-c2-s5","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"mt2-c17-s1","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"mt2-c2-s5"},{"id":"mt2-c3-s1","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"mt2-c17-s4","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"mt2-c3-s1"},{"id":"mt2-c17-s5","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"mt2-c3-s1"},{"id":"mt2-c3-s3","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"mt2-c3-s6","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"mt2-c17-s6","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"mt2-c3-s6"},{"id":"mt2-c3-s9","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"mt2-c2-s6","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"mt2-c17-s3","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"mt2-c2-s6"},{"id":"mt2-c4-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s3","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s5","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s7","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c17-s8","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s7"},{"id":"mt2-c4-s9","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c17-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s9"},{"id":"mt2-c17-s7","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s9"},{"id":"mt2-c17-s9","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s9"},{"id":"mt2-c4-s17","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s10","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s16","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c17-s10","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s16"},{"id":"mt2-c4-s11","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c4-s12","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c17-s11","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s12"},{"id":"mt2-c17-s12","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s12"},{"id":"mt2-c17-s13","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"mt2-c4-s12"},{"id":"mt2-c4-s14","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"mt2-c10-s5","chapter":4,"group":"Full teacher backprop examples","role":"Worked example"},{"id":"mt2-c10-s6","chapter":4,"group":"Full teacher backprop examples","role":"Worked example"},{"id":"mt2-c10-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"mt2-c10-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"mt2-c10-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"mt2-c10-s3","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"mt2-c10-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"mt2-c5-s2","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c5-s3","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s16","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s3"},{"id":"mt2-c17-s17","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s3"},{"id":"mt2-c5-s4","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s15","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s4"},{"id":"mt2-c5-s6","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s14","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s6"},{"id":"mt2-c5-s7","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c5-s8","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c5-s9","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s18","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s9"},{"id":"mt2-c17-s19","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s9"},{"id":"mt2-c5-s10","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s20","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s10"},{"id":"mt2-c17-s21","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s10"},{"id":"mt2-c5-s12","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s22","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s12"},{"id":"mt2-c17-s23","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s12"},{"id":"mt2-c5-s13","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s24","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s13"},{"id":"mt2-c17-s25","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s13"},{"id":"mt2-c5-s14","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c5-s15","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c17-s26","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s15"},{"id":"mt2-c17-s27","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"mt2-c5-s15"},{"id":"mt2-c5-s17","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c5-s18","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"mt2-c11-s4","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c11-s5","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c12-s4","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c12-s6","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c13-s0","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c13-s2","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c14-s0","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c14-s2","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c15-s1","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c15-s6","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c15-s7","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c16-s2","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c16-s7","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c16-s9","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"mt2-c6-s0","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"mt2-c6-s1","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"mt2-c17-s28","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"mt2-c6-s1"},{"id":"mt2-c17-s29","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"mt2-c6-s1"},{"id":"mt2-c17-s30","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"mt2-c6-s1"},{"id":"mt2-c17-s41","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"mt2-c6-s1"},{"id":"mt2-c6-s3","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"mt2-c6-s4","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"mt2-c6-s6","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"mt2-c6-s7","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"mt2-c17-s31","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"mt2-c6-s7"},{"id":"mt2-c17-s42","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"mt2-c6-s7"},{"id":"mt2-c11-s0","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c12-s0","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c13-s7","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c14-s3","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c15-s3","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c15-s9","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c16-s4","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"mt2-c7-s0","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s2","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c17-s32","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s2"},{"id":"mt2-c7-s3","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c17-s33","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s3"},{"id":"mt2-c17-s36","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s3"},{"id":"mt2-c7-s5","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s7","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c17-s34","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s7"},{"id":"mt2-c7-s8","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s9","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c17-s35","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s9"},{"id":"mt2-c17-s40","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s9"},{"id":"mt2-c17-s43","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"mt2-c7-s9"},{"id":"mt2-c7-s10","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s14","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s15","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s16","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s17","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c7-s18","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"mt2-c11-s6","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c11-s7","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c12-s3","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c12-s7","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c13-s1","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c14-s1","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c14-s4","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c14-s5","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c15-s0","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c15-s4","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c15-s8","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c16-s1","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c16-s3","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c16-s5","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c16-s8","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"mt2-c8-s0","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s1","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s2","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c17-s37","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"mt2-c8-s2"},{"id":"mt2-c8-s3","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c17-s38","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"mt2-c8-s3"},{"id":"mt2-c17-s45","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"mt2-c8-s3"},{"id":"mt2-c8-s4","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s7","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c17-s44","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"mt2-c8-s7"},{"id":"mt2-c8-s9","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s10","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s11","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s12","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s13","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s14","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s15","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s16","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s17","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c8-s18","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"mt2-c11-s2","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c11-s3","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c12-s2","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c12-s8","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c13-s3","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c13-s4","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c13-s5","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c14-s6","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c15-s5","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c16-s6","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"mt2-c19-s0","chapter":19,"group":"Final revision","role":"Review"},{"id":"mt2-c19-s1","chapter":19,"group":"Final revision","role":"Review"},{"id":"mt2-c19-s2","chapter":19,"group":"Final revision","role":"Review"},{"id":"mt2-c19-s3","chapter":19,"group":"Final revision","role":"Review"},{"id":"mt2-c19-s4","chapter":19,"group":"Final revision","role":"Review"},{"id":"mt2-c19-s5","chapter":19,"group":"Final revision","role":"Review"}],"tee":[{"id":"tee-c2-s5","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"tee-c17-s1","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"tee-c2-s5"},{"id":"tee-c3-s1","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"tee-c17-s4","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"tee-c3-s1"},{"id":"tee-c17-s5","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"tee-c3-s1"},{"id":"tee-c3-s3","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"tee-c3-s6","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"tee-c17-s6","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"tee-c3-s6"},{"id":"tee-c3-s9","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"tee-c2-s6","chapter":2,"group":"The arithmetic and calculator you need","role":"Maths revision"},{"id":"tee-c17-s3","chapter":2,"group":"The arithmetic and calculator you need","role":"Solved numerical","conceptId":"tee-c2-s6"},{"id":"tee-c4-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s5","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s3","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s21","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s8","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c17-s11","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s8"},{"id":"tee-c4-s9","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c17-s12","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s9"},{"id":"tee-c4-s10","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c17-s8","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s10"},{"id":"tee-c4-s12","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c17-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s12"},{"id":"tee-c17-s7","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s12"},{"id":"tee-c17-s9","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s12"},{"id":"tee-c4-s20","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s13","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s19","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c17-s10","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s19"},{"id":"tee-c4-s14","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c4-s15","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c17-s13","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s15"},{"id":"tee-c17-s14","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s15"},{"id":"tee-c17-s15","chapter":4,"group":"Machine learning and neural networks from zero","role":"Solved numerical","conceptId":"tee-c4-s15"},{"id":"tee-c4-s17","chapter":4,"group":"Machine learning and neural networks from zero","role":"Theory and working"},{"id":"tee-c10-s10","chapter":4,"group":"Full teacher backprop examples","role":"Worked example"},{"id":"tee-c10-s11","chapter":4,"group":"Full teacher backprop examples","role":"Worked example"},{"id":"tee-c10-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s3","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s5","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s7","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s8","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c10-s9","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c11-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c11-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c11-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c11-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c11-s13","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c11-s14","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c12-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c12-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c12-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c12-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c12-s13","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c12-s14","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c13-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c13-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c13-s5","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c13-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c13-s11","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c14-s0","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c14-s1","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c14-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c14-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c14-s8","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c15-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c15-s3","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c15-s6","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c15-s16","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c16-s2","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c16-s4","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c16-s8","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c16-s12","chapter":4,"group":"Machine learning and neural networks from zero","role":"Exam question + answer"},{"id":"tee-c5-s2","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c5-s3","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s18","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s3"},{"id":"tee-c17-s19","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s3"},{"id":"tee-c5-s4","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s17","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s4"},{"id":"tee-c5-s6","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s16","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s6"},{"id":"tee-c5-s7","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c5-s8","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c5-s9","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s20","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s9"},{"id":"tee-c17-s21","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s9"},{"id":"tee-c5-s10","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s22","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s10"},{"id":"tee-c17-s23","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s10"},{"id":"tee-c5-s12","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s24","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s12"},{"id":"tee-c17-s25","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s12"},{"id":"tee-c5-s13","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s26","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s13"},{"id":"tee-c17-s27","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s13"},{"id":"tee-c5-s14","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c5-s15","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c17-s28","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s15"},{"id":"tee-c17-s29","chapter":5,"group":"Optimization one update at a time","role":"Solved numerical","conceptId":"tee-c5-s15"},{"id":"tee-c5-s17","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c5-s18","chapter":5,"group":"Optimization one update at a time","role":"Theory and working"},{"id":"tee-c11-s8","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c11-s11","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c12-s8","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c12-s11","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c13-s1","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c13-s7","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c14-s2","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c14-s5","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c15-s1","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c15-s10","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c15-s12","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c16-s3","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c16-s13","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c16-s16","chapter":5,"group":"Optimization one update at a time","role":"Exam question + answer"},{"id":"tee-c6-s0","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"tee-c6-s1","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"tee-c17-s30","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"tee-c6-s1"},{"id":"tee-c17-s31","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"tee-c6-s1"},{"id":"tee-c17-s32","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"tee-c6-s1"},{"id":"tee-c17-s47","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"tee-c6-s1"},{"id":"tee-c6-s3","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"tee-c6-s4","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"tee-c6-s6","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"tee-c6-s7","chapter":6,"group":"Generalization and regularization","role":"Theory and working"},{"id":"tee-c17-s33","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"tee-c6-s7"},{"id":"tee-c17-s48","chapter":6,"group":"Generalization and regularization","role":"Solved numerical","conceptId":"tee-c6-s7"},{"id":"tee-c11-s2","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c12-s2","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c13-s15","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c14-s7","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c15-s7","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c15-s14","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c16-s6","chapter":6,"group":"Generalization and regularization","role":"Exam question + answer"},{"id":"tee-c7-s0","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s2","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c17-s34","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s2"},{"id":"tee-c7-s3","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c17-s35","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s3"},{"id":"tee-c17-s38","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s3"},{"id":"tee-c7-s5","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s7","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c17-s36","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s7"},{"id":"tee-c7-s8","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s9","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c17-s37","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s9"},{"id":"tee-c17-s46","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s9"},{"id":"tee-c17-s49","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Solved numerical","conceptId":"tee-c7-s9"},{"id":"tee-c7-s10","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s14","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s15","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s16","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s17","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c7-s18","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Theory and working"},{"id":"tee-c11-s12","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c11-s15","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c12-s7","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c12-s12","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c13-s3","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c14-s3","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c14-s9","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c14-s10","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c15-s0","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c15-s8","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c15-s13","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c16-s1","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c16-s5","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c16-s9","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c16-s14","chapter":7,"group":"CNN calculations from a grid of numbers","role":"Exam question + answer"},{"id":"tee-c8-s0","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s1","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s2","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c17-s39","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"tee-c8-s2"},{"id":"tee-c8-s3","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c17-s40","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"tee-c8-s3"},{"id":"tee-c17-s52","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"tee-c8-s3"},{"id":"tee-c8-s4","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s7","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c17-s51","chapter":8,"group":"CNN architectures and transfer learning","role":"Solved numerical","conceptId":"tee-c8-s7"},{"id":"tee-c8-s9","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s10","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s11","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s12","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s13","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s14","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s15","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s16","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s17","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c8-s18","chapter":8,"group":"CNN architectures and transfer learning","role":"Theory and working"},{"id":"tee-c11-s5","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c11-s7","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c12-s5","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c12-s15","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c13-s8","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c13-s10","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c13-s13","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c14-s13","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c15-s9","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c16-s10","chapter":8,"group":"CNN architectures and transfer learning","role":"Exam question + answer"},{"id":"tee-c9-s0","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s1","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s3","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s4","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s5","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c17-s41","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Solved numerical","conceptId":"tee-c9-s5"},{"id":"tee-c9-s6","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s7","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c17-s45","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Solved numerical","conceptId":"tee-c9-s7"},{"id":"tee-c9-s8","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s10","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s11","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s12","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c17-s42","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Solved numerical","conceptId":"tee-c9-s12"},{"id":"tee-c9-s13","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c17-s43","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Solved numerical","conceptId":"tee-c9-s13"},{"id":"tee-c17-s50","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Solved numerical","conceptId":"tee-c9-s13"},{"id":"tee-c9-s14","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c17-s44","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Solved numerical","conceptId":"tee-c9-s14"},{"id":"tee-c9-s15","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s17","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s18","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c9-s19","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Theory and working"},{"id":"tee-c11-s3","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c11-s9","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c11-s10","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c12-s3","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c12-s9","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c12-s10","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c13-s2","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c13-s9","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c13-s12","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c13-s14","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c14-s11","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c14-s12","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c14-s14","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c14-s15","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c15-s4","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c15-s5","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c15-s11","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c15-s15","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c16-s0","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c16-s7","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c16-s11","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c16-s15","chapter":9,"group":"Sequences RNN LSTM and GRU","role":"Exam question + answer"},{"id":"tee-c19-s0","chapter":19,"group":"Final revision","role":"Review"},{"id":"tee-c19-s1","chapter":19,"group":"Final revision","role":"Review"},{"id":"tee-c19-s2","chapter":19,"group":"Final revision","role":"Review"},{"id":"tee-c19-s3","chapter":19,"group":"Final revision","role":"Review"},{"id":"tee-c19-s4","chapter":19,"group":"Final revision","role":"Review"},{"id":"tee-c19-s5","chapter":19,"group":"Final revision","role":"Review"}]},"redirects":{"mt2":{"mt2-c2-s0":{"id":"mt2-c2-s5","chapter":2},"mt2-c2-s1":{"id":"mt2-c2-s5","chapter":2},"mt2-c2-s2":{"id":"mt2-c2-s5","chapter":2},"mt2-c2-s3":{"id":"mt2-c2-s5","chapter":2},"mt2-c2-s4":{"id":"mt2-c2-s5","chapter":2},"mt2-c2-s7":{"id":"mt2-c2-s6","chapter":2},"mt2-c2-s8":{"id":"mt2-c2-s5","chapter":2},"mt2-c2-s9":{"id":"mt2-c4-s9","chapter":4},"mt2-c3-s0":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s2":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s4":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s5":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s7":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s8":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s10":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s11":{"id":"mt2-c2-s5","chapter":2},"mt2-c3-s12":{"id":"mt2-c3-s6","chapter":2},"mt2-c4-s8":{"id":"mt2-c4-s7","chapter":4},"mt2-c4-s13":{"id":"mt2-c4-s12","chapter":4},"mt2-c5-s5":{"id":"mt2-c5-s4","chapter":5},"mt2-c5-s11":{"id":"mt2-c5-s10","chapter":5},"mt2-c5-s16":{"id":"mt2-c5-s15","chapter":5},"mt2-c6-s2":{"id":"mt2-c6-s1","chapter":6},"mt2-c6-s8":{"id":"mt2-c6-s7","chapter":6},"mt2-c7-s13":{"id":"mt2-c7-s9","chapter":7},"mt2-c9-s4":{"id":"tee-c9-s17","chapter":9,"exam":"tee"},"mt2-c14-s7":{"id":"tee-c14-s15","chapter":9,"exam":"tee"},"mt2-c16-s0":{"id":"tee-c16-s0","chapter":9,"exam":"tee"},"mt2-c9-s0":{"id":"tee-c9-s1","chapter":9,"exam":"tee"},"mt2-c15-s2":{"id":"tee-c15-s4","chapter":9,"exam":"tee"},"mt2-c9-s1":{"id":"tee-c9-s1","chapter":9,"exam":"tee"},"mt2-c11-s1":{"id":"tee-c11-s3","chapter":9,"exam":"tee"},"mt2-c9-intro":{"id":"tee-c9-s0","chapter":9,"exam":"tee"},"mt2-c13-s6":{"id":"tee-c13-s14","chapter":9,"exam":"tee"},"mt2-c17-s39":{"id":"tee-c17-s41","chapter":9,"exam":"tee"},"mt2-c12-s5":{"id":"tee-c12-s10","chapter":9,"exam":"tee"},"mt2-c9-s3":{"id":"tee-c9-s5","chapter":9,"exam":"tee"},"mt2-c9-s5":{"id":"tee-c9-s1","chapter":9,"exam":"tee"},"mt2-c12-s1":{"id":"tee-c12-s3","chapter":9,"exam":"tee"},"mt2-c9-s2":{"id":"tee-c9-s4","chapter":9,"exam":"tee"}},"tee":{"tee-c2-s0":{"id":"tee-c2-s5","chapter":2},"tee-c2-s1":{"id":"tee-c2-s5","chapter":2},"tee-c2-s2":{"id":"tee-c2-s5","chapter":2},"tee-c2-s3":{"id":"tee-c2-s5","chapter":2},"tee-c2-s4":{"id":"tee-c2-s5","chapter":2},"tee-c2-s7":{"id":"tee-c2-s6","chapter":2},"tee-c2-s8":{"id":"tee-c2-s5","chapter":2},"tee-c2-s9":{"id":"tee-c4-s12","chapter":4},"tee-c3-s0":{"id":"tee-c2-s5","chapter":2},"tee-c3-s2":{"id":"tee-c2-s5","chapter":2},"tee-c3-s4":{"id":"tee-c2-s5","chapter":2},"tee-c3-s5":{"id":"tee-c2-s5","chapter":2},"tee-c3-s7":{"id":"tee-c2-s5","chapter":2},"tee-c3-s8":{"id":"tee-c2-s5","chapter":2},"tee-c3-s10":{"id":"tee-c2-s5","chapter":2},"tee-c3-s11":{"id":"tee-c2-s5","chapter":2},"tee-c3-s12":{"id":"tee-c3-s6","chapter":2},"tee-c4-s11":{"id":"tee-c4-s10","chapter":4},"tee-c4-s16":{"id":"tee-c4-s15","chapter":4},"tee-c5-s5":{"id":"tee-c5-s4","chapter":5},"tee-c5-s11":{"id":"tee-c5-s10","chapter":5},"tee-c5-s16":{"id":"tee-c5-s15","chapter":5},"tee-c6-s2":{"id":"tee-c6-s1","chapter":6},"tee-c6-s8":{"id":"tee-c6-s7","chapter":6},"tee-c7-s13":{"id":"tee-c7-s9","chapter":7},"tee-c9-s9":{"id":"tee-c9-s7","chapter":9}}},"formulaGuides":{"mt2":[{"n":1,"title":"Mean, variance and standard deviation","intro":["<p>The mean is a measure of location; variance and standard deviation quantify dispersion. Distinguish population and sample conventions before calculating these statistics.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/515c6d49d5a0ee05.svg\" alt=\"\\mu=\\frac{1}{n}\\sum_i x_i\" width=\"138.12\" height=\"61.92\" style=\"width:138.12px;height:61.92px;aspect-ratio:138.12/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5b9364e6a03439b4.svg\" alt=\"v=\\frac{1}{n}\\sum_i(x_i-\\mu)^2\" width=\"205.45\" height=\"61.92\" style=\"width:205.45px;height:61.92px;aspect-ratio:205.45/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c9fd8a46ad5f2e60.svg\" alt=\"s=\\sqrt{v}\" width=\"76.73\" height=\"25.90\" style=\"width:76.73px;height:25.90px;aspect-ratio:76.73/25.90\" loading=\"lazy\"></div>"],"refs":["mt2-c3-s10"],"extra":["<h3>Population mean and spread: [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. For the population [1, 2, 3], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [1, 2, 3]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23a1d761557fba99.svg\" alt=\"1+2+3=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cde1ff63a64aa7ce.svg\" alt=\"(1-2)=-1\" width=\"137.13\" height=\"24.43\" style=\"width:137.13px;height:24.43px;aspect-ratio:137.13/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46782fbf983b8482.svg\" alt=\"(-1)^2=1\" width=\"105.71\" height=\"27.70\" style=\"width:105.71px;height:27.70px;aspect-ratio:105.71/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebe985168f035d36.svg\" alt=\"(3-2)=1\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4b8daac35aec1bc.svg\" alt=\"(1)^2=1\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e913fcfda4146fb6.svg\"><img class=\"math display-math\" src=\"assets/equations/33fa105b83cd3564.svg\" alt=\"\\sigma^2=\\frac{1+0+1}{3}\\approx0.666666667\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c7d94a64e886a59.svg\"><img class=\"math display-math\" src=\"assets/equations/28845fc5f4238747.svg\" alt=\"\\sigma=\\sqrt{0.666666667}\\approx0.816496581\" width=\"357.89\" height=\"26.49\" style=\"width:357.89px;height:26.49px;aspect-ratio:357.89/26.49\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.666666667; σ ≈ 0.816496581.</p>","<h3>Population mean and spread: [2, 2, 2]</h3>","<p class=\"inline-question\"><strong>Question. For the population [2, 2, 2], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [2, 2, 2]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fc38a48a0a6427f.svg\" alt=\"2+2+2=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b0fc9edc8362e2a5.svg\"><img class=\"math display-math\" src=\"assets/equations/f4e20a1682fadce3.svg\" alt=\"\\sigma^2=\\frac{0+0+0}{3}\\approx0.000000000\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.57px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9ee45ab162936835.svg\"><img class=\"math display-math\" src=\"assets/equations/c43ce89c0112ae99.svg\" alt=\"\\sigma=\\sqrt{0.000000000}\\approx0.000000000\" width=\"357.89\" height=\"26.37\" style=\"width:357.89px;height:26.37px;aspect-ratio:357.89/26.37\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.000000000; σ ≈ 0.000000000. Standardization is undefined with this zero standard deviation.</p>"]},{"n":2,"title":"Standardization","intro":["<p>Standardization has a meaning before it has a formula: measure how far an input is from its training mean, then express that distance in standard-deviation units. The worked question below calculates the mean and standard deviation first, so neither number appears without explanation.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a0a4f4a38fa7007.svg\" alt=\"x_{scaled}=\\frac{x-\\mu_{train}}{s_{train}}\" width=\"206.36\" height=\"51.38\" style=\"width:206.36px;height:51.38px;aspect-ratio:206.36/51.38\" loading=\"lazy\"></div>"],"refs":["mt2-c3-s11"],"extra":[]},{"n":3,"title":"Power, constant and sum derivatives","intro":["<p>Derivatives describe local rates of change. Partial derivatives hold other independent variables fixed; their collection forms the gradient used for optimization.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5c78e62c5b2a236.svg\" alt=\"\\frac{d}{dx}(cx^n)=cnx^{n-1}\" width=\"199.67\" height=\"50.50\" style=\"width:199.67px;height:50.50px;aspect-ratio:199.67/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d569e096ba9d6dba.svg\" alt=\"\\frac{d}{dx}c=0\" width=\"92.82\" height=\"50.50\" style=\"width:92.82px;height:50.50px;aspect-ratio:92.82/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/032a4e4c1f8b2817.svg\" alt=\"(f+g)\\prime=f\\prime+g\\prime\" width=\"181.68\" height=\"24.43\" style=\"width:181.68px;height:24.43px;aspect-ratio:181.68/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c3-s3"],"extra":[]},{"n":4,"title":"Chain rule","intro":["<p>The chain rule differentiates a composite function. Multiply local derivatives along a dependency path and add the contributions of different paths to the same variable.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/434e48fc84f871b4.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}\" width=\"154.58\" height=\"50.50\" style=\"width:154.58px;height:50.50px;aspect-ratio:154.58/50.50\" loading=\"lazy\"></div>"],"refs":["mt2-c3-s6","mt2-c17-s6"],"extra":[]},{"n":5,"title":"Dot product and a neuron","intro":["<p>A neuron starts with matched input–weight pairs. Multiply inside each pair, add the products, add the bias once, and then apply the activation. The summation sign is simply a shorter way to write those additions.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/051f16f4bf1744dd.svg\" alt=\"z=\\sum_i w_i x_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c4-s6","mt2-c4-s5","mt2-c17-s4"],"extra":[]},{"n":6,"title":"Matrix multiplication","intro":["<p>Matrix multiplication implements affine transformations in a dense layer. Dimensions determine which products are valid; each output component is the dot product of a weight row and the input vector, plus its bias.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47f627ca6464a106.svg\" alt=\"(AB)_{ij}=\\sum_k A_{ik}B_{kj}\" width=\"214.94\" height=\"52.91\" style=\"width:214.94px;height:52.91px;aspect-ratio:214.94/52.91\" loading=\"lazy\"></div>"],"refs":["mt2-c3-s1","mt2-c17-s5"],"extra":[]},{"n":7,"title":"Layer forward pass","intro":["<p>A layer does the neuron calculation for several receiving neurons. Finish all its outputs before using them as the next layer’s inputs. The bracketed superscript is a layer label, not a power.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/87472012ebbb4a9d.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)}\" width=\"228.73\" height=\"25.06\" style=\"width:228.73px;height:25.06px;aspect-ratio:228.73/25.06\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/85d817a60006abc5.svg\" alt=\"a^{(l)}=f(z^{(l)})\" width=\"130.56\" height=\"29.16\" style=\"width:130.56px;height:29.16px;aspect-ratio:130.56/29.16\" loading=\"lazy\"></div>"],"refs":["mt2-c4-s10","mt2-c4-s13","mt2-c4-s11","mt2-c17-s11","mt2-c17-s12"],"extra":[]},{"n":8,"title":"Sigmoid and its derivative","intro":["<p>Sigmoid takes a raw score and changes it to a number between 0 and 1. Its derivative is a different number: it tells backpropagation how sensitive that output is to its raw score. The complete example below calculates both and shows where each is used.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3083d9958c3932d.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}}\" width=\"164.64\" height=\"51.56\" style=\"width:164.64px;height:51.56px;aspect-ratio:164.64/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90cd2771a42dc9ef.svg\" alt=\"\\sigma\\prime(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"227.94\" height=\"24.43\" style=\"width:227.94px;height:24.43px;aspect-ratio:227.94/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c4-s16","mt2-c17-s10"],"extra":["<h3>sigmoid example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9feed82e056cf24.svg\" alt=\"-z=-(-2)=2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b83d9532e6445b5a.svg\" alt=\"e^{2}\\approx7.389056099\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4026cb0f8944f24f.svg\"><img class=\"math display-math\" src=\"assets/equations/fb7c0cac9ced67f0.svg\" alt=\"1+7.389056099\\approx8.389056099\" width=\"332.60\" height=\"18.52\" style=\"width:332.60px;height:18.52px;aspect-ratio:332.60/18.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f4a3cb96f1098e79.svg\"><img class=\"math display-math\" src=\"assets/equations/b44984dd703daaf9.svg\" alt=\"a=\\frac1{8.389056099}\\approx0.119202922\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/154ffcd0747b53aa.svg\"><img class=\"math display-math\" src=\"assets/equations/61cf4a9551a25fd6.svg\" alt=\"f\\prime(-2)=(0.119202922)(1-0.119202922)\\approx0.104993585\" width=\"602.56\" height=\"24.43\" style=\"width:602.56px;height:24.43px;aspect-ratio:602.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.119202922. Derivative ≈ 0.104993585.</p>","<h3>sigmoid example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17055d0f6bb7d8cb.svg\" alt=\"-z=-(0)=0\" width=\"157.99\" height=\"24.43\" style=\"width:157.99px;height:24.43px;aspect-ratio:157.99/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/88f353ee1ae5e616.svg\"><img class=\"math display-math\" src=\"assets/equations/048aaa762a498d29.svg\" alt=\"1+1.000000000\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55f56d862c8a637f.svg\"><img class=\"math display-math\" src=\"assets/equations/bb9808b4290f77c2.svg\" alt=\"a=\\frac1{2.000000000}\\approx0.500000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5e112d2ee69475de.svg\"><img class=\"math display-math\" src=\"assets/equations/fe0302f0c6aecdca.svg\" alt=\"f\\prime(0)=(0.500000000)(1-0.500000000)\\approx0.250000000\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.500000000. Derivative ≈ 0.250000000.</p>","<h3>sigmoid example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbbb55e23c6ba6a0.svg\" alt=\"-z=-(2)=-2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1264450d54002695.svg\"><img class=\"math display-math\" src=\"assets/equations/21d0f7a7fd447a52.svg\" alt=\"1+0.135335283\\approx1.135335283\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f08d0c34f5e2fdf7.svg\"><img class=\"math display-math\" src=\"assets/equations/6480e62e9ef0f8a2.svg\" alt=\"a=\\frac1{1.135335283}\\approx0.880797078\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278a4098b6b446b4.svg\"><img class=\"math display-math\" src=\"assets/equations/00492ebf856c8aae.svg\" alt=\"f\\prime(2)=(0.880797078)(1-0.880797078)\\approx0.104993585\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.880797078. Derivative ≈ 0.104993585.</p>"]},{"n":9,"title":"Tanh and its derivative","intro":["<p>Tanh can produce a negative or positive output. In the formula, calculate the exponential first, then form the top and bottom of the fraction separately. The derivative uses the activated answer, not the raw input.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8ee72519b086209.svg\" alt=\"\\tanh(z)=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"194.78\" height=\"56.48\" style=\"width:194.78px;height:56.48px;aspect-ratio:194.78/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc7dbcac123b9229.svg\" alt=\"\\tanh\\prime(z)=1-\\tanh^2(z)\" width=\"254.66\" height=\"27.91\" style=\"width:254.66px;height:27.91px;aspect-ratio:254.66/27.91\" loading=\"lazy\"></div>"],"refs":[],"extra":["<p class=\"inline-question\"><strong>Question. Calculate tanh(0.5) and its derivative with respect to the input.</strong></p>","<h3>Given</h3>","<p>z = 0.5.</p>","<h3>To find</h3>","<p>Find tanh(z) and its derivative.</p>","<h3>Formula — which one and why</h3>","<p><strong>Tanh and its slope.</strong> Tanh preserves a signed output between −1 and 1. Once its output a is known, the local slope is 1−a².</p>","<p>z = value entering tanh; a = its output. A prime means derivative, or local rate of change.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11b2c40e39b0ee66.svg\" alt=\"a=\\tanh z=\\frac{e^z-e^{-z}}{e^z+e^{-z}}\" width=\"239.38\" height=\"54.23\" style=\"width:239.38px;height:54.23px;aspect-ratio:239.38/54.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b6ac5e0c1df9b26.svg\" alt=\"\\frac{da}{dz}=1-a^2\" width=\"134.64\" height=\"50.50\" style=\"width:134.64px;height:50.50px;aspect-ratio:134.64/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh signed output deta hai; slope = 1 minus output ka square.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the input.</strong> The input z is 0.5. In this version of the tanh formula, the exponential uses 2z.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.27px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a761ae42b593cfbc.svg\"><img class=\"math display-math\" src=\"assets/equations/4ded3cb512b92053.svg\" alt=\"2z=2(0.5)=1,\\qquad e^{2z}=e^1\\approx2.718281828\" width=\"469.43\" height=\"27.70\" style=\"width:469.43px;height:27.70px;aspect-ratio:469.43/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the numerator.</strong> Subtract 1 from that exponential.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.72px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc5e5624414a3d95.svg\"><img class=\"math display-math\" src=\"assets/equations/057c3c395fc07789.svg\" alt=\"e^{2z}-1=2.718281828-1=1.718281828\" width=\"437.36\" height=\"23.60\" style=\"width:437.36px;height:23.60px;aspect-ratio:437.36/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the denominator.</strong> Add 1 to the same exponential.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.72px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/343ff32a5ddf3a45.svg\"><img class=\"math display-math\" src=\"assets/equations/4ae221248ca27fec.svg\" alt=\"e^{2z}+1=2.718281828+1=3.718281828\" width=\"437.36\" height=\"23.60\" style=\"width:437.36px;height:23.60px;aspect-ratio:437.36/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide the top by the bottom.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:128.52px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ebe33ccb05db4c46.svg\"><img class=\"math display-math\" src=\"assets/equations/4b6a824a25e2320c.svg\" alt=\"a=\\tanh(0.5)=\\frac{1.718281828}{3.718281828}\\approx0.462117157\" width=\"478.49\" height=\"50.34\" style=\"width:478.49px;height:50.34px;aspect-ratio:478.49/50.34\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: calculate the local derivative.</strong> Square the output a and subtract it from 1. Keep the calculator&#x27;s unrounded result.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.23px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/de782b0d8cb8f7bb.svg\"><img class=\"math display-math\" src=\"assets/equations/19090a10397c086b.svg\" alt=\"a^2\\approx0.213552267,\\qquad1-a^2\\approx0.786447733\" width=\"472.10\" height=\"26.34\" style=\"width:472.10px;height:26.34px;aspect-ratio:472.10/26.34\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> tanh output ≈ 0.462117157; local derivative ≈ 0.786447733. The output becomes the next layer&#x27;s input; the derivative is used when carrying a gradient backward.</p>","<h3>tanh example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ab8a21d8aab882c.svg\" alt=\"2z=2(-2)=-4\" width=\"182.43\" height=\"24.43\" style=\"width:182.43px;height:24.43px;aspect-ratio:182.43/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c3b8c152fd312b9.svg\" alt=\"e^{-4}\\approx0.018315639\" width=\"197.05\" height=\"22.32\" style=\"width:197.05px;height:22.32px;aspect-ratio:197.05/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/782210c69a20fd3b.svg\"><img class=\"math display-math\" src=\"assets/equations/38bd067833181d6c.svg\" alt=\"0.018315639-1\\approx-0.981684361\" width=\"351.62\" height=\"18.54\" style=\"width:351.62px;height:18.54px;aspect-ratio:351.62/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c7713b25655beb72.svg\"><img class=\"math display-math\" src=\"assets/equations/dee5ac5546f1b2f2.svg\" alt=\"0.018315639+1\\approx1.018315639\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.24px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/300fc0089c5516db.svg\"><img class=\"math display-math\" src=\"assets/equations/809bd6f34ad5f6a6.svg\" alt=\"a=\\frac{-0.981684361}{1.018315639}\\approx-0.964027580\" width=\"384.79\" height=\"50.36\" style=\"width:384.79px;height:50.36px;aspect-ratio:384.79/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.52px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bb2d4ce554c14198.svg\"><img class=\"math display-math\" src=\"assets/equations/c4ff92106fa31931.svg\" alt=\"f\\prime(-2)=1-(-0.964027580)^2\\approx0.070650825\" width=\"484.27\" height=\"27.70\" style=\"width:484.27px;height:27.70px;aspect-ratio:484.27/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ -0.964027580. Derivative ≈ 0.070650825.</p>","<h3>tanh example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83fefb855224c584.svg\" alt=\"2z=2(0)=0\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/40327f28206586d2.svg\"><img class=\"math display-math\" src=\"assets/equations/fa618ba26a236aab.svg\" alt=\"1.000000000-1\\approx0.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5e16c3256057084.svg\"><img class=\"math display-math\" src=\"assets/equations/46b371b545cc8bc8.svg\" alt=\"1.000000000+1\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/081512ac7f7a1b51.svg\"><img class=\"math display-math\" src=\"assets/equations/da7a029e0ae3e61f.svg\" alt=\"a=\\frac{0.000000000}{2.000000000}\\approx0.000000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3899b5f76509b8c.svg\"><img class=\"math display-math\" src=\"assets/equations/b3f22ac5fb036f65.svg\" alt=\"f\\prime(0)=1-(0.000000000)^2\\approx1.000000000\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 1.000000000.</p>","<h3>tanh example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28a6e73374f6be65.svg\" alt=\"2z=2(2)=4\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dcc7f746c4400033.svg\" alt=\"e^{4}\\approx54.598150033\" width=\"195.81\" height=\"22.32\" style=\"width:195.81px;height:22.32px;aspect-ratio:195.81/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f63e045301bde055.svg\"><img class=\"math display-math\" src=\"assets/equations/a7f29872524e69fc.svg\" alt=\"54.598150033-1\\approx53.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c86d55c9549cedd.svg\"><img class=\"math display-math\" src=\"assets/equations/1a7460c08ec0eb4e.svg\" alt=\"54.598150033+1\\approx55.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.45px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a5642fac7a0997.svg\"><img class=\"math display-math\" src=\"assets/equations/9d5e297333003136.svg\" alt=\"a=\\frac{53.598150033}{55.598150033}\\approx0.964027580\" width=\"358.99\" height=\"50.09\" style=\"width:358.99px;height:50.09px;aspect-ratio:358.99/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/52d252bd261b679f.svg\"><img class=\"math display-math\" src=\"assets/equations/6f2d0c822236e436.svg\" alt=\"f\\prime(2)=1-(0.964027580)^2\\approx0.070650825\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.964027580. Derivative ≈ 0.070650825.</p>"]},{"n":10,"title":"ReLU and its derivative","intro":["<p>ReLU compares its input with zero and keeps the larger value. Thus a negative input becomes zero and a positive input passes unchanged. Its slope is zero on the negative side and one on the positive side.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ad762a28c8a1a87.svg\" alt=\"f(z)=\\max(0,z)\" width=\"175.33\" height=\"24.43\" style=\"width:175.33px;height:24.43px;aspect-ratio:175.33/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/458083af5d5ba2ef.svg\" alt=\"f\\prime(z)=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z&lt;0\\end{cases}\" width=\"194.26\" height=\"58.62\" style=\"width:194.26px;height:58.62px;aspect-ratio:194.26/58.62\" loading=\"lazy\"></div>"],"refs":["mt2-c17-s8"],"extra":["<h3>ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbc65c947d4ed97f.svg\" alt=\"f\\prime(-2)=0\" width=\"115.19\" height=\"24.43\" style=\"width:115.19px;height:24.43px;aspect-ratio:115.19/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 0.000000000.</p>","<h3>ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>"]},{"n":11,"title":"Leaky ReLU","intro":["<p>Leaky ReLU changes only the negative side: multiply a negative input by the small slope α. That negative sign remains. The value α is supplied by the question or chosen as a model setting; it is not the sigmoid function.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3faffb967fafdf3.svg\" alt=\"f(z)=\\begin{cases}z&amp;z\\geq0\\\\az&amp;z&lt;0\\end{cases}\" width=\"199.61\" height=\"58.62\" style=\"width:199.61px;height:58.62px;aspect-ratio:199.61/58.62\" loading=\"lazy\"></div>"],"refs":["mt2-c17-s8"],"extra":["<h3>Leaky ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24b81e63d794388e.svg\" alt=\"a=-0.2\" width=\"95.75\" height=\"18.27\" style=\"width:95.75px;height:18.27px;aspect-ratio:95.75/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaab86572902924a.svg\" alt=\"f\\prime(-2)=0.1\" width=\"134.21\" height=\"24.43\" style=\"width:134.21px;height:24.43px;aspect-ratio:134.21/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ -0.200000000. Derivative ≈ 0.100000000.</p>","<h3>Leaky ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>Leaky ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>"]},{"n":12,"title":"Stable softmax","intro":["<p>Softmax turns several competing class scores into probabilities that add to one. Exponentiate each score, add those exponential values, and divide each one by their common total. Subtracting the same maximum score first gives the same probabilities with safer arithmetic.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>"],"refs":["mt2-c17-s9"],"extra":["<h3>Softmax for [0, 0, 0]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [0, 0, 0].</strong></p>","<h3>Given</h3>","<p>Logits = [0, 0, 0]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e35e2c8f440c3bf.svg\" alt=\"z-c=\\begin{bmatrix}0&amp;0&amp;0\\end{bmatrix}\" width=\"183.50\" height=\"24.43\" style=\"width:183.50px;height:24.43px;aspect-ratio:183.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5cbcea061b92c91b.svg\"><img class=\"math display-math\" src=\"assets/equations/77bfb08512787403.svg\" alt=\"D=1.000000000+1.000000000+1.000000000\\approx3.000000000\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/abb38634253b454f.svg\"><img class=\"math display-math\" src=\"assets/equations/aac567888a814ba9.svg\" alt=\"p_1=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6f93f83cf16d42a1.svg\"><img class=\"math display-math\" src=\"assets/equations/4e80a74382faa499.svg\" alt=\"p_2=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd8dca9605ca9fba.svg\"><img class=\"math display-math\" src=\"assets/equations/932805d4a7ff7186.svg\" alt=\"p_3=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.333333333, 0.333333333, 0.333333333]; they sum to 1 within rounding.</p>","<h3>Softmax for [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [1, 2, 3].</strong></p>","<h3>Given</h3>","<p>Logits = [1, 2, 3]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/36a969786afa504d.svg\" alt=\"z-c=\\begin{bmatrix}-2&amp;-1&amp;0\\end{bmatrix}\" width=\"221.52\" height=\"24.43\" style=\"width:221.52px;height:24.43px;aspect-ratio:221.52/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8b081af8baa5f1b.svg\" alt=\"e^{-1}\\approx0.367879441\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff6afad7c399e8cd.svg\"><img class=\"math display-math\" src=\"assets/equations/3e8d536144b8581d.svg\" alt=\"D=0.135335283+0.367879441+1.000000000\\approx1.503214724\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60d7f2c1aed7f3ca.svg\"><img class=\"math display-math\" src=\"assets/equations/806ad5813b3ff8c0.svg\" alt=\"p_1=\\frac{0.135335283}{1.503214724}\\approx0.090030573\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/958d44e6661ca616.svg\"><img class=\"math display-math\" src=\"assets/equations/a839a3e6b8973897.svg\" alt=\"p_2=\\frac{0.367879441}{1.503214724}\\approx0.244728471\" width=\"356.81\" height=\"50.36\" style=\"width:356.81px;height:50.36px;aspect-ratio:356.81/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6153a5efe8276ec2.svg\"><img class=\"math display-math\" src=\"assets/equations/fdcbdba7b8490dd2.svg\" alt=\"p_3=\\frac{1.000000000}{1.503214724}\\approx0.665240956\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.090030573, 0.244728471, 0.665240956]; they sum to 1 within rounding.</p>"]},{"n":13,"title":"Squared and absolute losses","intro":["<p>SSE, half SSE and MSE start with the same errors but apply different final divisions. First understand what an error and its square mean. The full question below keeps all three answers separate.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a288e1ba23bc9347.svg\" alt=\"\\mathrm{SSE}=\\sum_i(o_i-y_i)^2\" width=\"211.02\" height=\"52.35\" style=\"width:211.02px;height:52.35px;aspect-ratio:211.02/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1bdd5bbb9ca64f61.svg\" alt=\"L_{\\mathrm{half}}=\\frac{\\mathrm{SSE}}2\" width=\"135.29\" height=\"50.50\" style=\"width:135.29px;height:50.50px;aspect-ratio:135.29/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bdee7885d635e78c.svg\" alt=\"L_{\\mathrm{MSE}}=\\frac{\\mathrm{SSE}}n\" width=\"143.04\" height=\"50.77\" style=\"width:143.04px;height:50.77px;aspect-ratio:143.04/50.77\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42ae3654ddbdf33e.svg\" alt=\"L_{\\mathrm{MAE}}=\\frac1n\\sum_i|o_i-y_i|\" width=\"243.92\" height=\"61.92\" style=\"width:243.92px;height:61.92px;aspect-ratio:243.92/61.92\" loading=\"lazy\"></div>"],"refs":["mt2-c2-s9","mt2-c17-s2"],"extra":["<h3>Absolute error uses a different operation</h3>","<p class=\"inline-question\"><strong>Question. Targets are [2, 4] and predictions are [1, 6]. Find mean absolute error.</strong></p>","<h3>Given</h3>","<p>Targets = [2,4]; predictions = [1,6]; n = 2.</p>","<h3>To find</h3>","<p>Find mean absolute error.</p>","<h3>Formula — which one and why</h3>","<p><strong>Mean absolute error.</strong> Absolute value removes the sign of each prediction error without squaring its magnitude. Average those magnitudes.</p>","<p>n = number of predictions. |e| means the nonnegative magnitude of error e.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/da84fa0919b7d150.svg\" alt=\"\\mathrm{MAE}=\\frac1n\\sum_i|\\hat y_i-y_i|\" width=\"242.18\" height=\"61.92\" style=\"width:242.18px;height:61.92px;aspect-ratio:242.18/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MAE mein magnitude; MSE mein square.</p>","<h3>Solution — step by step</h3>","<p>The signed errors are 1 − 2 = −1 and 6 − 4 = 2. Absolute value keeps the size of a number without its sign, so their absolute errors are 1 and 2. Add them to obtain 3. There are two prediction–target pairs, so divide by 2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.98px;--narrow-height:155.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/506b26dfbefb2185.svg\"><img class=\"math display-math\" src=\"assets/equations/1aaa963ebac2df98.svg\" alt=\"\\mathrm{MAE}=\\frac{|1-2|+|6-4|}{2}=\\frac{1+2}{2}=1.5\" width=\"427.81\" height=\"52.41\" style=\"width:427.81px;height:52.41px;aspect-ratio:427.81/52.41\" loading=\"lazy\"></picture></div>","<p><strong>Final answer: MAE = 1.5.</strong> Do not square the errors for MAE.</p>"]},{"n":14,"title":"Binary cross entropy","intro":["<p>Binary cross-entropy measures how much probability was assigned to the correct binary answer. A target of 1 keeps the −ln(p) term; a target of 0 keeps the −ln(1−p) term. The factors y and 1−y select the appropriate term.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c17-s7"],"extra":["<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fcb072c6f4519069.svg\" alt=\"p=0.8\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65af868a518fd08e.svg\"><img class=\"math display-math\" src=\"assets/equations/710d02f73efd4006.svg\" alt=\"L=-(-0.223143551)=0.223143551\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.223143551 nats.</p>","<h3>Binary cross-entropy: target 0, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 0. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 0; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/438398f064595bb7.svg\" alt=\"1-p=1-0.8=0.2\" width=\"224.09\" height=\"21.02\" style=\"width:224.09px;height:21.02px;aspect-ratio:224.09/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a82bb66e18d1bf7c.svg\" alt=\"\\ln(0.2)\\approx-1.609437912\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe3e4a4ff07bc0e0.svg\"><img class=\"math display-math\" src=\"assets/equations/8a78ffe2df23393c.svg\" alt=\"L=-(-1.609437912)=1.609437912\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 1.609437912 nats.</p>","<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.5</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.5. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.5; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c8d4b00d7d4788e.svg\" alt=\"p=0.5\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89c211e38f586f86.svg\" alt=\"\\ln(0.5)\\approx-0.693147181\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e0e8fd22135c9d7b.svg\"><img class=\"math display-math\" src=\"assets/equations/4bf6a8c1047d0f4a.svg\" alt=\"L=-(-0.693147181)=0.693147181\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.693147181 nats.</p>"]},{"n":15,"title":"Categorical cross entropy","intro":["<p>For one-hot multiclass targets, only one target entry is 1. The other entries are zero, so the loss becomes minus the logarithm of the true class probability. The worked question first calculates every softmax probability, then selects the correct one.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/feb21e9c89a912d7.svg\" alt=\"H(p,q)=-\\sum_i p_i\\ln q_i\" width=\"237.82\" height=\"52.35\" style=\"width:237.82px;height:52.35px;aspect-ratio:237.82/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/945fabaced090f8f.svg\" alt=\"\\log_2q=\\frac{\\ln q}{\\ln2}\" width=\"137.21\" height=\"50.24\" style=\"width:137.21px;height:50.24px;aspect-ratio:137.21/50.24\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.42px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea93bf47748eb958.svg\"><img class=\"math display-math\" src=\"assets/equations/abecd65b7d7b5753.svg\" alt=\"L=-\\sum_i y_i\\ln p_i=-\\ln p_{true}\" width=\"306.83\" height=\"52.35\" style=\"width:306.83px;height:52.35px;aspect-ratio:306.83/52.35\" loading=\"lazy\"></picture></div>"],"refs":["mt2-c4-s17","mt2-c17-s9"],"extra":[]},{"n":16,"title":"Output delta for half squared loss","intro":["<p>Delta is a short name for the loss derivative with respect to a neuron’s raw input z. For half squared loss, multiply prediction minus target by the activation’s derivative. The result is then multiplied by an incoming activation to obtain a weight gradient.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc1948e719d0e70b.svg\" alt=\"\\delta^{out}=(o-y)f\\prime(z)\" width=\"193.19\" height=\"27.01\" style=\"width:193.19px;height:27.01px;aspect-ratio:193.19/27.01\" loading=\"lazy\"></div>"],"refs":["mt2-c3-s8","mt2-c4-s16","mt2-c17-s10","mt2-c17-s11","mt2-c17-s12"],"extra":[]},{"n":17,"title":"Sigmoid plus BCE; softmax plus CCE","intro":["<p>Some activation–loss pairs simplify together. Sigmoid with binary cross-entropy, and softmax with one-hot categorical cross-entropy, give prediction minus target at the raw-score level. This result already includes the activation’s effect.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/154ed49b87099426.svg\" alt=\"\\delta^{out}=p-y\" width=\"124.09\" height=\"25.92\" style=\"width:124.09px;height:25.92px;aspect-ratio:124.09/25.92\" loading=\"lazy\"></div>"],"refs":["mt2-c17-s7"],"extra":["<h3>The multiclass version, entry by entry</h3>","<p class=\"inline-question\"><strong>Question. Softmax probabilities are [0.1, 0.8, 0.1] and the one-hot target is [0, 1, 0]. For categorical cross-entropy on this one example, find the derivatives with respect to all three logits.</strong></p>","<h3>Given</h3>","<p>Softmax probabilities = [0.1,0.8,0.1]; target = [0,1,0].</p>","<p>One-example categorical cross-entropy.</p>","<h3>To find</h3>","<p>Find all three logit derivatives.</p>","<h3>Formula — which one and why</h3>","<p><strong>Softmax with categorical cross-entropy.</strong> For one example with one-hot target, differentiating softmax together with CCE simplifies the logit derivative to predicted probability minus target.</p>","<p>zᵢ = raw score before softmax; pᵢ = class probability; yᵢ = matching target entry.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f0494c85fef2342.svg\" alt=\"\\frac{\\partial L}{\\partial z_i}=p_i-y_i\" width=\"146.63\" height=\"54.60\" style=\"width:146.63px;height:54.60px;aspect-ratio:146.63/54.60\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Softmax + CCE together: p minus y. Extra sigmoid slope nahi.</p>","<h3>Solution — step by step</h3>","<p>A logit is the raw score before softmax. Subtract each target entry from its matching probability entry.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1d662617a540534.svg\" alt=\"\\frac{\\partial L}{\\partial z_1}=0.1-0=0.1\" width=\"216.32\" height=\"54.41\" style=\"width:216.32px;height:54.41px;aspect-ratio:216.32/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ed27397a5b5cfeec.svg\" alt=\"\\frac{\\partial L}{\\partial z_2}=0.8-1=-0.2\" width=\"235.33\" height=\"54.41\" style=\"width:235.33px;height:54.41px;aspect-ratio:235.33/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64941f713e55940c.svg\" alt=\"\\frac{\\partial L}{\\partial z_3}=0.1-0=0.1\" width=\"216.32\" height=\"54.80\" style=\"width:216.32px;height:54.80px;aspect-ratio:216.32/54.80\" loading=\"lazy\"></div>","<p><strong>Final answer: [0.1, −0.2, 0.1].</strong> Do not multiply these by a separate sigmoid derivative or by p(1−p). A mean over several examples introduces the corresponding averaging factor.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=1</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 1. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 1; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55554414edc61afc.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-1}{0.16}=-1.25\" width=\"251.78\" height=\"54.97\" style=\"width:251.78px;height:54.97px;aspect-ratio:251.78/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.60px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/352e50cd272ef421.svg\"><img class=\"math display-math\" src=\"assets/equations/b564b0f8f85410b8.svg\" alt=\"\\frac{dL}{dz}=(-1.25)(0.16)=-0.2\" width=\"299.42\" height=\"50.50\" style=\"width:299.42px;height:50.50px;aspect-ratio:299.42/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> dL/dz = -0.2. No further sigmoid derivative is needed.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=0</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 0. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 0; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcb217487ddffdd.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-0}{0.16}=5\" width=\"201.55\" height=\"54.97\" style=\"width:201.55px;height:54.97px;aspect-ratio:201.55/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86de3ab6d9deb754.svg\" alt=\"\\frac{dL}{dz}=(5)(0.16)=0.8\" width=\"230.17\" height=\"50.50\" style=\"width:230.17px;height:50.50px;aspect-ratio:230.17/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> dL/dz = 0.8. No further sigmoid derivative is needed.</p>"]},{"n":18,"title":"Hidden delta, weight gradient and bias gradient","intro":["<p>A hidden neuron can influence several outputs. Add all those backward contributions before multiplying by its own activation derivative. For each connection, use the receiving neuron’s delta and the sending neuron’s activation. Keep the old weights unchanged until all gradients have been found.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a85cefe361f399b.svg\" alt=\"\\delta_j^h=f\\prime(z_j^h)\\sum_k w_{kj}^{out}\\delta_k^{out}\" width=\"242.75\" height=\"52.91\" style=\"width:242.75px;height:52.91px;aspect-ratio:242.75/52.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c4e0f7ded9389700.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i\" width=\"130.68\" height=\"57.94\" style=\"width:130.68px;height:57.94px;aspect-ratio:130.68/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>"],"refs":["mt2-c4-s12","mt2-c4-s11","mt2-c17-s11","mt2-c17-s12","mt2-c17-s13"],"extra":[]},{"n":19,"title":"Gradient descent","intro":["<p>A gradient tells us the local direction in which loss rises. Gradient descent subtracts a small multiple of that gradient. Learning rate η controls the size of this correction. After the first update, calculate the next gradient at the new parameter.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/84b9c6c86f29aa06.svg\" alt=\"\\theta_{new}=\\theta-\\eta g\" width=\"141.99\" height=\"22.51\" style=\"width:141.99px;height:22.51px;aspect-ratio:141.99/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ac6a050d5a887603.svg\" alt=\"g=\\frac{\\partial J}{\\partial\\theta}\" width=\"84.28\" height=\"51.29\" style=\"width:84.28px;height:51.29px;aspect-ratio:84.28/51.29\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s0","mt2-c5-s3","mt2-c17-s16","mt2-c17-s17","mt2-c17-s6"],"extra":[]},{"n":20,"title":"Batch and mini-batch gradient","intro":["<p>A batch is a group of training examples used together for one update. An epoch is one pass through the dataset. Averaging gradients and counting updates are different questions, so both receive complete worked examples below.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/af742484e9a4fffc.svg\" alt=\"g_{batch}=\\frac1B\\sum_{i=1}^{B}g_i\" width=\"178.86\" height=\"72.79\" style=\"width:178.86px;height:72.79px;aspect-ratio:178.86/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24d8d40909055c78.svg\" alt=\"U_{epoch}=\\left\\lceil\\frac NB\\right\\rceil\" width=\"154.80\" height=\"58.62\" style=\"width:154.80px;height:58.62px;aspect-ratio:154.80/58.62\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s5","mt2-c5-s6","mt2-c17-s14","mt2-c17-s15"],"extra":[]},{"n":21,"title":"Momentum: signed velocity","intro":["<p>Momentum carries some of the previous movement into the next update. Here v is signed movement, so the new parameter is the old parameter plus v. A negative v moves the parameter down. Use the same convention throughout the calculation.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s11","mt2-c5-s9","mt2-c17-s18","mt2-c17-s19"],"extra":[]},{"n":22,"title":"Nesterov: look-ahead gradient","intro":["<p>Nesterov first uses the old movement to choose a temporary look-ahead position. It measures the gradient there, calculates the new movement, then adds that movement to the original parameter. The temporary look-ahead position does not replace the original parameter in the final addition.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47358875d94f2558.svg\" alt=\"\\theta_{look}=\\theta+\\beta v\" width=\"144.00\" height=\"21.97\" style=\"width:144.00px;height:21.97px;aspect-ratio:144.00/21.97\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9d756d38e5b7933.svg\" alt=\"v_{new}=\\beta v-\\eta g(\\theta_{look})\" width=\"220.01\" height=\"24.43\" style=\"width:220.01px;height:24.43px;aspect-ratio:220.01/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73afc93b70062b2d.svg\" alt=\"\\theta_{new}=\\theta+v_{new}\" width=\"162.85\" height=\"21.08\" style=\"width:162.85px;height:21.08px;aspect-ratio:162.85/21.08\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s10","mt2-c17-s20","mt2-c17-s21"],"extra":[]},{"n":23,"title":"AdaGrad","intro":["<p>AdaGrad stores a running sum of squared gradients for each parameter. Squaring removes the sign only in this stored total. The unsquared gradient in the numerator still decides the direction of the update.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s12","mt2-c17-s22","mt2-c17-s23"],"extra":[]},{"n":24,"title":"RMSProp","intro":["<p>RMSProp remembers a weighted average of squared gradients. With decay 0.9, keep 90% of the old stored value and add 10% of the new squared gradient. Calculate this new stored value before taking its square root and updating the parameter.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s8","mt2-c5-s13","mt2-c17-s24","mt2-c17-s25"],"extra":[]},{"n":25,"title":"Adam: both memories","intro":["<p>Adam keeps two separate running averages. The first remembers signed gradients and can be negative. The second remembers squared gradients and is nonnegative. These stored averages are not weights, and they are not extra gradients to multiply together.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s1","mt2-c5-s14","mt2-c17-s26","mt2-c17-s27"],"extra":[]},{"n":26,"title":"Adam: correction and update","intro":["<p>Adam starts its two averages at zero. Early averages therefore contain less total weight on observed gradients. Bias correction compensates for that initialization. The power in βᵗ uses the current update number, and both averages must be corrected before the parameter update.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4c24c9160cc537a1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9f81435f55f92a6.svg\" alt=\"\\widehat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"130.03\" height=\"53.28\" style=\"width:130.03px;height:53.28px;aspect-ratio:130.03/53.28\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8fbedcf992dd719a.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"231.71\" height=\"66.85\" style=\"width:231.71px;height:66.85px;aspect-ratio:231.71/66.85\" loading=\"lazy\"></div>"],"refs":["mt2-c5-s15","mt2-c5-s14","mt2-c17-s26","mt2-c17-s27"],"extra":[]},{"n":27,"title":"L1 penalty and update","intro":["<p>L1 adds a cost based on the absolute sizes of weights. Its derivative is positive for a positive weight and negative for a negative weight. The optimizer adds this penalty gradient to the data gradient before applying the usual update.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14b76928315b8569.svg\" alt=\"J=L+\\lambda\\sum_j|w_j|\" width=\"192.47\" height=\"55.67\" style=\"width:192.47px;height:55.67px;aspect-ratio:192.47/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e25593d3f219dc71.svg\" alt=\"w_{new}=w-\\eta\\left[g_{data}+\\lambda\\operatorname{sign}(w)\\right]\" width=\"334.16\" height=\"24.43\" style=\"width:334.16px;height:24.43px;aspect-ratio:334.16/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c6-s2","mt2-c6-s1","mt2-c17-s29","mt2-c17-s28","mt2-c17-s41"],"extra":[]},{"n":28,"title":"L2 penalty and update with a half","intro":["<p>L2 adds a cost based on squared weights. Differentiating a square produces a factor of 2. If the objective includes a half, that half cancels the 2; if it does not, the 2 remains. Read the objective before choosing the gradient.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/119bfafa31acc3ba.svg\" alt=\"J=L+\\frac\\lambda2\\sum_jw_j^2\" width=\"191.15\" height=\"65.94\" style=\"width:191.15px;height:65.94px;aspect-ratio:191.15/65.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/349319f842d12440.svg\" alt=\"w_{new}=w-\\eta(g_{data}+\\lambda w)\" width=\"270.21\" height=\"24.43\" style=\"width:270.21px;height:24.43px;aspect-ratio:270.21/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c6-s1","mt2-c17-s30","mt2-c17-s28","mt2-c17-s41"],"extra":[]},{"n":29,"title":"Inverted dropout","intro":["<p>Inverted dropout uses a mask: zero means drop this activation, one means keep it. During training, divide each retained activation by the keep probability. During inference, dropout is disabled and this training-time division is not repeated.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/536be85758e6d02d.svg\" alt=\"q=1-p\" width=\"98.20\" height=\"21.02\" style=\"width:98.20px;height:21.02px;aspect-ratio:98.20/21.02\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/504d04d32df8a91c.svg\" alt=\"a_{train}=\\frac{m\\odot a}{q}\" width=\"162.03\" height=\"52.26\" style=\"width:162.03px;height:52.26px;aspect-ratio:162.03/52.26\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1251aa7fa418d32.svg\" alt=\"a_{test}=a\" width=\"89.09\" height=\"18.10\" style=\"width:89.09px;height:18.10px;aspect-ratio:89.09/18.10\" loading=\"lazy\"></div>"],"refs":["mt2-c6-s8","mt2-c6-s3","mt2-c17-s31","mt2-c17-s42"],"extra":[]},{"n":30,"title":"Convolution output dimensions","intro":["<p>This formula counts how many legal filter positions fit along one image dimension. Padding adds space at both ends, the kernel occupies K positions, and stride controls how far the next window moves. The floor keeps only complete valid positions.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.70px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f467d926f905df6d.svg\"><img class=\"math display-math\" src=\"assets/equations/b7c680fad37aede4.svg\" alt=\"N_{out}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"293.79\" height=\"58.62\" style=\"width:293.79px;height:58.62px;aspect-ratio:293.79/58.62\" loading=\"lazy\"></picture></div>"],"refs":["mt2-c7-s0","mt2-c7-s3","mt2-c7-s18","mt2-c17-s33"],"extra":[]},{"n":31,"title":"Convolution value","intro":["<p>One convolution output is a sum of matched input–kernel products. Move the window and repeat that exact rule for the next output. With several input channels, add contributions from every channel and add the filter bias once.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:380.25px;--narrow-height:130.78px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5afb61a6d5f3879.svg\"><img class=\"math display-math\" src=\"assets/equations/0fcf0c4134fa9fe3.svg\" alt=\"Y_{ij,o}=\\sum_c\\sum_u\\sum_v K_{uvco}X_{iS+u-P,jS+v-P,c}+b_o\" width=\"473.49\" height=\"51.51\" style=\"width:473.49px;height:51.51px;aspect-ratio:473.49/51.51\" loading=\"lazy\"></picture></div>"],"refs":["mt2-c7-s5","mt2-c7-s14","mt2-c7-s15","mt2-c7-s2","mt2-c17-s32","mt2-c17-s40"],"extra":[]},{"n":32,"title":"Max, min and average pooling","intro":["<p>Pooling reduces each window to one value. Max pooling keeps the largest entry; average pooling adds all included entries and divides by their count. Pooling is performed independently in each channel.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/619bb1c028de4233.svg\" alt=\"y_{\\min}=\\min(x_1,x_2,x_3,x_4)\" width=\"266.30\" height=\"24.43\" style=\"width:266.30px;height:24.43px;aspect-ratio:266.30/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79973536a2057db8.svg\" alt=\"y_{max}=\\max_{(i,j)\\in W}x_{ij}\" width=\"174.90\" height=\"38.32\" style=\"width:174.90px;height:38.32px;aspect-ratio:174.90/38.32\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bd2034a9c3d7a387.svg\" alt=\"y_{avg}=\\frac1{|W|}\\sum_{(i,j)\\in W}x_{ij}\" width=\"220.47\" height=\"67.59\" style=\"width:220.47px;height:67.59px;aspect-ratio:220.47/67.59\" loading=\"lazy\"></div>"],"refs":["mt2-c7-s7","mt2-c7-s16","mt2-c17-s34","mt2-c17-s40"],"extra":[]},{"n":33,"title":"Convolution parameter count","intro":["<p>A filter has one learned weight for each spatial position in each input channel. Count the weights in one filter, add its one bias, then multiply by the number of filters. Sliding a filter to many positions reuses these weights; it does not create new parameters.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.37px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8a253f24fdf99d8e.svg\"><img class=\"math display-math\" src=\"assets/equations/bd7e05cdd2c763eb.svg\" alt=\"P_{conv}=(K_hK_wC_{in}+1)C_{out}\" width=\"293.70\" height=\"24.43\" style=\"width:293.70px;height:24.43px;aspect-ratio:293.70/24.43\" loading=\"lazy\"></picture></div>"],"refs":["mt2-c7-s12","mt2-c7-s13","mt2-c7-s17","mt2-c7-s8","mt2-c17-s35"],"extra":[]},{"n":34,"title":"Flatten and dense parameter count","intro":["<p>Flattening rearranges all activation values into a list. It learns no new numbers. A dense layer then connects every value in that list to every receiving neuron; each receiving neuron also has one bias.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31ebc79afc790262.svg\" alt=\"N_{flat}=HWC\" width=\"150.14\" height=\"24.43\" style=\"width:150.14px;height:24.43px;aspect-ratio:150.14/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c28314915c655018.svg\" alt=\"P_{dense}=(N_{in}+1)N_{out}\" width=\"239.08\" height=\"24.43\" style=\"width:239.08px;height:24.43px;aspect-ratio:239.08/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c4-s14","mt2-c7-s9","mt2-c17-s35","mt2-c17-s43"],"extra":[]},{"n":35,"title":"Convolution multiply-accumulate count","intro":["<p>A parameter count counts learned numbers. A multiply-accumulate count counts how many times input–weight products are used. One filter is reused at every output position, so computation includes output height and width even though its parameter count does not.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:276.71px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d20bfcc57cb122e.svg\"><img class=\"math display-math\" src=\"assets/equations/86ffc171b254aab9.svg\" alt=\"MAC=H_{out}W_{out}K_hK_wC_{in}C_{out}\" width=\"339.28\" height=\"21.35\" style=\"width:339.28px;height:21.35px;aspect-ratio:339.28/21.35\" loading=\"lazy\"></picture></div>"],"refs":["mt2-c8-s2","mt2-c8-s14","mt2-c17-s37"],"extra":["<h3>Bottleneck computation on an 8 × 8 input</h3>","<p class=\"inline-question\"><strong>Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.</strong></p>","<h3>Given</h3>","<p>Spatial output = 8 × 8 in both stages.</p>","<p>Input channels = 16; output filters = 8; main kernel = 3 × 3.</p>","<p>Bottleneck uses 4 filters of 1 × 1.</p>","<h3>To find</h3>","<p>Direct MACs, two-stage bottleneck MACs and savings.</p>","<h3>Formula — which one and why</h3>","<p>Each output scalar requires one multiply-accumulate per incoming kernel entry. A bottleneck reduces the input depth of the expensive spatial convolution.</p>","<p>One MAC is one multiply-accumulate pair. If counting multiplication and addition separately, the operation count is approximately twice the MAC count.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:276.19px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/40f8ac20e40ebe3e.svg\"><img class=\"math display-math\" src=\"assets/equations/13f4a3b9d3a03995.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K_hK_wC_{\\mathrm{in}}\" width=\"344.19\" height=\"21.35\" style=\"width:344.19px;height:21.35px;aspect-ratio:344.19/21.35\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Spatial kernel se pehle channels kam; dono stages ka cost add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count output positions per channel.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0917529398667f13.svg\" alt=\"8(8)=64\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count direct work per output scalar.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b0c2720e21a1506.svg\" alt=\"3(3)(16)=144\" width=\"156.12\" height=\"24.43\" style=\"width:156.12px;height:24.43px;aspect-ratio:156.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: count the full direct layer.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/531722215214eb67.svg\" alt=\"64(8)(144)=73728\" width=\"204.99\" height=\"24.43\" style=\"width:204.99px;height:24.43px;aspect-ratio:204.99/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: count the 1 × 1 reduction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a619ccae82b20a14.svg\" alt=\"64(4)(1)(1)(16)=4096\" width=\"243.01\" height=\"24.43\" style=\"width:243.01px;height:24.43px;aspect-ratio:243.01/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: count the reduced-depth 3 × 3 layer.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f478849ec0c64569.svg\" alt=\"64(8)(3)(3)(4)=18432\" width=\"243.01\" height=\"24.43\" style=\"width:243.01px;height:24.43px;aspect-ratio:243.01/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: sum both bottleneck stages.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4821e959cb7a516.svg\" alt=\"4096+18432=22528\" width=\"233.50\" height=\"18.54\" style=\"width:233.50px;height:18.54px;aspect-ratio:233.50/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: subtract to obtain savings.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be3a4d13f46b02ba.svg\" alt=\"73728-22528=51200\" width=\"245.71\" height=\"18.52\" style=\"width:245.71px;height:18.52px;aspect-ratio:245.71/18.52\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Direct = 73,728 MACs; bottleneck = 22,528 MACs; savings = 51,200 MACs.</p>"]},{"n":36,"title":"Concatenation and residual addition","intro":["<p>Concatenation and addition combine branches differently. Concatenation places channel groups next to each other and increases the channel count. Residual addition adds matching entries, so the two full shapes must be compatible.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/963754238ceb3b1d.svg\" alt=\"C_{concat}=\\sum_b C_b\" width=\"167.43\" height=\"52.91\" style=\"width:167.43px;height:52.91px;aspect-ratio:167.43/52.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d362a7b729c4f87f.svg\" alt=\"y_{res}=F(x)+x\" width=\"165.66\" height=\"24.43\" style=\"width:165.66px;height:24.43px;aspect-ratio:165.66/24.43\" loading=\"lazy\"></div>"],"refs":["mt2-c8-s7","mt2-c8-s3","mt2-c17-s44","mt2-c17-s45","mt2-c17-s38"],"extra":[]},{"n":46,"title":"Batch normalization and learned scale/shift","intro":["<p>Batch normalization first uses batch statistics, then applies a learned scale and shift. Epsilon belongs inside the square root. Inference ordinarily uses stored running statistics.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a91b1c9216cbd799.svg\" alt=\"\\mu_B=\\frac{1}{m}\\sum_{i=1}^{m}x_i\" width=\"160.06\" height=\"68.62\" style=\"width:160.06px;height:68.62px;aspect-ratio:160.06/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcfc8cc5fd3adc8.svg\" alt=\"\\sigma_B^2=\\frac{1}{m}\\sum_{i=1}^{m}(x_i-\\mu_B)^2\" width=\"244.63\" height=\"68.62\" style=\"width:244.63px;height:68.62px;aspect-ratio:244.63/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13126b94bcd9d415.svg\" alt=\"\\hat{x}_i=\\frac{x_i-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\" width=\"159.11\" height=\"75.23\" style=\"width:159.11px;height:75.23px;aspect-ratio:159.11/75.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7fd3e426f48f08b9.svg\" alt=\"y_i=\\gamma\\hat{x}_i+\\beta\" width=\"131.48\" height=\"25.07\" style=\"width:131.48px;height:25.07px;aspect-ratio:131.48/25.07\" loading=\"lazy\"></div>"],"refs":["mt2-c8-s15"],"extra":[]},{"n":47,"title":"Global average pooling","intro":["<p>Global average pooling takes one mean per complete spatial channel. The worked example compares the resulting dense classifier with a classifier after flattening.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/002749b4b374cf54.svg\" alt=\"g_c=\\frac{1}{HW}\\sum_{i=1}^{H}\\sum_{j=1}^{W}a_{i,j,c}\" width=\"239.71\" height=\"74.90\" style=\"width:239.71px;height:74.90px;aspect-ratio:239.71/74.90\" loading=\"lazy\"></div>"],"refs":["mt2-c8-s13"],"extra":[]},{"n":48,"title":"Top-k error percentage","intro":["<p>Top-k error counts examples whose correct class is absent from the highest-scoring k predictions. Success counts must not be added twice.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fb17785121a672d.svg\" alt=\"E_k=\\frac{N-C_k}{N}\\times100\\%\" width=\"239.34\" height=\"50.50\" style=\"width:239.34px;height:50.50px;aspect-ratio:239.34/50.50\" loading=\"lazy\"></div>"],"refs":["mt2-c8-s11"],"extra":[]}],"tee":[{"n":1,"title":"Mean, variance and standard deviation","intro":["<p>The mean is a measure of location; variance and standard deviation quantify dispersion. Distinguish population and sample conventions before calculating these statistics.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/515c6d49d5a0ee05.svg\" alt=\"\\mu=\\frac{1}{n}\\sum_i x_i\" width=\"138.12\" height=\"61.92\" style=\"width:138.12px;height:61.92px;aspect-ratio:138.12/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5b9364e6a03439b4.svg\" alt=\"v=\\frac{1}{n}\\sum_i(x_i-\\mu)^2\" width=\"205.45\" height=\"61.92\" style=\"width:205.45px;height:61.92px;aspect-ratio:205.45/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c9fd8a46ad5f2e60.svg\" alt=\"s=\\sqrt{v}\" width=\"76.73\" height=\"25.90\" style=\"width:76.73px;height:25.90px;aspect-ratio:76.73/25.90\" loading=\"lazy\"></div>"],"refs":["tee-c3-s10"],"extra":["<h3>Population mean and spread: [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. For the population [1, 2, 3], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [1, 2, 3]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/23a1d761557fba99.svg\" alt=\"1+2+3=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cde1ff63a64aa7ce.svg\" alt=\"(1-2)=-1\" width=\"137.13\" height=\"24.43\" style=\"width:137.13px;height:24.43px;aspect-ratio:137.13/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/46782fbf983b8482.svg\" alt=\"(-1)^2=1\" width=\"105.71\" height=\"27.70\" style=\"width:105.71px;height:27.70px;aspect-ratio:105.71/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ebe985168f035d36.svg\" alt=\"(3-2)=1\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a4b8daac35aec1bc.svg\" alt=\"(1)^2=1\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e913fcfda4146fb6.svg\"><img class=\"math display-math\" src=\"assets/equations/33fa105b83cd3564.svg\" alt=\"\\sigma^2=\\frac{1+0+1}{3}\\approx0.666666667\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.69px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0c7d94a64e886a59.svg\"><img class=\"math display-math\" src=\"assets/equations/28845fc5f4238747.svg\" alt=\"\\sigma=\\sqrt{0.666666667}\\approx0.816496581\" width=\"357.89\" height=\"26.49\" style=\"width:357.89px;height:26.49px;aspect-ratio:357.89/26.49\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.666666667; σ ≈ 0.816496581.</p>","<h3>Population mean and spread: [2, 2, 2]</h3>","<p class=\"inline-question\"><strong>Question. For the population [2, 2, 2], find mean, population variance and standard deviation.</strong></p>","<h3>Given</h3>","<p>Values = [2, 2, 2]; N = 3. Use population division by N.</p>","<h3>To find</h3>","<p>Mean μ, variance σ² and standard deviation σ.</p>","<h3>Formula — which one and why</h3>","<p>The question specifies a population, so use N rather than the N−1 sample-variance divisor.</p>","<p>μ is the centre; σ² averages squared distances from it; σ converts spread back to the original units.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d96a5eb55c670639.svg\" alt=\"\\mu=\\frac1N\\sum_i x_i\" width=\"145.16\" height=\"61.92\" style=\"width:145.16px;height:61.92px;aspect-ratio:145.16/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d7a9d7e061fca1d7.svg\" alt=\"\\sigma^2=\\frac1N\\sum_i(x_i-\\mu)^2\" width=\"225.26\" height=\"61.92\" style=\"width:225.26px;height:61.92px;aspect-ratio:225.26/61.92\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b5afbd2f5b393f2.svg\" alt=\"\\sigma=\\sqrt{\\sigma^2}\" width=\"96.08\" height=\"30.79\" style=\"width:96.08px;height:30.79px;aspect-ratio:96.08/30.79\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Mean, distance, square, mean again, then root.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: add all values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fc38a48a0a6427f.svg\" alt=\"2+2+2=6\" width=\"141.19\" height=\"18.27\" style=\"width:141.19px;height:18.27px;aspect-ratio:141.19/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: divide by the number of values.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f48ae6fcd2c250e.svg\" alt=\"\\mu=\\frac{6}{3}=2\" width=\"115.08\" height=\"50.09\" style=\"width:115.08px;height:50.09px;aspect-ratio:115.08/50.09\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: find and square deviation 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: find and square deviation 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: find and square deviation 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/21c8488d16b7e891.svg\" alt=\"(2-2)=0\" width=\"118.12\" height=\"24.43\" style=\"width:118.12px;height:24.43px;aspect-ratio:118.12/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8b9442558db09d6.svg\" alt=\"(0)^2=0\" width=\"86.69\" height=\"27.70\" style=\"width:86.69px;height:27.70px;aspect-ratio:86.69/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: average the squared deviations.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:164.34px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b0fc9edc8362e2a5.svg\"><img class=\"math display-math\" src=\"assets/equations/f4e20a1682fadce3.svg\" alt=\"\\sigma^2=\\frac{0+0+0}{3}\\approx0.000000000\" width=\"325.89\" height=\"50.09\" style=\"width:325.89px;height:50.09px;aspect-ratio:325.89/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: take the nonnegative square root.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:196.34px;--narrow-height:69.57px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9ee45ab162936835.svg\"><img class=\"math display-math\" src=\"assets/equations/c43ce89c0112ae99.svg\" alt=\"\\sigma=\\sqrt{0.000000000}\\approx0.000000000\" width=\"357.89\" height=\"26.37\" style=\"width:357.89px;height:26.37px;aspect-ratio:357.89/26.37\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> μ = 2; σ² ≈ 0.000000000; σ ≈ 0.000000000. Standardization is undefined with this zero standard deviation.</p>"]},{"n":2,"title":"Standardization","intro":["<p>Standardization has a meaning before it has a formula: measure how far an input is from its training mean, then express that distance in standard-deviation units. The worked question below calculates the mean and standard deviation first, so neither number appears without explanation.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6a0a4f4a38fa7007.svg\" alt=\"x_{scaled}=\\frac{x-\\mu_{train}}{s_{train}}\" width=\"206.36\" height=\"51.38\" style=\"width:206.36px;height:51.38px;aspect-ratio:206.36/51.38\" loading=\"lazy\"></div>"],"refs":["tee-c3-s11"],"extra":[]},{"n":3,"title":"Power, constant and sum derivatives","intro":["<p>Derivatives describe local rates of change. Partial derivatives hold other independent variables fixed; their collection forms the gradient used for optimization.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5c78e62c5b2a236.svg\" alt=\"\\frac{d}{dx}(cx^n)=cnx^{n-1}\" width=\"199.67\" height=\"50.50\" style=\"width:199.67px;height:50.50px;aspect-ratio:199.67/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d569e096ba9d6dba.svg\" alt=\"\\frac{d}{dx}c=0\" width=\"92.82\" height=\"50.50\" style=\"width:92.82px;height:50.50px;aspect-ratio:92.82/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/032a4e4c1f8b2817.svg\" alt=\"(f+g)\\prime=f\\prime+g\\prime\" width=\"181.68\" height=\"24.43\" style=\"width:181.68px;height:24.43px;aspect-ratio:181.68/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c3-s3"],"extra":[]},{"n":4,"title":"Chain rule","intro":["<p>The chain rule differentiates a composite function. Multiply local derivatives along a dependency path and add the contributions of different paths to the same variable.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/434e48fc84f871b4.svg\" alt=\"\\frac{dL}{dw}=\\frac{dL}{dz}\\frac{dz}{dw}\" width=\"154.58\" height=\"50.50\" style=\"width:154.58px;height:50.50px;aspect-ratio:154.58/50.50\" loading=\"lazy\"></div>"],"refs":["tee-c3-s6","tee-c17-s6"],"extra":[]},{"n":5,"title":"Dot product and a neuron","intro":["<p>A neuron starts with matched input–weight pairs. Multiply inside each pair, add the products, add the bias once, and then apply the activation. The summation sign is simply a shorter way to write those additions.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/051f16f4bf1744dd.svg\" alt=\"z=\\sum_i w_i x_i+b\" width=\"171.10\" height=\"52.35\" style=\"width:171.10px;height:52.35px;aspect-ratio:171.10/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/66df67478858e480.svg\" alt=\"a=f(z)\" width=\"89.32\" height=\"24.43\" style=\"width:89.32px;height:24.43px;aspect-ratio:89.32/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c4-s7","tee-c4-s6","tee-c17-s4"],"extra":[]},{"n":6,"title":"Matrix multiplication","intro":["<p>Matrix multiplication implements affine transformations in a dense layer. Dimensions determine which products are valid; each output component is the dot product of a weight row and the input vector, plus its bias.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47f627ca6464a106.svg\" alt=\"(AB)_{ij}=\\sum_k A_{ik}B_{kj}\" width=\"214.94\" height=\"52.91\" style=\"width:214.94px;height:52.91px;aspect-ratio:214.94/52.91\" loading=\"lazy\"></div>"],"refs":["tee-c3-s1","tee-c17-s5"],"extra":[]},{"n":7,"title":"Layer forward pass","intro":["<p>A layer does the neuron calculation for several receiving neurons. Finish all its outputs before using them as the next layer’s inputs. The bracketed superscript is a layer label, not a power.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/87472012ebbb4a9d.svg\" alt=\"z^{(l)}=W^{(l)}a^{(l-1)}+b^{(l)}\" width=\"228.73\" height=\"25.06\" style=\"width:228.73px;height:25.06px;aspect-ratio:228.73/25.06\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/85d817a60006abc5.svg\" alt=\"a^{(l)}=f(z^{(l)})\" width=\"130.56\" height=\"29.16\" style=\"width:130.56px;height:29.16px;aspect-ratio:130.56/29.16\" loading=\"lazy\"></div>"],"refs":["tee-c4-s13","tee-c4-s16","tee-c4-s14","tee-c17-s13","tee-c17-s14"],"extra":[]},{"n":8,"title":"Sigmoid and its derivative","intro":["<p>Sigmoid takes a raw score and changes it to a number between 0 and 1. Its derivative is a different number: it tells backpropagation how sensitive that output is to its raw score. The complete example below calculates both and shows where each is used.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c3083d9958c3932d.svg\" alt=\"\\sigma(z)=\\frac{1}{1+e^{-z}}\" width=\"164.64\" height=\"51.56\" style=\"width:164.64px;height:51.56px;aspect-ratio:164.64/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/90cd2771a42dc9ef.svg\" alt=\"\\sigma\\prime(z)=\\sigma(z)[1-\\sigma(z)]\" width=\"227.94\" height=\"24.43\" style=\"width:227.94px;height:24.43px;aspect-ratio:227.94/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c4-s19","tee-c17-s10"],"extra":["<h3>sigmoid example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9feed82e056cf24.svg\" alt=\"-z=-(-2)=2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b83d9532e6445b5a.svg\" alt=\"e^{2}\\approx7.389056099\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4026cb0f8944f24f.svg\"><img class=\"math display-math\" src=\"assets/equations/fb7c0cac9ced67f0.svg\" alt=\"1+7.389056099\\approx8.389056099\" width=\"332.60\" height=\"18.52\" style=\"width:332.60px;height:18.52px;aspect-ratio:332.60/18.52\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f4a3cb96f1098e79.svg\"><img class=\"math display-math\" src=\"assets/equations/b44984dd703daaf9.svg\" alt=\"a=\\frac1{8.389056099}\\approx0.119202922\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/154ffcd0747b53aa.svg\"><img class=\"math display-math\" src=\"assets/equations/61cf4a9551a25fd6.svg\" alt=\"f\\prime(-2)=(0.119202922)(1-0.119202922)\\approx0.104993585\" width=\"602.56\" height=\"24.43\" style=\"width:602.56px;height:24.43px;aspect-ratio:602.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.119202922. Derivative ≈ 0.104993585.</p>","<h3>sigmoid example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/17055d0f6bb7d8cb.svg\" alt=\"-z=-(0)=0\" width=\"157.99\" height=\"24.43\" style=\"width:157.99px;height:24.43px;aspect-ratio:157.99/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/88f353ee1ae5e616.svg\"><img class=\"math display-math\" src=\"assets/equations/048aaa762a498d29.svg\" alt=\"1+1.000000000\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/55f56d862c8a637f.svg\"><img class=\"math display-math\" src=\"assets/equations/bb9808b4290f77c2.svg\" alt=\"a=\\frac1{2.000000000}\\approx0.500000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5e112d2ee69475de.svg\"><img class=\"math display-math\" src=\"assets/equations/fe0302f0c6aecdca.svg\" alt=\"f\\prime(0)=(0.500000000)(1-0.500000000)\\approx0.250000000\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.500000000. Derivative ≈ 0.250000000.</p>","<h3>sigmoid example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the sigmoid output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = sigmoid.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3188e642a44baa47.svg\" alt=\"a=\\frac1{1+e^{-z}}\" width=\"133.24\" height=\"51.56\" style=\"width:133.24px;height:51.56px;aspect-ratio:133.24/51.56\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/97012822a1c7e305.svg\" alt=\"f\\prime(z)=a(1-a)\" width=\"170.07\" height=\"24.43\" style=\"width:170.07px;height:24.43px;aspect-ratio:170.07/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> One over one plus e ki minus-z power; slope = output × (1−output).</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: negate the whole input.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/cbbb55e23c6ba6a0.svg\" alt=\"-z=-(2)=-2\" width=\"177.00\" height=\"24.43\" style=\"width:177.00px;height:24.43px;aspect-ratio:177.00/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: add one in the denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/1264450d54002695.svg\"><img class=\"math display-math\" src=\"assets/equations/21d0f7a7fd447a52.svg\" alt=\"1+0.135335283\\approx1.135335283\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide one by the complete denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f08d0c34f5e2fdf7.svg\"><img class=\"math display-math\" src=\"assets/equations/6480e62e9ef0f8a2.svg\" alt=\"a=\\frac1{1.135335283}\\approx0.880797078\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: use the activated output in the slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:370.62px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/278a4098b6b446b4.svg\"><img class=\"math display-math\" src=\"assets/equations/00492ebf856c8aae.svg\" alt=\"f\\prime(2)=(0.880797078)(1-0.880797078)\\approx0.104993585\" width=\"583.56\" height=\"24.43\" style=\"width:583.56px;height:24.43px;aspect-ratio:583.56/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.880797078. Derivative ≈ 0.104993585.</p>"]},{"n":9,"title":"Tanh and its derivative","intro":["<p>Tanh can produce a negative or positive output. In the formula, calculate the exponential first, then form the top and bottom of the fraction separately. The derivative uses the activated answer, not the raw input.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a8ee72519b086209.svg\" alt=\"\\tanh(z)=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"194.78\" height=\"56.48\" style=\"width:194.78px;height:56.48px;aspect-ratio:194.78/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc7dbcac123b9229.svg\" alt=\"\\tanh\\prime(z)=1-\\tanh^2(z)\" width=\"254.66\" height=\"27.91\" style=\"width:254.66px;height:27.91px;aspect-ratio:254.66/27.91\" loading=\"lazy\"></div>"],"refs":[],"extra":["<p class=\"inline-question\"><strong>Question. Calculate tanh(0.5) and its derivative with respect to the input.</strong></p>","<h3>Given</h3>","<p>z = 0.5.</p>","<h3>To find</h3>","<p>Find tanh(z) and its derivative.</p>","<h3>Formula — which one and why</h3>","<p><strong>Tanh and its slope.</strong> Tanh preserves a signed output between −1 and 1. Once its output a is known, the local slope is 1−a².</p>","<p>z = value entering tanh; a = its output. A prime means derivative, or local rate of change.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/11b2c40e39b0ee66.svg\" alt=\"a=\\tanh z=\\frac{e^z-e^{-z}}{e^z+e^{-z}}\" width=\"239.38\" height=\"54.23\" style=\"width:239.38px;height:54.23px;aspect-ratio:239.38/54.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b6ac5e0c1df9b26.svg\" alt=\"\\frac{da}{dz}=1-a^2\" width=\"134.64\" height=\"50.50\" style=\"width:134.64px;height:50.50px;aspect-ratio:134.64/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh signed output deta hai; slope = 1 minus output ka square.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the input.</strong> The input z is 0.5. In this version of the tanh formula, the exponential uses 2z.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:246.27px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a761ae42b593cfbc.svg\"><img class=\"math display-math\" src=\"assets/equations/4ded3cb512b92053.svg\" alt=\"2z=2(0.5)=1,\\qquad e^{2z}=e^1\\approx2.718281828\" width=\"469.43\" height=\"27.70\" style=\"width:469.43px;height:27.70px;aspect-ratio:469.43/27.70\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 2: calculate the numerator.</strong> Subtract 1 from that exponential.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.72px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dc5e5624414a3d95.svg\"><img class=\"math display-math\" src=\"assets/equations/057c3c395fc07789.svg\" alt=\"e^{2z}-1=2.718281828-1=1.718281828\" width=\"437.36\" height=\"23.60\" style=\"width:437.36px;height:23.60px;aspect-ratio:437.36/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: calculate the denominator.</strong> Add 1 to the same exponential.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:233.72px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/343ff32a5ddf3a45.svg\"><img class=\"math display-math\" src=\"assets/equations/4ae221248ca27fec.svg\" alt=\"e^{2z}+1=2.718281828+1=3.718281828\" width=\"437.36\" height=\"23.60\" style=\"width:437.36px;height:23.60px;aspect-ratio:437.36/23.60\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide the top by the bottom.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:172.30px;--narrow-height:128.52px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ebe33ccb05db4c46.svg\"><img class=\"math display-math\" src=\"assets/equations/4b6a824a25e2320c.svg\" alt=\"a=\\tanh(0.5)=\\frac{1.718281828}{3.718281828}\\approx0.462117157\" width=\"478.49\" height=\"50.34\" style=\"width:478.49px;height:50.34px;aspect-ratio:478.49/50.34\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: calculate the local derivative.</strong> Square the output a and subtract it from 1. Keep the calculator&#x27;s unrounded result.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:227.23px;--narrow-height:70.07px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/de782b0d8cb8f7bb.svg\"><img class=\"math display-math\" src=\"assets/equations/19090a10397c086b.svg\" alt=\"a^2\\approx0.213552267,\\qquad1-a^2\\approx0.786447733\" width=\"472.10\" height=\"26.34\" style=\"width:472.10px;height:26.34px;aspect-ratio:472.10/26.34\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> tanh output ≈ 0.462117157; local derivative ≈ 0.786447733. The output becomes the next layer&#x27;s input; the derivative is used when carrying a gradient backward.</p>","<h3>tanh example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0ab8a21d8aab882c.svg\" alt=\"2z=2(-2)=-4\" width=\"182.43\" height=\"24.43\" style=\"width:182.43px;height:24.43px;aspect-ratio:182.43/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c3b8c152fd312b9.svg\" alt=\"e^{-4}\\approx0.018315639\" width=\"197.05\" height=\"22.32\" style=\"width:197.05px;height:22.32px;aspect-ratio:197.05/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/782210c69a20fd3b.svg\"><img class=\"math display-math\" src=\"assets/equations/38bd067833181d6c.svg\" alt=\"0.018315639-1\\approx-0.981684361\" width=\"351.62\" height=\"18.54\" style=\"width:351.62px;height:18.54px;aspect-ratio:351.62/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c7713b25655beb72.svg\"><img class=\"math display-math\" src=\"assets/equations/dee5ac5546f1b2f2.svg\" alt=\"0.018315639+1\\approx1.018315639\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:204.24px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/300fc0089c5516db.svg\"><img class=\"math display-math\" src=\"assets/equations/809bd6f34ad5f6a6.svg\" alt=\"a=\\frac{-0.981684361}{1.018315639}\\approx-0.964027580\" width=\"384.79\" height=\"50.36\" style=\"width:384.79px;height:50.36px;aspect-ratio:384.79/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:207.52px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/bb2d4ce554c14198.svg\"><img class=\"math display-math\" src=\"assets/equations/c4ff92106fa31931.svg\" alt=\"f\\prime(-2)=1-(-0.964027580)^2\\approx0.070650825\" width=\"484.27\" height=\"27.70\" style=\"width:484.27px;height:27.70px;aspect-ratio:484.27/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ -0.964027580. Derivative ≈ 0.070650825.</p>","<h3>tanh example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/83fefb855224c584.svg\" alt=\"2z=2(0)=0\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/40327f28206586d2.svg\"><img class=\"math display-math\" src=\"assets/equations/fa618ba26a236aab.svg\" alt=\"1.000000000-1\\approx0.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:171.05px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5e16c3256057084.svg\"><img class=\"math display-math\" src=\"assets/equations/46b371b545cc8bc8.svg\" alt=\"1.000000000+1\\approx2.000000000\" width=\"332.60\" height=\"18.27\" style=\"width:332.60px;height:18.27px;aspect-ratio:332.60/18.27\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:185.23px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/081512ac7f7a1b51.svg\"><img class=\"math display-math\" src=\"assets/equations/da7a029e0ae3e61f.svg\" alt=\"a=\\frac{0.000000000}{2.000000000}\\approx0.000000000\" width=\"346.78\" height=\"50.09\" style=\"width:346.78px;height:50.09px;aspect-ratio:346.78/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/d3899b5f76509b8c.svg\"><img class=\"math display-math\" src=\"assets/equations/b3f22ac5fb036f65.svg\" alt=\"f\\prime(0)=1-(0.000000000)^2\\approx1.000000000\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 1.000000000.</p>","<h3>tanh example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the tanh output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = tanh.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f6e15283db79ff2.svg\" alt=\"a=\\frac{e^{2z}-1}{e^{2z}+1}\" width=\"128.43\" height=\"56.48\" style=\"width:128.43px;height:56.48px;aspect-ratio:128.43/56.48\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e7efe34a06943be.svg\" alt=\"f\\prime(z)=1-a^2\" width=\"148.79\" height=\"27.70\" style=\"width:148.79px;height:27.70px;aspect-ratio:148.79/27.70\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Tanh ka answer −1 se 1; slope one minus output squared.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: double z before exponentiation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/28a6e73374f6be65.svg\" alt=\"2z=2(2)=4\" width=\"144.41\" height=\"24.43\" style=\"width:144.41px;height:24.43px;aspect-ratio:144.41/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the exponential.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dcc7f746c4400033.svg\" alt=\"e^{4}\\approx54.598150033\" width=\"195.81\" height=\"22.32\" style=\"width:195.81px;height:22.32px;aspect-ratio:195.81/22.32\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate numerator and denominator separately.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f63e045301bde055.svg\"><img class=\"math display-math\" src=\"assets/equations/a7f29872524e69fc.svg\" alt=\"54.598150033-1\\approx53.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:183.27px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2c86d55c9549cedd.svg\"><img class=\"math display-math\" src=\"assets/equations/1a7460c08ec0eb4e.svg\" alt=\"54.598150033+1\\approx55.598150033\" width=\"357.04\" height=\"18.54\" style=\"width:357.04px;height:18.54px;aspect-ratio:357.04/18.54\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: divide.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:197.45px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22a5642fac7a0997.svg\"><img class=\"math display-math\" src=\"assets/equations/9d5e297333003136.svg\" alt=\"a=\\frac{53.598150033}{55.598150033}\\approx0.964027580\" width=\"358.99\" height=\"50.09\" style=\"width:358.99px;height:50.09px;aspect-ratio:358.99/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 5: square the activated output for its slope.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:188.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/52d252bd261b679f.svg\"><img class=\"math display-math\" src=\"assets/equations/6f2d0c822236e436.svg\" alt=\"f\\prime(2)=1-(0.964027580)^2\\approx0.070650825\" width=\"446.25\" height=\"27.70\" style=\"width:446.25px;height:27.70px;aspect-ratio:446.25/27.70\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> a ≈ 0.964027580. Derivative ≈ 0.070650825.</p>"]},{"n":10,"title":"ReLU and its derivative","intro":["<p>ReLU compares its input with zero and keeps the larger value. Thus a negative input becomes zero and a positive input passes unchanged. Its slope is zero on the negative side and one on the positive side.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ad762a28c8a1a87.svg\" alt=\"f(z)=\\max(0,z)\" width=\"175.33\" height=\"24.43\" style=\"width:175.33px;height:24.43px;aspect-ratio:175.33/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/458083af5d5ba2ef.svg\" alt=\"f\\prime(z)=\\begin{cases}1&amp;z&gt;0\\\\0&amp;z&lt;0\\end{cases}\" width=\"194.26\" height=\"58.62\" style=\"width:194.26px;height:58.62px;aspect-ratio:194.26/58.62\" loading=\"lazy\"></div>"],"refs":["tee-c17-s8"],"extra":["<h3>ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fbc65c947d4ed97f.svg\" alt=\"f\\prime(-2)=0\" width=\"115.19\" height=\"24.43\" style=\"width:115.19px;height:24.43px;aspect-ratio:115.19/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Derivative ≈ 0.000000000.</p>","<h3>ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the ReLU output and state its derivative.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = ReLU.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e3267d2a19366c7b.svg\" alt=\"a=\\max(0,z)\" width=\"144.44\" height=\"24.43\" style=\"width:144.44px;height:24.43px;aspect-ratio:144.44/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>"]},{"n":11,"title":"Leaky ReLU","intro":["<p>Leaky ReLU changes only the negative side: multiply a negative input by the small slope α. That negative sign remains. The value α is supplied by the question or chosen as a model setting; it is not the sigmoid function.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3faffb967fafdf3.svg\" alt=\"f(z)=\\begin{cases}z&amp;z\\geq0\\\\az&amp;z&lt;0\\end{cases}\" width=\"199.61\" height=\"58.62\" style=\"width:199.61px;height:58.62px;aspect-ratio:199.61/58.62\" loading=\"lazy\"></div>"],"refs":["tee-c17-s8"],"extra":["<h3>Leaky ReLU example 1</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = -2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = -2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>-2 is negative, so use the negative branch.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24b81e63d794388e.svg\" alt=\"a=-0.2\" width=\"95.75\" height=\"18.27\" style=\"width:95.75px;height:18.27px;aspect-ratio:95.75/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/eaab86572902924a.svg\" alt=\"f\\prime(-2)=0.1\" width=\"134.21\" height=\"24.43\" style=\"width:134.21px;height:24.43px;aspect-ratio:134.21/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ -0.200000000. Derivative ≈ 0.100000000.</p>","<h3>Leaky ReLU example 2</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 0, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 0; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>Both branches meet at zero. The value is zero, but the left and right slopes differ.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e93d3c89fb4a0a4b.svg\" alt=\"a=0\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<p>The ordinary derivative at zero does not exist. A software subgradient convention may choose a value such as 0; state it if required.</p>","<p><strong>Final answer:</strong> a ≈ 0.000000000. Ordinary derivative is undefined at zero.</p>","<h3>Leaky ReLU example 3</h3>","<p class=\"inline-question\"><strong>Question. For preactivation z = 2, calculate the Leaky ReLU output and state its derivative. Use negative-side slope α = 0.1.</strong></p>","<h3>Given</h3>","<p>z = 2; activation = Leaky ReLU.</p>","<p>α = 0.1.</p>","<h3>To find</h3>","<p>The output a and the derivative with respect to z.</p>","<h3>Formula — which one and why</h3>","<p>Use the activation named in the question. The derivative is a second calculation required for a backward pass.</p>","<p>z is the raw sum; a is the activated output; f′(z) is the local slope.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ce8d71b3a5eb9dfc.svg\" alt=\"a=\\begin{cases}z&amp;z\\ge0\\\\0.1z&amp;z&lt;0\\end{cases}\" width=\"187.02\" height=\"58.62\" style=\"width:187.02px;height:58.62px;aspect-ratio:187.02/58.62\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Positive side slope 1; negative side ReLU 0, Leaky α. Zero par convention likho.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: select the branch from the sign of z.</strong></p>","<p>2 is positive, so retain it.</p>","<p class=\"worked-step\"><strong>Step 2: calculate the output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d3043f41a0385109.svg\" alt=\"a=2\" width=\"57.73\" height=\"18.27\" style=\"width:57.73px;height:18.27px;aspect-ratio:57.73/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: state the slope on that branch.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1b767f92de440262.svg\" alt=\"f\\prime(2)=1\" width=\"96.18\" height=\"24.43\" style=\"width:96.18px;height:24.43px;aspect-ratio:96.18/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> a ≈ 2.000000000. Derivative ≈ 1.000000000.</p>"]},{"n":12,"title":"Stable softmax","intro":["<p>Softmax turns several competing class scores into probabilities that add to one. Exponentiate each score, add those exponential values, and divide each one by their common total. Subtracting the same maximum score first gives the same probabilities with safer arithmetic.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>"],"refs":["tee-c17-s9"],"extra":["<h3>Softmax for [0, 0, 0]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [0, 0, 0].</strong></p>","<h3>Given</h3>","<p>Logits = [0, 0, 0]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7e35e2c8f440c3bf.svg\" alt=\"z-c=\\begin{bmatrix}0&amp;0&amp;0\\end{bmatrix}\" width=\"183.50\" height=\"24.43\" style=\"width:183.50px;height:24.43px;aspect-ratio:183.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5cbcea061b92c91b.svg\"><img class=\"math display-math\" src=\"assets/equations/77bfb08512787403.svg\" alt=\"D=1.000000000+1.000000000+1.000000000\\approx3.000000000\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/abb38634253b454f.svg\"><img class=\"math display-math\" src=\"assets/equations/aac567888a814ba9.svg\" alt=\"p_1=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6f93f83cf16d42a1.svg\"><img class=\"math display-math\" src=\"assets/equations/4e80a74382faa499.svg\" alt=\"p_2=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dd8dca9605ca9fba.svg\"><img class=\"math display-math\" src=\"assets/equations/932805d4a7ff7186.svg\" alt=\"p_3=\\frac{1.000000000}{3.000000000}\\approx0.333333333\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.333333333, 0.333333333, 0.333333333]; they sum to 1 within rounding.</p>","<h3>Softmax for [1, 2, 3]</h3>","<p class=\"inline-question\"><strong>Question. Find stable softmax probabilities for logits [1, 2, 3].</strong></p>","<h3>Given</h3>","<p>Logits = [1, 2, 3]; there are three mutually exclusive classes.</p>","<h3>To find</h3>","<p>All three class probabilities.</p>","<h3>Formula — which one and why</h3>","<p>Subtracting one common maximum preserves probabilities and keeps exponentials well scaled. Normalize using one shared sum.</p>","<p>A logit is a raw class score. c is the largest score; pᵢ is probability for class i.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c40885bb51eddb21.svg\" alt=\"c=\\max_j z_j\" width=\"113.22\" height=\"35.99\" style=\"width:113.22px;height:35.99px;aspect-ratio:113.22/35.99\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c7e5aa437b15aae.svg\" alt=\"p_i=\\frac{e^{z_i-c}}{\\sum_j e^{z_j-c}}\" width=\"151.48\" height=\"63.31\" style=\"width:151.48px;height:63.31px;aspect-ratio:151.48/63.31\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Max minus, e-power, same denominator se sab divide.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: subtract the largest score from every entry.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/36a969786afa504d.svg\" alt=\"z-c=\\begin{bmatrix}-2&amp;-1&amp;0\\end{bmatrix}\" width=\"221.52\" height=\"24.43\" style=\"width:221.52px;height:24.43px;aspect-ratio:221.52/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: exponentiate shifted entry 1.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9f6c4ea0634c6cc7.svg\" alt=\"e^{-2}\\approx0.135335283\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: exponentiate shifted entry 2.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c8b081af8baa5f1b.svg\" alt=\"e^{-1}\\approx0.367879441\" width=\"197.05\" height=\"22.14\" style=\"width:197.05px;height:22.14px;aspect-ratio:197.05/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: exponentiate shifted entry 3.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6b377e92ad2fd68c.svg\" alt=\"e^{0}\\approx1.000000000\" width=\"183.60\" height=\"22.14\" style=\"width:183.60px;height:22.14px;aspect-ratio:183.60/22.14\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: add all exponentials into one denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:181.79px;--narrow-height:141.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ff6afad7c399e8cd.svg\"><img class=\"math display-math\" src=\"assets/equations/3e8d536144b8581d.svg\" alt=\"D=0.135335283+0.367879441+1.000000000\\approx1.503214724\" width=\"661.00\" height=\"18.69\" style=\"width:661.00px;height:18.69px;aspect-ratio:661.00/18.69\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: divide entry 1 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/60d7f2c1aed7f3ca.svg\"><img class=\"math display-math\" src=\"assets/equations/806ad5813b3ff8c0.svg\" alt=\"p_1=\\frac{0.135335283}{1.503214724}\\approx0.090030573\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 7: divide entry 2 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.46px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/958d44e6661ca616.svg\"><img class=\"math display-math\" src=\"assets/equations/a839a3e6b8973897.svg\" alt=\"p_2=\\frac{0.367879441}{1.503214724}\\approx0.244728471\" width=\"356.81\" height=\"50.36\" style=\"width:356.81px;height:50.36px;aspect-ratio:356.81/50.36\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 8: divide entry 3 by the same denominator.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:195.25px;--narrow-height:89.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6153a5efe8276ec2.svg\"><img class=\"math display-math\" src=\"assets/equations/fdcbdba7b8490dd2.svg\" alt=\"p_3=\\frac{1.000000000}{1.503214724}\\approx0.665240956\" width=\"356.81\" height=\"50.09\" style=\"width:356.81px;height:50.09px;aspect-ratio:356.81/50.09\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Probabilities ≈ [0.090030573, 0.244728471, 0.665240956]; they sum to 1 within rounding.</p>"]},{"n":13,"title":"Squared and absolute losses","intro":["<p>SSE, half SSE and MSE start with the same errors but apply different final divisions. First understand what an error and its square mean. The full question below keeps all three answers separate.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a288e1ba23bc9347.svg\" alt=\"\\mathrm{SSE}=\\sum_i(o_i-y_i)^2\" width=\"211.02\" height=\"52.35\" style=\"width:211.02px;height:52.35px;aspect-ratio:211.02/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1bdd5bbb9ca64f61.svg\" alt=\"L_{\\mathrm{half}}=\\frac{\\mathrm{SSE}}2\" width=\"135.29\" height=\"50.50\" style=\"width:135.29px;height:50.50px;aspect-ratio:135.29/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bdee7885d635e78c.svg\" alt=\"L_{\\mathrm{MSE}}=\\frac{\\mathrm{SSE}}n\" width=\"143.04\" height=\"50.77\" style=\"width:143.04px;height:50.77px;aspect-ratio:143.04/50.77\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42ae3654ddbdf33e.svg\" alt=\"L_{\\mathrm{MAE}}=\\frac1n\\sum_i|o_i-y_i|\" width=\"243.92\" height=\"61.92\" style=\"width:243.92px;height:61.92px;aspect-ratio:243.92/61.92\" loading=\"lazy\"></div>"],"refs":["tee-c2-s9","tee-c17-s2"],"extra":["<h3>Absolute error uses a different operation</h3>","<p class=\"inline-question\"><strong>Question. Targets are [2, 4] and predictions are [1, 6]. Find mean absolute error.</strong></p>","<h3>Given</h3>","<p>Targets = [2,4]; predictions = [1,6]; n = 2.</p>","<h3>To find</h3>","<p>Find mean absolute error.</p>","<h3>Formula — which one and why</h3>","<p><strong>Mean absolute error.</strong> Absolute value removes the sign of each prediction error without squaring its magnitude. Average those magnitudes.</p>","<p>n = number of predictions. |e| means the nonnegative magnitude of error e.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/da84fa0919b7d150.svg\" alt=\"\\mathrm{MAE}=\\frac1n\\sum_i|\\hat y_i-y_i|\" width=\"242.18\" height=\"61.92\" style=\"width:242.18px;height:61.92px;aspect-ratio:242.18/61.92\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> MAE mein magnitude; MSE mein square.</p>","<h3>Solution — step by step</h3>","<p>The signed errors are 1 − 2 = −1 and 6 − 4 = 2. Absolute value keeps the size of a number without its sign, so their absolute errors are 1 and 2. Add them to obtain 3. There are two prediction–target pairs, so divide by 2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.98px;--narrow-height:155.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/506b26dfbefb2185.svg\"><img class=\"math display-math\" src=\"assets/equations/1aaa963ebac2df98.svg\" alt=\"\\mathrm{MAE}=\\frac{|1-2|+|6-4|}{2}=\\frac{1+2}{2}=1.5\" width=\"427.81\" height=\"52.41\" style=\"width:427.81px;height:52.41px;aspect-ratio:427.81/52.41\" loading=\"lazy\"></picture></div>","<p><strong>Final answer: MAE = 1.5.</strong> Do not square the errors for MAE.</p>"]},{"n":14,"title":"Binary cross entropy","intro":["<p>Binary cross-entropy measures how much probability was assigned to the correct binary answer. A target of 1 keeps the −ln(p) term; a target of 0 keeps the −ln(1−p) term. The factors y and 1−y select the appropriate term.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c17-s7"],"extra":["<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fcb072c6f4519069.svg\" alt=\"p=0.8\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4d6b8e2a24a05d6f.svg\" alt=\"\\ln(0.8)\\approx-0.223143551\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/65af868a518fd08e.svg\"><img class=\"math display-math\" src=\"assets/equations/710d02f73efd4006.svg\" alt=\"L=-(-0.223143551)=0.223143551\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.223143551 nats.</p>","<h3>Binary cross-entropy: target 0, predicted positive-class probability 0.8</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.8. The target is y = 0. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 0; p = P(y=1) = 0.8; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/438398f064595bb7.svg\" alt=\"1-p=1-0.8=0.2\" width=\"224.09\" height=\"21.02\" style=\"width:224.09px;height:21.02px;aspect-ratio:224.09/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a82bb66e18d1bf7c.svg\" alt=\"\\ln(0.2)\\approx-1.609437912\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fe3e4a4ff07bc0e0.svg\"><img class=\"math display-math\" src=\"assets/equations/8a78ffe2df23393c.svg\" alt=\"L=-(-1.609437912)=1.609437912\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 1.609437912 nats.</p>","<h3>Binary cross-entropy: target 1, predicted positive-class probability 0.5</h3>","<p class=\"inline-question\"><strong>Question. A binary classifier predicts P(y=1) = 0.5. The target is y = 1. Calculate binary cross-entropy using natural logarithms.</strong></p>","<h3>Given</h3>","<p>Target y = 1; p = P(y=1) = 0.5; use natural log ln.</p>","<h3>To find</h3>","<p>The binary cross-entropy loss for this one example.</p>","<h3>Formula — which one and why</h3>","<p>The target selects the probability assigned to the correct class. Take its negative natural logarithm.</p>","<p>p is always the probability of class 1. When y = 0, the correct-class probability is 1−p.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e55d3d5e343976d3.svg\" alt=\"L=-[y\\ln p+(1-y)\\ln(1-p)]\" width=\"335.38\" height=\"24.43\" style=\"width:335.38px;height:24.43px;aspect-ratio:335.38/24.43\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> True class ki probability lo, uska minus ln lo.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: identify the correct-class probability.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8c8d4b00d7d4788e.svg\" alt=\"p=0.5\" width=\"76.11\" height=\"21.02\" style=\"width:76.11px;height:21.02px;aspect-ratio:76.11/21.02\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: evaluate its natural logarithm.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/89c211e38f586f86.svg\" alt=\"\\ln(0.5)\\approx-0.693147181\" width=\"251.18\" height=\"24.43\" style=\"width:251.18px;height:24.43px;aspect-ratio:251.18/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: apply the minus sign outside the logarithm.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:235.22px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e0e8fd22135c9d7b.svg\"><img class=\"math display-math\" src=\"assets/equations/4bf6a8c1047d0f4a.svg\" alt=\"L=-(-0.693147181)=0.693147181\" width=\"396.77\" height=\"24.43\" style=\"width:396.77px;height:24.43px;aspect-ratio:396.77/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Loss ≈ 0.693147181 nats.</p>"]},{"n":15,"title":"Categorical cross entropy","intro":["<p>For one-hot multiclass targets, only one target entry is 1. The other entries are zero, so the loss becomes minus the logarithm of the true class probability. The worked question first calculates every softmax probability, then selects the correct one.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/feb21e9c89a912d7.svg\" alt=\"H(p,q)=-\\sum_i p_i\\ln q_i\" width=\"237.82\" height=\"52.35\" style=\"width:237.82px;height:52.35px;aspect-ratio:237.82/52.35\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/945fabaced090f8f.svg\" alt=\"\\log_2q=\\frac{\\ln q}{\\ln2}\" width=\"137.21\" height=\"50.24\" style=\"width:137.21px;height:50.24px;aspect-ratio:137.21/50.24\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.42px;--narrow-height:91.43px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea93bf47748eb958.svg\"><img class=\"math display-math\" src=\"assets/equations/abecd65b7d7b5753.svg\" alt=\"L=-\\sum_i y_i\\ln p_i=-\\ln p_{true}\" width=\"306.83\" height=\"52.35\" style=\"width:306.83px;height:52.35px;aspect-ratio:306.83/52.35\" loading=\"lazy\"></picture></div>"],"refs":["tee-c4-s20","tee-c17-s9"],"extra":[]},{"n":16,"title":"Output delta for half squared loss","intro":["<p>Delta is a short name for the loss derivative with respect to a neuron’s raw input z. For half squared loss, multiply prediction minus target by the activation’s derivative. The result is then multiplied by an incoming activation to obtain a weight gradient.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/dc1948e719d0e70b.svg\" alt=\"\\delta^{out}=(o-y)f\\prime(z)\" width=\"193.19\" height=\"27.01\" style=\"width:193.19px;height:27.01px;aspect-ratio:193.19/27.01\" loading=\"lazy\"></div>"],"refs":["tee-c3-s8","tee-c4-s19","tee-c17-s10","tee-c17-s13","tee-c17-s14"],"extra":[]},{"n":17,"title":"Sigmoid plus BCE; softmax plus CCE","intro":["<p>Some activation–loss pairs simplify together. Sigmoid with binary cross-entropy, and softmax with one-hot categorical cross-entropy, give prediction minus target at the raw-score level. This result already includes the activation’s effect.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/154ed49b87099426.svg\" alt=\"\\delta^{out}=p-y\" width=\"124.09\" height=\"25.92\" style=\"width:124.09px;height:25.92px;aspect-ratio:124.09/25.92\" loading=\"lazy\"></div>"],"refs":["tee-c17-s7"],"extra":["<h3>The multiclass version, entry by entry</h3>","<p class=\"inline-question\"><strong>Question. Softmax probabilities are [0.1, 0.8, 0.1] and the one-hot target is [0, 1, 0]. For categorical cross-entropy on this one example, find the derivatives with respect to all three logits.</strong></p>","<h3>Given</h3>","<p>Softmax probabilities = [0.1,0.8,0.1]; target = [0,1,0].</p>","<p>One-example categorical cross-entropy.</p>","<h3>To find</h3>","<p>Find all three logit derivatives.</p>","<h3>Formula — which one and why</h3>","<p><strong>Softmax with categorical cross-entropy.</strong> For one example with one-hot target, differentiating softmax together with CCE simplifies the logit derivative to predicted probability minus target.</p>","<p>zᵢ = raw score before softmax; pᵢ = class probability; yᵢ = matching target entry.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f0494c85fef2342.svg\" alt=\"\\frac{\\partial L}{\\partial z_i}=p_i-y_i\" width=\"146.63\" height=\"54.60\" style=\"width:146.63px;height:54.60px;aspect-ratio:146.63/54.60\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Softmax + CCE together: p minus y. Extra sigmoid slope nahi.</p>","<h3>Solution — step by step</h3>","<p>A logit is the raw score before softmax. Subtract each target entry from its matching probability entry.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b1d662617a540534.svg\" alt=\"\\frac{\\partial L}{\\partial z_1}=0.1-0=0.1\" width=\"216.32\" height=\"54.41\" style=\"width:216.32px;height:54.41px;aspect-ratio:216.32/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ed27397a5b5cfeec.svg\" alt=\"\\frac{\\partial L}{\\partial z_2}=0.8-1=-0.2\" width=\"235.33\" height=\"54.41\" style=\"width:235.33px;height:54.41px;aspect-ratio:235.33/54.41\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/64941f713e55940c.svg\" alt=\"\\frac{\\partial L}{\\partial z_3}=0.1-0=0.1\" width=\"216.32\" height=\"54.80\" style=\"width:216.32px;height:54.80px;aspect-ratio:216.32/54.80\" loading=\"lazy\"></div>","<p><strong>Final answer: [0.1, −0.2, 0.1].</strong> Do not multiply these by a separate sigmoid derivative or by p(1−p). A mean over several examples introduces the corresponding averaging factor.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=1</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 1. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 1; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/55554414edc61afc.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-1}{0.16}=-1.25\" width=\"251.78\" height=\"54.97\" style=\"width:251.78px;height:54.97px;aspect-ratio:251.78/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:216.60px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/352e50cd272ef421.svg\"><img class=\"math display-math\" src=\"assets/equations/b564b0f8f85410b8.svg\" alt=\"\\frac{dL}{dz}=(-1.25)(0.16)=-0.2\" width=\"299.42\" height=\"50.50\" style=\"width:299.42px;height:50.50px;aspect-ratio:299.42/50.50\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> dL/dz = -0.2. No further sigmoid derivative is needed.</p>","<h3>Sigmoid+BCE logit gradient: p=0.8, y=0</h3>","<p class=\"inline-question\"><strong>Question. A sigmoid output is p = 0.8 and target y = 0. For binary cross-entropy on one example, find the derivative with respect to the pre-sigmoid score z.</strong></p>","<h3>Given</h3>","<p>p = 0.8; y = 0; single-example BCE; p = sigmoid(z).</p>","<h3>To find</h3>","<p>dL/dz, not dL/dp.</p>","<h3>Formula — which one and why</h3>","<p>Apply the chain rule to BCE followed backward through sigmoid. The factors p(1−p) cancel, leaving p−y.</p>","<p>p is an activated probability; z is its raw score; the requested derivative is with respect to z.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6db0182710f5e684.svg\" alt=\"\\frac{dL}{dp}=\\frac{p-y}{p(1-p)}\" width=\"169.11\" height=\"56.93\" style=\"width:169.11px;height:56.93px;aspect-ratio:169.11/56.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0c0df88360e53bd3.svg\" alt=\"\\frac{dp}{dz}=p(1-p)\" width=\"154.01\" height=\"50.50\" style=\"width:154.01px;height:50.50px;aspect-ratio:154.01/50.50\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2e2f1b40461ded43.svg\" alt=\"\\frac{dL}{dz}=p-y\" width=\"126.81\" height=\"50.50\" style=\"width:126.81px;height:50.50px;aspect-ratio:126.81/50.50\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> BCE + sigmoid together ka shortcut p−y; chain already included.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the sigmoid slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1d74c616a26b88e.svg\" alt=\"p(1-p)=0.8(0.2)=0.16\" width=\"275.76\" height=\"24.43\" style=\"width:275.76px;height:24.43px;aspect-ratio:275.76/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: differentiate BCE with respect to p.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcb217487ddffdd.svg\" alt=\"\\frac{dL}{dp}=\\frac{0.8-0}{0.16}=5\" width=\"201.55\" height=\"54.97\" style=\"width:201.55px;height:54.97px;aspect-ratio:201.55/54.97\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: multiply the two local derivatives.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/86de3ab6d9deb754.svg\" alt=\"\\frac{dL}{dz}=(5)(0.16)=0.8\" width=\"230.17\" height=\"50.50\" style=\"width:230.17px;height:50.50px;aspect-ratio:230.17/50.50\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> dL/dz = 0.8. No further sigmoid derivative is needed.</p>"]},{"n":18,"title":"Hidden delta, weight gradient and bias gradient","intro":["<p>A hidden neuron can influence several outputs. Add all those backward contributions before multiplying by its own activation derivative. For each connection, use the receiving neuron’s delta and the sending neuron’s activation. Keep the old weights unchanged until all gradients have been found.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7a85cefe361f399b.svg\" alt=\"\\delta_j^h=f\\prime(z_j^h)\\sum_k w_{kj}^{out}\\delta_k^{out}\" width=\"242.75\" height=\"52.91\" style=\"width:242.75px;height:52.91px;aspect-ratio:242.75/52.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c4e0f7ded9389700.svg\" alt=\"\\frac{\\partial L}{\\partial w_{ji}}=\\delta_j a_i\" width=\"130.68\" height=\"57.94\" style=\"width:130.68px;height:57.94px;aspect-ratio:130.68/57.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b9f5adb924b1f09e.svg\" alt=\"\\frac{\\partial L}{\\partial b_j}=\\delta_j\" width=\"96.79\" height=\"57.94\" style=\"width:96.79px;height:57.94px;aspect-ratio:96.79/57.94\" loading=\"lazy\"></div>"],"refs":["tee-c4-s15","tee-c4-s14","tee-c17-s13","tee-c17-s14","tee-c17-s15"],"extra":[]},{"n":19,"title":"Gradient descent","intro":["<p>A gradient tells us the local direction in which loss rises. Gradient descent subtracts a small multiple of that gradient. Learning rate η controls the size of this correction. After the first update, calculate the next gradient at the new parameter.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/84b9c6c86f29aa06.svg\" alt=\"\\theta_{new}=\\theta-\\eta g\" width=\"141.99\" height=\"22.51\" style=\"width:141.99px;height:22.51px;aspect-ratio:141.99/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ac6a050d5a887603.svg\" alt=\"g=\\frac{\\partial J}{\\partial\\theta}\" width=\"84.28\" height=\"51.29\" style=\"width:84.28px;height:51.29px;aspect-ratio:84.28/51.29\" loading=\"lazy\"></div>"],"refs":["tee-c5-s0","tee-c5-s3","tee-c17-s18","tee-c17-s19","tee-c17-s6"],"extra":[]},{"n":20,"title":"Batch and mini-batch gradient","intro":["<p>A batch is a group of training examples used together for one update. An epoch is one pass through the dataset. Averaging gradients and counting updates are different questions, so both receive complete worked examples below.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/af742484e9a4fffc.svg\" alt=\"g_{batch}=\\frac1B\\sum_{i=1}^{B}g_i\" width=\"178.86\" height=\"72.79\" style=\"width:178.86px;height:72.79px;aspect-ratio:178.86/72.79\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/24d8d40909055c78.svg\" alt=\"U_{epoch}=\\left\\lceil\\frac NB\\right\\rceil\" width=\"154.80\" height=\"58.62\" style=\"width:154.80px;height:58.62px;aspect-ratio:154.80/58.62\" loading=\"lazy\"></div>"],"refs":["tee-c5-s5","tee-c5-s6","tee-c17-s16","tee-c17-s17"],"extra":[]},{"n":21,"title":"Momentum: signed velocity","intro":["<p>Momentum carries some of the previous movement into the next update. Here v is signed movement, so the new parameter is the old parameter plus v. A negative v moves the parameter down. Use the same convention throughout the calculation.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14e98f110476e8df.svg\" alt=\"v_t=\\beta v_{t-1}-\\eta g_t\" width=\"170.66\" height=\"22.51\" style=\"width:170.66px;height:22.51px;aspect-ratio:170.66/22.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14de701208151b5b.svg\" alt=\"\\theta_t=\\theta_{t-1}+v_t\" width=\"144.10\" height=\"22.31\" style=\"width:144.10px;height:22.31px;aspect-ratio:144.10/22.31\" loading=\"lazy\"></div>"],"refs":["tee-c5-s11","tee-c5-s9","tee-c17-s20","tee-c17-s21"],"extra":[]},{"n":22,"title":"Nesterov: look-ahead gradient","intro":["<p>Nesterov first uses the old movement to choose a temporary look-ahead position. It measures the gradient there, calculates the new movement, then adds that movement to the original parameter. The temporary look-ahead position does not replace the original parameter in the final addition.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/47358875d94f2558.svg\" alt=\"\\theta_{look}=\\theta+\\beta v\" width=\"144.00\" height=\"21.97\" style=\"width:144.00px;height:21.97px;aspect-ratio:144.00/21.97\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9d756d38e5b7933.svg\" alt=\"v_{new}=\\beta v-\\eta g(\\theta_{look})\" width=\"220.01\" height=\"24.43\" style=\"width:220.01px;height:24.43px;aspect-ratio:220.01/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/73afc93b70062b2d.svg\" alt=\"\\theta_{new}=\\theta+v_{new}\" width=\"162.85\" height=\"21.08\" style=\"width:162.85px;height:21.08px;aspect-ratio:162.85/21.08\" loading=\"lazy\"></div>"],"refs":["tee-c5-s10","tee-c17-s22","tee-c17-s23"],"extra":[]},{"n":23,"title":"AdaGrad","intro":["<p>AdaGrad stores a running sum of squared gradients for each parameter. Squaring removes the sign only in this stored total. The unsquared gradient in the numerator still decides the direction of the update.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2633d5c0ed034026.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{G_t}+\\epsilon}\" width=\"222.84\" height=\"52.24\" style=\"width:222.84px;height:52.24px;aspect-ratio:222.84/52.24\" loading=\"lazy\"></div>"],"refs":["tee-c5-s12","tee-c17-s24","tee-c17-s25"],"extra":[]},{"n":24,"title":"RMSProp","intro":["<p>RMSProp remembers a weighted average of squared gradients. With decay 0.9, keep 90% of the old stored value and add 10% of the new squared gradient. Calculate this new stored value before taking its square root and updating the parameter.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8de35fe2ee69fe63.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta g_t}{\\sqrt{s_t}+\\epsilon}\" width=\"215.09\" height=\"52.24\" style=\"width:215.09px;height:52.24px;aspect-ratio:215.09/52.24\" loading=\"lazy\"></div>"],"refs":["tee-c5-s8","tee-c5-s13","tee-c17-s26","tee-c17-s27"],"extra":[]},{"n":25,"title":"Adam: both memories","intro":["<p>Adam keeps two separate running averages. The first remembers signed gradients and can be negative. The second remembers squared gradients and is nonnegative. These stored averages are not weights, and they are not extra gradients to multiply together.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c684b3ce4733fb3b.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t\" width=\"273.99\" height=\"24.43\" style=\"width:273.99px;height:24.43px;aspect-ratio:273.99/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/caedeeee27912e58.svg\" alt=\"v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"257.18\" height=\"27.82\" style=\"width:257.18px;height:27.82px;aspect-ratio:257.18/27.82\" loading=\"lazy\"></div>"],"refs":["tee-c5-s1","tee-c5-s14","tee-c17-s28","tee-c17-s29"],"extra":[]},{"n":26,"title":"Adam: correction and update","intro":["<p>Adam starts its two averages at zero. Early averages therefore contain less total weight on observed gradients. Bias correction compensates for that initialization. The power in βᵗ uses the current update number, and both averages must be corrected before the parameter update.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4c24c9160cc537a1.svg\" alt=\"\\widehat m_t=\\frac{m_t}{1-\\beta_1^t}\" width=\"139.63\" height=\"53.25\" style=\"width:139.63px;height:53.25px;aspect-ratio:139.63/53.25\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a9f81435f55f92a6.svg\" alt=\"\\widehat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"130.03\" height=\"53.28\" style=\"width:130.03px;height:53.28px;aspect-ratio:130.03/53.28\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8fbedcf992dd719a.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\eta\\frac{\\widehat m_t}{\\sqrt{\\widehat v_t}+\\epsilon}\" width=\"231.71\" height=\"66.85\" style=\"width:231.71px;height:66.85px;aspect-ratio:231.71/66.85\" loading=\"lazy\"></div>"],"refs":["tee-c5-s15","tee-c5-s14","tee-c17-s28","tee-c17-s29"],"extra":[]},{"n":27,"title":"L1 penalty and update","intro":["<p>L1 adds a cost based on the absolute sizes of weights. Its derivative is positive for a positive weight and negative for a negative weight. The optimizer adds this penalty gradient to the data gradient before applying the usual update.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/14b76928315b8569.svg\" alt=\"J=L+\\lambda\\sum_j|w_j|\" width=\"192.47\" height=\"55.67\" style=\"width:192.47px;height:55.67px;aspect-ratio:192.47/55.67\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e25593d3f219dc71.svg\" alt=\"w_{new}=w-\\eta\\left[g_{data}+\\lambda\\operatorname{sign}(w)\\right]\" width=\"334.16\" height=\"24.43\" style=\"width:334.16px;height:24.43px;aspect-ratio:334.16/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c6-s2","tee-c6-s1","tee-c17-s31","tee-c17-s30","tee-c17-s47"],"extra":[]},{"n":28,"title":"L2 penalty and update with a half","intro":["<p>L2 adds a cost based on squared weights. Differentiating a square produces a factor of 2. If the objective includes a half, that half cancels the 2; if it does not, the 2 remains. Read the objective before choosing the gradient.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/119bfafa31acc3ba.svg\" alt=\"J=L+\\frac\\lambda2\\sum_jw_j^2\" width=\"191.15\" height=\"65.94\" style=\"width:191.15px;height:65.94px;aspect-ratio:191.15/65.94\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/349319f842d12440.svg\" alt=\"w_{new}=w-\\eta(g_{data}+\\lambda w)\" width=\"270.21\" height=\"24.43\" style=\"width:270.21px;height:24.43px;aspect-ratio:270.21/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c6-s1","tee-c17-s32","tee-c17-s30","tee-c17-s47"],"extra":[]},{"n":29,"title":"Inverted dropout","intro":["<p>Inverted dropout uses a mask: zero means drop this activation, one means keep it. During training, divide each retained activation by the keep probability. During inference, dropout is disabled and this training-time division is not repeated.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/536be85758e6d02d.svg\" alt=\"q=1-p\" width=\"98.20\" height=\"21.02\" style=\"width:98.20px;height:21.02px;aspect-ratio:98.20/21.02\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/504d04d32df8a91c.svg\" alt=\"a_{train}=\\frac{m\\odot a}{q}\" width=\"162.03\" height=\"52.26\" style=\"width:162.03px;height:52.26px;aspect-ratio:162.03/52.26\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1251aa7fa418d32.svg\" alt=\"a_{test}=a\" width=\"89.09\" height=\"18.10\" style=\"width:89.09px;height:18.10px;aspect-ratio:89.09/18.10\" loading=\"lazy\"></div>"],"refs":["tee-c6-s8","tee-c6-s3","tee-c17-s33","tee-c17-s48"],"extra":[]},{"n":30,"title":"Convolution output dimensions","intro":["<p>This formula counts how many legal filter positions fit along one image dimension. Padding adds space at both ends, the kernel occupies K positions, and stride controls how far the next window moves. The floor keeps only complete valid positions.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.70px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f467d926f905df6d.svg\"><img class=\"math display-math\" src=\"assets/equations/b7c680fad37aede4.svg\" alt=\"N_{out}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"293.79\" height=\"58.62\" style=\"width:293.79px;height:58.62px;aspect-ratio:293.79/58.62\" loading=\"lazy\"></picture></div>"],"refs":["tee-c7-s0","tee-c7-s3","tee-c7-s18","tee-c17-s35"],"extra":[]},{"n":31,"title":"Convolution value","intro":["<p>One convolution output is a sum of matched input–kernel products. Move the window and repeat that exact rule for the next output. With several input channels, add contributions from every channel and add the filter bias once.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:380.25px;--narrow-height:130.78px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e5afb61a6d5f3879.svg\"><img class=\"math display-math\" src=\"assets/equations/0fcf0c4134fa9fe3.svg\" alt=\"Y_{ij,o}=\\sum_c\\sum_u\\sum_v K_{uvco}X_{iS+u-P,jS+v-P,c}+b_o\" width=\"473.49\" height=\"51.51\" style=\"width:473.49px;height:51.51px;aspect-ratio:473.49/51.51\" loading=\"lazy\"></picture></div>"],"refs":["tee-c7-s5","tee-c7-s14","tee-c7-s15","tee-c7-s2","tee-c17-s34","tee-c17-s46"],"extra":[]},{"n":32,"title":"Max, min and average pooling","intro":["<p>Pooling reduces each window to one value. Max pooling keeps the largest entry; average pooling adds all included entries and divides by their count. Pooling is performed independently in each channel.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/619bb1c028de4233.svg\" alt=\"y_{\\min}=\\min(x_1,x_2,x_3,x_4)\" width=\"266.30\" height=\"24.43\" style=\"width:266.30px;height:24.43px;aspect-ratio:266.30/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/79973536a2057db8.svg\" alt=\"y_{max}=\\max_{(i,j)\\in W}x_{ij}\" width=\"174.90\" height=\"38.32\" style=\"width:174.90px;height:38.32px;aspect-ratio:174.90/38.32\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bd2034a9c3d7a387.svg\" alt=\"y_{avg}=\\frac1{|W|}\\sum_{(i,j)\\in W}x_{ij}\" width=\"220.47\" height=\"67.59\" style=\"width:220.47px;height:67.59px;aspect-ratio:220.47/67.59\" loading=\"lazy\"></div>"],"refs":["tee-c7-s7","tee-c7-s16","tee-c17-s36","tee-c17-s46"],"extra":[]},{"n":33,"title":"Convolution parameter count","intro":["<p>A filter has one learned weight for each spatial position in each input channel. Count the weights in one filter, add its one bias, then multiply by the number of filters. Sliding a filter to many positions reuses these weights; it does not create new parameters.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.37px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8a253f24fdf99d8e.svg\"><img class=\"math display-math\" src=\"assets/equations/bd7e05cdd2c763eb.svg\" alt=\"P_{conv}=(K_hK_wC_{in}+1)C_{out}\" width=\"293.70\" height=\"24.43\" style=\"width:293.70px;height:24.43px;aspect-ratio:293.70/24.43\" loading=\"lazy\"></picture></div>"],"refs":["tee-c7-s12","tee-c7-s13","tee-c7-s17","tee-c7-s8","tee-c17-s37"],"extra":[]},{"n":34,"title":"Flatten and dense parameter count","intro":["<p>Flattening rearranges all activation values into a list. It learns no new numbers. A dense layer then connects every value in that list to every receiving neuron; each receiving neuron also has one bias.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/31ebc79afc790262.svg\" alt=\"N_{flat}=HWC\" width=\"150.14\" height=\"24.43\" style=\"width:150.14px;height:24.43px;aspect-ratio:150.14/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c28314915c655018.svg\" alt=\"P_{dense}=(N_{in}+1)N_{out}\" width=\"239.08\" height=\"24.43\" style=\"width:239.08px;height:24.43px;aspect-ratio:239.08/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c4-s17","tee-c7-s9","tee-c17-s37","tee-c17-s49"],"extra":[]},{"n":35,"title":"Convolution multiply-accumulate count","intro":["<p>A parameter count counts learned numbers. A multiply-accumulate count counts how many times input–weight products are used. One filter is reused at every output position, so computation includes output height and width even though its parameter count does not.</p>"],"formulas":["<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:276.71px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/7d20bfcc57cb122e.svg\"><img class=\"math display-math\" src=\"assets/equations/86ffc171b254aab9.svg\" alt=\"MAC=H_{out}W_{out}K_hK_wC_{in}C_{out}\" width=\"339.28\" height=\"21.35\" style=\"width:339.28px;height:21.35px;aspect-ratio:339.28/21.35\" loading=\"lazy\"></picture></div>"],"refs":["tee-c8-s2","tee-c8-s14","tee-c17-s39"],"extra":["<h3>Bottleneck computation on an 8 × 8 input</h3>","<p class=\"inline-question\"><strong>Question. An 8 × 8 × 16 input must produce 8 channels using a same-padded 3 × 3 convolution. Compare direct computation with 1 × 1 reduction to 4 channels followed by the 3 × 3 layer. Count MACs and ignore bias additions.</strong></p>","<h3>Given</h3>","<p>Spatial output = 8 × 8 in both stages.</p>","<p>Input channels = 16; output filters = 8; main kernel = 3 × 3.</p>","<p>Bottleneck uses 4 filters of 1 × 1.</p>","<h3>To find</h3>","<p>Direct MACs, two-stage bottleneck MACs and savings.</p>","<h3>Formula — which one and why</h3>","<p>Each output scalar requires one multiply-accumulate per incoming kernel entry. A bottleneck reduces the input depth of the expensive spatial convolution.</p>","<p>One MAC is one multiply-accumulate pair. If counting multiplication and addition separately, the operation count is approximately twice the MAC count.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:276.19px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/40f8ac20e40ebe3e.svg\"><img class=\"math display-math\" src=\"assets/equations/13f4a3b9d3a03995.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K_hK_wC_{\\mathrm{in}}\" width=\"344.19\" height=\"21.35\" style=\"width:344.19px;height:21.35px;aspect-ratio:344.19/21.35\" loading=\"lazy\"></picture></div>","<p><strong>Yaad rakhne ka cue:</strong> Spatial kernel se pehle channels kam; dono stages ka cost add.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: count output positions per channel.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0917529398667f13.svg\" alt=\"8(8)=64\" width=\"100.46\" height=\"24.43\" style=\"width:100.46px;height:24.43px;aspect-ratio:100.46/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: count direct work per output scalar.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7b0c2720e21a1506.svg\" alt=\"3(3)(16)=144\" width=\"156.12\" height=\"24.43\" style=\"width:156.12px;height:24.43px;aspect-ratio:156.12/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: count the full direct layer.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/531722215214eb67.svg\" alt=\"64(8)(144)=73728\" width=\"204.99\" height=\"24.43\" style=\"width:204.99px;height:24.43px;aspect-ratio:204.99/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: count the 1 × 1 reduction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a619ccae82b20a14.svg\" alt=\"64(4)(1)(1)(16)=4096\" width=\"243.01\" height=\"24.43\" style=\"width:243.01px;height:24.43px;aspect-ratio:243.01/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: count the reduced-depth 3 × 3 layer.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f478849ec0c64569.svg\" alt=\"64(8)(3)(3)(4)=18432\" width=\"243.01\" height=\"24.43\" style=\"width:243.01px;height:24.43px;aspect-ratio:243.01/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 6: sum both bottleneck stages.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e4821e959cb7a516.svg\" alt=\"4096+18432=22528\" width=\"233.50\" height=\"18.54\" style=\"width:233.50px;height:18.54px;aspect-ratio:233.50/18.54\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 7: subtract to obtain savings.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/be3a4d13f46b02ba.svg\" alt=\"73728-22528=51200\" width=\"245.71\" height=\"18.52\" style=\"width:245.71px;height:18.52px;aspect-ratio:245.71/18.52\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> Direct = 73,728 MACs; bottleneck = 22,528 MACs; savings = 51,200 MACs.</p>"]},{"n":36,"title":"Concatenation and residual addition","intro":["<p>Concatenation and addition combine branches differently. Concatenation places channel groups next to each other and increases the channel count. Residual addition adds matching entries, so the two full shapes must be compatible.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/963754238ceb3b1d.svg\" alt=\"C_{concat}=\\sum_b C_b\" width=\"167.43\" height=\"52.91\" style=\"width:167.43px;height:52.91px;aspect-ratio:167.43/52.91\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d362a7b729c4f87f.svg\" alt=\"y_{res}=F(x)+x\" width=\"165.66\" height=\"24.43\" style=\"width:165.66px;height:24.43px;aspect-ratio:165.66/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c8-s7","tee-c8-s3","tee-c17-s51","tee-c17-s52","tee-c17-s40"],"extra":[]},{"n":37,"title":"Vanilla RNN","intro":["<p>A recurrent state uses two sources: the current input and the previous hidden state. Transform each with its own weight, add the contributions and bias, and apply tanh. The activated state—not its raw sum—is carried into the next time step.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/015d839835ad8254.svg\" alt=\"h_t=\\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h)\" width=\"361.62\" height=\"24.43\" style=\"width:361.62px;height:24.43px;aspect-ratio:361.62/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d195662850af1e7e.svg\" alt=\"o_t=W_{hy}h_t+b_y\" width=\"169.40\" height=\"24.16\" style=\"width:169.40px;height:24.16px;aspect-ratio:169.40/24.16\" loading=\"lazy\"></div>"],"refs":["tee-c9-s4","tee-c9-s5","tee-c17-s41"],"extra":[]},{"n":38,"title":"Perceptron update","intro":["<p>The perceptron uses a threshold to choose a class and an error-based learning rule to change weights. Its threshold convention must be stated, especially at zero. This discrete learning rule is different from sigmoid backpropagation.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9c6e513ba240f8dc.svg\" alt=\"\\widehat y=\\operatorname{step}(w^Tx+b)\" width=\"193.15\" height=\"27.90\" style=\"width:193.15px;height:27.90px;aspect-ratio:193.15/27.90\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/82b6f20b5710456c.svg\" alt=\"w_{new}=w+\\eta(y-\\widehat y)x\" width=\"229.21\" height=\"25.90\" style=\"width:229.21px;height:25.90px;aspect-ratio:229.21/25.90\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a75f55d01930a8a4.svg\" alt=\"b_{new}=b+\\eta(y-\\widehat y)\" width=\"201.20\" height=\"25.90\" style=\"width:201.20px;height:25.90px;aspect-ratio:201.20/25.90\" loading=\"lazy\"></div>"],"refs":["tee-c4-s8","tee-c17-s11"],"extra":[]},{"n":39,"title":"BPTT hidden delta","intro":["<p>At an RNN hidden state, a loss gradient can arrive from the current output and from the next time step. Add these two contributions, then multiply by the local activation derivative. The displayed output term p−y assumes softmax with categorical cross-entropy.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/77be07478b9cbea0.svg\" alt=\"\\delta_t=\\left[W_{hy}^T(p_t-y_t)+W_{hh}^T\\delta_{t+1}\\right]\\odot(1-h_t^2)\" width=\"437.03\" height=\"31.63\" style=\"width:437.03px;height:31.63px;aspect-ratio:437.03/31.63\" loading=\"lazy\"></div>"],"refs":["tee-c9-s6"],"extra":["<p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, the current hidden state is hₜ = 0.6. The current output path contributes 0.1 to the derivative with respect to hₜ. The next hidden preactivation has delta 0.4 and recurrent weight 0.5. Find the current hidden preactivation delta.</strong></p>","<h3>Given</h3>","<p>Current hₜ = 0.6; local output-path derivative = 0.1.</p>","<p>Next-step delta = 0.4; recurrent weight = 0.5; current activation = tanh.</p>","<h3>To find</h3>","<p>Find the current hidden preactivation delta.</p>","<h3>Formula — which one and why</h3>","<p><strong>Current and future recurrent paths.</strong> Add the local-output contribution and the weighted next-step delta, then multiply by the current tanh slope.</p>","<p>hₜ = current activated state; qₜ = current output-path derivative; u = recurrent weight; δₜ₊₁ = next-step preactivation delta.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Current path plus future path, phir current activation slope.</p>","<h3>Solution — step by step</h3>","<p>The next-step contribution must travel through the recurrent weight. Multiply that weight by the supplied next delta.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:202.49px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/76c508722fc577c7.svg\"><img class=\"math display-math\" src=\"assets/equations/71202ea5331ced5a.svg\" alt=\"\\text{future contribution}=0.5(0.4)=0.2\" width=\"380.34\" height=\"24.43\" style=\"width:380.34px;height:24.43px;aspect-ratio:380.34/24.43\" loading=\"lazy\"></picture></div>","<p>Add the current output-path contribution. These are two routes to the same hidden state, so addition is required.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6685e4ec204aeb2d.svg\" alt=\"\\frac{\\partial L}{\\partial h_t}=0.1+0.2=0.3\" width=\"235.65\" height=\"54.60\" style=\"width:235.65px;height:54.60px;aspect-ratio:235.65/54.60\" loading=\"lazy\"></div>","<p>The current activation is tanh. Its derivative uses the current activated value hₜ.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:247.20px;--narrow-height:66.92px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/dca805bc28733c27.svg\"><img class=\"math display-math\" src=\"assets/equations/cdb26bda41e90caa.svg\" alt=\"1-h_t^2=1-(0.6)^2=1-0.36=0.64\" width=\"396.54\" height=\"27.82\" style=\"width:396.54px;height:27.82px;aspect-ratio:396.54/27.82\" loading=\"lazy\"></picture></div>","<p>Multiply the combined gradient by this local derivative.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4f408ded05ecb892.svg\" alt=\"\\delta_t=0.3(0.64)=0.192\" width=\"233.63\" height=\"24.43\" style=\"width:233.63px;height:24.43px;aspect-ratio:233.63/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer: δₜ = 0.192.</strong> This is the derivative with respect to the current hidden raw score. At the last step, there is no future-state contribution unless the question connects another computation there.</p>","<h3>One BPTT delta at h = 0.5</h3>","<p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, h_t = 0.5, current output-path derivative = 0.2, next-step delta = 0.3 and recurrent weight = 0.4. Find the current preactivation delta.</strong></p>","<h3>Given</h3>","<p>Activated h_t = 0.5; q_t = 0.2; δ_(t+1) = 0.3; recurrent weight u = 0.4.</p>","<h3>To find</h3>","<p>Current preactivation delta δ_t.</p>","<h3>Formula — which one and why</h3>","<p>Two paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.</p>","<p>q_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Future aur current dono add; tanh slope uske baad.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the future path contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bb48ef38d6d22273.svg\" alt=\"0.4(0.3)=0.12\" width=\"157.50\" height=\"24.43\" style=\"width:157.50px;height:24.43px;aspect-ratio:157.50/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the current output contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fdbe3cda286c3c16.svg\" alt=\"0.2+0.12=0.32\" width=\"180.57\" height=\"18.27\" style=\"width:180.57px;height:18.27px;aspect-ratio:180.57/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the current tanh slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7f60b4793b26f591.svg\" alt=\"1-(0.5)^2=0.75\" width=\"179.02\" height=\"27.70\" style=\"width:179.02px;height:27.70px;aspect-ratio:179.02/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: multiply by that slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e726c1bb32ed233e.svg\" alt=\"\\delta_t=(0.32)(0.75)=0.24\" width=\"252.63\" height=\"24.43\" style=\"width:252.63px;height:24.43px;aspect-ratio:252.63/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> δ_t = 0.24.</p>","<h3>One BPTT delta at h = -0.2</h3>","<p class=\"inline-question\"><strong>Question. In a scalar tanh RNN, h_t = -0.2, current output-path derivative = 0.1, next-step delta = 0 and recurrent weight = 0.5. Find the current preactivation delta.</strong></p>","<h3>Given</h3>","<p>Activated h_t = -0.2; q_t = 0.1; δ_(t+1) = 0; recurrent weight u = 0.5.</p>","<h3>To find</h3>","<p>Current preactivation delta δ_t.</p>","<h3>Formula — which one and why</h3>","<p>Two paths affect the current hidden state: its current output and the future recurrent step. Add both before differentiating the current tanh.</p>","<p>q_t is already a derivative with respect to the hidden activation; the next delta is with respect to next preactivation.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b43734482c48bdd.svg\" alt=\"\\delta_t=(q_t+u\\delta_{t+1})(1-h_t^2)\" width=\"260.76\" height=\"27.82\" style=\"width:260.76px;height:27.82px;aspect-ratio:260.76/27.82\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Future aur current dono add; tanh slope uske baad.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: calculate the future path contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1ad7c98370e2604f.svg\" alt=\"0.5(0)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: add the current output contribution.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9d31df4938e5db9a.svg\" alt=\"0.1+0=0.1\" width=\"137.13\" height=\"18.27\" style=\"width:137.13px;height:18.27px;aspect-ratio:137.13/18.27\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 3: calculate the current tanh slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/fb671dc68ac70d16.svg\" alt=\"1-(-0.2)^2=0.96\" width=\"198.03\" height=\"27.70\" style=\"width:198.03px;height:27.70px;aspect-ratio:198.03/27.70\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 4: multiply by that slope.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c494eb0b53453545.svg\" alt=\"\\delta_t=(0.1)(0.96)=0.096\" width=\"252.63\" height=\"24.43\" style=\"width:252.63px;height:24.43px;aspect-ratio:252.63/24.43\" loading=\"lazy\"></div>","<p><strong>Final answer:</strong> δ_t = 0.096.</p>"]},{"n":40,"title":"BPTT recurrent-weight gradient","intro":["<p>The same recurrent weight is reused at several times. Each use contributes to its gradient, so sum all required time-step contributions before updating it. For vectors, delta is a column and the previous state is transposed into a row: their outer product has the same shape as the weight matrix.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/bc3f87fdb9a197b4.svg\" alt=\"g_{\\mathrm{clipped}}=g\\min\\left(1,\\frac{\\tau}{\\lVert g\\rVert_2}\\right)\" width=\"277.13\" height=\"58.87\" style=\"width:277.13px;height:58.87px;aspect-ratio:277.13/58.87\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/0db4b816627efa5e.svg\" alt=\"\\frac{\\partial L}{\\partial W_{hh}}=\\sum_t\\delta_t h_{t-1}^T\" width=\"205.05\" height=\"62.51\" style=\"width:205.05px;height:62.51px;aspect-ratio:205.05/62.51\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4953486e2063f6f0.svg\" alt=\"\\frac{\\partial L}{\\partial W_{xh}}=\\sum_t\\delta_t x_t^T\" width=\"188.73\" height=\"62.51\" style=\"width:188.73px;height:62.51px;aspect-ratio:188.73/62.51\" loading=\"lazy\"></div>"],"refs":["tee-c9-s8","tee-c17-s45"],"extra":[]},{"n":41,"title":"LSTM gates and candidate","intro":["<p>An LSTM gate is a multiplier between zero and one. The forget gate chooses the fraction of old cell content retained; the input gate chooses the fraction of candidate content admitted. Each gate is calculated from its own weighted sum and sigmoid.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/42d259e3cca6ee0a.svg\" alt=\"f_t=\\sigma(W_f[h_{t-1},x_t]+b_f)\" width=\"263.38\" height=\"25.53\" style=\"width:263.38px;height:25.53px;aspect-ratio:263.38/25.53\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/48984d6eb2de43b5.svg\" alt=\"i_t=\\sigma(W_i[h_{t-1},x_t]+b_i)\" width=\"252.75\" height=\"24.43\" style=\"width:252.75px;height:24.43px;aspect-ratio:252.75/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c9-s10","tee-c9-s11","tee-c9-s13","tee-c17-s43"],"extra":[]},{"n":42,"title":"LSTM candidate and output gate","intro":["<p>The candidate is proposed new cell content, so it may be negative. The output gate is a positive sigmoid multiplier that controls how much of the activated cell is exposed. Candidate content and gate values therefore have different roles.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6c797c7201f58bbb.svg\" alt=\"\\widetilde C_t=\\tanh(W_C[h_{t-1},x_t]+b_C)\" width=\"311.07\" height=\"31.40\" style=\"width:311.07px;height:31.40px;aspect-ratio:311.07/31.40\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e82eb2b55af9249e.svg\" alt=\"o_t=\\sigma(W_o[h_{t-1},x_t]+b_o)\" width=\"261.01\" height=\"24.43\" style=\"width:261.01px;height:24.43px;aspect-ratio:261.01/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c9-s13","tee-c17-s43","tee-c17-s50"],"extra":[]},{"n":43,"title":"LSTM cell and hidden state","intro":["<p>First calculate the retained old contribution. Separately calculate the admitted new contribution. Add them to obtain the cell state. Only afterward apply tanh and the output gate to obtain the hidden state.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8751dee634f91753.svg\" alt=\"C_t=f_t\\odot C_{t-1}+i_t\\odot\\widetilde C_t\" width=\"258.41\" height=\"30.37\" style=\"width:258.41px;height:30.37px;aspect-ratio:258.41/30.37\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5a01a031c432f962.svg\" alt=\"h_t=o_t\\odot\\tanh(C_t)\" width=\"198.55\" height=\"24.43\" style=\"width:198.55px;height:24.43px;aspect-ratio:198.55/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c9-s11","tee-c17-s42","tee-c17-s50","tee-c17-s43"],"extra":[]},{"n":44,"title":"GRU gates, candidate and update","intro":["<p>A GRU has a reset gate and an update gate. Reset changes how earlier state enters the candidate calculation; update controls the final old/new mixture. The numerical below states its convention explicitly: z is the fraction of the new candidate admitted.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/facdae4e8c80fb1f.svg\" alt=\"z_t=\\sigma(W_zx_t+U_zh_{t-1}+b_z)\" width=\"292.00\" height=\"24.43\" style=\"width:292.00px;height:24.43px;aspect-ratio:292.00/24.43\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/70d5c123a1a8d5b7.svg\" alt=\"r_t=\\sigma(W_rx_t+U_rh_{t-1}+b_r)\" width=\"290.93\" height=\"24.43\" style=\"width:290.93px;height:24.43px;aspect-ratio:290.93/24.43\" loading=\"lazy\"></div>"],"refs":["tee-c9-s14","tee-c17-s44"],"extra":[]},{"n":45,"title":"GRU state under the retain-old convention","intro":["<p>Some GRU questions use the opposite naming convention: z is the fraction of the OLD state retained. The formula below uses that convention. Do not combine its formula with an explanation that says z retains the new candidate.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3cb42e5f674e4241.svg\" alt=\"\\widetilde h_t=\\tanh(W_hx_t+U_h(r_t\\odot h_{t-1})+b_h)\" width=\"403.57\" height=\"31.13\" style=\"width:403.57px;height:31.13px;aspect-ratio:403.57/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.80px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fa76004105af78bd.svg\"><img class=\"math display-math\" src=\"assets/equations/f047371c1b66f6fe.svg\" alt=\"h_t=z_t\\odot h_{t-1}+(1-z_t)\\odot\\widetilde h_t\" width=\"311.64\" height=\"31.13\" style=\"width:311.64px;height:31.13px;aspect-ratio:311.64/31.13\" loading=\"lazy\"></picture></div>"],"refs":[],"extra":["<p class=\"inline-question\"><strong>Question. Use the retain-old GRU convention. Given hprevious = 0.4, reset gate r = 0.5, update gate z = 0.25, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and the next hidden state.</strong></p>","<h3>Given</h3>","<p>h_old = 0.4; r = 0.5; z = 0.25; x = 1.</p>","<p>W = 0.2; U = 0.5; b = 0; z retains the old state.</p>","<h3>To find</h3>","<p>Find the candidate and new hidden state.</p>","<h3>Formula — which one and why</h3>","<p><strong>GRU with a retain-old update gate.</strong> Form the candidate using reset memory; then z retains the old state and 1−z admits the candidate. Follow this question-specific convention.</p>","<p>r = reset gate; z = retain-old gate; h_old = previous state; h̃ = candidate.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Question mein z kisko multiply karta hai wahi meaning; yahan old ko retain.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/b5a08a736e0f6884.svg\" alt=\"r h_{\\mathrm{previous}}=0.5(0.4)=0.2\" width=\"268.01\" height=\"25.35\" style=\"width:268.01px;height:25.35px;aspect-ratio:268.01/25.35\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate&#x27;s raw input.</strong> Its new-input contribution is 0.2 × 1; its reset-memory contribution is 0.5 × 0.2.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.81px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ed7061874c7df25f.svg\"><img class=\"math display-math\" src=\"assets/equations/c9ea266a45504d10.svg\" alt=\"a=0.2(1)+0.5(0.2)+0=0.2+0.1=0.3\" width=\"450.10\" height=\"24.43\" style=\"width:450.10px;height:24.43px;aspect-ratio:450.10/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: apply tanh to this raw input.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5d5bc478f8a3566.svg\"><img class=\"math display-math\" src=\"assets/equations/8ef1fca1e3e9a662.svg\" alt=\"\\widetilde h=\\tanh(0.3)\\approx0.291312612\" width=\"307.34\" height=\"31.13\" style=\"width:307.34px;height:31.13px;aspect-ratio:307.34/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: calculate how much old state is retained.</strong> In this question, z = 0.25 multiplies the original old state 0.4.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/62b46633101b4f4e.svg\" alt=\"z h_{\\mathrm{previous}}=0.25(0.4)=0.1\" width=\"280.57\" height=\"25.35\" style=\"width:280.57px;height:25.35px;aspect-ratio:280.57/25.35\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate how much candidate is admitted.</strong> The other fraction is 1 − z = 0.75.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/854154216ffe0396.svg\" alt=\"1-z=1-0.25=0.75\" width=\"247.59\" height=\"18.52\" style=\"width:247.59px;height:18.52px;aspect-ratio:247.59/18.52\" loading=\"lazy\"></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:224.00px;--narrow-height:109.32px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/f5dda0f46575aa22.svg\"><img class=\"math display-math\" src=\"assets/equations/47e740aad633e99c.svg\" alt=\" (1-z)\\widetilde h=0.75(0.291312612)\\approx0.218484459\" width=\"472.09\" height=\"31.13\" style=\"width:472.09px;height:31.13px;aspect-ratio:472.09/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: add the two final contributions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:236.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/b283dd6b6dd4cf79.svg\"><img class=\"math display-math\" src=\"assets/equations/a53355ba328d8b0b.svg\" alt=\"h=0.1+0.218484459=0.318484459\" width=\"398.27\" height=\"18.96\" style=\"width:398.27px;height:18.96px;aspect-ratio:398.27/18.96\" loading=\"lazy\"></picture></div>","<p><strong>Final answer: h ≈ 0.318484459.</strong> The candidate was 0.291312612; the final hidden state is a mixture of that candidate and the original old state. Under the admit-new convention with the same numeric z, the result would instead be 0.372828153.</p>","<h3>Retain-old GRU with gate 0</h3>","<p class=\"inline-question\"><strong>Question. Use h_new = z h_old+(1−z) candidate. Given h_old = 0.4, z = 0, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new state.</strong></p>","<h3>Given</h3>","<p>h_old = 0.4; z = 0; r = 0.5; x = 1.</p>","<p>W = 0.2; U = 0.5; b = 0; z is the retain-old gate.</p>","<h3>To find</h3>","<p>Candidate and final hidden state.</p>","<h3>Formula — which one and why</h3>","<p>The reset gate changes old-state input to the candidate. The update gate separately mixes the original old state and candidate.</p>","<p>The question explicitly makes z multiply the old state. r and z do different jobs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Reset sirf candidate mein; update mix mein original old state.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/298840de1c01f101.svg\" alt=\"rh_{\\mathrm{old}}=0.5(0.4)=0.2\" width=\"228.03\" height=\"24.43\" style=\"width:228.03px;height:24.43px;aspect-ratio:228.03/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate raw sum.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:219.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/708a856537eccf89.svg\"><img class=\"math display-math\" src=\"assets/equations/f6b1201a9f34684a.svg\" alt=\"a=0.2(1)+0.5(0.2)+0=0.3\" width=\"325.20\" height=\"24.43\" style=\"width:325.20px;height:24.43px;aspect-ratio:325.20/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: apply tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/c5d5bc478f8a3566.svg\"><img class=\"math display-math\" src=\"assets/equations/8ef1fca1e3e9a662.svg\" alt=\"\\widetilde h=\\tanh(0.3)\\approx0.291312612\" width=\"307.34\" height=\"31.13\" style=\"width:307.34px;height:31.13px;aspect-ratio:307.34/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: retain the old-state fraction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/81c714ea0d0f3d30.svg\" alt=\"0(0.4)=0\" width=\"107.25\" height=\"24.43\" style=\"width:107.25px;height:24.43px;aspect-ratio:107.25/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the candidate fraction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.29px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5b85f83251c9025c.svg\"><img class=\"math display-math\" src=\"assets/equations/fb448a828d5eb818.svg\" alt=\"(1-0)(0.291312612)\\approx0.291312612\" width=\"382.84\" height=\"24.43\" style=\"width:382.84px;height:24.43px;aspect-ratio:382.84/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: add the two fractions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:177.84px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/fb12f65fb3a6f99d.svg\"><img class=\"math display-math\" src=\"assets/equations/05b6b2f57ab16b9a.svg\" alt=\"h_{\\mathrm{new}}=0+(0.291312612)\\approx0.291312612\" width=\"430.05\" height=\"24.43\" style=\"width:430.05px;height:24.43px;aspect-ratio:430.05/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Candidate ≈ 0.291312612; new state ≈ 0.291312612.</p>","<h3>Retain-old GRU with gate 0.8</h3>","<p class=\"inline-question\"><strong>Question. Use h_new = z h_old+(1−z) candidate. Given h_old = -0.2, z = 0.8, r = 0.5, x = 1, W = 0.2, U = 0.5 and b = 0, calculate the candidate and new state.</strong></p>","<h3>Given</h3>","<p>h_old = -0.2; z = 0.8; r = 0.5; x = 1.</p>","<p>W = 0.2; U = 0.5; b = 0; z is the retain-old gate.</p>","<h3>To find</h3>","<p>Candidate and final hidden state.</p>","<h3>Formula — which one and why</h3>","<p>The reset gate changes old-state input to the candidate. The update gate separately mixes the original old state and candidate.</p>","<p>The question explicitly makes z multiply the old state. r and z do different jobs.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2a33ca0d61aaaa89.svg\" alt=\"\\widetilde h=\\tanh(Wx+U(rh_{\\mathrm{old}})+b)\" width=\"312.29\" height=\"31.13\" style=\"width:312.29px;height:31.13px;aspect-ratio:312.29/31.13\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/88df46d24a37114e.svg\" alt=\"h_{\\mathrm{new}}=zh_{\\mathrm{old}}+(1-z)\\widetilde h\" width=\"245.35\" height=\"31.13\" style=\"width:245.35px;height:31.13px;aspect-ratio:245.35/31.13\" loading=\"lazy\"></div>","<p><strong>Yaad rakhne ka cue:</strong> Reset sirf candidate mein; update mix mein original old state.</p>","<h3>Solution — step by step</h3>","<p class=\"worked-step\"><strong>Step 1: reset the old state for candidate formation.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/c07f11824db74c75.svg\" alt=\"rh_{\\mathrm{old}}=0.5(-0.2)=-0.1\" width=\"266.05\" height=\"24.43\" style=\"width:266.05px;height:24.43px;aspect-ratio:266.05/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 2: calculate the candidate raw sum.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:238.31px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/177d51be8807173f.svg\"><img class=\"math display-math\" src=\"assets/equations/ba304bd37c97d1fe.svg\" alt=\"a=0.2(1)+0.5(-0.1)+0=0.15\" width=\"356.42\" height=\"24.43\" style=\"width:356.42px;height:24.43px;aspect-ratio:356.42/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 3: apply tanh.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:70.22px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/22b0ab9fe31c5dbb.svg\"><img class=\"math display-math\" src=\"assets/equations/89f3eabbc08b8f86.svg\" alt=\"\\widetilde h=\\tanh(0.15)\\approx0.148885034\" width=\"319.55\" height=\"31.13\" style=\"width:319.55px;height:31.13px;aspect-ratio:319.55/31.13\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 4: retain the old-state fraction.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/8d5d62808c22a4a6.svg\" alt=\"0.8(-0.2)=-0.16\" width=\"195.51\" height=\"24.43\" style=\"width:195.51px;height:24.43px;aspect-ratio:195.51/24.43\" loading=\"lazy\"></div>","<p class=\"worked-step\"><strong>Step 5: calculate the candidate fraction.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:240.30px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/47661b22efc0daeb.svg\"><img class=\"math display-math\" src=\"assets/equations/349c3a8b18523729.svg\" alt=\"(1-0.8)(0.148885034)\\approx0.029777007\" width=\"401.85\" height=\"24.43\" style=\"width:401.85px;height:24.43px;aspect-ratio:401.85/24.43\" loading=\"lazy\"></picture></div>","<p class=\"worked-step\"><strong>Step 6: add the two fractions.</strong></p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:180.55px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a559a88735fecf3e.svg\"><img class=\"math display-math\" src=\"assets/equations/78f9973806e42ffa.svg\" alt=\"h_{\\mathrm{new}}=-0.16+(0.029777007)\\approx-0.130222993\" width=\"499.29\" height=\"24.43\" style=\"width:499.29px;height:24.43px;aspect-ratio:499.29/24.43\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> Candidate ≈ 0.148885034; new state ≈ -0.130222993.</p>"]},{"n":46,"title":"Batch normalization and learned scale/shift","intro":["<p>Batch normalization first uses batch statistics, then applies a learned scale and shift. Epsilon belongs inside the square root. Inference ordinarily uses stored running statistics.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/a91b1c9216cbd799.svg\" alt=\"\\mu_B=\\frac{1}{m}\\sum_{i=1}^{m}x_i\" width=\"160.06\" height=\"68.62\" style=\"width:160.06px;height:68.62px;aspect-ratio:160.06/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7dcfc8cc5fd3adc8.svg\" alt=\"\\sigma_B^2=\\frac{1}{m}\\sum_{i=1}^{m}(x_i-\\mu_B)^2\" width=\"244.63\" height=\"68.62\" style=\"width:244.63px;height:68.62px;aspect-ratio:244.63/68.62\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/13126b94bcd9d415.svg\" alt=\"\\hat{x}_i=\\frac{x_i-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\" width=\"159.11\" height=\"75.23\" style=\"width:159.11px;height:75.23px;aspect-ratio:159.11/75.23\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/7fd3e426f48f08b9.svg\" alt=\"y_i=\\gamma\\hat{x}_i+\\beta\" width=\"131.48\" height=\"25.07\" style=\"width:131.48px;height:25.07px;aspect-ratio:131.48/25.07\" loading=\"lazy\"></div>"],"refs":["tee-c8-s15"],"extra":[]},{"n":47,"title":"Global average pooling","intro":["<p>Global average pooling takes one mean per complete spatial channel. The worked example compares the resulting dense classifier with a classifier after flattening.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/002749b4b374cf54.svg\" alt=\"g_c=\\frac{1}{HW}\\sum_{i=1}^{H}\\sum_{j=1}^{W}a_{i,j,c}\" width=\"239.71\" height=\"74.90\" style=\"width:239.71px;height:74.90px;aspect-ratio:239.71/74.90\" loading=\"lazy\"></div>"],"refs":["tee-c8-s13"],"extra":[]},{"n":48,"title":"Top-k error percentage","intro":["<p>Top-k error counts examples whose correct class is absent from the highest-scoring k predictions. Success counts must not be added twice.</p>"],"formulas":["<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/3fb17785121a672d.svg\" alt=\"E_k=\\frac{N-C_k}{N}\\times100\\%\" width=\"239.34\" height=\"50.50\" style=\"width:239.34px;height:50.50px;aspect-ratio:239.34/50.50\" loading=\"lazy\"></div>"],"refs":["tee-c8-s11"],"extra":[]}]},"mocks":{"A":[{"title":"Q1a","question":["<p class=\"inline-question\"><strong>Q1a compulsory (2 marks). Explain the key difference between the AdaGrad and RMSProp accumulators. Why can AdaGrad&#x27;s effective learning rate become very small during prolonged training?</strong></p>"],"answer":["<h3>1. AdaGrad stores a running sum</h3>","<p>Let gₜ be the current gradient and Gₜ the stored sum of squared gradients. AdaGrad updates that sum as follows:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/221c2b3d2079d996.svg\" alt=\"G_t=G_{t-1}+g_t^2\" width=\"161.79\" height=\"27.82\" style=\"width:161.79px;height:27.82px;aspect-ratio:161.79/27.82\" loading=\"lazy\"></div>","<p>Every added square is nonnegative, so G cannot decrease. All past squared gradients remain in the sum.</p>","<h3>2. RMSProp stores a decaying average</h3>","<p>Let sₜ be the stored squared-gradient average and ρ the fraction of the previous average retained.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9b03d623d9793c84.svg\" alt=\"s_t=\\rho s_{t-1}+(1-\\rho)g_t^2\" width=\"232.66\" height=\"27.82\" style=\"width:232.66px;height:27.82px;aspect-ratio:232.66/27.82\" loading=\"lazy\"></div>","<p>RMSProp gradually reduces the influence of older squared gradients. Its accumulator can rise or fall, depending on the new squared gradient.</p>","<h3>3. Explain the effect on step size</h3>","<p>AdaGrad&#x27;s effective learning rate is:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/6f335dbb7b791f6d.svg\" alt=\"\\eta_{effective}=\\frac{\\eta}{\\sqrt{G_t}+\\epsilon}\" width=\"216.83\" height=\"52.24\" style=\"width:216.83px;height:52.24px;aspect-ratio:216.83/52.24\" loading=\"lazy\"></div>","<p>Here η is the base learning rate and ε is a small positive number that stabilizes division. When G becomes large, its square root becomes large, so dividing by it produces a smaller effective learning rate. RMSProp&#x27;s decaying average avoids this particular permanent-accumulation problem.</p>","<p><strong>Final answer:</strong> AdaGrad uses a nondecreasing sum of all squared gradients; RMSProp uses a decaying average. AdaGrad&#x27;s growing denominator can make future updates very small.</p>","<p><strong>Yaad rakho:</strong> AdaGrad sab squares jodta rehta hai; RMSProp purane squares ka asar dheere kam karta hai.</p>"]},{"title":"Q1b","question":["<p class=\"inline-question\"><strong>Q1b compulsory (2 marks). Explain local connectivity and parameter sharing in a CNN. How do they reduce the number of learned parameters compared with a fully connected mapping of an image?</strong></p>"],"answer":["<h3>1. Local connectivity</h3>","<p>Each convolutional output depends on a small spatial neighbourhood of the input, called its receptive field, rather than every pixel in the entire image. The filter spans the input channels within that neighbourhood. This limits the connections used to calculate each output.</p>","<h3>2. Parameter sharing</h3>","<p>The same filter weights and bias are reused at every spatial position where that filter is applied. A CNN therefore learns one set of parameters for that filter, rather than a separate set for each image location.</p>","<h3>3. Concrete image example</h3>","<p>An edge-detecting filter can identify a vertical boundary near the left of an image and then slide to look for a similar boundary near the right. Both locations use the same learned filter. The network does not need to learn an independent edge detector for every position.</p>","<h3>4. Comparison with a fully connected mapping</h3>","<p>A fully connected layer generally learns a separate weight for every input-to-output connection. Convolution reduces this requirement in two ways: local connectivity restricts each output&#x27;s input region, while parameter sharing reuses one filter across locations. More output positions create more activations and computation, but do not create new parameters for that shared filter.</p>","<p><strong>Final answer:</strong> local connectivity uses a limited input neighbourhood; parameter sharing reuses the filter&#x27;s learned values across spatial positions. Together they can require far fewer parameters than a fully connected image mapping.</p>","<p><strong>Yaad rakho:</strong> Filter ke numbers ek baar seekhte hain; image par baar-baar wahi use hote hain.</p>"]},{"title":"Q2","question":["<p class=\"inline-question\"><strong>Q2 optional (3 marks). An input of size 7 × 7 × 3 passes through a convolutional layer with two 3 × 3 filters, stride 2 and padding 1 on each side; then a 2 × 2 pooling layer with stride 2 and no padding; then flattening; then a dense layer with three output units. Find the output shape after every layer and the total trainable parameters. Include one bias per convolutional filter and per dense unit.</strong></p>"],"answer":["<h3>Given</h3>","<p>- Input: height 7, width 7, channels 3.</p>","<p>- Convolution: kernel 3 × 3, filters 2, stride 2, padding 1 per side.</p>","<p>- Pooling: window 2 × 2, stride 2, padding 0.</p>","<p>- Flattening followed by 3 dense output units.</p>","<p>- Include all specified biases. Pooling and flattening have no learned parameters.</p>","<h3>To find</h3>","<p>The convolution output, pooling output, flatten length, dense output length and total trainable parameter count.</p>","<h3>Formula — which one and why</h3>","<p>For either spatial axis, use the output-size formula. N is that axis&#x27;s input size, K the window size, S its stride and P padding per side. The floor means discard any fractional part because a full window must fit.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:252.17px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/930fa72046a69449.svg\"><img class=\"math display-math\" src=\"assets/equations/4a7024fc5224e01a.svg\" alt=\"N_{\\mathrm{out}}=\\left\\lfloor\\frac{N+2P-K}{S}\\right\\rfloor+1\" width=\"294.26\" height=\"58.62\" style=\"width:294.26px;height:58.62px;aspect-ratio:294.26/58.62\" loading=\"lazy\"></picture></div>","<p>Each convolution filter spans all input channels; each dense unit connects to every flattened input. Therefore:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:225.51px;--narrow-height:105.89px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/683bcf7c089c902f.svg\"><img class=\"math display-math\" src=\"assets/equations/e06582d1ab100452.svg\" alt=\"P_{\\mathrm{conv}}=(K^2C_{\\mathrm{in}}+1)C_{\\mathrm{out}},\\qquad P_{\\mathrm{dense}}=(n_{\\mathrm{in}}+1)n_{\\mathrm{out}}\" width=\"543.72\" height=\"27.70\" style=\"width:543.72px;height:27.70px;aspect-ratio:543.72/27.70\" loading=\"lazy\"></picture></div>","<p>Flattening simply counts all values in the preceding feature maps:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/1321cd9ddfcf5b42.svg\" alt=\"n_{\\mathrm{flat}}=HWC\" width=\"140.59\" height=\"21.08\" style=\"width:140.59px;height:21.08px;aspect-ratio:140.59/21.08\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<h3>Step 1: convolution height and width</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:256.13px;--narrow-height:97.97px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a2592712257363b0.svg\"><img class=\"math display-math\" src=\"assets/equations/3ba361586be8312e.svg\" alt=\"N_{\\mathrm{conv}}=\\left\\lfloor\\frac{7+2(1)-3}{2}\\right\\rfloor+1=3+1=4\" width=\"429.90\" height=\"58.87\" style=\"width:429.90px;height:58.87px;aspect-ratio:429.90/58.87\" loading=\"lazy\"></picture></div>","<p>The numerator is 7 + 2 − 3 = 6. Divide by stride 2 to get 3, then add 1 to get 4 positions. The same calculation applies to height and width. Two filters create two output channels.</p>","<p><strong>Convolution output: 4 × 4 × 2.</strong></p>","<h3>Step 2: convolution parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:251.28px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/e6c2c8a35c15f9ce.svg\"><img class=\"math display-math\" src=\"assets/equations/fa20139330cc7a23.svg\" alt=\"\\text{weights}=3\\times3\\times3\\times2=54\" width=\"308.30\" height=\"21.99\" style=\"width:308.30px;height:21.99px;aspect-ratio:308.30/21.99\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.88px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fa35646db3c8aec.svg\"><img class=\"math display-math\" src=\"assets/equations/b8f0882262171dff.svg\" alt=\"\\text{biases}=2,\\qquad P_{\\mathrm{conv}}=54+2=56\" width=\"376.11\" height=\"21.70\" style=\"width:376.11px;height:21.70px;aspect-ratio:376.11/21.70\" loading=\"lazy\"></picture></div>","<h3>Step 3: pooling shape and parameters</h3>","<p>The pooling input size is now 4, not the original 7.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:221.55px;--narrow-height:97.72px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/75bb76e8c3f74574.svg\"><img class=\"math display-math\" src=\"assets/equations/6833d7ee27072935.svg\" alt=\"N_{\\mathrm{pool}}=\\left\\lfloor\\frac{4-2}{2}\\right\\rfloor+1=1+1=2\" width=\"353.25\" height=\"58.62\" style=\"width:353.25px;height:58.62px;aspect-ratio:353.25/58.62\" loading=\"lazy\"></picture></div>","<p>Pooling operates separately on each channel, so the two channels remain two.</p>","<p><strong>Pooling output: 2 × 2 × 2. Pooling parameters: 0.</strong></p>","<h3>Step 4: flattening</h3>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/4eb23baff49f82cf.svg\" alt=\"n_{\\mathrm{flat}}=2\\times2\\times2=8\" width=\"215.91\" height=\"20.13\" style=\"width:215.91px;height:20.13px;aspect-ratio:215.91/20.13\" loading=\"lazy\"></div>","<p>There are eight values to send to the dense layer. Flattening rearranges them into a list and learns no parameters.</p>","<p><strong>Flatten output: 8 values. Flatten parameters: 0.</strong></p>","<h3>Step 5: dense output and parameters</h3>","<p>Each of the three dense units receives eight inputs and has one bias.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:230.91px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/5d064152bee760f3.svg\"><img class=\"math display-math\" src=\"assets/equations/ff79309a11966950.svg\" alt=\"\\text{weights}=8\\times3=24,\\quad\\text{biases}=3,\\quad P_{\\mathrm{dense}}=27\" width=\"518.32\" height=\"21.99\" style=\"width:518.32px;height:21.99px;aspect-ratio:518.32/21.99\" loading=\"lazy\"></picture></div>","<p><strong>Dense output: 3 values.</strong></p>","<h3>Step 6: total trainable parameters</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:248.73px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/8013f82d7c04ad92.svg\"><img class=\"math display-math\" src=\"assets/equations/021c0c327e9ed57d.svg\" alt=\"P_{\\mathrm{total}}=56+0+0+27=83\" width=\"305.76\" height=\"20.54\" style=\"width:305.76px;height:20.54px;aspect-ratio:305.76/20.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> 4 × 4 × 2 → 2 × 2 × 2 → 8 → 3. <strong>Total: 83 trainable parameters.</strong></p>","<p><strong>Yaad rakho:</strong> Pehle shape; phir weights. Ek layer ka output hi next layer ka input hai.</p>"]},{"title":"Q3","question":["<p class=\"inline-question\"><strong>Q3 optional (3 marks). Apply the printed kernel K to input I using the deep-learning cross-correlation convention, with stride 1, no padding and zero bias. Do not flip K. Apply ReLU to the resulting map, followed by 2 × 2 max pooling with stride 2 and no padding. Show every convolution entry and find the final output.</strong></p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/9bf8a81efcf4cdbd.svg\" alt=\"I=\\begin{bmatrix}1&amp;2&amp;1\\\\0&amp;1&amp;3\\\\2&amp;1&amp;0\\end{bmatrix},\\quad K=\\begin{bmatrix}1&amp;-1\\\\0&amp;1\\end{bmatrix}\" width=\"346.30\" height=\"92.85\" style=\"width:346.30px;height:92.85px;aspect-ratio:346.30/92.85\" loading=\"lazy\"></div>"],"answer":["<h3>Given</h3>","<p>- Input I is the printed 3 × 3 matrix; kernel K is the printed 2 × 2 matrix.</p>","<p>- Convolution stride 1, padding 0, bias 0; use K in its printed orientation.</p>","<p>- Activation: ReLU.</p>","<p>- Pooling: max, 2 × 2 window, stride 2, padding 0.</p>","<h3>To find</h3>","<p>All four convolution values, the ReLU output matrix and the final pooled output.</p>","<h3>Formula — which one and why</h3>","<p>For each input window, multiply entries at matching positions, then add all products and the bias once.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.86px;--narrow-height:93.75px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6652d02289b39594.svg\"><img class=\"math display-math\" src=\"assets/equations/357d6cd4ecbfd331.svg\" alt=\"Y_{ij}=\\sum_{u,v}X_{iS+u,jS+v}K_{uv}+b\" width=\"290.21\" height=\"54.66\" style=\"width:290.21px;height:54.66px;aspect-ratio:290.21/54.66\" loading=\"lazy\"></picture></div>","<p>X is the input, S is stride, u and v select a kernel entry, and b is bias. This formula uses zero-based array indices; the written solution labels positions from 1 for readability.</p>","<p>ReLU is required because the question requests activation after convolution. It replaces a negative value by zero.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/67fab45c729a152a.svg\" alt=\"\\operatorname{ReLU}(z)=\\max(0,z)\" width=\"224.32\" height=\"24.43\" style=\"width:224.32px;height:24.43px;aspect-ratio:224.32/24.43\" loading=\"lazy\"></div>","<p>Max pooling selects the largest value in its current window V.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e971be750f6cd770.svg\" alt=\"y_{\\max}=\\max V\" width=\"147.07\" height=\"21.70\" style=\"width:147.07px;height:21.70px;aspect-ratio:147.07/21.70\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<p class=\"visual-reading-note\">Follow each selected input window below. Matching row colors connect its input cells, kernel coefficients and products; the outlined output cell shows where their sum belongs.</p>","<h3>Step 1: determine the convolution shape</h3>","<p>For each axis: (3 − 2)/1 + 1 = 2. Therefore calculate a 2 × 2 output matrix.</p>","<h3>Step 2: top-left output, position (1,1)</h3>","<p>The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/eed57e81393ab435.svg\" alt=\"\\begin{bmatrix}1 &amp; 2\\\\0 &amp; 1\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 1 × 1 = 1; 2 × (−1) = −2; 0 × 0 = 0; 1 × 1 = 1.</p>","<p>Add the products and bias: 1 − 2 + 0 + 1 + 0 = <strong>0</strong>.</p>","<h3>Step 3: top-right output, position (1,2)</h3>","<p>Move the window one column to the right. The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/85c116687119a006.svg\" alt=\"\\begin{bmatrix}2 &amp; 1\\\\1 &amp; 3\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 2 × 1 = 2; 1 × (−1) = −1; 1 × 0 = 0; 3 × 1 = 3.</p>","<p>Add: 2 − 1 + 0 + 3 + 0 = <strong>4</strong>.</p>","<h3>Step 4: bottom-left output, position (2,1)</h3>","<p>The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/e06165b70c0dec06.svg\" alt=\"\\begin{bmatrix}0 &amp; 1\\\\2 &amp; 1\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 0 × 1 = 0; 1 × (−1) = −1; 2 × 0 = 0; 1 × 1 = 1.</p>","<p>Add: 0 − 1 + 0 + 1 + 0 = <strong>0</strong>.</p>","<h3>Step 5: bottom-right output, position (2,2)</h3>","<p>The window is <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/9f01f837180dd993.svg\" alt=\"\\begin{bmatrix}1 &amp; 3\\\\1 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</p>","<p>Multiply matching cells: 1 × 1 = 1; 3 × (−1) = −3; 1 × 0 = 0; 0 × 1 = 0.</p>","<p>Add: 1 − 3 + 0 + 0 + 0 = <strong>−2</strong>.</p>","<p><strong>Convolution map: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f2f63d345efa8255.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; -2\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span>.</strong></p>","<h3>Step 6: apply ReLU separately to every entry</h3>","<p>- max(0,0) = 0.</p>","<p>- max(0,4) = 4.</p>","<p>- max(0,0) = 0.</p>","<p>- max(0,−2) = 0.</p>","<p><strong>ReLU map: <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ca987c6e03219656.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span>.</strong></p>","<h3>Step 7: max pooling</h3>","<p>The 2 × 2 pooling window covers all four activated entries. Compare 0, 4, 0 and 0. Their maximum is <strong>4</strong>.</p>","<p><strong>Final answer:</strong> convolution <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/f2f63d345efa8255.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; -2\\end{bmatrix}\" width=\"72.86\" height=\"45.61\" style=\"width:72.86px;height:45.61px;aspect-ratio:72.86/45.61\" loading=\"lazy\"></span> → ReLU <span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/ca987c6e03219656.svg\" alt=\"\\begin{bmatrix}0 &amp; 4\\\\0 &amp; 0\\end{bmatrix}\" width=\"58.08\" height=\"45.61\" style=\"width:58.08px;height:45.61px;aspect-ratio:58.08/45.61\" loading=\"lazy\"></span> → pooled output <strong><span class=\"math-inline\"><img class=\"math inline-math\" src=\"assets/equations/eaf8e658e6675411.svg\" alt=\"\\begin{bmatrix}4\\end{bmatrix}\" width=\"20.07\" height=\"19.00\" style=\"width:20.07px;height:19.00px;aspect-ratio:20.07/19.00\" loading=\"lazy\"></span></strong>, a 1 × 1 map.</p>","<p><strong>Yaad rakho:</strong> Multiply-add se convolution; negative hatao ReLU; biggest uthao max pool.</p>"]},{"title":"Q4","question":["<p class=\"inline-question\"><strong>Q4 optional (3 marks). What is overfitting? Explain how dropout and early stopping help improve generalization. State which dataset should select the stopping point.</strong></p>"],"answer":["<h3>1. Definition and identification</h3>","<p>Overfitting occurs when a model learns training-specific details or noise that do not generalize to new data. It commonly shows low training error together with substantially higher validation error. Generalization means performing well on new examples drawn from the task&#x27;s data distribution.</p>","<h3>2. Dropout</h3>","<p>During training, dropout randomly sets selected activations to zero. The active subnetwork changes across training passes, discouraging reliance on a fixed combination of hidden units. Under inverted dropout, retained activations are divided by the keep probability to preserve their expected scale. During ordinary inference, the masking is disabled and all units are used without that training-time rescaling.</p>","<p>Dropout is a regularizer; it can reduce overfitting, but excessive dropout can cause underfitting.</p>","<h3>3. Early stopping</h3>","<p>Train on the training set and monitor performance on a separate <strong>validation set</strong>. Save the model whenever validation loss improves. Stop after the chosen number of consecutive non-improving evaluations, called patience, then restore the saved best model.</p>","<p>For example, validation losses 0.8, 0.6, 0.5, 0.53 and 0.55 have their minimum at epoch 3. With patience 2, stop after epoch 5 and restore epoch 3. The stopping epoch and saved-model epoch are different.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_early_stop.svg\" aria-label=\"Enlarge diagram: Early stopping retains the model with the best validation performance, not necessarily the final trained model.\"><img src=\"assets/figures/v_early_stop.svg\" alt=\"Early stopping retains the model with the best validation performance, not necessarily the final trained model.\" width=\"1080\" height=\"610\" loading=\"lazy\"></button><figcaption>Early stopping retains the model with the best validation performance, not necessarily the final trained model. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<p><strong>Final answer:</strong> dropout restricts dependence on particular training-time activations; early stopping limits training after validation performance stops improving. Choose the stopping point using validation data and reserve the test set for final evaluation.</p>","<p><strong>Yaad rakho:</strong> Training se seekho, validation se best model chuno, test se final result batao.</p>"]}],"B":[{"title":"Q1a","question":["<p class=\"inline-question\"><strong>Q1a compulsory (2 marks). Explain the purpose of scaling retained activations in inverted dropout. For activations [1,2,3,4], keep probability 0.5 and mask [1,0,1,0], calculate the activations used during this training pass. A mask value of 1 means keep and 0 means drop.</strong></p>"],"answer":["<h3>Theory: why scale retained values?</h3>","<p>Randomly dropping units would reduce the average activation. Inverted dropout divides every retained activation by the keep probability. Averaged over the random masks, this preserves the original activation&#x27;s expected value. A dropped activation is still zero.</p>","<h3>Given</h3>","<p>- Original activations a = [1,2,3,4].</p>","<p>- Keep probability q = 0.5, meaning a unit has a 50% chance of being kept.</p>","<p>- This pass&#x27;s supplied mask m = [1,0,1,0].</p>","<h3>To find</h3>","<p>The four post-dropout activations used in this training pass.</p>","<h3>Formula — which one and why</h3>","<p>Multiply the original activation aᵢ by its mask mᵢ, then divide by keep probability q.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/93807008ce7b52a8.svg\" alt=\"a_i^{\\mathrm{train}}=\\frac{m_ia_i}{q}\" width=\"145.18\" height=\"48.82\" style=\"width:145.18px;height:48.82px;aspect-ratio:145.18/48.82\" loading=\"lazy\"></div>","<h3>Solution — step by step</h3>","<h3>Step 1: first activation</h3>","<p>Mask 1 keeps the value. Multiply 1 × 1 = 1; divide 1 by 0.5 to get <strong>2</strong>.</p>","<h3>Step 2: second activation</h3>","<p>Mask 0 drops the value. Multiply 0 × 2 = 0; divide 0 by 0.5 to get <strong>0</strong>.</p>","<h3>Step 3: third activation</h3>","<p>Mask 1 keeps the value. Multiply 1 × 3 = 3; divide 3 by 0.5 to get <strong>6</strong>.</p>","<h3>Step 4: fourth activation</h3>","<p>Mask 0 drops the value. Multiply 0 × 4 = 0; divide 0 by 0.5 to get <strong>0</strong>.</p>","<p><strong>Final answer: [2,0,6,0].</strong> This is the training-pass result. In ordinary inference with inverted dropout, disable the mask and its scaling.</p>","<p><strong>Yaad rakho:</strong> Mask lagao; bache hue values ko keep probability se divide karo.</p>"]},{"title":"Q1b","question":["<p class=\"inline-question\"><strong>Q1b compulsory (2 marks). Explain a ResNet shortcut. Why must the two tensors being added have matching shapes, and what can be done if their shapes differ?</strong></p>"],"answer":["<h3>1. Residual addition</h3>","<p>A residual block combines a learned transformation F(x) with a shortcut carrying the input x:</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/d30a7ff979462f45.svg\" alt=\"H(x)=F(x)+x\" width=\"182.40\" height=\"24.43\" style=\"width:182.40px;height:24.43px;aspect-ratio:182.40/24.43\" loading=\"lazy\"></div>","<p>F(x) is the output of the learned residual branch. Adding x provides a direct path for information and gradients, helping optimize deep networks. If the branch produces zero, the addition stage returns x. A post-addition activation, if specified by the architecture, is applied afterward.</p>","<h3>2. Why matching shapes are needed</h3>","<p>The addition is entry by entry. Each element in F(x) needs a corresponding element in x, so height, width and channel count must match. For example, a 14 × 14 × 32 tensor cannot be directly added to a 14 × 14 × 64 tensor in a standard residual shortcut.</p>","<h3>3. How a projection helps</h3>","<p>A learned projection, commonly a 1 × 1 convolution with an appropriate number of filters and stride, maps the shortcut to the required shape. Then add the projected shortcut and the residual branch. This is addition, not channel concatenation.</p>","<p><strong>Final answer:</strong> a shortcut adds input information to the learned residual branch. Use an identity shortcut when shapes match and a suitable projection when they do not.</p>","<p><strong>Yaad rakho:</strong> Same-size entries jodte hain; mismatch ho toh shortcut ka size pehle match karo.</p>"]},{"title":"Q2","question":["<p class=\"inline-question\"><strong>Q2 optional (3 marks). (a) Explain why Adam uses bias correction for its initially zero moment estimates. (1 mark) (b) Adam starts with θ₀ = 1 and m₀ = v₀ = 0. Use learning rate η = 0.1, β₁ = 0.9 and β₂ = 0.99. The supplied gradients are g₁ = 2 and g₂ = −1. Perform two bias-corrected updates. Show the raw first and second moments, corrected moments and updated parameter after each iteration. Set ε = 0 only for this nonzero-denominator hand calculation. (2 marks)</strong></p>"],"answer":["<h3>Part (a): why Adam corrects the moments</h3>","<p>Adam initializes both moving averages to zero. At early iterations, too little gradient history has accumulated, so the raw estimates are biased toward zero. Dividing mₜ by 1 − β₁ᵗ and vₜ by 1 − β₂ᵗ corrects this initialization bias before the parameter update. The power uses the current iteration number t. As t increases, these denominators approach 1.</p>","<h3>Part (b): numerical solution</h3>","<h3>Given</h3>","<p>- Starting parameter θ₀ = 1.</p>","<p>- Starting first moment m₀ = 0 and second moment v₀ = 0.</p>","<p>- Learning rate η = 0.1.</p>","<p>- Decay factors β₁ = 0.9 and β₂ = 0.99.</p>","<p>- Supplied gradients, in order: 2, then −1.</p>","<p>- ε = 0 for this exercise; both denominators will be nonzero.</p>","<h3>To find</h3>","<p>For iterations 1 and 2, calculate m, v, their bias-corrected values and the new parameter θ.</p>","<h3>Formula — which one and why</h3>","<p>Adam keeps two moving averages: m stores signed gradients and v stores squared gradients. Zero initialization makes these averages initially too small, so divide by the correction factors for the current iteration t.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.18px;--narrow-height:106.01px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/903aa08b8d83755c.svg\"><img class=\"math display-math\" src=\"assets/equations/28d34b30a47142d0.svg\" alt=\"m_t=\\beta_1m_{t-1}+(1-\\beta_1)g_t,\\quad v_t=\\beta_2v_{t-1}+(1-\\beta_2)g_t^2\" width=\"566.46\" height=\"27.82\" style=\"width:566.46px;height:27.82px;aspect-ratio:566.46/27.82\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:146.43px;--narrow-height:121.19px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/637a35db2d99492a.svg\"><img class=\"math display-math\" src=\"assets/equations/19f778fcb8d9f7b4.svg\" alt=\"\\hat m_t=\\frac{m_t}{1-\\beta_1^t},\\quad\\hat v_t=\\frac{v_t}{1-\\beta_2^t}\" width=\"304.97\" height=\"53.28\" style=\"width:304.97px;height:53.28px;aspect-ratio:304.97/53.28\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/2f5e5116ef55c3b3.svg\" alt=\"\\theta_t=\\theta_{t-1}-\\frac{\\eta\\hat m_t}{\\sqrt{\\hat v_t}+\\varepsilon}\" width=\"221.03\" height=\"66.12\" style=\"width:221.03px;height:66.12px;aspect-ratio:221.03/66.12\" loading=\"lazy\"></div>","<p>The hat marks a corrected value. Carry the <strong>raw</strong> m and v into the next moving-average recurrence, not the corrected values. Keep full calculator precision until the final answer.</p>","<h3>Solution — step by step</h3>","<h3>Step 1: iteration 1, raw first moment</h3>","<p>The current gradient is 2. Retain 90% of the old first moment and add 10% of this gradient.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/5ac027abcdfcdb75.svg\" alt=\"m_1=0.9(0)+0.1(2)=0.2\" width=\"283.29\" height=\"24.43\" style=\"width:283.29px;height:24.43px;aspect-ratio:283.29/24.43\" loading=\"lazy\"></div>","<h3>Step 2: iteration 1, raw second moment</h3>","<p>Square the gradient first: 2² = 4. Retain 99% of the old second moment and add 1% of that square.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:244.98px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/4af117593c0c60f1.svg\"><img class=\"math display-math\" src=\"assets/equations/9e506bfe9fd357f5.svg\" alt=\"v_1=0.99(0)+0.01(2)^2=0.04\" width=\"321.01\" height=\"27.70\" style=\"width:321.01px;height:27.70px;aspect-ratio:321.01/27.70\" loading=\"lazy\"></picture></div>","<h3>Step 3: iteration 1, bias correction</h3>","<p>Use t = 1. The correction denominators are 1 − 0.9 = 0.1 and 1 − 0.99 = 0.01.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/f8975b50fed0845b.svg\" alt=\"\\widehat m_1=\\frac{0.2}{1-0.9^{1}}=2\" width=\"204.24\" height=\"54.93\" style=\"width:204.24px;height:54.93px;aspect-ratio:204.24/54.93\" loading=\"lazy\"></div>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/ecdf53b308191b04.svg\" alt=\"\\widehat v_1=\\frac{0.04}{1-0.99^{1}}=4\" width=\"206.85\" height=\"55.20\" style=\"width:206.85px;height:55.20px;aspect-ratio:206.85/55.20\" loading=\"lazy\"></div>","<h3>Step 4: iteration 1, parameter update</h3>","<p>The square root of the corrected second moment is √4 = 2. The step is 0.1 × 2 ÷ 2 = 0.1.</p>","<div class=\"equation\"><img class=\"math display-math\" src=\"assets/equations/e1122171b0bd236e.svg\" alt=\"\\theta_1=1-\\frac{0.1\\times(2)}{\\sqrt{4}}=0.9\" width=\"263.68\" height=\"60.60\" style=\"width:263.68px;height:60.60px;aspect-ratio:263.68/60.60\" loading=\"lazy\"></div>","<h3>Step 5: iteration 2, raw first moment</h3>","<p>Use supplied gradient −1, previous raw m = 0.2 and previous raw v = 0.04.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:257.50px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/85e3c1c423ab1151.svg\"><img class=\"math display-math\" src=\"assets/equations/69b54ca313d8829c.svg\" alt=\"m_2=0.9(0.2)+0.1(-1)=0.08\" width=\"333.54\" height=\"24.43\" style=\"width:333.54px;height:24.43px;aspect-ratio:333.54/24.43\" loading=\"lazy\"></picture></div>","<p>The two contributions are 0.18 and −0.1; their sum is 0.08.</p>","<h3>Step 6: iteration 2, raw second moment</h3>","<p>The square of −1 is +1.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:234.68px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/9fa8fd0cf3a03d97.svg\"><img class=\"math display-math\" src=\"assets/equations/76708a6ba327fc21.svg\" alt=\"v_2=0.99(0.04)+0.01(-1)^2=0.0496\" width=\"395.68\" height=\"27.70\" style=\"width:395.68px;height:27.70px;aspect-ratio:395.68/27.70\" loading=\"lazy\"></picture></div>","<p>The two contributions are 0.0396 and 0.01; their sum is 0.0496.</p>","<h3>Step 7: iteration 2, bias correction</h3>","<p>Use t = 2. The correction denominators are 1 − 0.9² = 0.19 and 1 − 0.99² = 0.0199.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:161.55px;--narrow-height:94.02px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ad611d8dfc7121b6.svg\"><img class=\"math display-math\" src=\"assets/equations/b68cf26945a449a6.svg\" alt=\"\\widehat m_2=\\frac{0.08}{1-0.9^{2}}=0.421052632\" width=\"320.99\" height=\"54.93\" style=\"width:320.99px;height:54.93px;aspect-ratio:320.99/54.93\" loading=\"lazy\"></picture></div>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:162.05px;--narrow-height:94.29px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/77a755525cf83c35.svg\"><img class=\"math display-math\" src=\"assets/equations/7d078eb9618846c0.svg\" alt=\"\\widehat v_2=\\frac{0.0496}{1-0.99^{2}}=2.492462312\" width=\"323.60\" height=\"55.20\" style=\"width:323.60px;height:55.20px;aspect-ratio:323.60/55.20\" loading=\"lazy\"></picture></div>","<h3>Step 8: iteration 2, parameter update</h3>","<p>Start from the updated parameter 0.9. Take the square root of the corrected second moment, divide the corrected first moment by it, multiply by 0.1 and subtract.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:249.70px;--narrow-height:138.79px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/a3614192f516725e.svg\"><img class=\"math display-math\" src=\"assets/equations/bd194d13466767bb.svg\" alt=\"\\theta_2=0.9-\\frac{0.1\\times(0.421052632)}{\\sqrt{2.492462312}}=0.873330057\" width=\"497.18\" height=\"60.60\" style=\"width:497.18px;height:60.60px;aspect-ratio:497.18/60.60\" loading=\"lazy\"></picture></div>","<p>The displayed decimals are rounded; evaluate using the unrounded fractions when possible.</p>","<p><strong>Final answer:</strong> θ₁ = <strong>0.9</strong> and θ₂ ≈ <strong>0.873330057</strong>. The second supplied gradient is negative, but the first-moment estimate is still positive because it retains part of the previous positive gradient.</p>","<p><strong>Yaad rakho:</strong> Do raw memories banao → current t se hats nikalo → update; next round mein raw memories le jao.</p>"]},{"title":"Q3","question":["<p class=\"inline-question\"><strong>Q3 optional (3 marks). A 16 × 16 × 64 feature map is processed by 32 filters of size 3 × 3 using stride 1 and same padding. Compare the direct convolution&#x27;s MAC count with a bottleneck that first applies eight 1 × 1 filters, then the same 32-filter 3 × 3 convolution. Both stages keep spatial size 16 × 16. Find both costs, the absolute saving and percentage saving. Count one multiply–accumulate as one MAC and omit bias additions.</strong></p>"],"answer":["<h3>Given</h3>","<p>- Input map: 16 × 16 with 64 channels.</p>","<p>- Direct layer: 32 filters, each 3 × 3, receiving 64 channels.</p>","<p>- Bottleneck stage 1: eight 1 × 1 filters, receiving 64 channels.</p>","<p>- Bottleneck stage 2: 32 filters, each 3 × 3, now receiving only 8 channels.</p>","<p>- Every layer has output height and width 16; ignore bias additions.</p>","<h3>To find</h3>","<p>Direct MACs, both bottleneck-stage MACs, their total, absolute saving and saving percentage.</p>","<h3>Formula — which one and why</h3>","<p>Each output entry uses K²Cᵢₙ weight–input pairs. There are HₒᵤₜWₒᵤₜCₒᵤₜ output entries. Multiply these counts:</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.97px;--narrow-height:66.80px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/6c847f45a17553cd.svg\"><img class=\"math display-math\" src=\"assets/equations/4ef70226a6e5e478.svg\" alt=\"\\mathrm{MACs}=H_{\\mathrm{out}}W_{\\mathrm{out}}C_{\\mathrm{out}}K^2C_{\\mathrm{in}}\" width=\"309.98\" height=\"25.46\" style=\"width:309.98px;height:25.46px;aspect-ratio:309.98/25.46\" loading=\"lazy\"></picture></div>","<p>The bottleneck has two layers, so calculate each layer&#x27;s work and add them. Saving is direct work minus reduced work, expressed as a fraction of direct work.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:253.90px;--narrow-height:89.60px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/ea97c94764a3090c.svg\"><img class=\"math display-math\" src=\"assets/equations/e413f16bb5ba7714.svg\" alt=\"\\mathrm{saving\\ percentage}=100\\frac{\\mathrm{direct}-\\mathrm{reduced}}{\\mathrm{direct}}\" width=\"441.43\" height=\"50.50\" style=\"width:441.43px;height:50.50px;aspect-ratio:441.43/50.50\" loading=\"lazy\"></picture></div>","<h3>Solution — step by step</h3>","<h3>Step 1: direct convolution</h3>","<p>Each output entry uses 3 × 3 × 64 = <strong>576</strong> weight–input pairs.</p>","<p>There are 16 × 16 × 32 = <strong>8,192</strong> output entries.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:198.21px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/673cd31676ab87d1.svg\"><img class=\"math display-math\" src=\"assets/equations/660ea75dfc92d56c.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{direct}}=8192\\times576=4{,}718{,}592\" width=\"392.94\" height=\"22.24\" style=\"width:392.94px;height:22.24px;aspect-ratio:392.94/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 2: 1 × 1 bottleneck reduction</h3>","<p>Each reduction output uses 1 × 1 × 64 = <strong>64</strong> weight–input pairs.</p>","<p>There are 16 × 16 × 8 = <strong>2,048</strong> reduction outputs.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:254.16px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/0bcc137de649f71d.svg\"><img class=\"math display-math\" src=\"assets/equations/07ded70ae81c3cd5.svg\" alt=\"\\mathrm{MACs}_{1\\times1}=16\\times16\\times8\\times1\\times1\\times64=131{,}072\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<p>The new map is <strong>16 × 16 × 8</strong>. This changes the next layer&#x27;s input channels to 8.</p>","<h3>Step 3: following 3 × 3 convolution</h3>","<p>Each output now uses 3 × 3 × 8 = <strong>72</strong> weight–input pairs, instead of 576.</p>","<p>The number of outputs remains 16 × 16 × 32 = <strong>8,192</strong>.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:212.07px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/da27ae2a69680cb6.svg\"><img class=\"math display-math\" src=\"assets/equations/798ae9e57f70e0ad.svg\" alt=\"\\mathrm{MACs}_{3\\times3}=16\\times16\\times32\\times3\\times3\\times8=589{,}824\" width=\"505.32\" height=\"22.24\" style=\"width:505.32px;height:22.24px;aspect-ratio:505.32/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 4: total bottleneck cost</h3>","<p>Include both stages; do not compare the direct layer against only the second stage.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:222.64px;--narrow-height:102.62px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/741f21ae6e5bfc83.svg\"><img class=\"math display-math\" src=\"assets/equations/ec8abadaa9257a67.svg\" alt=\"\\mathrm{MACs}_{\\mathrm{bottleneck}}=131{,}072+589{,}824=720{,}896\" width=\"483.59\" height=\"22.24\" style=\"width:483.59px;height:22.24px;aspect-ratio:483.59/22.24\" loading=\"lazy\"></picture></div>","<h3>Step 5: absolute saving</h3>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:241.66px;--narrow-height:63.53px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/005360b3f69dc10a.svg\"><img class=\"math display-math\" src=\"assets/equations/03fa81b05dc71237.svg\" alt=\"\\mathrm{saving}=4{,}718{,}592-720{,}896=3{,}997{,}696\" width=\"440.68\" height=\"21.58\" style=\"width:440.68px;height:21.58px;aspect-ratio:440.68/21.58\" loading=\"lazy\"></picture></div>","<h3>Step 6: percentage saving</h3>","<p>Divide the saving by the original direct cost, then multiply by 100.</p>","<div class=\"equation\"><picture class=\"responsive-equation\" style=\"--narrow-width:208.96px;--narrow-height:132.73px\"><source media=\"(max-width:670px)\" srcset=\"assets/equations/2a96913f36caca06.svg\"><img class=\"math display-math\" src=\"assets/equations/46344c94632c2247.svg\" alt=\"\\mathrm{saving\\ percent}=\\frac{3{,}997{,}696}{4{,}718{,}592}\\times100=84.722222\\%\" width=\"518.68\" height=\"54.54\" style=\"width:518.68px;height:54.54px;aspect-ratio:518.68/54.54\" loading=\"lazy\"></picture></div>","<p><strong>Final answer:</strong> direct <strong>4,718,592 MACs</strong>; bottleneck <strong>720,896 MACs</strong>; saving <strong>3,997,696 MACs</strong>, approximately <strong>84.72%</strong>. Both routes end in a 16 × 16 × 32 output, though they are different learned transformations.</p>","<p><strong>Yaad rakho:</strong> 1 × 1 se channels kam; expensive 3 × 3 ka kaam kam. Dono stages ka cost jodna hai.</p>"]},{"title":"Q4","question":["<p class=\"inline-question\"><strong>Q4 optional (3 marks). Explain transfer learning for image classification with limited labelled data. Distinguish feature extraction from fine-tuning and describe a suitable training procedure.</strong></p>"],"answer":["<h3>1. Definition</h3>","<p>Transfer learning reuses knowledge learned on a source task to help solve a target task. For image classification, a pretrained CNN can provide visual features that a new classifier uses for the target classes. This can reduce the amount of target data and training needed, provided the source features are useful for the target task.</p>","<h3>2. Feature extraction and fine-tuning</h3>","<div class=\"table-scroll\"><table><thead><tr><th>Method</th><th>Which parameters learn?</th><th>Main effect</th></tr></thead><tbody><tr><td>Feature extraction</td><td>Keep pretrained backbone weights fixed; train a new classification head</td><td>Learn to classify using fixed pretrained features</td></tr><tr><td>Fine-tuning</td><td>Update selected pretrained layers as well as the new head</td><td>Adapt representations to the target task</td></tr></tbody></table></div>","<p>Freezing a layer stops its parameter updates; it does not remove its stored weights. Fine-tuning typically exposes more trainable parameters and therefore needs particular care with small datasets.</p>","<figure><button class=\"diagram-open\" data-action=\"diagram\" data-src=\"assets/figures/v_transfer.svg\" aria-label=\"Enlarge diagram: Feature extraction freezes the pretrained backbone; fine-tuning permits selected pretrained layers to update.\"><img src=\"assets/figures/v_transfer.svg\" alt=\"Feature extraction freezes the pretrained backbone; fine-tuning permits selected pretrained layers to update.\" width=\"1080\" height=\"605\" loading=\"lazy\"></button><figcaption>Feature extraction freezes the pretrained backbone; fine-tuning permits selected pretrained layers to update. <span class=\"diagram-hint\">Tap the diagram to enlarge.</span></figcaption></figure>","<h3>3. Training procedure</h3>","<p>1. Create separate training, validation and test splits for the target problem.</p>","<p>2. Choose a suitable pretrained CNN and apply its required input size and preprocessing.</p>","<p>3. Replace the original classifier with a new head matching the target classes.</p>","<p>4. Freeze the backbone and train the new head on the training set.</p>","<p>5. If validation results justify it, unfreeze selected later layers and continue with an appropriately smaller learning rate.</p>","<p>6. Select the best checkpoint using validation performance; evaluate the final model on the held-out test set.</p>","<h3>4. Concrete example</h3>","<p>For a small dataset containing cats and dogs, reuse a pretrained image backbone and replace its original classifier with a binary-classification head. First learn the new head with the backbone frozen. Later, selected high-level layers may be fine-tuned if this improves validation performance.</p>","<p><strong>Final answer:</strong> feature extraction learns a new classifier over fixed features; fine-tuning also adapts selected pretrained features. The correct choice depends on target data quantity, similarity to the source data and validation results.</p>","<p><strong>Yaad rakho:</strong> Freeze mein purane features fixed; fine-tune mein selected purane features bhi seekhte hain.</p>"]}]}}
