Implement the generator forward pass for a linear GAN generator. Compute
G(Z)=tanh(ZW+b)Here, Z∈RB×N contains B noise vectors of width N, W∈RN×D contains the supplied generator weights, b∈RD is the supplied bias, and G(Z)∈RB×D contains generated samples. Return G(Z) as a float64 NumPy array with shape (B,D).
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).
Constraints
- Z has shape (B,N).
- W has shape (N,D).
- b has shape (D).
- 1≤B≤4, 1≤N≤5, and 1≤D≤6.
- All input values are finite real numbers.
All steps in GAN
Accepts: array
Accepts: array
Accepts: array
Generator
Implement the generator forward pass for a linear GAN generator. Compute
G(Z)=tanh(ZW+b)Here, Z∈RB×N contains B noise vectors of width N, W∈RN×D contains the supplied generator weights, b∈RD is the supplied bias, and G(Z)∈RB×D contains generated samples. Return G(Z) as a float64 NumPy array with shape (B,D).
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).
Constraints
- Z has shape (B,N).
- W has shape (N,D).
- b has shape (D).
- 1≤B≤4, 1≤N≤5, and 1≤D≤6.
- All input values are finite real numbers.
All steps in GAN
Accepts: array
Accepts: array
Accepts: array