示例#1
0
// AdjustSkills returns the new skill level distribution for all provided
// players based on game configuration and draw status.
func (ts Config) AdjustSkills(players Players, draw bool) (Players, float64) {
	// Sort players
	// sort.Sort(players)

	draws := []bool{}
	for i := 0; i < players.Len()-1; i++ {
		draws = append(draws, draw)
	}

	// TODO: Rewrite the distribution bag and simplify the factor list as well
	prior := gaussian.NewFromPrecision(0, 0)
	varBag := collection.NewDistributionBag(prior)

	skillFactors, skillIndex, factorList := buildSkillFactors(ts, players, draws, varBag)

	sched := buildSkillFactorSchedule(players.Len(), skillFactors, loopMaxDelta)

	// delta
	_ = schedule.Run(sched, -1)

	logZ := factorList.LogNormalization()
	probability := math.Exp(logZ)

	newPlayerSkills := Players{}
	for _, id := range skillIndex {
		newPlayerSkills = append(newPlayerSkills, Player{Gaussian: varBag.Get(id)})
	}

	return newPlayerSkills, probability
}
示例#2
0
// NewGaussianFactors initializes a gaussian factor with a distribution bag and
// returns it.
func NewGaussianFactors() GaussianFactors {
	prior := gaussian.NewFromPrecision(0, 0)
	return GaussianFactors{
		msgBag: collection.NewDistributionBag(prior),
	}
}