1
1
using . GenericTensorNetworks: generate_tensors, GraphProblem, flavors, labels
2
2
3
+ # update models
4
+ export update_temperature
5
+
3
6
"""
4
7
$TYPEDSIGNATURES
5
8
@@ -20,6 +23,24 @@ function TensorInference.TensorNetworkModel(problem::GraphProblem, β::Real; evi
20
23
factors = [Factor ((ix... ,), t) for (ix, t) in zip (ixs, tensors)]
21
24
return TensorNetworkModel (lbs, fill (nflavors, length (lbs)), factors; openvars= iy, evidence, optimizer, simplifier, mars)
22
25
end
26
+
27
+ """
28
+ $TYPEDSIGNATURES
29
+
30
+ Update the temperature of a tensor network model.
31
+ The program will regenerate tensors from the problem, without repeated optimizing the contraction order.
32
+
33
+ ### Arguments
34
+ - `tnet` is the [`TensorNetworkModel`](@ref) instance.
35
+ - `problem` is the target constraint satisfiability problem.
36
+ - `β` is the inverse temperature.
37
+ """
38
+ function update_temperature (tnet:: TensorNetworkModel , problem:: GraphProblem , β:: Real )
39
+ tensors = generate_tensors (exp (β), problem)
40
+ alltensors = [tnet. tensors[1 : end - length (tensors)]. .. , tensors... ]
41
+ return TensorNetworkModel (tnet. vars, tnet. code, alltensors, tnet. evidence, tnet. mars)
42
+ end
43
+
23
44
function TensorInference. MMAPModel (problem:: GraphProblem , β:: Real ;
24
45
queryvars,
25
46
evidence = Dict {labeltype(problem.code), Int} (),
@@ -37,6 +58,10 @@ function TensorInference.MMAPModel(problem::GraphProblem, β::Real;
37
58
optimizer, simplifier,
38
59
marginalize_optimizer, marginalize_simplifier)
39
60
end
61
+ function update_temperature (tnet:: MMAPModel , problem:: GraphProblem , β:: Real )
62
+ error (" We haven't got time to implement setting temperatures for `MMAPModel`.
63
+ It is about one or two hours of works. If you need it, please file an issue to let us know: https://github.com/TensorBFS/TensorInference.jl/issues" )
64
+ end
40
65
41
66
@info " `TensorInference` loaded `GenericTensorNetworks` extension successfully,
42
67
`TensorNetworkModel` and `MMAPModel` can be used for converting a `GraphProblem` to a probabilistic model now."
0 commit comments