-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpredict_win.go
31 lines (24 loc) · 898 Bytes
/
predict_win.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
package openskill
import (
"math"
"github.com/samber/lo"
)
// PredictWin returns the probability of each team has to win ordered by the order of the
// teams. If there is only one team, the function will return nil.
func PredictWin(teams []Team, options *Options) []float64 {
betaSq := betaSq(options)
teamRatings := teamRatings(options)(teams)
if len(teams) < 2 {
return nil
}
n := float64(len(teams))
denom := (n * (n - 1)) / 2
return lo.Map(teamRatings, func(item *teamRating, index int) float64 {
filteredRatings := lo.Filter(teamRatings, func(localItem *teamRating, localIndex int) bool {
return localIndex != index
})
return lo.Sum(lo.Map(filteredRatings, func(localItem *teamRating, localIndex int) float64 {
return cdf((item.TeamMu - localItem.TeamMu) / math.Sqrt(n*betaSq+math.Pow(item.TeamSigmaSq, 2)+math.Pow(localItem.TeamSigmaSq, 2)))
})) / denom
})
}