Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-206

Delay via Mutual Information

Problem

Choose an embedding delay by mutual information. For each lag k from 1 to max_delay compute the mutual information between x[:-k] and x[k:] using four equal-width bins over the combined range, and return the lag with the largest value (the smallest lag wins ties).

Return 1 when the parameters are invalid or all values tie at zero.

Hint

The first minimum of mutual information is the classical delay choice, but here we take the maximum.

Test cases

case 1
in: [[1,2,1,2,1,2,1,2],3]
expected: 2
case 2
in: [[1,2,3,4,5,6,7,8],3]
expected: 2
case 3
in: [[5,5,5,5,5],3]
expected: 1
case 4
in: [[0,1,0,1,1,0,1,0],4]
expected: 4
Starter codePython
import math
def delay_mutual_information(series, max_delay):
    # Your code here
    pass

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