本文整理汇总了C#中DenseMatrix.At方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.At方法的具体用法?C# DenseMatrix.At怎么用?C# DenseMatrix.At使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.At方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DenseEvd
/// <summary>
/// Initializes a new instance of the <see cref="DenseEvd"/> class. This object will compute the
/// the eigenvalue decomposition when the constructor is called and cache it's decomposition.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If EVD algorithm failed to converge with matrix <paramref name="matrix"/>.</exception>
public DenseEvd(DenseMatrix matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (matrix.RowCount != matrix.ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSquare);
}
var order = matrix.RowCount;
// Initialize matrices for eigenvalues and eigenvectors
MatrixEv = DenseMatrix.Identity(order);
MatrixD = matrix.CreateMatrix(order, order);
VectorEv = new DenseVector(order);
IsSymmetric = true;
for (var i = 0; IsSymmetric && i < order; i++)
{
for (var j = 0; IsSymmetric && j < order; j++)
{
IsSymmetric &= matrix.At(i, j) == matrix.At(j, i).Conjugate();
}
}
Control.LinearAlgebraProvider.EigenDecomp(IsSymmetric, order, matrix.Values, ((DenseMatrix) MatrixEv).Values,
((DenseVector) VectorEv).Values, ((DenseMatrix) MatrixD).Values);
}
示例2: DenseEvd
/// <summary>
/// Initializes a new instance of the <see cref="DenseEvd"/> class. This object will compute the
/// the eigenvalue decomposition when the constructor is called and cache it's decomposition.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If EVD algorithm failed to converge with matrix <paramref name="matrix"/>.</exception>
public DenseEvd(DenseMatrix matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (matrix.RowCount != matrix.ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSquare);
}
var order = matrix.RowCount;
// Initialize matricies for eigenvalues and eigenvectors
MatrixEv = DenseMatrix.Identity(order);
MatrixD = matrix.CreateMatrix(order, order);
VectorEv = new DenseVector(order);
IsSymmetric = true;
for (var i = 0; i < order & IsSymmetric; i++)
{
for (var j = 0; j < order & IsSymmetric; j++)
{
IsSymmetric &= matrix.At(i, j) == matrix.At(j, i).Conjugate();
}
}
if (IsSymmetric)
{
var matrixCopy = matrix.ToArray();
var tau = new Complex[order];
var d = new double[order];
var e = new double[order];
SymmetricTridiagonalize(matrixCopy, d, e, tau, order);
SymmetricDiagonalize(((DenseMatrix)MatrixEv).Values, d, e, order);
SymmetricUntridiagonalize(((DenseMatrix)MatrixEv).Values, matrixCopy, tau, order);
for (var i = 0; i < order; i++)
{
VectorEv[i] = new Complex(d[i], e[i]);
}
}
else
{
var matrixH = matrix.ToArray();
NonsymmetricReduceToHessenberg(((DenseMatrix)MatrixEv).Values, matrixH, order);
NonsymmetricReduceHessenberToRealSchur(((DenseVector)VectorEv).Values, ((DenseMatrix)MatrixEv).Values, matrixH, order);
}
MatrixD.SetDiagonal(VectorEv);
}
示例3: DenseEvd
/// <summary>
/// Initializes a new instance of the <see cref="DenseEvd"/> class. This object will compute the
/// the eigenvalue decomposition when the constructor is called and cache it's decomposition.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If EVD algorithm failed to converge with matrix <paramref name="matrix"/>.</exception>
public DenseEvd(DenseMatrix matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (matrix.RowCount != matrix.ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSquare);
}
var order = matrix.RowCount;
// Initialize matricies for eigenvalues and eigenvectors
MatrixEv = matrix.CreateMatrix(order, order);
MatrixD = matrix.CreateMatrix(order, order);
VectorEv = new LinearAlgebra.Complex.DenseVector(order);
IsSymmetric = true;
for (var i = 0; i < order & IsSymmetric; i++)
{
for (var j = 0; j < order & IsSymmetric; j++)
{
IsSymmetric &= matrix.At(i, j) == matrix.At(j, i);
}
}
var d = new float[order];
var e = new float[order];
if (IsSymmetric)
{
matrix.CopyTo(MatrixEv);
d = MatrixEv.Row(order - 1).ToArray();
SymmetricTridiagonalize(((DenseMatrix)MatrixEv).Values, d, e, order);
SymmetricDiagonalize(((DenseMatrix)MatrixEv).Values, d, e, order);
}
else
{
var matrixH = matrix.ToArray();
NonsymmetricReduceToHessenberg(((DenseMatrix)MatrixEv).Values, matrixH, order);
NonsymmetricReduceHessenberToRealSchur(((DenseMatrix)MatrixEv).Values, matrixH, d, e, order);
}
for (var i = 0; i < order; i++)
{
MatrixD.At(i, i, d[i]);
if (e[i] > 0)
{
MatrixD.At(i, i + 1, e[i]);
}
else if (e[i] < 0)
{
MatrixD.At(i, i - 1, e[i]);
}
}
for (var i = 0; i < order; i++)
{
VectorEv[i] = new Complex(d[i], e[i]);
}
}
示例4: Create
/// <summary>
/// Initializes a new instance of the <see cref="DenseEvd"/> class. This object will compute the
/// the eigenvalue decomposition when the constructor is called and cache it's decomposition.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If EVD algorithm failed to converge with matrix <paramref name="matrix"/>.</exception>
public static DenseEvd Create(DenseMatrix matrix)
{
if (matrix.RowCount != matrix.ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSquare);
}
var order = matrix.RowCount;
// Initialize matrices for eigenvalues and eigenvectors
var eigenVectors = DenseMatrix.Identity(order);
var blockDiagonal = new DenseMatrix(order);
var eigenValues = new LinearAlgebra.Complex.DenseVector(order);
var isSymmetric = true;
for (var i = 0; isSymmetric && i < order; i++)
{
for (var j = 0; isSymmetric && j < order; j++)
{
isSymmetric &= matrix.At(i, j) == matrix.At(j, i).Conjugate();
}
}
Control.LinearAlgebraProvider.EigenDecomp(isSymmetric, order, matrix.Values, eigenVectors.Values, eigenValues.Values, blockDiagonal.Values);
return new DenseEvd(eigenVectors, eigenValues, blockDiagonal, isSymmetric);
}
示例5: DoSample
/// <summary>
/// Samples the distribution.
/// </summary>
/// <param name="rnd">The random number generator to use.</param>
/// <param name="nu">The nu parameter to use.</param>
/// <param name="s">The S parameter to use.</param>
/// <param name="chol">The cholesky decomposition to use.</param>
/// <returns>a random number from the distribution.</returns>
private static Matrix<double> DoSample(Random rnd, double nu, Matrix<double> s, Cholesky<double> chol)
{
var count = s.RowCount;
// First generate a lower triangular matrix with Sqrt(Chi-Squares) on the diagonal
// and normal distributed variables in the lower triangle.
var a = new DenseMatrix(count, count);
for (var d = 0; d < count; d++)
{
a.At(d, d, Math.Sqrt(Gamma.Sample(rnd, (nu - d)/2.0, 0.5)));
}
for (var i = 1; i < count; i++)
{
for (var j = 0; j < i; j++)
{
a.At(i, j, Normal.Sample(rnd, 0.0, 1.0));
}
}
var factor = chol.Factor;
return factor * a * a.Transpose() * factor.Transpose();
}