From d225be42954db8127d0d32792193144acb6d7f37 Mon Sep 17 00:00:00 2001 From: annamariadziubyna Date: Fri, 22 Sep 2023 12:06:03 +0200 Subject: [PATCH] add types --- src/bp.jl | 8 +++----- src/clustered_hamiltonian.jl | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bp.jl b/src/bp.jl index d415540..af40d27 100644 --- a/src/bp.jl +++ b/src/bp.jl @@ -5,7 +5,7 @@ export projector -function belief_propagation(cl_h, beta; tol=1e-6, iter=1) +function belief_propagation(cl_h::LabelledGraph{S, T}, beta::Real; tol=1e-6, iter=1) where {S, T} messages_ve = Dict() messages_ev = Dict() @@ -93,7 +93,7 @@ end Base.adjoint(s::MergedEnergy) = MergedEnergy(s.e11', s.e21', s.e12', s.e22') -function update_message( E_bond::AbstractArray, message::Vector, beta::Real) +function update_message(E_bond::AbstractArray, message::Vector, beta::Real) E_bond = E_bond .- minimum(E_bond) exp.(-beta * E_bond) * message end @@ -246,9 +246,7 @@ function projector(cl_h::LabelledGraph{S, T}, v::NTuple{N, Int64}, w::NTuple{N, end end -function fuse_projectors( - projectors::NTuple{N, K} - ) where {N, K} +function fuse_projectors(projectors::NTuple{N, K}) where {N, K} fused, transitions_matrix = rank_reveal(hcat(projectors...), :PE) transitions = Tuple(Array(t) for t ∈ eachcol(transitions_matrix)) fused, transitions diff --git a/src/clustered_hamiltonian.jl b/src/clustered_hamiltonian.jl index ed418d0..c97bc66 100644 --- a/src/clustered_hamiltonian.jl +++ b/src/clustered_hamiltonian.jl @@ -86,7 +86,7 @@ function clustered_hamiltonian(ig::IsingGraph; spectrum::Function=full_spectrum, clustered_hamiltonian(ig, Dict{T, Int}(), spectrum=spectrum, cluster_assignment_rule=cluster_assignment_rule) end -function rank_reveal(energy, order=:PE) where T <: Real +function rank_reveal(energy, order=:PE) where T <: Real #TODO: add type @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 E, idx = unique_dims(energy, dim) @@ -99,7 +99,7 @@ Returns Dict(vertex of ising graph -> spin value) Assumes that state has the same order as vertices in factor graph! TODO: check the order consistency over external packages. """ -function decode_clustered_hamiltonian_state(cl_h, state::Vector{Int}) +function decode_clustered_hamiltonian_state(cl_h::LabelledGraph{S, T}, state::Vector{Int}) where {S, T} ret = Dict{Int, Int}() for (i, vert) ∈ zip(state, vertices(cl_h)) spins = get_prop(cl_h, vert, :cluster).labels