Skip to content

Commit 0639d3e

Browse files
committed
added average wins data
1 parent fb5f095 commit 0639d3e

File tree

4 files changed

+78
-68
lines changed

4 files changed

+78
-68
lines changed

src/SharpNeatDomains/IPD/IPDDomain.cs

+54-52
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ partial class IPDDomain : AbstractDomainView
3131
private ToolStripMenuItem _history;
3232
private ToolStripMenuItem _save;
3333
private DataGridViewColumn _cumulative;
34+
private DataGridViewColumn _wins;
3435
private DataGridViewColumn _rankings;
3536

3637
private ZedGraphControl _graphArchive;
@@ -219,9 +220,16 @@ private void CreateArchiveGraph()
219220
g.XAxis.Title.Text = "Archive Index";
220221
g.YAxis.Title.Text = "Score";
221222

223+
g.Y2AxisList.Add("Rank");
224+
g.Y2AxisList[1].IsVisible = false;
225+
g.Y2AxisList[1].Scale.Min = 0.0;
226+
g.Y2AxisList[1].Scale.Max = _info.OpponentPool.Length;
227+
222228
g.Y2Axis.IsVisible = true;
229+
g.Y2Axis.Title.Text = "Wins";
223230
g.Y2Axis.Scale.Min = 0.0;
224-
g.Y2Axis.Scale.Max = 1.0;
231+
g.Y2Axis.Scale.Max = _info.OpponentPool.Length;
232+
225233

226234
Controls.Add(_graphArchive);
227235
}
@@ -236,36 +244,25 @@ private void UpdateArchiveGraph()
236244

237245
double[] ii = new double[archive.Count];
238246
double[] score = new double[archive.Count];
239-
double[] rank = new double[archive.Count];
247+
double[] averageWins = new double[archive.Count];
240248
double[] averageRank = new double[archive.Count];
241-
PointPairList averageWinningScore = new PointPairList();
242-
PointPairList winningScores = new PointPairList();
243-
PointPairList topScore = new PointPairList();
244-
245-
double averageRankCounter = 0;
246-
double averageWinningScoreCounter = 0;
247-
//double topScoreCounter = -1;
248-
int first = -1;
249+
PointPairList gold = new PointPairList();
250+
251+
double avgW = 0;
252+
double avgR = 0;
249253
for (int i = 0; i < ii.Length; i++)
250254
{
251255
ii[i] = i;
252256
score[i] = archive[i].Score;
253-
rank[i] = archive[i].Rank;
254257

255-
averageRankCounter += rank[i];
256-
averageRank[i] = averageRankCounter / (i + 1);
257-
//topScoreCounter = (score[i] > topScoreCounter) ? score[i] : topScoreCounter;
258-
//topScore.Add(new PointPair(i, topScoreCounter));
258+
avgR += archive[i].Rank;
259+
averageRank[i] = avgR / (i + 1);
259260

260-
if (rank[i] == 1.0)
261-
{
262-
if (first == -1)
263-
first = i;
261+
avgW += archive[i].Wins; //==avgR when single opponent
262+
averageWins[i] = avgW / (i + 1);
264263

265-
averageWinningScoreCounter += score[i]; //average score, only counting those with rank 1
266-
averageWinningScore.Add(new PointPair(i, averageWinningScoreCounter / (averageWinningScore.Count + 1)));
267-
268-
}
264+
if (archive[i].Wins == _info.OpponentPool.Length && archive[i].Rank == 1.0)
265+
gold.Add(new PointPair(i, score[i]));
269266
}
270267

271268
Color[] greyscale = new Color[4]
@@ -275,41 +272,25 @@ private void UpdateArchiveGraph()
275272
Color.FromArgb(60, 60, 60),
276273
Color.FromArgb(0, 0, 0) //darkest
277274
};
278-
279-
//var f = g.AddCurve("First hit", new PointPairList() { new PointPair(first, 1.0d) }, Color.White, SymbolType.Triangle);
280-
//f.IsY2Axis = true;
281-
//f.Symbol.Size = 20;
282-
//f.Symbol.Fill = new Fill(Brushes.Green);
283275

284-
var ar = g.AddCurve("Average Rank", ii, averageRank, greyscale[3], SymbolType.None);
276+
var gp = g.AddCurve("Optimal Behavior", gold, greyscale[3], SymbolType.Diamond);
277+
gp.Line.IsVisible = false;
278+
gp.Symbol.Size = 6;
279+
gp.Symbol.Fill = new Fill(greyscale[3]);
280+
281+
var ar = g.AddCurve("Average Rank", ii, averageRank, greyscale[2], SymbolType.None);
285282
ar.IsY2Axis = true;
283+
ar.YAxisIndex = 1;
286284
ar.Line.Width = 3;
287285

288-
var @as = g.AddCurve("Average Winning Score", averageWinningScore, greyscale[2], SymbolType.Star);
289-
@as.Line.Width = 0;
290-
@as.Line.IsVisible = false;
291-
@as.Symbol.Size = 2;
292-
@as.Symbol.Fill = new Fill(greyscale[2]);
293-
294-
//var ws = g.AddCurve("Winning Behavior", winningScores, greyscale[2], SymbolType.Star);
295-
//ws.Line.Width = 0;
296-
//ws.Line.IsVisible = false;
297-
//ws.Symbol.Size = 3;
298-
//ws.Symbol.Fill = new Fill(greyscale[2]);
299-
300-
//var t = g.AddCurve("Top Score", topScore, greyscale[0], SymbolType.None);
301-
//t.Line.Width = 2;
286+
var aw = g.AddCurve("Average Wins", ii, averageWins, greyscale[0], SymbolType.None);
287+
aw.IsY2Axis = true;
288+
aw.Line.Width = 3;
302289

303290
var s = g.AddCurve("Behavior", ii, score, greyscale[1], SymbolType.HDash);
304291
s.Line.IsVisible = false;
305292
s.Symbol.Size = 3;
306-
307-
//var r = g.AddCurve("Ranking", ii, rank, Color.Coral, SymbolType.Diamond);
308-
//r.IsY2Axis = true;
309-
//r.Symbol.Fill = new Fill(Brushes.Coral);
310-
//r.Symbol.Size = 3;
311-
//r.Line.IsVisible = false;
312-
293+
313294
_graphArchive.AxisChange();
314295
}
315296

@@ -351,13 +332,19 @@ private void CreateTable()
351332
}
352333
_table.Rows.AddRange(rows);
353334

354-
//Cumulative and Ranking columns
335+
//Cumulative, Wins and Ranking columns
355336
_cumulative = new DataGridViewTextBoxColumn();
356337
_cumulative.HeaderText = "Cumulative Score";
357338
_cumulative.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
358339
_cumulative.SortMode = DataGridViewColumnSortMode.NotSortable;
359340
_table.Columns.Add(_cumulative);
360341

342+
_wins = new DataGridViewTextBoxColumn();
343+
_wins.HeaderText = "Total Wins";
344+
_wins.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
345+
_wins.SortMode = DataGridViewColumnSortMode.NotSortable;
346+
_table.Columns.Add(_wins);
347+
361348
_rankings = new DataGridViewTextBoxColumn();
362349
_rankings.HeaderText = "Ranking";
363350
_rankings.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
@@ -374,6 +361,7 @@ private void UpdateTable()
374361

375362
//Fill in table
376363
double[] totals = new double[_players.Length];
364+
double[] wins = new double[_players.Length];
377365
for (int i = 0; i < _players.Length; i++)
378366
for (int j = i + 1; j < _players.Length; j++)
379367
if (i != j)
@@ -391,6 +379,13 @@ private void UpdateTable()
391379

392380
totals[i] += iScore;
393381
totals[j] += jScore;
382+
383+
if (iScore == jScore)
384+
{
385+
wins[i] += 0.5;
386+
wins[j] += 0.5;
387+
}
388+
else wins[(iScore > jScore) ? i : j]++;
394389
}
395390

396391
//Calculate cumulative column
@@ -399,7 +394,14 @@ private void UpdateTable()
399394
_table.Rows[i].Cells[_cumulative.DisplayIndex].Value = totals[i];
400395
_table.Rows[i].Cells[_cumulative.DisplayIndex].ToolTipText = _players[i].Name + "'s total score";
401396
}
402-
397+
398+
//Calculate wins
399+
for (int i = 0; i < _players.Length; i++)
400+
{
401+
_table.Rows[i].Cells[_wins.DisplayIndex].Value = wins[i];
402+
_table.Rows[i].Cells[_cumulative.DisplayIndex].ToolTipText = _players[i].Name + "'s total wins";
403+
}
404+
403405
//Calculate rankings column
404406
var ranks = totals.Rank();
405407
for (int i = 0; i < _players.Length; i++)

src/SharpNeatDomains/IPD/IPDEvaluator.cs

+19-11
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public FitnessInfo Evaluate(IBlackBox phenome)
5151
{
5252
case IPDExperiment.EvaluationMode.Novelty:
5353
primaryFitness = noveltyFitness; break;
54-
case IPDExperiment.EvaluationMode.Rank:
55-
primaryFitness = pi.Rank; break;
54+
case IPDExperiment.EvaluationMode.Wins:
55+
primaryFitness = pi.Wins; break;
5656
default:
5757
case IPDExperiment.EvaluationMode.Score:
5858
primaryFitness = pi.Score; break;
@@ -75,6 +75,7 @@ private PhenomeInfo EvaluateBehavior(IBlackBox phenome)
7575
{
7676
Players.IPDPlayerPhenome p = new Players.IPDPlayerPhenome(phenome);
7777
double[] scores = new double[_info.OpponentPool.Length + 1];
78+
double wins = 0;
7879
int phenomeIndex = _info.OpponentPool.Length;
7980
IPDGame[] games = new IPDGame[phenomeIndex];
8081

@@ -84,6 +85,11 @@ private PhenomeInfo EvaluateBehavior(IBlackBox phenome)
8485
var s = games[i].Evaluate(_info.RandomRobustCheck);
8586
scores[i] += s.a + _info.OpponentScores[i];
8687
scores[phenomeIndex] += s.b;
88+
89+
if (s.a == s.b)
90+
wins += 0.5;
91+
else if (s.b > s.a)
92+
wins += 1.0;
8793
}
8894

8995
double score = scores[phenomeIndex];
@@ -94,10 +100,10 @@ private PhenomeInfo EvaluateBehavior(IBlackBox phenome)
94100
//Ties are not allowed
95101
for (int i = 0; i < scores.Length; i++)
96102
if (scores[i] == scores[phenomeIndex] && i != phenomeIndex)
97-
rank -= 0.05d;
103+
rank -= (1.0 / (double)_info.OpponentPool.Length) / 2.0;
98104
}
99105

100-
return new PhenomeInfo(phenome, rank, score, games);
106+
return new PhenomeInfo(phenome, rank, wins, score, games);
101107
}
102108

103109
private double EvaluateNovelty(PhenomeInfo info)
@@ -184,22 +190,24 @@ public static void Initialize(IPDExperiment.Info info)
184190

185191
public IBlackBox Phenome { get; private set; }
186192
public double Rank { get; private set; }
193+
public double Wins { get; private set; }
187194
public double Score { get; private set; }
188195
public IPDGame[] Games { get; private set; }
189-
public AuxFitnessInfo[] AuxiliaryFitnessInfo { get { _aux[0]._value = Score; _aux[1]._value = Rank; return _aux; } }
196+
public AuxFitnessInfo[] AuxiliaryFitnessInfo { get { _aux[0]._value = Score; _aux[1]._value = Wins; return _aux; } }
190197

191198
public long ID { get; set; }
192199

193200
private double[] _pc;
194201
private AuxFitnessInfo[] _aux;
195202

196-
public PhenomeInfo(IBlackBox phenome, double rank, double score, IPDGame[] games)
203+
public PhenomeInfo(IBlackBox phenome, double rank, double wins, double score, IPDGame[] games)
197204
{
198205
Phenome = phenome;
199206
Rank = rank;
207+
Wins = wins;
200208
Score = score;
201209
Games = games;
202-
_aux = new AuxFitnessInfo[2] { new AuxFitnessInfo("Score", 0), new AuxFitnessInfo("Rank", 0) };
210+
_aux = new AuxFitnessInfo[2] { new AuxFitnessInfo("Score", 0), new AuxFitnessInfo("Wins", 0) };
203211

204212
if (_metric == IPDExperiment.NoveltyMetric.Choice)
205213
{
@@ -230,16 +238,16 @@ public double Distance(PhenomeInfo other)
230238

231239
public override string ToString()
232240
{
233-
return ID + "; Score: " + Score.ToString() + ", Rank: " + Rank.ToString();
241+
return ID + "; Score: " + Score.ToString() + ", Wins: " + Wins.ToString();
234242
}
235243

236244
public int CompareTo(PhenomeInfo other)
237245
{
238-
if (Rank > other.Rank)
246+
if (Wins > other.Wins)
239247
return 1;
240-
if (Rank < other.Rank)
248+
if (Wins < other.Wins)
241249
return -1;
242-
if (Rank == other.Rank)
250+
if (Wins == other.Wins)
243251
{
244252
if (Score > other.Score)
245253
return 1;

src/SharpNeatDomains/IPD/IPDExperiment.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public enum Opponent
5151
public enum EvaluationMode
5252
{
5353
Score,
54-
Rank,
54+
Wins,
5555
Novelty
5656
}
5757

src/SharpNeatDomains/SharpNeatDomains.experiments.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
<Description>
1515
TBD.
1616
</Description>
17-
<EvaluationMode>Score</EvaluationMode>
17+
<EvaluationMode>Novelty</EvaluationMode>
1818
<!--
1919
Score, (objective)
20-
Rank, (objective)
20+
Wins, (objective)
2121
Novelty (novelty)
2222
-->
2323
<PopulationSize>150</PopulationSize>
2424
<IPDGames>100</IPDGames>
25-
<NoveltyK>3</NoveltyK>
25+
<NoveltyK>4</NoveltyK>
2626
<PastInputReach>5</PastInputReach>
2727
<EvaluationLimit>100000</EvaluationLimit>
2828
<StaticOpponents>
@@ -57,7 +57,7 @@
5757
CD,
5858
DC
5959
-->
60-
<NoveltyMetric>Choice</NoveltyMetric>
60+
<NoveltyMetric>Past</NoveltyMetric>
6161
<!--
6262
Score,
6363
Past,

0 commit comments

Comments
 (0)