Practice
1.
import numpy as np
# Forward pass for a single neuron
inputs = np.array([1.0, 2.0, 3.0])
weights = np.array([0.2, 0.8, -0.5])
bias = 2.0
output = np.dot(inputs, weights) + bias
print(output)easy
Solution
Step 1: Calculate dot product
np.dot(inputs, weights) = 1.0*0.2 + 2.0*0.8 + 3.0*(-0.5) = 0.2 + 1.6 - 1.5 = 0.3Step 2: Add bias
0.3 + 2.0 = 2.3Final Answer:
Option A -> Option AQuick Check:
Dot product then add bias [OK]
Hint: Dot product then add bias [OK]
Common Mistakes:
2. What is the time complexity of the following non-max suppression implementation?
def non_max_suppression(boxes, scores, iou_threshold):
indices = np.argsort(scores)[::-1]
keep = []
while len(indices) > 0:
current = indices[0]
keep.append(current)
indices = indices[1:]
indices = [i for i in indices if iou(boxes[current], boxes[i]) < iou_threshold]
return keepeasy
Solution
Step 1: Analyze the loop structure
The outer loop runs n times, and the inner loop (IoU calculation) also runs n times in the worst case.Step 2: Determine complexity
Each IoU calculation is O(1), making the overall complexity O(n^2).Final Answer:
Option B -> Option BQuick Check:
Nested loops suggest O(n^2) [OK]
Hint: Nested loops suggest O(n^2) [OK]
Common Mistakes:
3. What is the time complexity of calculating the mean Average Precision (mAP) for a single image with N predicted bounding boxes and M ground truth boxes?
easy
Solution
Step 1: Understand the Process
For each predicted box, IoU is calculated with each ground truth box, leading to N * M comparisons.Step 2: Determine Complexity
Each comparison is constant time, so the overall complexity is O(N * M).Final Answer:
Option C -> Option CQuick Check:
IoU comparisons drive complexity [OK]
Hint: IoU comparisons drive complexity [OK]
Common Mistakes:
4. What does the following Python code snippet output when implementing sinusoidal positional encoding?
import numpy as np
def positional_encoding(position, d_model):
angle_rads = np.arange(position)[:, np.newaxis] / np.power(10000, (2 * (np.arange(d_model)[np.newaxis, :] // 2)) / np.float32(d_model))
angle_rads[:, 0::2] = np.sin(angle_rads[:, 0::2])
angle_rads[:, 1::2] = np.cos(angle_rads[:, 1::2])
return angle_rads
pe = positional_encoding(4, 4)
print(pe)easy
Solution
Step 1: Understand the code logic
The code generates a matrix where each row corresponds to a position and each column to a dimension, filled with sinusoidal values.Step 2: Eliminate wrong options
A 4x4 matrix with all zeros is incorrect because the matrix is not filled with zeros. A 4x4 identity matrix is incorrect because the matrix is not an identity matrix. A 4x4 matrix with random values is incorrect because the values are not random but deterministic sinusoidal values.Final Answer:
Option A -> Option AQuick Check:
Sinusoidal encoding alternates sine/cosine. [OK]
Hint: Sinusoidal encoding alternates sine/cosine. [OK]
Common Mistakes:
5. In a Random Forest implementation, how would you apply feature sampling to handle high-dimensional data effectively?
medium
Solution
Step 1: Understand Feature Sampling
Feature sampling involves selecting a random subset of features for each tree to reduce dimensionality.Step 2: Evaluate Options
Using all features (A) or a fixed subset (C) doesn't reduce dimensionality; correlation-based selection (D) isn't random.Final Answer:
Option C -> Option CQuick Check:
Random subsets reduce dimensionality [OK]
Hint: Random subsets reduce dimensionality [OK]
Common Mistakes:
