Problems
Loading...
Step 1 of 6
Generator
Easy

Implement the generator forward pass for a linear GAN generator. Compute

G(Z)=tanh⁡(ZW+b)G(Z) = \tanh(ZW + b)

Here, Z∈RB×NZ \in \mathbb{R}^{B \times N} contains BB noise vectors of width NN, W∈RN×DW \in \mathbb{R}^{N \times D} contains the supplied generator weights, b∈RDb \in \mathbb{R}^{D} is the supplied bias, and G(Z)∈RB×DG(Z) \in \mathbb{R}^{B \times D} contains generated samples. Return G(Z)G(Z) as a float64 NumPy array with shape (B,D)(B, D).

Loading visualization...

Examples

Input: z = [[1,0,-1],[0.5,0.5,0.5]], W = [[0.3,-0.1,0.2,0.5],[0.1,0.4,-0.3,0.2],[-0.2,0.1,0.6,-0.4]], b = [0.1,-0.1,0,0.2]

Output: [[0.53705,-0.291313,-0.379949,0.800499],[0.197375,0.099668,0.244919,0.336376]]

Explanation: The affine projection maps each noise vector into data space, and tanh bounds every generated feature between minus one and one.

Input: z = [[2,-1]], W = [[0.5,-0.2,0.3],[-0.1,0.4,0.6]], b = [0,0.1,-0.1]

Output: [[0.800499,-0.604368,-0.099668]]

Input: z = [[0.5,-0.5],[1,1],[-1,0]], W = [[0.4,0.3],[-0.2,0.5]], b = [0.1,-0.1]

Output: [[0.379949,-0.197375],[0.291313,0.604368],[-0.291313,-0.379949]]

Hint 1

Broadcast the bias across the rows of the matrix product.

Hint 2

NumPy applies tanh elementwise to the projected batch.

Requirements

  • Use NumPy.
  • Apply the supplied affine transformation to every noise vector.
  • Apply the hyperbolic tangent elementwise.
  • Return a float64 NumPy array with shape (B,D)(B, D).

Constraints

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