Skip to content

Commit

Permalink
add types
Browse files Browse the repository at this point in the history
  • Loading branch information
annamariadziubyna committed Sep 22, 2023
1 parent ceff03a commit d225be4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/bp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/clustered_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit d225be4

Please sign in to comment.