using System.Collections.Generic; using System.Linq; using Moserware.Numerics; using Moserware.Skills.FactorGraphs; using Moserware.Skills.TrueSkill.Factors; namespace Moserware.Skills.TrueSkill.Layers { internal class PlayerSkillsToPerformancesLayer : TrueSkillFactorGraphLayer , GaussianLikelihoodFactor, KeyedVariable> { public PlayerSkillsToPerformancesLayer(TrueSkillFactorGraph parentGraph) : base(parentGraph) { } public override void BuildLayer() { foreach (var currentTeam in InputVariablesGroups) { var currentTeamPlayerPerformances = new List>(); foreach (var playerSkillVariable in currentTeam) { KeyedVariable playerPerformance = CreateOutputVariable(playerSkillVariable.Key); AddLayerFactor(CreateLikelihood(playerSkillVariable, playerPerformance)); currentTeamPlayerPerformances.Add(playerPerformance); } OutputVariablesGroups.Add(currentTeamPlayerPerformances); } } private GaussianLikelihoodFactor CreateLikelihood(KeyedVariable playerSkill, KeyedVariable playerPerformance) { return new GaussianLikelihoodFactor(Square(ParentFactorGraph.GameInfo.Beta), playerPerformance, playerSkill); } private KeyedVariable CreateOutputVariable(TPlayer key) { return ParentFactorGraph.VariableFactory.CreateKeyedVariable(key, "{0}'s performance", key); } public override Schedule CreatePriorSchedule() { return ScheduleSequence( from likelihood in LocalFactors select new ScheduleStep("Skill to Perf step", likelihood, 0), "All skill to performance sending"); } public override Schedule CreatePosteriorSchedule() { return ScheduleSequence( from likelihood in LocalFactors select new ScheduleStep("name", likelihood, 1), "All skill to performance sending"); } } }