Practice
1. What is the time complexity of the forward pass of batch normalization for a dataset with n samples and d features?
easy
Solution
Step 1: Analyze the operations
Batch normalization involves computing mean and variance, both O(n * d) operations.Step 2: Consider the normalization step
Normalizing each feature is also O(n * d).Final Answer:
Option D -> Option DQuick Check:
Batch norm: O(n * d) for mean/variance [OK]
Hint: Batch norm: O(n * d) for mean/variance [OK]
Common Mistakes:
2. What does the following Python code snippet output when calculating the Intersection over Union (IoU) for two bounding boxes?
import numpy as np
def iou(box1, box2):
x1 = max(box1[0], box2[0])
y1 = max(box1[1], box2[1])
x2 = min(box1[2], box2[2])
y2 = min(box1[3], box2[3])
intersection = max(0, x2 - x1) * max(0, y2 - y1)
area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
union = area1 + area2 - intersection
return intersection / union
box1 = [0, 0, 2, 2]
box2 = [1, 1, 3, 3]
print(iou(box1, box2))easy
Solution
Step 1: Calculate Intersection and Union
The intersection area is 1 (from (1,1) to (2,2)). The union area is 7 (4 from box1 + 4 from box2 - 1 intersection).Step 2: Calculate IoU
IoU = 1/7 = 0.14285714285714285.Final Answer:
Option A -> Option AQuick Check:
Intersection over Union formula [OK]
Hint: Intersection over Union formula [OK]
Common Mistakes:
3. In which scenario is gradient checking most useful?
medium
Solution
Step 1: Identify scenarios where gradient checking is applicable
Gradient checking is crucial when implementing new components to ensure correctness.Step 2: Eliminate unrelated scenarios
Options A, C, and D are not directly related to verifying gradient correctness.Final Answer:
Option A -> Option AQuick Check:
Use gradient check for new components. [OK]
Hint: Use gradient check for new components. [OK]
Common Mistakes:
4. In a PCA implementation, you need to project data onto the first two principal components. Which approach is correct?
medium
Solution
Step 1: Understand projection in PCA
Projection involves multiplying the data matrix by the eigenvectors corresponding to the desired components.Step 2: Eliminate wrong options
Multiply the data matrix by the first two eigenvalues. is incorrect because eigenvalues are not used for projection. Multiply the covariance matrix by the first two eigenvectors. and D incorrectly use the covariance matrix instead of the data matrix.Final Answer:
Option A -> Option AQuick Check:
Project data using eigenvectors, not eigenvalues. [OK]
Hint: Project data using eigenvectors, not eigenvalues. [OK]
Common Mistakes:
5. How can you optimize the computation of softmax and cross-entropy loss for a batch of inputs in a neural network?
hard
Solution
Step 1: Identify optimization opportunity
Combining softmax and cross-entropy avoids intermediate storage of probabilities.Step 2: Reduce computational overhead
This reduces both memory usage and computational cost.Final Answer:
Option C -> Option CQuick Check:
Combine operations to save resources [OK]
Hint: Combine operations to save resources [OK]
Common Mistakes:
