Skip to content

Commit 20048f0

Browse files
committed
fix the energy mode
1 parent 09004cf commit 20048f0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/cspmodels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function generate_tensors(β::T, problem::ConstraintSatisfactionProblem) where T
44
objs = ProblemReductions.objectives(problem)
55
ixs = vcat([t.variables for t in cons], [t.variables for t in objs])
66
# generate tensors for x = e^β
7-
x = exp(β)
7+
x = energy_mode(problem) === LargerSizeIsBetter() ? exp(β) : exp(-β)
88
tensors = vcat(
99
Array{T}[reshape(map(s -> s ? one(x) : zero(x), t.specification), ntuple(i->num_flavors(problem), length(t.variables))) for t in cons],
1010
Array{T}[reshape(map(s -> x^s, t.specification), ntuple(i->num_flavors(problem), length(t.variables))) for t in objs]

test/cspmodels.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Test
2-
using TensorInference
2+
using TensorInference, ProblemReductions.Graphs
33
using GenericTensorNetworks
44

55
@testset "marginals" begin
@@ -25,4 +25,10 @@ using GenericTensorNetworks
2525
model = MMAPModel(problem, β; queryvars=[1,4])
2626
logp, config = most_probable_config(model)
2727
@test config == [0, 0]
28+
29+
β = 1.0
30+
problem = SpinGlass(g, -ones(Int, ne(g)), zeros(Int, nv(g)))
31+
model = TensorNetworkModel(problem, β; mars=[[2, 3]])
32+
samples = sample(model, 100)
33+
@test sum(energy.(Ref(problem), samples))/100 <= -14
2834
end

0 commit comments

Comments
 (0)