Skip to content
DeepForgeby svx
All problems

Weighted Behavioral Cloning Loss

Problem

Compute a weighted behavioral cloning loss.

Each demonstrated action contributes weights[i] * log_probs[i]; return the negative weighted mean, normalizing by the total weight. If the total weight is zero or the batch is empty, return 0.0.

Hint

Weighting demonstrations keeps rare but important behaviors from being drowned out.

Test cases

case 1
in: [[-0.5,-1],[1,1]]
expected: 0.75
case 2
in: [[-0.5,-1],[1,3]]
expected: 0.875
case 3
in: [[],[]]
expected: 0
case 4
in: [[-2],[0]]
expected: 0
Starter codePython
def bc_weighted_loss(log_probs, weights):
    # Your code here
    pass

4 test cases · run your code against them in the editor