private void Evaluate(Individual first, Individual second, out double score1, out double score2) { double total1 = 0, total2 = 0; for (int i = 0; i < HandsPerEvaluation; i++) { double s1; double s2; double[] probs1 = first.Genome; double[] probs2 = second.Genome; if (i % 2 == 0) { Evaluate(i, probs1, probs2, out s1, out s2); } else { Evaluate(i, probs2, probs1, out s2, out s1); } total1 += s1; total2 += s2; //total1 += Math.Min(0, s1); //total2 += Math.Min(0, s2); } score1 = total1; score2 = total2; }
public void Evaluate(Individual[] pop) { CacheCards(); for (int i = 0; i < pop.Length; i++) pop[i].Fitness = 0; for (int i = 0; i < pop.Length; i++) for (int j = 0; j < pop.Length; j++) { double s1, s2; //Randomly sample N hands //Evaluate(pop[i], pop[j], out s1, out s2); //Calculate EV of the two strategies against each other var g1 = pop[i].Genome; var g2 = pop[j].Genome; s1 = CalculateExpectedValue(g1, g2); s2 = CalculateExpectedValue(g2, g1); switch (Type) { case FitnessTypes.Winnings: pop[i].Fitness += s1; pop[j].Fitness += s2; break; case FitnessTypes.SquaredLosses: if (s1 - s2 < 0) pop[i].Fitness -= (s1 - s2) * (s1 - s2); if (s2 - s1 < 0) pop[i].Fitness -= (s2 - s1) * (s2 - s1); break; case FitnessTypes.BestOpponent: if (s1 - s2 < pop[i].Fitness) pop[i].Fitness = s1 - s2; if (s2 - s1 < pop[j].Fitness) pop[j].Fitness = s2 - s1; break; default: break; } } }
private void Evaluate(Individual first, Individual second, out double score1, out double score2) { double total1 = 0, total2 = 0; for (int i = 0; i < HandsPerEvaluation; i++) { double s1; double s2; double[] probs1 = first.Genome; double[] probs2 = second.Genome; Evaluate(i, probs1, probs2, out s1, out s2); //IncrementScore(first, score1); //IncrementScore(second, score2); total1 += s1 < 0 ? s1 : 0; total2 += s2 < 0 ? s2 : 0; } score1 = total1; score2 = total2; }
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; } }
private void Evaluate(Individual first, Individual second, out double score1, out double score2) { double total1 = 0, total2 = 0; for (int i = 0; i < HandsPerEvaluation; i++) { double s1; double s2; double[] probs1 = first.Genome; double[] probs2 = second.Genome; if(i % 2 == 0) Evaluate(i, probs1, probs2, out s1, out s2); else Evaluate(i, probs2, probs1, out s2, out s1); total1 += s1; total2 += s2; //total1 += Math.Min(0, s1); //total2 += Math.Min(0, s2); } score1 = total1; score2 = total2; }
private void CompeteIndividuals(Individual[] pop, int i, int j) { double s1, s2; if (EvaluationType == ThreeCardPokerFitness.EvaluationTypes.RandomSampling) //Randomly sample N hands Evaluate(pop[i], pop[j], out s1, out s2); else { //Calculate EV of the two strategies against each other var g1 = pop[i].Genome; var g2 = pop[j].Genome; s1 = CalculateExpectedValue(g1, g2); s2 = CalculateExpectedValue(g2, g1); } switch (Type) { case FitnessTypes.Winnings: pop[i].Fitness += s1; pop[j].Fitness += s2; break; case FitnessTypes.SquaredLosses: if (s1 - s2 < 0) pop[i].Fitness -= Math.Min(0,(s1 - s2)) * (s1 - s2); if (s2 - s1 < 0) pop[i].Fitness -= Math.Min(0,(s2 - s1)) * (s2 - s1); break; case FitnessTypes.BestOpponent: if (s1 - s2 < pop[i].Fitness) pop[i].Fitness = s1 - s2; if (s2 - s1 < pop[j].Fitness) pop[j].Fitness = s2 - s1; break; default: break; } if (EvalStrategy == EvaluationStrategy.UCB1) { switch (Type) { case FitnessTypes.Winnings: _ucbScores[i].Backup(s1); _ucbScores[j].Backup(s2); break; case FitnessTypes.SquaredLosses: _ucbScores[i].Backup(-1 * Math.Min(0, (s1 - s2)) * (s1 - s2)); _ucbScores[j].Backup(-1 * Math.Min(0, (s2 - s1)) * (s2 - s1)); break; case FitnessTypes.BestOpponent: throw new Exception("Not sure how to do this"); default: break; } } }
private void Evaluate(Individual first, Individual second, out double score1, out double score2) { double total1 = 0, total2 = 0; for (int i = 0; i < HandsPerEvaluation; i++) { double s1; double s2; double[] probs1 = first.Genome; double[] probs2 = second.Genome; Evaluate(i, probs1, probs2, out s1, out s2); //IncrementScore(first, score1); //IncrementScore(second, score2); total1 += s1 < 0 ? s1 : 0; total2 += s2 < 0 ? s2 : 0; } score1 = total1; score2 = total2; }