DQN Targets with a Target Network

~16 mincode completion

Implement dqn_targets_and_loss(rewards, dones, q_target_next, q_online, actions, gamma) returning one array: the targets followed by the loss, so it has length .

Where this shows up

~16 min

6 employers weight this skill

4 autonomy companies, 2 defense companies. Top match scores 87.

Python
import numpy as np


def dqn_targets_and_loss(rewards, dones, q_target_next, q_online, actions, gamma):
    """
    DQN regression targets from a target network, and the TD loss.

    Args:
        rewards:       (B,) reward of each transition
        dones:         (B,) 1 if the episode ended on this transition, else 0
        q_target_next: (B, A) target-network Q-values at the next state s'
        q_online:      (B, A) online-network Q-values at the current state s
        actions:       (B,) index of the action taken in s
        gamma:         discount factor

    Returns:
        (B + 1,) array: [y_1, ..., y_B, loss]
    """
    # YOUR CODE HERE
    pass

Run your code to see results

⌘↵ runs against the visible tests

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.