Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-195

Recurrence Rate

Problem

Compute the recurrence rate: the fraction of unordered pairs (i, j) with abs(x[i] - x[j]) <= threshold.

Return 0.0 for a series with fewer than two points. Pairs are counted once.

Hint

This is the simplest point of a recurrence plot: its overall density.

Test cases

case 1
in: [[1,2,3,4],1]
expected: 0.5
case 2
in: [[1,1,1],0]
expected: 1
case 3
in: [[0,10],5]
expected: 0
case 4
in: [[1,2],1]
expected: 1
Starter codePython
def recurrence_rate(series, threshold):
    # Your code here
    pass

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