-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scoring.go
53 lines (42 loc) · 916 Bytes
/
Scoring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package MultiElo
import (
"fmt"
"math"
us "github.com/rjNemo/underscore"
)
func Create(base float32) func(int) []float32 {
if base < 1 {
panic(fmt.Sprintf("The value of base must be 1 or greater, but we recieved a value of %v", 2))
}
if base == 1 {
return func(n int) []float32 {
return Liner(n)
}
}
return func(n int) []float32 {
return Exponential(n, base)
}
}
func Liner(n int) (scores []float32) {
var nf = float32(n)
for p := 1; p <= n; p++ {
pf := float32(p)
scores = append(scores, (nf-pf)/(nf*(nf-1)/2))
}
return scores
}
func Exponential(n int, base float32) []float32 {
var nf = float64(n)
var output = make([]float32, 0)
for p := 1; p <= n; p++ {
pf := float64(p)
output = append(output, float32(math.Pow(float64(base), nf-pf)-1))
}
sum := us.Sum(output)
return us.Map(output, func(x float32) float32 {
if x == 0 {
return x
}
return x / sum
})
}