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=N1i=1∑N(xij−μj)2 s=D1j=1∑DsjHere, N is the number of generated samples, D is the number of features, xij is feature j of sample i, μj is that feature's batch mean, sj is its population standard deviation, and s is the diversity score. Mark the batch as collapsed only when s is strictly less than threshold. Return a dictionary containing diversity_score as a Python float and is_collapsed as a boolean.
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).
- 2≤N≤9 and 1≤D≤6.
- threshold is a positive finite float.
- All sample values are finite real numbers.
All steps in GAN
Accepts: array
Accepts: number
Mode Collapse
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=N1i=1∑N(xij−μj)2 s=D1j=1∑DsjHere, N is the number of generated samples, D is the number of features, xij is feature j of sample i, μj is that feature's batch mean, sj is its population standard deviation, and s is the diversity score. Mark the batch as collapsed only when s is strictly less than threshold. Return a dictionary containing diversity_score as a Python float and is_collapsed as a boolean.
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).
- 2≤N≤9 and 1≤D≤6.
- threshold is a positive finite float.
- All sample values are finite real numbers.
All steps in GAN
Accepts: array
Accepts: number