Analysis.PCA.MainForm.btnCompute_Click C# (CSharp) Method

btnCompute_Click() private method

Launched when the user clicks the "Run analysis" button.
private btnCompute_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        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).Learn(sourceMatrix);

            // Show the descriptive analysis on the screen
            dgvDistributionMeasures.DataSource = sda.Measures;

            // Populates statistics overview tab with analysis data
            dgvStatisticCenter.DataSource = new ArrayDataView(sda.DeviationScores, columnNames);
            dgvStatisticStandard.DataSource = new ArrayDataView(sda.StandardScores, columnNames);

            dgvStatisticCovariance.DataSource = new ArrayDataView(sda.CovarianceMatrix, columnNames);
            dgvStatisticCorrelation.DataSource = new ArrayDataView(sda.CorrelationMatrix, columnNames);


            var method = (PrincipalComponentMethod)cbMethod.SelectedValue;

            // Create the Principal Component Analysis of the data 
            pca = new PrincipalComponentAnalysis(method);


            pca.Learn(sourceMatrix);  // Finally, compute the analysis!


            // Populate components overview with analysis data
            dgvFeatureVectors.DataSource = new ArrayDataView(pca.ComponentVectors);
            dgvPrincipalComponents.DataSource = pca.Components;
            dgvProjectionComponents.DataSource = pca.Components;
            distributionView.DataSource = pca.Components;
            cumulativeView.DataSource = pca.Components;

            numComponents.Maximum = pca.Components.Count;
            numComponents.Value = 1;
            numThreshold.Value = (decimal)pca.Components[0].CumulativeProportion * 100;
        }