Skip to content

Commit

Permalink
bug fix & renaming of a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kzahedi committed Apr 3, 2019
1 parent 985b1d2 commit 99fea2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions discrete/sparse/ConditionalMutualInformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func ConditionalMutualInformation(pxyz sm.SparseMatrix, ln lnFunc) float64 {
}

for _, index := range pxCz.Indices {
zi := sm.SparseMatrixIndex{index[2]}
zi := sm.SparseMatrixIndex{index[1]}
v, _ := pz.Get(zi)
pxCz.Mul(zi, 1.0/v)
}

for _, index := range pyCz.Indices {
zi := sm.SparseMatrixIndex{index[2]}
zi := sm.SparseMatrixIndex{index[1]}
v, _ := pz.Get(zi)
pyCz.Mul(zi, 1.0/v)
}
Expand All @@ -58,7 +58,7 @@ func ConditionalMutualInformation(pxyz sm.SparseMatrix, ln lnFunc) float64 {
xyz, _ := pxyz.Get(index)
xyCz, _ := pxyCz.Get(index)
xCz, _ := pxCz.Get(sm.SparseMatrixIndex{xi, zi})
yCz, _ := pxCz.Get(sm.SparseMatrixIndex{yi, zi})
yCz, _ := pyCz.Get(sm.SparseMatrixIndex{yi, zi})

if xyz > 0.0 && xyCz > 0.0 && xCz > 0.0 && yCz > 0.0 {
r += xyz * (ln(xyCz) - ln(xCz*yCz))
Expand Down
6 changes: 3 additions & 3 deletions discrete/sparse/MutualInformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func MutualInformation(pxy sm.SparseMatrix, log lnFunc) float64 {
py.Add(y, v)
}

mi := 0.0
var r float64

for _, index := range pxy.Indices {
x := sm.SparseMatrixIndex{index[0]}
Expand All @@ -34,11 +34,11 @@ func MutualInformation(pxy sm.SparseMatrix, log lnFunc) float64 {
yv, _ := py.Get(y)

if xyv > 0.0 && xv > 0.0 && yv > 0.0 {
mi += xyv * (log(xyv) - log(xv*yv))
r += xyv * (log(xyv) - log(xv*yv))
}
}

return mi
return r
}

// MutualInformationBaseE calculates the mutual information with base e
Expand Down

0 comments on commit 99fea2f

Please sign in to comment.