Implement inverted dropout using a supplied binary mask. During training, retained values are divided by 1−p so their expected scale is unchanged:
y=1−px⊙m.Here, p is the drop probability and m is the supplied mask. During evaluation, return x unchanged. Return a new float64 NumPy array.
Examples
Input: x = [1,2,3,4], p = 0.5, training = true, mask = [0,1,1,0]
Output: [0,4,6,0]
Explanation: The retained values are multiplied by two because 1 / (1 - 0.5) = 2.
Input: x = [1,-2,3], p = 0.5, training = false, mask = [0,0,0]
Output: [1,-2,3]
Input: x = [[1,2],[3,4]], p = 0.25, training = true, mask = [[1,0],[1,1]]
Output: [[1.333333,0],[4,5.333333]]
Hint 1
Training mode uses x * mask / (1 - p).
Hint 2
Evaluation mode should return x.copy().
Requirements
- In training mode, multiply x by mask and divide by 1−p.
- In evaluation mode, return an unchanged copy of x.
- Do not modify the supplied arrays.
- Return a float64 NumPy array with the same shape as x.
Constraints
- x and mask have the same nonempty shape.
- mask contains only 0 and 1.
- 0≤p<1.
- training is a Boolean.
All steps in AlexNet
Accepts: array
Accepts: number
Accepts: array
Dropout Regularization
Implement inverted dropout using a supplied binary mask. During training, retained values are divided by 1−p so their expected scale is unchanged:
y=1−px⊙m.Here, p is the drop probability and m is the supplied mask. During evaluation, return x unchanged. Return a new float64 NumPy array.
Examples
Input: x = [1,2,3,4], p = 0.5, training = true, mask = [0,1,1,0]
Output: [0,4,6,0]
Explanation: The retained values are multiplied by two because 1 / (1 - 0.5) = 2.
Input: x = [1,-2,3], p = 0.5, training = false, mask = [0,0,0]
Output: [1,-2,3]
Input: x = [[1,2],[3,4]], p = 0.25, training = true, mask = [[1,0],[1,1]]
Output: [[1.333333,0],[4,5.333333]]
Hint 1
Training mode uses x * mask / (1 - p).
Hint 2
Evaluation mode should return x.copy().
Requirements
- In training mode, multiply x by mask and divide by 1−p.
- In evaluation mode, return an unchanged copy of x.
- Do not modify the supplied arrays.
- Return a float64 NumPy array with the same shape as x.
Constraints
- x and mask have the same nonempty shape.
- mask contains only 0 and 1.
- 0≤p<1.
- training is a Boolean.
All steps in AlexNet
Accepts: array
Accepts: number
Accepts: array