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 = columnNames
};
sda.Learn(sourceMatrix);
// Show the descriptive analysis on the screen
dgvDistributionMeasures.DataSource = sda.Measures;
// Create the kernel function
IKernel kernel = createKernel();
// 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();
var method = (PrincipalComponentMethod)cbMethod.SelectedValue;
// Creates the Kernel Principal Component Analysis of the given source
kpca = new KernelPrincipalComponentAnalysis()
{
Kernel = kernel,
Method = method
};
// Whether to center in space
kpca.Center = cbCenter.Checked;
var classifier = kpca.Learn(inputs); // Finally, compute the analysis!
double[][] result = kpca.Transform(inputs);
double[][] reduced;
if (kpca.Components.Count >= 2)
{
// Perform the transformation of the data using two components
kpca.NumberOfOutputs = 2;
reduced = kpca.Transform(inputs);
}
else
{
kpca.NumberOfOutputs = 1;
reduced = kpca.Transform(inputs);
reduced = reduced.InsertColumn(Vector.Zeros(reduced.GetLength(0)));
}
// Create a new plot with the original Z column
double[][] points = reduced.InsertColumn(sourceMatrix.GetColumn(2));
// Create output scatter plot
outputScatterplot.DataSource = points;
CreateScatterplot(graphMapFeature, points);
// Create output table
dgvProjectionResult.DataSource = new ArrayDataView(points, columnNames);
dgvReversionSource.DataSource = new ArrayDataView(result);
// Populates components overview with analysis data
dgvFeatureVectors.DataSource = new ArrayDataView(kpca.ComponentVectors);
dgvPrincipalComponents.DataSource = kpca.Components;
cumulativeView.DataSource = kpca.Components;
distributionView.DataSource = kpca.Components;
numNeighbor.Maximum = result.Rows();
numNeighbor.Value = System.Math.Min(10, numNeighbor.Maximum);
lbStatus.Text = "Good! Feel free to browse the other tabs to see what has been found.";
}