Implement the discriminator forward pass for a linear GAN discriminator. For a batch of samples, compute
D(X)=σ(XW) σ(a)=1+e−a1Here, X∈RB×D contains B samples with D features, W∈RD×1 contains the supplied discriminator weights, and D(X)∈RB×1 contains the probability assigned to each sample being real. Return D(X) as a float64 NumPy array with shape (B,1).
Examples
Input: x = [[1,0],[0,1],[0.5,0.5]], W = [[0.8],[-0.3]]
Output: [[0.689974],[0.425557],[0.562177]]
Explanation: The matrix product produces one logit per sample, and sigmoid maps each logit to a probability.
Input: x = [[1,1,1],[-1,-1,-1]], W = [[0.5],[0.2],[-0.3]]
Output: [[0.598688],[0.401312]]
Input: x = [[0.3,-0.7,0.5,0.1]], W = [[0.4],[-0.2],[0.6],[0.1]]
Output: [[0.638763]]
Hint 1
Use matrix multiplication to obtain one logit per row.
Hint 2
Apply the sigmoid elementwise with NumPy broadcasting.
Requirements
- Use NumPy.
- Apply the supplied weight matrix to every sample.
- Apply the sigmoid function elementwise to the logits.
- Return a float64 NumPy array with shape (B,1).
Constraints
- X has shape (B,D).
- W has shape (D,1).
- 1≤B≤5 and 1≤D≤6.
- All input values are finite real numbers.
All steps in GAN
Accepts: array
Accepts: array
Discriminator
Implement the discriminator forward pass for a linear GAN discriminator. For a batch of samples, compute
D(X)=σ(XW) σ(a)=1+e−a1Here, X∈RB×D contains B samples with D features, W∈RD×1 contains the supplied discriminator weights, and D(X)∈RB×1 contains the probability assigned to each sample being real. Return D(X) as a float64 NumPy array with shape (B,1).
Examples
Input: x = [[1,0],[0,1],[0.5,0.5]], W = [[0.8],[-0.3]]
Output: [[0.689974],[0.425557],[0.562177]]
Explanation: The matrix product produces one logit per sample, and sigmoid maps each logit to a probability.
Input: x = [[1,1,1],[-1,-1,-1]], W = [[0.5],[0.2],[-0.3]]
Output: [[0.598688],[0.401312]]
Input: x = [[0.3,-0.7,0.5,0.1]], W = [[0.4],[-0.2],[0.6],[0.1]]
Output: [[0.638763]]
Hint 1
Use matrix multiplication to obtain one logit per row.
Hint 2
Apply the sigmoid elementwise with NumPy broadcasting.
Requirements
- Use NumPy.
- Apply the supplied weight matrix to every sample.
- Apply the sigmoid function elementwise to the logits.
- Return a float64 NumPy array with shape (B,1).
Constraints
- X has shape (B,D).
- W has shape (D,1).
- 1≤B≤5 and 1≤D≤6.
- All input values are finite real numbers.
All steps in GAN
Accepts: array
Accepts: array