本文整理汇总了C#中DenseMatrix.Transpose方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.Transpose方法的具体用法?C# DenseMatrix.Transpose怎么用?C# DenseMatrix.Transpose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.Transpose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRandomPositiveDefiniteMatrix
public static Matrix GenerateRandomPositiveDefiniteMatrix(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Distributions.Normal();
normal.RandomSource = new Random.MersenneTwister(1);
var A = new DenseMatrix(order);
for (int i = 0; i < order; i++)
{
for (int j = 0; j < order; j++)
{
A[i, j] = normal.Sample();
}
}
// Generate a matrix which is positive definite.
return A.Transpose() * A;
}
示例2: 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, 0.0);
for (var d = 0; d < count; d++)
{
a[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[i, j] = Normal.Sample(rnd, 0.0, 1.0);
}
}
var factor = chol.Factor;
return factor * a * a.Transpose() * factor.Transpose();
}
示例3: GenerateRandomPositiveDefiniteDenseMatrix
/// <summary>
/// Creates a positive definite <c>DenseMatrix</c> with random values.
/// </summary>
/// <param name="order">The order of the matrix.</param>
/// <returns>A positive definite <c>DenseMatrix</c> with the given order and random values.</returns>
public static Matrix<double> GenerateRandomPositiveDefiniteDenseMatrix(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal(new MersenneTwister(1));
var matrixA = new DenseMatrix(order);
for (var i = 0; i < order; i++)
{
for (var j = 0; j < order; j++)
{
matrixA[i, j] = normal.Sample();
}
}
// Generate a matrix which is positive definite.
return matrixA.Transpose()*matrixA;
}
示例4: GaussianKernal
public static Matrix GaussianKernal(int N)
{
var m = new DenseMatrix(N, N, 1);
for (int i = 1; i < N; ++i) {
for (int j = N - 2; j >= 0; --j) {
m[i, j] = m[i, j + 1] + m[i - 1, j];
}
}
var diag = m.GetDiagonal();
var w = new DenseMatrix(N, 1);
for (int i = 0; i < N; ++i) {
w[i, 0] = diag[i] * Math.Pow(2, 1 - N);
}
return w * w.Transpose();
}
示例5: Bookstein
//function [cx,cy,E,L]=bookstein(X,Y,beta_k);
public void Bookstein(Matrix X, Matrix Y, double? beta_k,
ref Matrix cx, ref Matrix cy, ref double E)
{
//% [cx,cy,E,L]=bookstein(X,Y,beta_k);
//%
//% Bookstein PAMI89
//N=size(X,1);
int N = X.Rows;
//Nb=size(Y,1);
int Nb = Y.Rows;
//if N~=Nb
// error('number of landmarks must be equal')
//end
if (N != Nb) {
throw new Exception("标记数必须相等");
}
//% compute distances between left points
//r2=dist2(X,X); % dist2函数定义在dist.m里吧
var r2 = Dist2(X, X);
//K=r2.*log(r2+eye(N,N)); % add identity matrix to make K zero on the diagonal
//% 据说eye函数产生n*n的单位矩阵
var K = r2.PointMultiply((r2 + Eye(N, N)).Each(Math.Log));
//P=[ones(N,1) X]; % Matlab还能这样表示矩阵……内牛满面
var P = new DenseMatrix(N, 1 + X.Columns);
P.SetSubMatrix(0, N, 0, 1, Ones(N, 1));
P.SetSubMatrix(0, N, 1, X.Columns, X);
//L=[K P
// P' zeros(3,3)]; % 内牛满面again
var Pt = P.Transpose();
var L = new DenseMatrix(K.Rows + Pt.Rows, K.Columns + P.Columns);
L.SetSubMatrix(0, K.Rows, 0, K.Columns, K); // 左上角K
L.SetSubMatrix(K.Rows, Pt.Rows, 0, Pt.Columns, Pt); // 左下角Pt
L.SetSubMatrix(0, P.Rows, K.Columns, P.Columns, P); // 右上角P
L.SetSubMatrix(K.Rows, 3, K.Columns, 3, Zeros(3, 3)); // 右下角Zeros
//V=[Y' zeros(2,3)];
var Yt = Y.Transpose();
var V = new DenseMatrix(Yt.Rows, Yt.Columns + 3);
V.SetSubMatrix(0, Yt.Rows, 0, Yt.Columns, Yt);
V.SetSubMatrix(0, Yt.Rows, Yt.Columns, 3, Zeros(2, 3));
//if nargin>2 % nargin哪来的,晕
if (beta_k != null) {
// % regularization
// L(1:N,1:N)=L(1:N,1:N)+beta_k*eye(N,N); % 算算算
L.SetSubMatrix(0, N, 0, N, L.GetSubMatrix(0, N, 0, N) + beta_k.Value * Eye(N, N));
//end
}
//invL=inv(L); % 求逆。。。
var invL = L.Inverse();
//c=invL*V'; % 矩阵乘法
var c = invL * V.Transpose();
cx = c.GetSubMatrix(0, c.Rows, 0, 1);//cx=c(:,1);
cy = c.GetSubMatrix(0, c.Rows, 1, 1);//cy=c(:,2);
//if nargout>2 % nargout哪来的?晕死
// % compute bending energy (w/o regularization) % 传说中的弯曲能量?
// Q=c(1:N,:)'*K*c(1:N,:); % 看不懂看不懂看不懂
var c1n = c.GetSubMatrix(0, N, 0, c.Columns);
var Q = c1n.Transpose() * K * c1n;
// E=mean(diag(Q)); % 对角线?的均值
E = Q.GetDiagonal().Average();
//end
}
示例6: Givens_Decomposition
void Givens_Decomposition(Matrix A, Vector b)
{
Matrix q,R;
q = new DenseMatrix(n, n);
R = new DenseMatrix(n, n);
q = new DenseMatrix(A);
double r0, c1, s1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i == j) q[i, j] = 1;
else
q[i, j] = 0;
for (int r = 0; r < n; r++)
{
for (int i = r + 1; i < n; i++)
{
r0 = Math.Sqrt((A[r, r] * A[r, r] + A[i, r] * A[i, r]));
if (r0 < eps) { c1 = 1; s1 = 0; }
else { c1 = A[r, r] / r0; s1 = A[i, r] / r0; }
R = generate_rotate(r, i, c1, s1);
print_matrix(R);
A = R.Multiply(A); // R[r,i]
b = R.Multiply(b); // R[r,i]
q = R.Multiply(q); // R[r,i]
}
}
Giv_R = A;
Giv_b = b;
Giv_Q = q.Transpose();
}