Problems
Loading...
Step 2 of 6
Discriminator
Medium

Implement the discriminator forward pass for a linear GAN discriminator. For a batch of samples, compute

D(X)=σ(XW)D(X) = \sigma(XW) σ(a)=11+e−a\sigma(a) = \frac{1}{1 + e^{-a}}

Here, X∈RB×DX \in \mathbb{R}^{B \times D} contains BB samples with DD features, W∈RD×1W \in \mathbb{R}^{D \times 1} contains the supplied discriminator weights, and D(X)∈RB×1D(X) \in \mathbb{R}^{B \times 1} contains the probability assigned to each sample being real. Return D(X)D(X) as a float64 NumPy array with shape (B,1)(B, 1).

Loading visualization...

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)(B, 1).

Constraints

  • XX has shape (B,D)(B, D).
  • WW has shape (D,1)(D, 1).
  • 1≤B≤51 \le B \le 5 and 1≤D≤61 \le D \le 6.
  • All input values are finite real numbers.