GAN Discriminator BCE

~10 mincode completion

Implement discriminator_bce(y, d) returning a scalar.

Examples

Two reals at 0.8 and 0.9

Input
discriminator_bce([1, 1], [0.8, 0.9])
Output
0.16425

Two fakes at 0.2 and 0.1 (symmetric of t1)

Input
discriminator_bce([0, 0], [0.2, 0.1])
Output
0.16425

A mixed pair

Input
discriminator_bce([1, 0], [0.7, 0.4])
Output
0.43375

Hints

Hint 1

bounds an array in one call.

Hint 2

Do not forget to the fake term. That step is easy to skip.

Requirements

  • y: labels, 1 for real and 0 for fake

  • d: predicted probabilities in (0, 1), same shape as y

  • Return scalar

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

8 employers weight this skill

4 autonomy companies, 1 enterprise vendor, 1 defense company, 1 health and bio company, 1 AI product company. Top match scores 87.

Python
import numpy as np


def discriminator_bce(y, d):
    """
    Mean binary cross-entropy of discriminator probabilities.

    Args:
        y: labels, 1 for real and 0 for fake
        d: predicted probabilities in (0, 1), same shape as y

    Returns:
        scalar
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.