REINFORCE Gradient for a Softmax Policy

~14 mincode completion

Implement reinforce_grad(logits, action, ret) returning the gradient of with respect to the logits, as an array the same length as logits.

Python
import numpy as np


def reinforce_grad(logits, action, ret):
    """
    Gradient of ret * log softmax(logits)[action] with respect to the logits.

    Args:
        logits: (A,) unnormalized action scores
        action: index of the action taken
        ret:    return G that followed the action

    Returns:
        (A,) array, the gradient with respect to each logit
    """
    # 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.