Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-275

Martingale Property Check

Problem

A payoff vector x is a martingale for a Markov chain when E[x_next | state i] = x[i], that is when the sum over j of matrix[i][j] * x[j] equals x[i] for every state i. Return True when all states satisfy this within 1e-9. Return False for malformed input.

Hint

Check that the transition matrix applied to the payoff vector reproduces the vector.

Test cases

case 1
in: [[[0.5,0.5],[0.5,0.5]],[1,1]]
expected: true
case 2
in: [[[0.5,0.5],[0.5,0.5]],[1,2]]
expected: false
case 3
in: [[[1,0],[0,1]],[3,7]]
expected: true
case 4
in: [[[0.25,0.75],[0.75,0.25]],[0,0]]
expected: true
case 5
in: [[[0.5,0.5]],[]]
expected: false
Starter codePython
def martingale_property_check(matrix, payoff):
    # Your code here
    pass

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