Esempio n. 1
0
        public void RevertTest3()
        {
            string path = @"Resources\examples.xls";

            // Create a new reader, opening a given path
            ExcelReader reader = new ExcelReader(path);

            // Afterwards, we can query the file for all
            // worksheets within the specified workbook:
            string[] sheets = reader.GetWorksheetList();

            // Finally, we can request an specific sheet:
            DataTable table = reader.GetWorksheet("Wikipedia");

            // Now, we have loaded the Excel file into a DataTable. We
            // can go further and transform it into a matrix to start
            // running other algorithms on it:

            double[,] matrix = table.ToMatrix();

            IKernel kernel = new Polynomial(2);

            // Create analysis
            KernelPrincipalComponentAnalysis target = new KernelPrincipalComponentAnalysis(matrix,
                                                                                           kernel, AnalysisMethod.Center, centerInFeatureSpace: true);

            target.Compute();

            double[,] forward = target.Result;

            double[,] reversion = target.Revert(forward);

            Assert.IsTrue(!reversion.HasNaN());
        }
Esempio n. 2
0
        private void btnReversion_Click(object sender, EventArgs e)
        {
            double[][] reversionSource = (double[][])(dgvReversionSource.DataSource as ArrayDataView).ArrayData;
            double[][] reversionResult = kpca.Revert(reversionSource, (int)numNeighbor.Value);
            dgvReversionResult.DataSource = new ArrayDataView(reversionResult);

            // Creates a matrix from the source data table
            double[][] sourceMatrix = (dgvProjectionSource.DataSource as DataTable).ToJagged();

            // Create a new plot with the original Z column
            double[][] graph = reversionResult.InsertColumn(sourceMatrix.GetColumn(2));
            reversionScatterplot.DataSource = graph;
        }
        public void RevertTest()
        {
            // Using a linear kernel should be equivalent to standard PCA
            IKernel kernel = new Linear();

            // Create analysis
            KernelPrincipalComponentAnalysis target = new KernelPrincipalComponentAnalysis(data, kernel, AnalysisMethod.Center);

            // Compute
            target.Compute();

            // Compute image
            double[,] image = target.Transform(data, 2);

            // Compute pre-image
            double[,] preimage = target.Revert(image);

            // Check if pre-image equals the original data
            Assert.IsTrue(Matrix.IsEqual(data, preimage, 0.0001));
        }
Esempio n. 4
0
        private void btnReversion_Click(object sender, EventArgs e)
        {
            double[,] reversionSource = (double[, ])(dgvReversionSource.DataSource as ArrayDataView).ArrayData;
            double[,] m = kpca.Revert(reversionSource, (int)numNeighbor.Value);
            dgvReversionResult.DataSource = new ArrayDataView(m);

            // Creates a matrix from the source data table
            double[,] sourceMatrix = (dgvProjectionSource.DataSource as DataTable).ToMatrix();


            // Create a new plot with the original Z column
            double[,] graph = new double[sourceMatrix.GetLength(0), 3];
            for (int i = 0; i < graph.GetLength(0); i++)
            {
                graph[i, 0] = m[i, 0];
                graph[i, 1] = m[i, 1];
                graph[i, 2] = sourceMatrix[i, 2];
            }

            reversionScatterplot.DataSource = graph;
        }
Esempio n. 5
0
        public void RevertTest2_new_method()
        {
            string path = @"Resources\examples.xls";

            // Create a new reader, opening a given path
            ExcelReader reader = new ExcelReader(path);

            // Afterwards, we can query the file for all
            // worksheets within the specified workbook:
            string[] sheets = reader.GetWorksheetList();

            // Finally, we can request an specific sheet:
            DataTable table = reader.GetWorksheet("Wikipedia");

            // Now, we have loaded the Excel file into a DataTable. We
            // can go further and transform it into a matrix to start
            // running other algorithms on it:

            double[][] matrix = table.ToArray();

            IKernel kernel = new Gaussian(5);

            // Create analysis
            var target = new KernelPrincipalComponentAnalysis(kernel)
            {
                Method = PrincipalComponentMethod.Center,
                Center = true // Center in feature space
            };

            var regression = target.Learn(matrix);

            double[][] forward = regression.Transform(matrix);

            double[][] reversion = target.Revert(forward);

            Assert.IsTrue(!reversion.HasNaN());
        }