double[][] data = { new[] { 2.5, 2.4 }, new[] { 0.5, 0.7 }, new[] { 2.2, 2.9 }, new[] { 1.9, 2.2 }, new[] { 3.1, 3.0 }, new[] { 2.3, 2.7 }, new[] { 2.0, 1.6 }, new[] { 1.0, 1.1 }, new[] { 1.5, 1.6 }, new[] { 1.1, 0.9 } }; var method = PrincipalComponentMethod.Center; var pca = new PrincipalComponentAnalysis(method); pca.Learn(data); double[] eigenvalues = { 1.28402771, 0.0490833989 }; double[] proportion = eigenvalues.Divide(eigenvalues.Sum()); double[,] eigenvectors = { { -0.677873399, -0.735178656 }, { -0.735178656, 0.677873399 } }; double[] v = eigenvectors.GetColumn(0); eigenvectors.SetColumn(0, v.Multiply(-1)); Assert.IsTrue(eigenvectors.IsEqual(pca.ComponentMatrix, rtol: 1e-9)); Assert.IsTrue(proportion.IsEqual(pca.ComponentProportions, rtol: 1e-9)); Assert.IsTrue(eigenvalues.IsEqual(pca.Eigenvalues, rtol: 1e-5)); double[][] actual = pca.Transform(data); double[,] expected = new double[,] { { 0.827970186, -0.175115307 }, { -1.77758033, 0.142857227 }, { 0.992197494, 0.384374989 }, { 0.274210416, 0.130417207 }, { 1.67580142, -0.209498461 }, { 0.912949103, 0.175282444 }, { -0.099109437, -0.349824698 }, { -1.14457216, 0.046417258 }, { -0.438046137, 0.017764629 }, { -1.22382056, -0.162675287 }, }; Assert.IsTrue(expected.IsEqual(actual, atol: 1e-8)); pca.NumberOfOutputs = 1; actual = pca.Transform(data); expected = new double[,] { { 0.827970186 }, { -1.77758033, }, { 0.992197494 }, { 0.274210416 }, { 1.67580142, }, { 0.912949103 }, { -0.099109437 }, { -1.14457216, }, { -0.438046137 }, { -1.22382056, }, }; Assert.IsTrue(expected.IsEqual(actual, atol: 1e-8));
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4