Skip to content

Commit

Permalink
stdev fix and new result form
Browse files Browse the repository at this point in the history
Fixed stdev and p-value calculations.
Changed result form for Github compatibility
  • Loading branch information
zardav committed Jul 14, 2014
1 parent 21649c9 commit 25ab58a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 176 deletions.
183 changes: 31 additions & 152 deletions FishBench/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 29 additions & 19 deletions FishBench/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,17 @@ private void startButton_Click(object sender, EventArgs e)
t = new Tester(baseLocationText.Text, stockfishLocationText.Text);
t.Amount = (int)amountTestNumeric.Value;

baseAverageText.Text = "0";
stockfishAverageText.Text = "0";
diffAverageText.Text = "0";

baseStdevText.Text = "0";
stockfishStdevText.Text = "0";
diffStdevText.Text = "0";

pvalText.Text = "0";
setResult(0, 0, 0, 0, 0, 0, 0, 0);
progressBar.Value = 0;

progressMessage.Text = string.Format(finishedMask, 0, (int)amountTestNumeric.Value * 2);
terminateButton.Enabled = true;
startButton.Enabled = false;
t.TestFinished += delegate
{
baseAverageText.SetAsync("Text", t.AverageA.ToString());
stockfishAverageText.SetAsync("Text", t.AverageB.ToString());
diffAverageText.SetAsync("Text", t.AverageDiff.ToString());

baseStdevText.SetAsync("Text", t.StdevA.ToString());
stockfishStdevText.SetAsync("Text", t.StdevB.ToString());
diffStdevText.SetAsync("Text", t.StdevDiff.ToString());

pvalText.SetAsync("Text", t.p_value.ToString());

progressBar.SetAsync("Value", (int)t.PercentCompleted);
progressMessage.SetAsync("Text", string.Format(finishedMask, t.Completed, t.Amount));
setResult(t.AverageA, t.AverageB, t.AverageDiff, t.StdevA, t.StdevB, t.StdevDiff, t.CompletedEach, Math.Round(t.p_value, 3));
};
t.JobFinished += delegate
{
Expand Down Expand Up @@ -153,5 +136,32 @@ private void terminateButton_Click(object sender, EventArgs e)
startButton.Enabled = true;
}
}

string resultLineFormat = " {0,-8}{1,-10}{2,-10}{3,-10}\r\n";
private void setResult(object baseMean, object testMean, object diffMean,
object baseStdev, object testStdev, object diffStdev,
object testAmount, object pval)
{
resultsBox.SetAsync("Text",
"Results for " + testAmount.ToString() + " tests for each version:\r\n\r\n" +
string.Format(resultLineFormat, "", "Base", "Test", "Diff") +
string.Format(resultLineFormat, "Mean", baseMean, testMean, diffMean) +
string.Format(resultLineFormat, "StDev", baseStdev, testStdev, diffStdev) +
"\r\np-value: " + pval.ToString());
}

private void copyButton_Click(object sender, EventArgs e)
{
Clipboard.SetText(resultsBox.Text);
copyButton.BackColor = Color.PaleGreen;
Timer t = new Timer();
t.Tick += delegate
{
t.Stop();
copyButton.BackColor = SystemColors.Control;
};
t.Interval = 1000;
t.Start();
}
}
}
11 changes: 6 additions & 5 deletions FishBench/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Tester
private Thread job;

public int Completed { get { return completedA + completedB; } }
public int CompletedEach { get { return completedB; } }

public double PercentCompleted
{
Expand Down Expand Up @@ -71,8 +72,8 @@ public long StdevA
get
{
long avg = AverageA;
return completedA == 0 ?
0 : (long)Math.Sqrt( (long)listA.Select(d => (d - avg) * (d - avg)).Sum() / (long)completedA );
return completedA <= 1 ?
0 : (long)Math.Sqrt( (long)listA.Select(d => (d - avg) * (d - avg)).Sum() / (long)(completedA - 1) );
}
}

Expand All @@ -81,8 +82,8 @@ public long StdevB
get
{
long avg = AverageB;
return completedB == 0 ?
0 : (long)Math.Sqrt((long)listB.Select(d => (d - avg) * (d - avg)).Sum() / (long)completedB);
return completedB <= 1 ?
0 : (long)Math.Sqrt((long)listB.Select(d => (d - avg) * (d - avg)).Sum() / (long)(completedB - 1) );
}
}

Expand All @@ -98,7 +99,7 @@ public long StdevDiff
cur *= cur;
sum += cur;
}
return len == 0 ? 0 : (long)Math.Sqrt(sum / (len * 2));
return len <= 1 ? 0 : (long)Math.Sqrt(sum / (len - 1));
}
}

Expand Down

0 comments on commit 25ab58a

Please sign in to comment.