Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix undeclared variable #10

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ Returns the maximum weigths for each state per frame and the corresponding path.
"""
function ωrecursion(g::FSM, llh::Matrix{T}; pruning::Union{Real, NoPruning} = nopruning) where T <: AbstractFloat
pruning! = pruning ≠ nopruning ? ThresholdPruning(pruning) : pruning

activestates = Dict{State, T}(initstate(g) => T(0.0))
# Weights per state and per frame
ω = Vector{Dict{State, T}}()
# Weights per state and per frame
ω = Vector{Dict{State, T}}()
# Partial path how we reach the state in each frame
ψ = Vector{Dict{State, Tuple{State, Vector}}}()
ψ = Vector{Dict{State, Tuple{State, Vector}}}()

for n in 1:size(llh, 2)
push!(ω, Dict{State, T}())
push!(ψ, Dict{State, Tuple{State, Vector}}())
Expand All @@ -192,18 +192,18 @@ function ωrecursion(g::FSM, llh::Matrix{T}; pruning::Union{Real, NoPruning} = n
nweightpath = weightpath + linkweight
m = max(get(ω[n], nstate, T(-Inf)), nweightpath)
ω[n][nstate] = m
if m === nweightpath
if m === nweightpath
# Update the best path for nstate
ψ[n][nstate] = (state, path) # path: state -> nstate
end
end
end
for s in keys(ω[n]) ω[n][s] += llh[s.pdfindex, n] end

empty!(activestates)
merge!(activestates, pruning!(ω[n]))
end

# Remove emiting states with no direct connection with the final state
fes = finalemittingstates(g)
filter!(ψ[end]) do p
Expand All @@ -212,13 +212,13 @@ function ωrecursion(g::FSM, llh::Matrix{T}; pruning::Union{Real, NoPruning} = n
filter!(ω[end]) do p
haskey(fes, p.first)
end

# Add path from last emiting state to FSM's final state
for s in keys(ψ[end])
(_, path) = ψ[end][s]
append!(path, fes[s])
end

ω,ψ
end

Expand All @@ -231,14 +231,14 @@ function viterbi(g::FSM, llh::Matrix{T}; pruning::Union{Real, NoPruning} = nopru

@warn "viterbi is depracated! Use bestpath instead."
lnω, ψ = ωrecursion(g, llh; pruning = pruning)

bestpath = Vector{Link}()
_, state = findmax(lnω[end])
for n in length(ψ):-1:1
state, path = ψ[n][state]
prepend!(bestpath, path)
end

ng = FSM()
prevs = initstate(ng)
for l in bestpath
Expand All @@ -248,7 +248,7 @@ function viterbi(g::FSM, llh::Matrix{T}; pruning::Union{Real, NoPruning} = nopru
prevs = s
end
link!(ng, prevs, finalstate(ng))

ng |> removenilstates!
end

Expand All @@ -260,12 +260,12 @@ Compute bestpath using forward pass.
function maxβrecursion(
g::FSM,
lnα::Vector{Dict{State, T}}) where T <: AbstractFloat

π = FSM()
prevs = finalstate(g)
lasts = finalstate(π)

for n in size(llh, 2):-1:1
for n in length(lnα):-1:1
m = T(-Inf)
bests = nothing
bestp = nothing
Expand Down