Skip to content

Commit

Permalink
[orientation] Use SumLog in EvaluateQ()
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Jul 3, 2018
1 parent a2f34a3 commit 9cc9ada
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
16 changes: 12 additions & 4 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,29 @@ func Round(input float64) float64 {
return math.Floor(input + 0.5)
}

// SumLog returns the kernel of sum of log likelihood
func SumLog(a []int) float64 {
sum := 0.0
for _, val := range a {
sum += math.Log(float64(val))
}
return sum
}

// HmeanInt returns the harmonic mean
// That is: n / (1/x1 + 1/x2 + ... + 1/xn)
func HmeanInt(a []int, amin, amax int) int {
func HmeanInt(a []int, amin, amax int) float64 {
size := len(a)
sum := 0.0
for i := 0; i < size; i++ {
val := a[i]
for _, val := range a {
if val > amax {
val = amax
} else if val < amin {
val = amin
}
sum += 1.0 / float64(val)
}
return int(Round(float64(size) / sum))
return float64(size) / sum
}

// GoldenArray is given list of ints, we aggregate similar values so that it becomes an
Expand Down
5 changes: 3 additions & 2 deletions clm.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type OrientedPair struct {
type Contact struct {
strandedness int
nlinks int
meanDist int
meanDist float64
}

// TigF stores the index to activeTigs and size of the tig
Expand Down Expand Up @@ -192,7 +192,8 @@ func (r *CLM) ParseClm() {

// Store all these info in contacts
gdists := GoldenArray(line.links)
meanDist := HmeanInt(line.links, GRLB, GRUB)
// meanDist := Hmean(line.links, GRLB, GRUB)
meanDist := SumLog(line.links)
strandedness := 1
if line.ao != line.bo {
strandedness = -1
Expand Down
9 changes: 6 additions & 3 deletions orientation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package allhic

import (
"fmt"
"math"

"github.com/gonum/matrix/mat64"
)
Expand Down Expand Up @@ -155,9 +156,10 @@ func (r *CLM) Q() [][]GArray {
// plus the actual link distances. Maximize Sum(1 / distance) for all links.
// For performance consideration, we actually use a histogram to approximate
// all link distances. See goldenArray() for details.
func (r *CLM) EvaluateQ() (score float64) {
func (r *CLM) EvaluateQ() float64 {
tour := r.Tour
Q := r.Q()
score := 0.0

size := tour.Len()
cumsize := make([]int, size)
Expand All @@ -181,10 +183,11 @@ func (r *CLM) EvaluateQ() (score float64) {
break
}
for k := 0; k < BB; k++ {
score += float64(Q[a][b][k]) / float64(GR[k]+dist)
// score += float64(Q[a][b][k]) / float64(GR[k]+dist)
score -= float64(Q[a][b][k]) * math.Log(float64(GR[k]+dist))
}
// fmt.Println(r.Tigs[a], r.Tigs[b], Q[a][b], score)
}
}
return
return score
}

0 comments on commit 9cc9ada

Please sign in to comment.