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)); }
public void RevertTest3() { string path = @"..\..\..\..\Unit Tests\Accord.Tests.Statistics\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()); }
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()); }