本文整理汇总了C#中DenseMatrix.SetSubMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.SetSubMatrix方法的具体用法?C# DenseMatrix.SetSubMatrix怎么用?C# DenseMatrix.SetSubMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.SetSubMatrix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RepMat
/// <summary>
/// 重复
/// </summary>
public static DenseMatrix RepMat(this Matrix m, int rows, int cols)
{
DenseMatrix result = new DenseMatrix(rows * m.Rows, cols * m.Columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
result.SetSubMatrix(i * m.Rows, m.Rows, j * m.Columns, m.Columns, m);
}
}
return result;
}
示例2: RankVertical
public static Matrix RankVertical(params Matrix[] ms)
{
Matrix result = new DenseMatrix(ms.Sum(m => m.Rows), ms[0].Columns);
int row_offset = 0;
foreach (var m in ms) {
result.SetSubMatrix(row_offset, m.Rows, 0, result.Columns, m);
row_offset += m.Rows;
}
return result;
}
示例3: 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
}
示例4: RankHorizon
public static Matrix RankHorizon(params Matrix[] ms)
{
Matrix result = new DenseMatrix(ms[0].Rows, ms.Sum(m => m.Columns));
int col_offset = 0;
foreach (var m in ms) {
result.SetSubMatrix(0, result.Rows, col_offset, m.Columns, m);
col_offset += m.Columns;
}
return result;
}
示例5: MatchIteration
//.........这里部分代码省略.........
if (affine_start_flag) {
if (k == 0)
lambda_o = 1000;
else
lambda_o = beta_init * Math.Pow(r, k - 1); // lambda_o=beta_init*r^(k-2);
} else {
lambda_o = beta_init * Math.Pow(r, k); // lambda_o=beta_init*r^(k-1);
}
double beta_k = mean_dist_2 * mean_dist_2 * lambda_o;
#endregion
#region 计算代价矩阵
timer.Restart();
var costmat_shape = HistCost(BH1, BH2); // costmat_shape = hist_cost_2(BH1, BH2);
// theta_diff=repmat(tk,1,nsamp)-repmat(t2',nsamp,1);
var theta_diff = tk.RepMat(1, nsamp) - t2.Transpose().RepMat(nsamp, 1);
Matrix costmat_theta;
if (polarity_flag) {
// costmat_theta=0.5*(1-cos(theta_diff));
//costmat_theta = 0.5 * (Ones(costmat_shape.Rows, costmat_shape.Columns) - theta_diff.Each(v => Math.Cos(v)));
costmat_theta = theta_diff.Each(v => 0.5 * (1 - Math.Cos(v)));
} else {
// costmat_theta=0.5*(1-cos(2*theta_diff));
//costmat_theta = 0.5 * (Ones(costmat_shape.Rows, costmat_shape.Columns) - theta_diff.Each(v => Math.Cos(2 * v)));
costmat_theta = theta_diff.Each(v => 0.5 * (1 - Math.Cos(2 * v)));
}
// costmat=(1-ori_weight)*costmat_shape+ori_weight*costmat_theta;
var costmat = (1 - ori_weight) * costmat_shape + ori_weight * costmat_theta;
int nptsd = nsamp + ndum; // nptsd=nsamp+ndum;
var costmat2 = new DenseMatrix(nptsd, nptsd, eps_dum); // costmat2=eps_dum*ones(nptsd,nptsd);
costmat2.SetSubMatrix(0, nsamp, 0, nsamp, costmat); // costmat2(1:nsamp,1:nsamp)=costmat;
timeused += timer.StopAndSay("计算代价矩阵");
#endregion
#region 匈牙利算法
timer.Restart();
var costmat_int = new int[nptsd, nptsd];
for (int i = 0; i < nptsd; ++i) {
for (int j = 0; j < nptsd; ++j) {
costmat_int[i, j] = (int)(costmat2[i, j] * 10000);
}
}
var km = new KM(nptsd, costmat_int);
km.Match(false);
matchcost = km.MatchResult / 10000.0;
int[] cvec = km.MatchPair; // cvec=hungarian(costmat2);
timeused += timer.StopAndSay("匈牙利算法");
#endregion
#region 计算野点标记向量,重排匹配点
timer.Restart();
int[] cvec2 = cvec.Select((v, i) => new { Val = v, Idx = i })
.OrderBy(v => v.Val)
.Select(v => v.Idx)
.ToArray();// [a,cvec2]=sort(cvec);
out_vec_1 = cvec2.Take(nsamp1).Select(v => v > nsamp2).ToArray(); // out_vec_1=cvec2(1:nsamp1)>nsamp2;
out_vec_2 = cvec.Take(nsamp2).Select(v => v > nsamp1).ToArray(); // out_vec_2=cvec(1:nsamp2)>nsamp1;
//X2 = NaNs(nptsd, 2); // X2=NaN*ones(nptsd,2);
//X2.SetSubMatrix(0, nsamp1, 0, X2.Columns, Xk); // X2(1:nsamp1,:)=Xk;
//X2 = X2.SortRowsBy(cvec); // X2=X2(cvec,:);
X2b = NaNs(nptsd, 2); // X2b=NaN*ones(nptsd,2);