All problems
Detailed Balance Check
Problem
Check that pi satisfies detailed balance with respect to the transition matrix:
pi[i] * matrix[i][j] = pi[j] * matrix[j][i] for all i, j
within a tolerance of 1e-9. Return True or False, and False for malformed input.
Hint
Check both directions of every off-diagonal flow.
Test cases
case 1
in: [[0.5,0.5],[[0.5,0.5],[0.5,0.5]]]
expected: true
case 2
in: [[0.5,0.5],[[0.8,0.2],[0.2,0.8]]]
expected: true
case 3
in: [[0.3,0.7],[[0.5,0.5],[0.5,0.5]]]
expected: false
case 4
in: [[0.5,0.5],[[0.9,0.1],[0.2,0.8]]]
expected: false
Starter codePython
def detailed_balance_check(pi, matrix):
# Your code here
pass4 test cases · run your code against them in the editor