Consider adding a method that measures the "frustration" of a BQM #1369
Open
Description
"Frustration" is in some sense a measure of problem hardness. That is, what is the energy contribution of the linear and quadratic biases that are violated by a given solution.
Something like
import dimod
def frustration(bqm, sample):
frustration = 0
for v, bias in bqm.linear.items():
frustration += max(0, sample[v] * bias)
for (u, v), bias in bqm.quadratic.items():
frustration += max(0, sample[u] * sample[v] * bias)
return frustration
if __name__ == "__main__":
bqm = dimod.generators.gnp_random_bqm(10, .5, "SPIN")
sampleset = dimod.ExactSolver().sample(bqm)
sample = sampleset.first.sample
print("energy:", sampleset.first.energy)
print("frustration:", frustration(bqm, sample))