The Maxout Discriminator, With Dropout and the Gradient It Passes Back
In the experiments of Goodfellow et al. (2014) the discriminator uses maxout units and is trained with dropout, and the generator learns from the gradient of the discriminator's output with respect to its input. Implement the forward pass of a two-hidden-layer maxout discriminator and that input gradient.
Implement maxout_discriminator(X, params, k, masks=None, keep_in=0.8, keep_hidden=0.5).
Maxout layer. A layer with u units and k pieces computes ku affine outputs t=Wh+b and returns u values; unit j (counting from 0) takes the largest of its own block of k consecutive outputs:
maxout(t)j=max(tjk,tjk+1,…,tjk+k−1).
On a tie the first (lowest-index) piece is the selected one.
The network. X is an m×d list (one input per row). params is a dict with "W1" (u1k×d), "b1" (u1k), "W2" (u2k×u1), "b2" (u2k), "w3" (u2) and the float "b3". For each row x:
h1=maxout(W1x~+b1),h2=maxout(W2h~1+b2),a=w3⊤h~2+b3,D=σ(a).
Dropout. If masks is None (evaluation), x~=x, h~1=h1, h~2=h2. Otherwise masks is a dict of 0/1 lists "in" (m×d), "h1" (m×u1), "h2" (m×u2), and each layer's input is masked and rescaled: x~=x⊙min/pin, h~1=h1⊙m1/ph, h~2=h2⊙m2/ph, with pin = keep_in and ph = keep_hidden.
Output: a dict with "logit" (list of a), "D" (list of D), and "grad_x", the m×d list of ∂a/∂x for each row, through the same masks and the selected pieces.
Notes
- Compute σ stably. Return plain Python floats in lists. Do not round.