11using . GenericTensorNetworks: generate_tensors, GraphProblem, flavors, labels
22
3+ # update models
4+ export update_temperature
5+
36"""
47$TYPEDSIGNATURES
58
@@ -20,6 +23,24 @@ function TensorInference.TensorNetworkModel(problem::GraphProblem, β::Real; evi
2023 factors = [Factor ((ix... ,), t) for (ix, t) in zip (ixs, tensors)]
2124 return TensorNetworkModel (lbs, fill (nflavors, length (lbs)), factors; openvars= iy, evidence, optimizer, simplifier, mars)
2225end
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+
2344function TensorInference. MMAPModel (problem:: GraphProblem , β:: Real ;
2445 queryvars,
2546 evidence = Dict {labeltype(problem.code), Int} (),
@@ -37,6 +58,10 @@ function TensorInference.MMAPModel(problem::GraphProblem, β::Real;
3758 optimizer, simplifier,
3859 marginalize_optimizer, marginalize_simplifier)
3960end
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
4065
4166@info " `TensorInference` loaded `GenericTensorNetworks` extension successfully,
4267`TensorNetworkModel` and `MMAPModel` can be used for converting a `GraphProblem` to a probabilistic model now."
0 commit comments