Skip to content

Commit 8557cab

Browse files
committed
fixed tree functions
1 parent 458af43 commit 8557cab

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/graphicalmodel.jl

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,34 +481,45 @@ function isTree(gbp::Union{GraphicalModel, GraphicalModelTree})
481481

482482
## Pilling the factor graph
483483
hasSingleVariable = true; hasSingleFactor = true;
484-
@inbounds while hasSingleVariable || hasSingleFactor
485-
for i in iterateVariable
486-
for (k, j) in enumerate(rowptr[colptr[i][1]])
487-
if i == j
488-
deleteat!(rowptr[colptr[i][1]], k)
489-
deleteat!(colptr[i], 1)
484+
@inbounds while hasSingleFactor || hasSingleVariable
485+
for variable in iterateVariable
486+
factor = colptr[variable][1]
487+
for (k, variables) in enumerate(rowptr[factor])
488+
if variable == variables
489+
deleteat!(rowptr[factor], k)
490+
deleteat!(colptr[variable], 1)
490491
end
491492
end
492-
if length(rowptr[colptr[i][1]]) == 1
493-
push!(iterateFactor, colptr[i][1])
493+
if length(rowptr[factor]) == 1
494+
push!(iterateFactor, factor)
494495
end
495496
end
496497
if isempty(iterateFactor)
497498
hasSingleFactor = false
498499
end
499500
iterateVariable = Int64[]
500501

501-
for i in iterateFactor
502-
for (k, j) in enumerate(colptr[rowptr[i][1]])
503-
if i == j
504-
deleteat!(colptr[rowptr[i][1]], k)
505-
deleteat!(rowptr[i], 1)
502+
for factor in iterateFactor
503+
variable = rowptr[factor][1]
504+
for (k, factors) in enumerate(colptr[variable])
505+
if factor == factors
506+
deleteat!(colptr[variable], k)
507+
deleteat!(rowptr[factor], 1)
506508
end
507509
end
508-
if length(colptr[rowptr[i][1]]) == 1
509-
push!(iterateVariable, rowptr[i][1])
510+
if length(colptr[variable]) == 1
511+
push!(iterateVariable, variable)
510512
end
511513
end
514+
515+
flag = true
516+
for i in colptr[iterateVariable]
517+
if !isempty(i)
518+
flag = false
519+
end
520+
end
521+
if flag break end
522+
512523
if isempty(iterateVariable)
513524
hasSingleVariable = false
514525
end

src/inferencetree.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function forwardVariableFactor(gbp::GraphicalModelTree)
1919
for (k, variables) in enumerate(gbp.graph.rowForward[factor])
2020
if variable == variables
2121
deleteat!(gbp.graph.rowForward[factor], k)
22-
deleteat!(gbp.graph.colForward[variable], 1)
2322
end
2423
end
2524
if length(gbp.graph.rowForward[factor]) == 1
@@ -51,7 +50,6 @@ function forwardFactorVariable(gbp::GraphicalModelTree)
5150
for (k, factors) in enumerate(gbp.graph.colForward[variable])
5251
if factor == factors
5352
deleteat!(gbp.graph.colForward[variable], k)
54-
deleteat!(gbp.graph.rowForward[factor], 1)
5553
end
5654
end
5755
if length(gbp.graph.colForward[variable]) == 1 && variable != gbp.graph.root

0 commit comments

Comments
 (0)