Skip to content
DeepForgeby svx
All problems

Length Bias Correlation

Problem

Measure length bias as the Pearson correlation between rewards and response lengths.

Return cov / sqrt(var_r * var_l) computed with population moments. Return 0.0 when there are fewer than two points or either variance is zero.

Hint

A positive reward-length correlation is the classic signature of length bias.

Test cases

case 1
in: [[1,2,3],[10,20,30]]
expected: 1
case 2
in: [[3,2,1],[10,20,30]]
expected: -1
case 3
in: [[1,2],[5,5]]
expected: 0
case 4
in: [[1],[2]]
expected: 0
Starter codePython
import math
def length_bias_correlation(rewards, lengths):
    # Your code here
    pass

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