Skip to content

Instantly share code, notes, and snippets.

@mz1988
Created July 14, 2015 22:04
Show Gist options
  • Save mz1988/21495f83c5b661dd3c6e to your computer and use it in GitHub Desktop.
Save mz1988/21495f83c5b661dd3c6e to your computer and use it in GitHub Desktop.
Confidence Comment Algorithm by Go (golang)
package main
import (
"fmt"
"math"
)
func _confidence(ups int32, downs int32) float64 {
d := ups + downs
var n float64 = float64(d)
z := 1.0 //1.0 = 85%, 1.6 = 95%
phat := float64(ups) / n
return math.Sqrt(phat+z*z/(2*n)-z*((phat*(1-phat)+z*z/(4*n))/n)) / (1 + z*z/n)
}
func confidence(ups int32, downs int32) float64 {
d := ups + downs
var n float64 = float64(d)
if n == 0 {
return 0
} else {
return _confidence(ups, downs)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment