public Evd ( Symmetricity symmetricity = Symmetricity.Unknown ) : Evd |
||
symmetricity | Symmetricity | |
리턴 | Evd |
public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order) { var A = new DenseMatrix(order, order); A[0, 0] = 1; A[order - 1, order - 1] = 1; for (var i = 1; i < order - 1; i++) { A[i, i - 1] = 1; A[i, i + 1] = 1; A[i - 1, i] = 1; A[i + 1, i] = 1; } var factorEvd = A.Evd(); Assert.AreEqual(factorEvd.Determinant, 0); Assert.AreEqual(factorEvd.Rank, order - 1); }
public void CanCheckRankOfSquareSingular(int order) { var matrixA = new DenseMatrix(order, order); matrixA[0, 0] = 1; matrixA[order - 1, order - 1] = 1; for (var i = 1; i < order - 1; i++) { matrixA[i, i - 1] = 1; matrixA[i, i + 1] = 1; matrixA[i - 1, i] = 1; matrixA[i + 1, i] = 1; } var factorEvd = matrixA.Evd(); Assert.AreEqual(factorEvd.Determinant, 0); Assert.AreEqual(factorEvd.Rank, order - 1); }
Evd evd; //factorization storage #endregion Fields #region Constructors public vanillaLogCov(float[,] matrix1, float[,] matrix2) { //deep copy the covariances //densematrix allocates new memory for the matrix cov1 = new DenseMatrix(Covariance(matrix1)); cov2 = new DenseMatrix(Covariance(matrix2)); evd = cov1.Evd(); diag = evd.D(); //could make this a function but thats for later cleanup.... < . < //should be square matrix so matrix lengths dont matter for (int i = 0; i < diag.RowCount; i++) { diag[i, i] = (float)Math.Log(Math.Abs((double)diag[i, i])); } logcov1 = evd.EigenVectors() * diag * evd.EigenVectors().Transpose(); evd = cov2.Evd(); diag = evd.D(); //could make this a function but thats for later cleanup.... < . < //should be square matrix so matrix lengths dont matter for (int i = 0; i < diag.RowCount; i++) { diag[i, i] = (float)Math.Log(Math.Abs((double)diag[i, i])); } logcov2 = evd.EigenVectors() * diag * evd.EigenVectors().Transpose(); //compute distance distance = 0; //initialize to empty for (int i = 0; i < logcov2.RowCount; i++) { for (int j = 0; j < logcov2.RowCount; j++) { distance += (float)Math.Pow(logcov1[i, j] - logcov2[i, j], 2); } } distance = (float)Math.Sqrt(distance); }
public MathNet.Numerics.LinearAlgebra.Generic.Matrix<float> ToCovMat(int VectDimen, int FPSegment, float[,] DistData, float[] MeanDist) { DenseMatrix Cov = new DenseMatrix(VectDimen); for (int i = 0; i < VectDimen; i++) { for (int j = i; j < VectDimen; j++) { for (int t = 0; t < FPSegment; t++) { Cov[i, j] += DistData[i, t] * DistData[j, t]; } Cov[i, j] -= MeanDist[i] * MeanDist[j] * FPSegment; Cov[i, j] /= FPSegment - 1; } } for (int i = 0; i < VectDimen; i++) { for (int j = i; j < VectDimen; j++) { Cov[j, i] = Cov[i, j]; } } MathNet.Numerics.LinearAlgebra.Single.Factorization.Evd evd; MathNet.Numerics.LinearAlgebra.Generic.Matrix<float> LogD; var thread = new Thread(() => tryEvd(Cov)); thread.Start(); if (!thread.Join(3000)) { LogD = Cov; LogD.Clear(); return LogD; } evd = Cov.Evd(); LogD = evd.D(); for (int i = 0; i < VectDimen; i++) { LogD[i, i] = (float)Math.Log(Math.Abs((double)LogD[i, i])); } MathNet.Numerics.LinearAlgebra.Generic.Matrix<float> LogCov; LogCov = evd.EigenVectors() * LogD * evd.EigenVectors().Transpose(); return LogCov; }