TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement Wasserstein Critic Loss

Loss Functions
Easy

Compute the Wasserstein critic loss from raw critic scores:

L=1Nf∑i=1NfD(xifake)−1Nr∑i=1NrD(xireal)L = \frac{1}{N_f}\sum_{i=1}^{N_f}D(x_i^{\mathrm{fake}}) - \frac{1}{N_r}\sum_{i=1}^{N_r}D(x_i^{\mathrm{real}})L=Nf​1​i=1∑Nf​​D(xifake​)−Nr​1​i=1∑Nr​​D(xireal​)

Here, D(x)D(x)D(x) is a raw critic score, NfN_fNf​ is the number of fake samples, and NrN_rNr​ is the number of real samples. The two score arrays may have different lengths. Return the difference of their means as a Python float.

Loading visualization...

Examples

Input: real_scores = [2.0, 1.5, 3.0], fake_scores = [-1.0, 0.0, 0.5]

Output: -2.333333

Explanation: The fake-score mean is -0.166667 and the real-score mean is 2.166667.

Input: real_scores = [1.0, 2.0, 3.0], fake_scores = [2.0, 2.0, 2.0]

Output: 0.0

Input: real_scores = [0.0, 0.0], fake_scores = [1.0, 2.0, 3.0]

Output: 2.0

Hint 1

Use np.mean separately on the real and fake arrays.

Hint 2

Return float(mean_fake - mean_real).

Requirements

  • Compute the fake-score mean and real-score mean independently
  • Subtract the real mean from the fake mean
  • Return the result as a Python float

Constraints

  • real_scores and fake_scores are nonempty finite numeric lists
  • The two lists may have different lengths
  • Use raw scores without applying an activation
  • Use NumPy only
Try Similar Problems
Cross Entropy LossKl DivergenceHinge LossMean Squared ErrorHuber Loss

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Implement Wasserstein Critic Loss

Loss Functions
Easy

Compute the Wasserstein critic loss from raw critic scores:

L=1Nf∑i=1NfD(xifake)−1Nr∑i=1NrD(xireal)L = \frac{1}{N_f}\sum_{i=1}^{N_f}D(x_i^{\mathrm{fake}}) - \frac{1}{N_r}\sum_{i=1}^{N_r}D(x_i^{\mathrm{real}})L=Nf​1​i=1∑Nf​​D(xifake​)−Nr​1​i=1∑Nr​​D(xireal​)

Here, D(x)D(x)D(x) is a raw critic score, NfN_fNf​ is the number of fake samples, and NrN_rNr​ is the number of real samples. The two score arrays may have different lengths. Return the difference of their means as a Python float.

Loading visualization...

Examples

Input: real_scores = [2.0, 1.5, 3.0], fake_scores = [-1.0, 0.0, 0.5]

Output: -2.333333

Explanation: The fake-score mean is -0.166667 and the real-score mean is 2.166667.

Input: real_scores = [1.0, 2.0, 3.0], fake_scores = [2.0, 2.0, 2.0]

Output: 0.0

Input: real_scores = [0.0, 0.0], fake_scores = [1.0, 2.0, 3.0]

Output: 2.0

Hint 1

Use np.mean separately on the real and fake arrays.

Hint 2

Return float(mean_fake - mean_real).

Requirements

  • Compute the fake-score mean and real-score mean independently
  • Subtract the real mean from the fake mean
  • Return the result as a Python float

Constraints

  • real_scores and fake_scores are nonempty finite numeric lists
  • The two lists may have different lengths
  • Use raw scores without applying an activation
  • Use NumPy only
Try Similar Problems
Cross Entropy LossKl DivergenceHinge LossMean Squared ErrorHuber Loss

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.