All problems
Ising Gibbs Conditional Probability
Problem
For an Ising model with local field field, couplings couplings[j] to neighboring spins, and current neighbor spin values, the Gibbs conditional probability that the node equals 1 is sigmoid(2 * (field + sum of couplings[j] * neighbors[j])). Neighbor spins must be 0 or 1. Return 0.0 for mismatched lengths or an invalid spin.
Hint
Collect the field and the coupling-weighted neighbor spins into a single local field.
Test cases
case 1
in: [0,[0.5],[1]]
expected: 0.7310585786300049
case 2
in: [-0.2,[0.3,0.4],[0.5,0.5]]
expected: 0
case 3
in: [0,[0.5],[0]]
expected: 0.5
case 4
in: [1,[1],[0]]
expected: 0.8807970779778823
case 5
in: [0.5,[0.5,0.5],[1,0]]
expected: 0.8807970779778823
Starter codePython
import math
def ising_gibbs_conditional_probability(field, couplings, neighbors):
# Your code here
pass5 test cases · run your code against them in the editor