Problems
Loading...
Step 5 of 6
Mode Collapse
Easy

Implement a specified diversity heuristic for detecting possible mode collapse. Compute the population standard deviation of every feature across the generated batch, then average those deviations.

sj=1N∑i=1N(xij−μj)2s_j = \sqrt{\frac{1}{N}\sum_{i=1}^{N}(x_{ij}-\mu_j)^2} s=1D∑j=1Dsjs = \frac{1}{D}\sum_{j=1}^{D}s_j

Here, NN is the number of generated samples, DD is the number of features, xijx_{ij} is feature jj of sample ii, μj\mu_j is that feature's batch mean, sjs_j is its population standard deviation, and ss is the diversity score. Mark the batch as collapsed only when ss is strictly less than threshold. Return a dictionary containing diversity_score as a Python float and is_collapsed as a boolean.

Loading visualization...

Examples

Input: generated_samples = [[1,2,3],[1,2,3],[1,2,3]], threshold = 0.1

Output: {"diversity_score":0,"is_collapsed":true}

Explanation: Identical rows have zero deviation in every feature, so their diversity score falls below the threshold.

Input: generated_samples = [[1,0],[-1,2],[0.5,-1.5],[2,1],[-0.5,0.5]], threshold = 0.1

Output: {"diversity_score":1.112646,"is_collapsed":false}

Input: generated_samples = [[1,2],[1.01,2.02],[0.99,1.98],[1,2.01]], threshold = 0.1

Output: {"diversity_score":0.010931,"is_collapsed":true}

Hint 1

Reduce the standard deviation over axis zero.

Hint 2

Average the resulting per-feature values before comparing with the threshold.

Requirements

  • Use NumPy.
  • Compute population standard deviations across the batch axis.
  • Average the per-feature deviations.
  • Use a strict comparison with the supplied threshold.
  • Return exactly the documented dictionary.

Constraints

  • generated_samples has shape (N,D)(N, D).
  • 2≤N≤92 \le N \le 9 and 1≤D≤61 \le D \le 6.
  • threshold is a positive finite float.
  • All sample values are finite real numbers.