public void ComputeTest2() { Accord.Math.Tools.SetupGenerator(0); double[,] S = Matrix.Random(5000, 2); double[,] A = { { 1, 1 }, { -1, 3 }, }; A = A.Divide(Norm.Norm1(A)); double[,] X = S.Multiply(A); IndependentComponentAnalysis ica = new IndependentComponentAnalysis(X, IndependentComponentAlgorithm.Deflation); Assert.AreEqual(IndependentComponentAlgorithm.Deflation, ica.Algorithm); ica.Compute(2); var result = ica.Result; var mixingMatrix = ica.MixingMatrix; var revertMatrix = ica.DemixingMatrix; // Verify mixing matrix mixingMatrix = mixingMatrix.Divide(Norm.Norm1(mixingMatrix)); Assert.IsTrue(A.IsEqual(mixingMatrix, 0.05)); // Verify demixing matrix double[,] expected = { { 3, -1 }, { 1, 1 }, }; expected = expected.Divide(Norm.Norm1(expected)); revertMatrix = revertMatrix.Divide(Norm.Norm1(revertMatrix)); Assert.IsTrue(expected.IsEqual(revertMatrix, 0.05)); var reverted = Accord.Statistics.Tools.ZScores(result).Abs(); var original = Accord.Statistics.Tools.ZScores(S).Abs(); Assert.IsTrue(reverted.IsEqual(original, 0.1)); }
public void Norm1Test() { double[,] a = { { 2, 1, 5 }, { 2, 2, 2 }, { 1, 6, 4 } }; double expected = 11; double actual = Norm.Norm1(a); Assert.AreEqual(expected, actual); }