public void covariance_new_interface()
{
double[] mean = Measures.Mean(data, dimension: 0);
double[][] cov = Measures.Covariance(data.ToJagged());
#region doc_learn_3
// Create the Principal Component Analysis
// specifying the CovarianceMatrix method:
var pca = new PrincipalComponentAnalysis()
{
Method = PrincipalComponentMethod.CovarianceMatrix,
Means = mean // pass the original data mean vectors
};
// Learn the PCA projection using passing the cov matrix
MultivariateLinearRegression transform = pca.Learn(cov);
// Now, we can transform data as usual
double[,] actual = pca.Transform(data);
#endregion
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 },
};
// Verify both are equal with 0.01 tolerance value
Assert.IsTrue(Matrix.IsEqual(actual, expected, 0.01));
// Transform
double[,] image = pca.Transform(data);
// Reverse
double[,] reverse = pca.Revert(image);
// Verify both are equal with 0.01 tolerance value
Assert.IsTrue(Matrix.IsEqual(reverse, data, 1e-5));
actual = transform.Transform(data.ToJagged()).ToMatrix();
Assert.IsTrue(Matrix.IsEqual(actual, expected, 1e-5));
}