Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kzahedi committed Apr 3, 2019
1 parent 99fea2f commit 4977366
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions discrete/ProbabilityEstimator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package discrete

import (
"math"

"github.com/kzahedi/goent/sm"
)

Expand Down Expand Up @@ -137,8 +139,15 @@ func Empirical3DSparse(d [][]int) sm.SparseMatrix {
}

l := float64(rows)
var sum float64
for _, index := range p.Indices {
p.Mul(index, 1.0/l)
v, _ := p.Get(index)
sum += v
}

if math.Abs(sum-1.0) > 0.00001 {
panic("P does not sum up to one")
}

return p
Expand Down
6 changes: 3 additions & 3 deletions discrete/sparse/ConditionalMutualInformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ func ConditionalMutualInformation(pxyz sm.SparseMatrix, ln lnFunc) float64 {
for _, index := range pxyCz.Indices {
zi := sm.SparseMatrixIndex{index[2]}
v, _ := pz.Get(zi)
pxyCz.Mul(zi, 1.0/v)
pxyCz.Mul(index, 1.0/v)
}

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

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

r := 0.0
Expand Down

0 comments on commit 4977366

Please sign in to comment.