本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.Evd方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.Evd方法的具体用法?C# DenseMatrix.Evd怎么用?C# DenseMatrix.Evd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.Evd方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCheckRankOfSquareSingular
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);
}
示例2: CanCheckRankOfSquareSingular
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);
}
示例3: Run
/// <summary>
/// Run example
/// </summary>
/// <seealso cref="http://en.wikipedia.org/wiki/Eigenvalue,_eigenvector_and_eigenspace">EVD decomposition</seealso>
public void Run()
{
// Format matrix output to console
var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
formatProvider.TextInfo.ListSeparator = " ";
// Create square symmetric matrix
var matrix = new DenseMatrix(new[,] { { 1.0, 2.0, 3.0 }, { 2.0, 1.0, 4.0 }, { 3.0, 4.0, 1.0 } });
Console.WriteLine(@"Initial square symmetric matrix");
Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Perform eigenvalue decomposition of symmetric matrix
var evd = matrix.Evd();
Console.WriteLine(@"Perform eigenvalue decomposition of symmetric matrix");
// 1. Eigen vectors
Console.WriteLine(@"1. Eigen vectors");
Console.WriteLine(evd.EigenVectors().ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Eigen values as a complex vector
Console.WriteLine(@"2. Eigen values as a complex vector");
Console.WriteLine(evd.EigenValues().ToString("N", formatProvider));
Console.WriteLine();
// 3. Eigen values as the block diagonal matrix
Console.WriteLine(@"3. Eigen values as the block diagonal matrix");
Console.WriteLine(evd.D().ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 4. Multiply V by its transpose VT
var identity = evd.EigenVectors().TransposeAndMultiply(evd.EigenVectors());
Console.WriteLine(@"4. Multiply V by its transpose VT: V*VT = I");
Console.WriteLine(identity.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 5. Reconstruct initial matrix: A = V*D*V'
var reconstruct = evd.EigenVectors() * evd.D() * evd.EigenVectors().Transpose();
Console.WriteLine(@"5. Reconstruct initial matrix: A = V*D*V'");
Console.WriteLine(reconstruct.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 6. Determinant of the matrix
Console.WriteLine(@"6. Determinant of the matrix");
Console.WriteLine(evd.Determinant);
Console.WriteLine();
// 7. Rank of the matrix
Console.WriteLine(@"7. Rank of the matrix");
Console.WriteLine(evd.Rank);
Console.WriteLine();
// Fill matrix by random values
var rnd = new Random(1);
for (var i = 0; i < matrix.RowCount; i++)
{
for (var j = 0; j < matrix.ColumnCount; j++)
{
matrix[i, j] = rnd.NextDouble();
}
}
Console.WriteLine(@"Fill matrix by random values");
Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Perform eigenvalue decomposition of non-symmetric matrix
evd = matrix.Evd();
Console.WriteLine(@"Perform eigenvalue decomposition of non-symmetric matrix");
// 8. Eigen vectors
Console.WriteLine(@"8. Eigen vectors");
Console.WriteLine(evd.EigenVectors().ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 9. Eigen values as a complex vector
Console.WriteLine(@"9. Eigen values as a complex vector");
Console.WriteLine(evd.EigenValues().ToString("N", formatProvider));
Console.WriteLine();
// 10. Eigen values as the block diagonal matrix
Console.WriteLine(@"10. Eigen values as the block diagonal matrix");
Console.WriteLine(evd.D().ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 11. Multiply A * V
var av = matrix * evd.EigenVectors();
Console.WriteLine(@"11. Multiply A * V");
Console.WriteLine(av.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 12. Multiply V * D
var vd = evd.EigenVectors() * evd.D();
Console.WriteLine(@"12. Multiply V * D");
Console.WriteLine(vd.ToString("#0.00\t", formatProvider));
//.........这里部分代码省略.........
示例4: ComputeModeGoodnessRatio
// Method to rate mode goodness and then sort (use first mode as base)
private void ComputeModeGoodnessRatio()
{
// Use no more than Max_N (which is 5 I believe)
int n = lstCentroids.Count; // find as many Gaussians as modes.
// Don't do too many Gaussians because it will take a long time and perform poorly
if (n > GCount)
{
n = GCount;
}
// Multiple dist map and diff map if necessary
//DateTime startTime = DateTime.Now;
ComputeRealMap();
//DateTime stopTime = DateTime.Now;
//TimeSpan duration = stopTime - startTime;
//double RunTime = duration.TotalSeconds;
//System.Windows.Forms.MessageBox.Show("ComputeRealMap Run time " + RunTime + " seconds!");
// Allocate memory for output matrices
Array arrModes = new double[n];
Array arrProportions = new double[n];
Array arrMUs = new double[n, 2];
Array arrSigmaXSigmaY = new double[n];
Array junkModes = new double[n];
Array junkMUs = new double[n, 2];
Array junkSigmaXSigmaY = new double[n];
#region Using MATLAB for GMM
////startTime = DateTime.Now;
//double[,] arrSamplesR;
//double[,] arrSamplesI;
//// Generate samples from map to get ready to perform mixed Gaussian fitting
//PrepareSamples(out arrSamplesR, out arrSamplesI);
////stopTime = DateTime.Now;
////duration = stopTime - startTime;
////RunTime = duration.TotalSeconds;
////System.Windows.Forms.MessageBox.Show("PrepareSamples Run time " + RunTime + " seconds!");
//// Perform mixed Gaussian fitting and get parameters
////startTime = DateTime.Now;
//// Using MATLAB to do GMM
//GaussianFitting(n, arrSamplesR, arrSamplesI, ref arrModes, ref arrMUs, ref arrSigmaXSigmaY, ref junkModes, ref junkMUs, ref junkSigmaXSigmaY);
////stopTime = DateTime.Now;
////duration = stopTime - startTime;
////RunTime = duration.TotalSeconds;
////System.Windows.Forms.MessageBox.Show("GaussianFitting Run time " + RunTime + " seconds!");
//// Debug
//// curRequest.SetLog("\nMATLAB GMM results\n");
#endregion
#region Using C# for GMM
// Prepare samples into the format needed
double[][] arrSamples;
// Generate samples from map to get ready to perform mixed Gaussian fitting
PrepareSamplesAccord(out arrSamples);
// Using Accord.net library to do GMM
GaussianMixtureModel gmm = new GaussianMixtureModel(n);
List<MapMode> lstGaussians = new List<MapMode>(); // Results stored in a list of MapModes for sorting
// If Accord.net library fails, try it again up to 3 times
for (int ii = 0; ii < ProjectConstants.MaxAccordRun; ii++)
{
try
{
gmm.Compute(arrSamples, 10);
//// Debug code
//// Print out means and covariances and proportions so we can plot
//Console.WriteLine("Accord.net run number " + ii);
//for (int i = 0; i < n; i++)
//{
// Console.WriteLine("Gaussian number " + i);
// // Means
// Console.Write("Mean: (" + gmm.Gaussians[i].Mean[0] + " " + gmm.Gaussians[i].Mean[1] + ") ");
// // Area
// Console.Write("Covariance Matrix [" + gmm.Gaussians[i].Covariance[0, 0] + " "
// + gmm.Gaussians[i].Covariance[0, 1] + "; "
// + gmm.Gaussians[i].Covariance[1, 0] + " "
// + gmm.Gaussians[i].Covariance[1, 1] + "] ");
// Console.Write("Proportion: " + gmm.Gaussians[i].Proportion + "\n");
//}
// Getting arrays ready
for (int i = 0; i < n; i++)
{
// Means
arrMUs.SetValue(gmm.Gaussians[i].Mean[0], i, 0);
arrMUs.SetValue(gmm.Gaussians[i].Mean[1], i, 1);
// Area
DenseMatrix m = new DenseMatrix(gmm.Gaussians[i].Covariance);
System.Numerics.Complex[] d = m.Evd().EigenValues().ToArray();
double SigmaXSigmaY = Math.Sqrt(d[0].Real) * Math.Sqrt(d[1].Real);
arrSigmaXSigmaY.SetValue(SigmaXSigmaY, i);
//.........这里部分代码省略.........