本文整理汇总了C#中InitializedList.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# InitializedList.Sort方法的具体用法?C# InitializedList.Sort怎么用?C# InitializedList.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InitializedList
的用法示例。
在下文中一共展示了InitializedList.Sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SymmetricSchurDecomposition
//.........这里部分代码省略.........
Matrix ss = new Matrix(s);
Vector tmpDiag = new Vector(diagonal_);
Vector tmpAccumulate = new Vector(size, 0.0);
double threshold, epsPrec = 1e-15;
bool keeplooping = true;
int maxIterations = 100, ite = 1;
do {
//main loop
double sum = 0;
for (int a=0; a<size-1; a++) {
for (int b=a+1; b<size; b++) {
sum += Math.Abs(ss[a,b]);
}
}
if (sum==0) {
keeplooping = false;
} else {
/* To speed up computation a threshold is introduced to
make sure it is worthy to perform the Jacobi rotation
*/
if (ite<5) threshold = 0.2*sum/(size*size);
else threshold = 0.0;
int j, k, l;
for (j=0; j<size-1; j++) {
for (k=j+1; k<size; k++) {
double sine, rho, cosin, heig, tang, beta;
double smll = Math.Abs(ss[j,k]);
if(ite> 5 &&
smll<epsPrec*Math.Abs(diagonal_[j]) &&
smll<epsPrec*Math.Abs(diagonal_[k])) {
ss[j,k] = 0;
} else if (Math.Abs(ss[j,k])>threshold) {
heig = diagonal_[k]-diagonal_[j];
if (smll<epsPrec*Math.Abs(heig)) {
tang = ss[j,k]/heig;
} else {
beta = 0.5*heig/ss[j,k];
tang = 1.0/(Math.Abs(beta)+
Math.Sqrt(1+beta*beta));
if (beta<0)
tang = -tang;
}
cosin = 1/Math.Sqrt(1+tang*tang);
sine = tang*cosin;
rho = sine/(1+cosin);
heig = tang*ss[j,k];
tmpAccumulate[j] -= heig;
tmpAccumulate[k] += heig;
diagonal_[j] -= heig;
diagonal_[k] += heig;
ss[j,k] = 0.0;
for (l=0; l+1<=j; l++)
jacobiRotate_(ss, rho, sine, l, j, l, k);
for (l=j+1; l<=k-1; l++)
jacobiRotate_(ss, rho, sine, j, l, l, k);
for (l=k+1; l<size; l++)
jacobiRotate_(ss, rho, sine, j, l, k, l);
for (l=0; l<size; l++)
jacobiRotate_(eigenVectors_,
rho, sine, l, j, l, k);
}
}
}
for (k=0; k<size; k++) {
tmpDiag[k] += tmpAccumulate[k];
diagonal_[k] = tmpDiag[k];
tmpAccumulate[k] = 0.0;
}
}
} while (++ite<=maxIterations && keeplooping);
if(!(ite<=maxIterations))
throw new ApplicationException("Too many iterations (" + maxIterations + ") reached");
// sort (eigenvalues, eigenvectors)
List<KeyValuePair<double, Vector>> temp = new InitializedList<KeyValuePair<double, Vector>>(size);
int row, col;
for (col=0; col<size; col++) {
Vector eigenVector = new Vector(size);
eigenVectors_.column(col).ForEach((ii, xx) => eigenVector[ii] = xx);
temp[col] = new KeyValuePair<double,Vector>(diagonal_[col], eigenVector);
}
// sort descending: std::greater
temp.Sort((x, y) => y.Key.CompareTo(x.Key));
double maxEv = temp[0].Key;
for (col=0; col<size; col++) {
// check for round-off errors
diagonal_[col] = (Math.Abs(temp[col].Key/maxEv)<1e-16 ? 0.0 : temp[col].Key);
double sign = 1.0;
if (temp[col].Value[0]<0.0)
sign = -1.0;
for (row=0; row<size; row++) {
eigenVectors_[row,col] = sign * temp[col].Value[row];
}
}
}