private void btnTestingRun_Click(object sender, EventArgs e)
{
if (ann == null || dgvTestingSource.DataSource == null)
{
MessageBox.Show("Please create a machine first.");
return;
}
// Creates a matrix from the source data table
double[,] sourceMatrix = (dgvTestingSource.DataSource as DataTable).ToMatrix();
// Extract inputs
double[][] inputs = new double[sourceMatrix.GetLength(0)][];
for (int i = 0; i < inputs.Length; i++)
inputs[i] = new double[] { sourceMatrix[i, 0], sourceMatrix[i, 1] };
// Get only the label outputs
int[] expected = new int[sourceMatrix.GetLength(0)];
for (int i = 0; i < expected.Length; i++)
expected[i] = (int)sourceMatrix[i, 2];
// Compute the machine outputs
int[] output = new int[expected.Length];
for (int i = 0; i < expected.Length; i++)
output[i] = System.Math.Sign(ann.Compute(inputs[i])[0]);
double[] expectedd = new double[expected.Length];
double[] outputd = new double[expected.Length];
for (int i = 0; i < expected.Length; i++)
{
expectedd[i] = expected[i];
outputd[i] = output[i];
}
// Use confusion matrix to compute some statistics.
ConfusionMatrix confusionMatrix = new ConfusionMatrix(output, expected, 1, -1);
dgvPerformance.DataSource = new List<ConfusionMatrix> { confusionMatrix };
foreach (DataGridViewColumn col in dgvPerformance.Columns) col.Visible = true;
Column1.Visible = Column2.Visible = false;
// Create performance scatterplot
CreateResultScatterplot(zedGraphControl1, inputs, expectedd, outputd);
}