public void Evaluate(Individual[] pop) { CacheCards(); for (int i = 0; i < pop.Length; i++) { pop[i].Fitness = 0; } switch (EvalStrategy) { case EvaluationStrategy.RoundRobin: for (int i = 0; i < pop.Length; i++) { for (int j = 0; j < pop.Length; j++) { CompeteIndividuals(pop, i, j); } } break; case EvaluationStrategy.UCB1: _ucbScores = new UcbData[pop.Length]; for (int i = 0; i < _ucbScores.Length; i++) { _ucbScores[i] = new UcbData(); } for (int i = 0; i < RandomSamplingFaceoffs; i++) //fair comparison to round robin { CacheCards(); // TEMP // sort by score and select top 2 individuals var best = pop.Select((ind, n) => n) .Shuffle(random) .OrderByDescending(n => _ucbScores[n].Trials < 100 ? double.MaxValue : _ucbScores[n].Score(0.5, i)) .Take(2); int p1 = best.ElementAt(0); int p2 = best.ElementAt(1); //Console.WriteLine("({0}, {1})\t{0}=({2},{3})\t{1}=({4},{5})", p1, p2, _ucbScores[p1].Trials, _ucbScores[p1].Score(0.5, i), _ucbScores[p2].Trials, _ucbScores[p2].Score(0.5, i)); CompeteIndividuals(pop, best.ElementAt(0), best.ElementAt(1)); } for (int i = 0; i < pop.Length; i++) { pop[i].Fitness = _ucbScores[i].Score(0, RandomSamplingFaceoffs); } break; default: break; } }
public void Evaluate(Individual[] pop) { CacheCards(); for (int i = 0; i < pop.Length; i++) pop[i].Fitness = 0; switch (EvalStrategy) { case EvaluationStrategy.RoundRobin: for (int i = 0; i < pop.Length; i++) for (int j = 0; j < pop.Length; j++) CompeteIndividuals(pop, i, j); break; case EvaluationStrategy.UCB1: _ucbScores = new UcbData[pop.Length]; for (int i = 0; i < _ucbScores.Length; i++) _ucbScores[i] = new UcbData(); for (int i = 0; i < RandomSamplingFaceoffs; i++)//fair comparison to round robin { CacheCards();// TEMP // sort by score and select top 2 individuals var best = pop.Select((ind, n) => n) .Shuffle(random) .OrderByDescending(n => _ucbScores[n].Trials < 100 ? double.MaxValue : _ucbScores[n].Score(0.5, i)) .Take(2); int p1 = best.ElementAt(0); int p2 = best.ElementAt(1); //Console.WriteLine("({0}, {1})\t{0}=({2},{3})\t{1}=({4},{5})", p1, p2, _ucbScores[p1].Trials, _ucbScores[p1].Score(0.5, i), _ucbScores[p2].Trials, _ucbScores[p2].Score(0.5, i)); CompeteIndividuals(pop, best.ElementAt(0), best.ElementAt(1)); } for (int i = 0; i < pop.Length; i++) pop[i].Fitness = _ucbScores[i].Score(0, RandomSamplingFaceoffs); break; default: break; } }