TensorTonic
Problems
Reparameterized Gaussian Sample
Diffusion ModelsProbabilityGenerative Models
Easy

Turn standard Gaussian noise into samples from a diagonal Gaussian with a given mean and log variance, using the reparameterization trick.

z=μ+exp⁡ ⁣(12log⁡σ2)⊙ϵz = \mu + \exp\!\left(\tfrac{1}{2} \log \sigma^2\right) \odot \epsilonz=μ+exp(21​logσ2)⊙ϵ

Here mean holds the means μ\muμ, log_variance holds the natural logarithm log⁡σ2\log \sigma^2logσ2 of each coordinate's variance, and noise holds the standard Gaussian values ϵ\epsilonϵ. The factor exp⁡(12log⁡σ2)\exp(\tfrac{1}{2} \log \sigma^2)exp(21​logσ2) is the standard deviation σ\sigmaσ, and ⊙\odot⊙ is elementwise multiplication. The operation is purely elementwise, and the arrays follow NumPy broadcasting rules, so a single mean of shape (D,) can be combined with a batch of noise of shape (N, D) to give N samples at once.

Return a NumPy array of dtype float64 whose shape is the broadcast shape of mean, log_variance and noise.

Examples

Input: mean = [0.0,1.0,-2.0], log_variance = [0.0,1.386294,-1.386294], noise = [1.0,-0.5,2.0]

Output: [1.0,0.0,-1.0]

Explanation: The three log variances are log 1, log 4 and log 0.25 to six decimals, so the standard deviations are 1, 2 and 0.5. The noise values 1, -0.5 and 2 then move the means 0, 1 and -2 to 1, 0 and -1.

Input: mean = [1.0,-1.0], log_variance = [-0.6931,0.6931], noise = [[0.0,0.0],[1.0,1.0],[-2.0,0.5]]

Output: [[1.0,-1.0],[1.707123,0.41418],[-0.414247,-0.29291]]

Input: mean = [[0.5,0.25]], log_variance = [[-20.0,-20.0]], noise = [[3.0,-3.0]]

Output: [[0.500136,0.249864]]

Hint 1

np.exp(0.5 * log_variance) turns a log variance into a standard deviation.

Hint 2

A (D,) array broadcasts against an (N, D) array without reshaping.

Hint 3

Avoid += on an input array so the inputs stay unchanged.

Requirements

  • Use NumPy array operations.
  • Leave the inputs unchanged.

Constraints

  • mean and log_variance are float64 NumPy arrays of the same shape, with at least one dimension.
  • noise is a float64 NumPy array whose shape broadcasts with the shape of mean.
  • log_variance values lie in [-20, 5], so every standard deviation is positive and finite.
  • All values are finite.
Try Similar Problems
Diagonal Gaussian KL DivergenceEasyPosterior Mean and VarianceMediumGaussian Mixture ScoreMediumForward Diffusion SampleEasyNoise Prediction LossEasyPrediction ParameterizationMediumDDPM Ancestral StepMediumDDIM StepHardToy DDPM SamplerHardAutoencoder Forward PassMediumVariational Autoencoder Forward PassMediumGAN Training StepHard

Accepts: array

Accepts: array

Accepts: array

You must run your code first.

Reparameterized Gaussian Sample

Diffusion ModelsProbabilityGenerative Models
Easy

Turn standard Gaussian noise into samples from a diagonal Gaussian with a given mean and log variance, using the reparameterization trick.

z=μ+exp⁡ ⁣(12log⁡σ2)⊙ϵz = \mu + \exp\!\left(\tfrac{1}{2} \log \sigma^2\right) \odot \epsilonz=μ+exp(21​logσ2)⊙ϵ

Here mean holds the means μ\muμ, log_variance holds the natural logarithm log⁡σ2\log \sigma^2logσ2 of each coordinate's variance, and noise holds the standard Gaussian values ϵ\epsilonϵ. The factor exp⁡(12log⁡σ2)\exp(\tfrac{1}{2} \log \sigma^2)exp(21​logσ2) is the standard deviation σ\sigmaσ, and ⊙\odot⊙ is elementwise multiplication. The operation is purely elementwise, and the arrays follow NumPy broadcasting rules, so a single mean of shape (D,) can be combined with a batch of noise of shape (N, D) to give N samples at once.

Return a NumPy array of dtype float64 whose shape is the broadcast shape of mean, log_variance and noise.

Examples

Input: mean = [0.0,1.0,-2.0], log_variance = [0.0,1.386294,-1.386294], noise = [1.0,-0.5,2.0]

Output: [1.0,0.0,-1.0]

Explanation: The three log variances are log 1, log 4 and log 0.25 to six decimals, so the standard deviations are 1, 2 and 0.5. The noise values 1, -0.5 and 2 then move the means 0, 1 and -2 to 1, 0 and -1.

Input: mean = [1.0,-1.0], log_variance = [-0.6931,0.6931], noise = [[0.0,0.0],[1.0,1.0],[-2.0,0.5]]

Output: [[1.0,-1.0],[1.707123,0.41418],[-0.414247,-0.29291]]

Input: mean = [[0.5,0.25]], log_variance = [[-20.0,-20.0]], noise = [[3.0,-3.0]]

Output: [[0.500136,0.249864]]

Hint 1

np.exp(0.5 * log_variance) turns a log variance into a standard deviation.

Hint 2

A (D,) array broadcasts against an (N, D) array without reshaping.

Hint 3

Avoid += on an input array so the inputs stay unchanged.

Requirements

  • Use NumPy array operations.
  • Leave the inputs unchanged.

Constraints

  • mean and log_variance are float64 NumPy arrays of the same shape, with at least one dimension.
  • noise is a float64 NumPy array whose shape broadcasts with the shape of mean.
  • log_variance values lie in [-20, 5], so every standard deviation is positive and finite.
  • All values are finite.
Try Similar Problems
Diagonal Gaussian KL DivergenceEasyPosterior Mean and VarianceMediumGaussian Mixture ScoreMediumForward Diffusion SampleEasyNoise Prediction LossEasyPrediction ParameterizationMediumDDPM Ancestral StepMediumDDIM StepHardToy DDPM SamplerHardAutoencoder Forward PassMediumVariational Autoencoder Forward PassMediumGAN Training StepHard

Accepts: array

Accepts: array

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1