本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.L2Norm方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.L2Norm方法的具体用法?C# DenseMatrix.L2Norm怎么用?C# DenseMatrix.L2Norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.L2Norm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Run example
/// </summary>
/// <seealso cref="http://en.wikipedia.org/wiki/Matrix_norm">Matrix norm</seealso>
public void Run()
{
// Format matrix output to console
var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
formatProvider.TextInfo.ListSeparator = " ";
// Create square matrix
var matrix = new DenseMatrix(new[,] { { 1.0, 2.0, 3.0 }, { 6.0, 5.0, 4.0 }, { 8.0, 9.0, 7.0 } });
Console.WriteLine(@"Initial square matrix");
Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 1. 1-norm of the matrix
Console.WriteLine(@"1. 1-norm of the matrix");
Console.WriteLine(matrix.L1Norm());
Console.WriteLine();
// 2. 2-norm of the matrix
Console.WriteLine(@"2. 2-norm of the matrix");
Console.WriteLine(matrix.L2Norm());
Console.WriteLine();
// 3. Frobenius norm of the matrix
Console.WriteLine(@"3. Frobenius norm of the matrix");
Console.WriteLine(matrix.FrobeniusNorm());
Console.WriteLine();
// 4. Infinity norm of the matrix
Console.WriteLine(@"4. Infinity norm of the matrix");
Console.WriteLine(matrix.InfinityNorm());
Console.WriteLine();
// 5. Normalize matrix columns
Console.WriteLine(@"5. Normalize matrix columns: before normalize");
foreach (var keyValuePair in matrix.ColumnEnumerator())
{
Console.WriteLine(@"Column {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
}
Console.WriteLine();
var normalized = matrix.NormalizeColumns(2);
Console.WriteLine(@"5. Normalize matrix columns: after normalize");
foreach (var keyValuePair in normalized.ColumnEnumerator())
{
Console.WriteLine(@"Column {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
}
Console.WriteLine();
// 6. Normalize matrix columns
Console.WriteLine(@"6. Normalize matrix rows: before normalize");
foreach (var keyValuePair in matrix.RowEnumerator())
{
Console.WriteLine(@"Row {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
}
Console.WriteLine();
normalized = matrix.NormalizeRows(2);
Console.WriteLine(@"6. Normalize matrix rows: after normalize");
foreach (var keyValuePair in normalized.RowEnumerator())
{
Console.WriteLine(@"Row {0} 2-nd norm is: {1}", keyValuePair.Item1, keyValuePair.Item2.Norm(2));
}
}
示例2: Aca
/// <summary>
/// Adaptive Cross Approximation (ACA) matrix compression
/// the result is stored in U and V matrices like U*V
/// </summary>
/// <param name="acaThres">Relative error threshold to stop adding rows and columns in ACA iteration</param>
/// <param name="m">Row indices of Z submatrix to compress</param>
/// <param name="n">Column indices of Z submatrix to compress</param>
/// <param name="U">to store result</param>
/// <param name="V">to store result</param>
/// <returns>pair with matrix U and V</returns>
public static Tuple<Matrix, Matrix> Aca(double acaThres, List<int> m, List<int> n, Matrix U, Matrix V)
{
int M = m.Count;
int N = n.Count;
int Min = Math.Min(M, N);
U = new DenseMatrix(Min, Min);
V = new DenseMatrix(Min, Min);
//if Z is a vector, there is nothing to compress
if (M == 1 || N == 1)
{
U = UserImpedance(m, n);
V = new DenseMatrix(1, 1);
V[0, 0] = 1.0;
return new Tuple<Matrix,Matrix>(U,V);
}
//Indices of columns picked up from Z
//Vector J = new DenseVector(N);
//List<int> J = new List<int>(N);
List<int> J = new List<int>(new int [N]);
//int[] J = new int[N];
//Indices of rows picked up from Z
//Vector I = new DenseVector(M);
List<int> I = new List<int>(new int [M]);
//int[] I = new int[M];
//Row indices to search for maximum in R
//Vector i = new DenseVector(M);
List<int> i = new List<int>();
//int[] i = new int[M];
//Column indices to search for maximum in R
//Vector j = new DenseVector(N);
List<int> j = new List<int>();
//int[] j = new int[N];
for (int k = 1; k < M; k++)
{
i.Add(k);
}
for (int k = 0; k < N; k++)
{
j.Add(k);
}
//Initialization
//Initialize the 1st row index I(1) = 1
I[0] = 0;
//Initialize the 1st row of the approximate error matrix
List<int> m0 = new List<int>();
m0.Add(m[I[0]]);
Matrix Rik = UserImpedance(m0, n);
//Find the 1st column index J(0)
double max = -1.0;
int col = 0;
foreach (int ind in j)
{
if (Math.Abs(Rik[0, ind]) > max)
{
max = Math.Abs(Rik[0, ind]);
col = ind;
}
}
//J[0] = j[col];
J[0] = col;
j.Remove(J[0]);
//First row of V
V = new DenseMatrix(1, Rik.ColumnCount);
V.SetRow(0, Rik.Row(0).Divide(Rik[0, J[0]]));
//Initialize the 1st column of the approximate error matrix
List<int> n0 = new List<int>();
n0.Add(n[J[0]]);
Matrix Rjk = UserImpedance(m, n0);
//First column of U
U = new DenseMatrix(Rjk.RowCount, 1);
U.SetColumn(0, Rjk.Column(0));
// Norm of (approximate) Z, to test error
double d1 = U.L2Norm();
double d2 = V.L2Norm();
double normZ = d1 * d1 * d2 * d2;
//.........这里部分代码省略.........