Skip to content

Commit

Permalink
apply same optimization logic to tpm in BMC
Browse files Browse the repository at this point in the history
  • Loading branch information
camilogarciabotero committed Aug 26, 2023
1 parent 6ac0c22 commit 8a1e3fa
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct BioMarkovChain{M<:AbstractMatrix, I<:AbstractVector, N<:Integer} <: Abstr
inits::I # the initials distribution of probabilities
n::N # The order of the Markov chain
function BioMarkovChain(tpm::M, inits::I, n::N=1) where {M<:AbstractMatrix, I<:AbstractVector, N<:Integer}
bmc = new{M,I,N}(tpm^(n), inits, n)
bmc = new{M,I,N}(n > 1 ? tpm^n : tpm, inits, n)
return bmc
end

Expand All @@ -49,12 +49,10 @@ struct BioMarkovChain{M<:AbstractMatrix, I<:AbstractVector, N<:Integer} <: Abstr

rowsums = sum(tcm, dims = 2)
freqs = tcm ./ rowsums
freqs[isinf.(freqs)] .= 0.0
freqs[isnan.(freqs)] .= 0.0

tpm = freqs^(n)
freqs[isnan.(freqs) .| isinf.(freqs)] .= 0.0 # Handling NaN and Inf

bmc = new{Matrix{Float64},Vector{Float64},Int64}(tpm, inits, n)
bmc = new{Matrix{Float64},Vector{Float64},Int64}(n > 1 ? freqs^n : freqs, inits, n)
return bmc
end
end
Expand Down

0 comments on commit 8a1e3fa

Please sign in to comment.