github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/helper/confidencesort.go (about)

     1  package helper
     2  
     3  import (
     4  	"math"
     5  )
     6  
     7  //Reddit信任度排序算法 返回数值越大则越信任度越高
     8  func Confidence(ups int64, downs int64) float64 {
     9  
    10  	n := float64(ups + downs)
    11  	if n == 0.0 {
    12  		return 0.0
    13  	}
    14  
    15  	z := 1.0 //1.0 = 85%, 1.6 = 95%
    16  	phat := float64(ups) / n
    17  	return math.Sqrt(phat+z*z/(2*n)-z*((phat*(1-phat)+z*z/(4*n))/n)) / (1 + z*z/n)
    18  
    19  }