private void btnCompute_Click(object sender, EventArgs e)
{
// Save any pending changes
dgvAnalysisSource.EndEdit();
if (dgvAnalysisSource.DataSource == null)
{
MessageBox.Show("Please load some data using File > Open!");
return;
}
// Create a matrix from the source data table
double[][] sourceMatrix = (dgvAnalysisSource.DataSource as DataTable).ToArray(out columnNames);
// Create and compute a new Simple Descriptive Analysis
sda = new DescriptiveAnalysis(columnNames);
sda.Learn(sourceMatrix);
// Show the descriptive analysis on the screen
dgvDistributionMeasures.DataSource = sda.Measures;
// Get the input values (the two first columns)
double[][] inputs = sourceMatrix.GetColumns(0, 1);
// Get only the associated labels (last column)
int[] outputs = sourceMatrix.GetColumn(2).ToInt32();
outputs = outputs.Subtract(outputs.Min()); // start at 0
// Create a Linear Discriminant Analysis for the data
lda = new LinearDiscriminantAnalysis()
{
NumberOfOutputs = 2
};
// Compute the analysis!
lda.Learn(inputs, outputs);
// Perform the transformation of the data
double[][] result = lda.Transform(inputs);
// Create a new plot with the original Z column
double[][] points = result.InsertColumn(sourceMatrix.GetColumn(2));
// Create output scatter plot
outputScatterplot.DataSource = points;
// Create the output table
dgvProjectionResult.DataSource = new ArrayDataView(points, columnNames);
// Populate discriminants overview with analysis data
dgvFeatureVectors.DataSource = new ArrayDataView(lda.DiscriminantVectors);
dgvScatterBetween.DataSource = new ArrayDataView(lda.ScatterBetweenClass);
dgvScatterWithin.DataSource = new ArrayDataView(lda.ScatterWithinClass);
dgvScatterTotal.DataSource = new ArrayDataView(lda.ScatterMatrix);
dgvPrincipalComponents.DataSource = lda.Discriminants;
distributionView.DataSource = lda.Discriminants;
cumulativeView.DataSource = lda.Discriminants;
// Populate classes information
dgvClasses.DataSource = lda.Classes;
lbStatus.Text = "Good! Feel free to browse the other tabs to see what has been found.";
}