Implement inverted dropout for a NumPy array. During training, independently drop each element with probability p. Scale every retained element by 1/(1−p) so the expected output magnitude is unchanged.
Use rng.random(x.shape) when an rng generator is provided. Otherwise, use np.random.random(x.shape). The test panel displays a seed; the runner creates np.random.default_rng(seed) and passes that generator as rng.
Return (output, dropout_pattern), where dropout_pattern is the scaled mask applied to the input. Its entries are 0 for dropped elements and 1/(1−p) for retained elements.
Input: x = [[1, 2], [3, 4]], p = 0.5, seed = 123
Output: ([[0.0, 4.0], [6.0, 8.0]], [[0.0, 2.0], [2.0, 2.0]])
Explanation: The seeded generator drops the first element. Retained elements are multiplied by 2 because p = 0.5.
Input: x = [[1, 2], [3, 4]], p = 0.0, seed = 7
Output: ([[1.0, 2.0], [3.0, 4.0]], [[1.0, 1.0], [1.0, 1.0]])
Generate one random value per input element and retain positions below 1 - p.
Build the pattern with 1 / (1 - p) at retained positions and zero elsewhere.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Implement inverted dropout for a NumPy array. During training, independently drop each element with probability p. Scale every retained element by 1/(1−p) so the expected output magnitude is unchanged.
Use rng.random(x.shape) when an rng generator is provided. Otherwise, use np.random.random(x.shape). The test panel displays a seed; the runner creates np.random.default_rng(seed) and passes that generator as rng.
Return (output, dropout_pattern), where dropout_pattern is the scaled mask applied to the input. Its entries are 0 for dropped elements and 1/(1−p) for retained elements.
Input: x = [[1, 2], [3, 4]], p = 0.5, seed = 123
Output: ([[0.0, 4.0], [6.0, 8.0]], [[0.0, 2.0], [2.0, 2.0]])
Explanation: The seeded generator drops the first element. Retained elements are multiplied by 2 because p = 0.5.
Input: x = [[1, 2], [3, 4]], p = 0.0, seed = 7
Output: ([[1.0, 2.0], [3.0, 4.0]], [[1.0, 1.0], [1.0, 1.0]])
Generate one random value per input element and retain positions below 1 - p.
Build the pattern with 1 / (1 - p) at retained positions and zero elsewhere.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number