本文整理汇总了C#中Matrix.Evd方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Evd方法的具体用法?C# Matrix.Evd怎么用?C# Matrix.Evd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Evd方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: determineCoordsBasedOnEigVecs
public Matrix<double> determineCoordsBasedOnEigVecs(Matrix<double> theta, int depth,
out double[] normedFilteredEigenValuesOfTheta)
{
int nodeNO = theta.RowCount;
Evd<double> evdOfTheta = theta.Evd();
List<double> eigenValuesOfTheta = evdOfTheta.EigenValues.
Select(eigComplexVal => eigComplexVal.Real).ToList();
eigenValuesOfTheta.Sort();
Matrix<double> objCoords = Matrix<double>.Build.DenseDiagonal(nodeNO, depth, 0.0);
int cntOfDepth = 0;
// TODO: remove following comment lines:
//for (int idxOfEigVal = evdOfTheta.EigenValues.Count - 1; (idxOfEigVal >= 0) && (cntOfDepth != depth);
// idxOfEigVal--)
//{
// for (int nThEigVal = 2; nThEigVal < depth + 2; nThEigVal++)
// {
// double currentEigVal = eigenValuesOfTheta[nodeNO - nThEigVal];
// if (Math.Abs(evdOfTheta.EigenValues[idxOfEigVal].Real - currentEigVal) < 0.0000001)
// {
// Vector<double> currentEigVec = evdOfTheta.EigenVectors.Column(idxOfEigVal);
// for (int idxOfObj = 0; idxOfObj < nodeNO; idxOfObj++)
// {
// objCoords[idxOfObj, nThEigVal - 2] = currentEigVec[idxOfObj];
// }
// cntOfDepth++;
// break;
// }
// }
//}
// Based on documentation (see: http://numerics.mathdotnet.com/api/MathNet.Numerics.LinearAlgebra.Factorization/Evd%601.htm#EigenValues)
// The property EigenValues of Evd stores eigenvalues of matrix in ascending order
for (int idx = evdOfTheta.EigenValues.Count - 1; (idx >= 0) && (cntOfDepth < depth); idx--)
{
Vector<double> currentEigVec = evdOfTheta.EigenVectors.Column(idx);
for (int idxOfObj = 0; idxOfObj < nodeNO; idxOfObj++)
{
objCoords[idxOfObj, cntOfDepth] = currentEigVec[idxOfObj];
}
cntOfDepth++;
}
eigenValuesOfTheta.Reverse();
List<double> filteredEigenValuesOfTheta = eigenValuesOfTheta.GetRange(0, depth);
double norm = filteredEigenValuesOfTheta.Sum();
normedFilteredEigenValuesOfTheta = filteredEigenValuesOfTheta.Select(x => x / norm).ToArray();
return objCoords;
}
示例2: determineNthLargestEigVec
public Vector<double> determineNthLargestEigVec(Matrix<double> theta, int index)
{
Evd<double> evdOfTheta = theta.Evd();
// Based on documentation (see: http://numerics.mathdotnet.com/api/MathNet.Numerics.LinearAlgebra.Factorization/Evd%601.htm#EigenValues)
// The property EigenValues of Evd stores eigenvalues of matrix in ascending order
int nthLargestIdx = theta.RowCount - index;
// TODO: remove following comment lines:
//List<double> eigenValuesOfTheta = evdOfTheta.EigenValues.
// Select(eigComplexVal => eigComplexVal.Real).ToList();
//eigenValuesOfTheta.Sort();
//double nthLargestEigVal = eigenValuesOfTheta[theta.RowCount - index];
//int nthLargestIdx = 0;
//for (int idx = 0; idx < evdOfTheta.EigenValues.Count; idx++)
//{
// if (Math.Abs(evdOfTheta.EigenValues[idx].Real - nthLargestEigVal) < 0.0000001)
// {
// nthLargestIdx = idx;
// }
//}
return evdOfTheta.EigenVectors.Column(nthLargestIdx);
}
示例3: determineSignTraces
private string[] determineSignTraces(int nodeNO, Matrix<double> theta)
{
string[] signTraces = new string[nodeNO];
Evd<double> evdOfTheta = theta.Evd();
for (int idx = 0; idx < nodeNO; idx++)
{
// The following vector should be reversed because the original ordering of eigen values is ascending:
Vector<double> currentRow = evdOfTheta.EigenVectors.Row(idx);
// the first eigen vector is unnecessary for the following so ...Take(currentRow.Count - 1)...
List<double> currentRowList = currentRow.Take(currentRow.Count - 1).Reverse()
.Take(nodeNO * nodeNO - 1).ToList();
string signTrace = "";
foreach (var item in currentRowList)
{
signTrace = determineSign(signTrace, item);
}
signTraces[idx] = signTrace;
}
return signTraces;
}
示例4: determineSecondLargestEigVec
public Vector<double> determineSecondLargestEigVec(Matrix<double> theta)
{
Evd<double> evdOfTheta = theta.Evd();
return determineNthLargestEigVec(theta, 2);
// TODO: remove following comment lines:
//List<double> eigenValuesOfTheta = evdOfTheta.EigenValues.
// Select(eigComplexVal => eigComplexVal.Real).ToList();
//eigenValuesOfTheta.Sort();
//double secondLargestEigVal = eigenValuesOfTheta[theta.RowCount - 2];
//int secondLargestIdx = 0;
//for (int idx = 0; idx < evdOfTheta.EigenValues.Count; idx++)
//{
// if (Math.Abs(evdOfTheta.EigenValues[idx].Real - secondLargestEigVal) < 0.0000001)
// {
// secondLargestIdx = idx;
// }
//}
//return evdOfTheta.EigenVectors.Column(secondLargestIdx);
}
示例5: apply
public Dictionary<string, List<int>> apply(int K, int vertexNO, Matrix<double> theta)
{
Dictionary<string, List<int>> dict = new Dictionary<string, List<int>>();
Evd<double> evdOfTheta = theta.Evd();
int minNecessaryLevel = (int)Math.Log(K, 2.0);
for (int levelIdx = minNecessaryLevel; (levelIdx < vertexNO * vertexNO) && (dict.Keys.Count < K); levelIdx++)
{
dict.Clear();
for (int idx = 0; idx < vertexNO; idx++)
{
// The following vector should be reversed because the original ordering of eigen values is ascending:
Vector<double> currentRow = evdOfTheta.EigenVectors.Row(idx);
// the first eigen vector is unnecessary for the following so ...Take(currentRow.Count - 1)...
List<double> currentRowList = currentRow.Take(currentRow.Count - 1).Reverse().Take(levelIdx).ToList();
string str = "";
foreach (var item in currentRowList)
{
str = determineSign(str, item);
}
List<int> currentElements;
if (dict.TryGetValue(str, out currentElements))
{
currentElements.Add(idx);
dict[str] = currentElements;
}
else
{
dict[str] = new List<int>(new int[] { idx });
}
}
}
//for (int idx = 0; idx < nodeNO; idx++)
//{
// // The following vector should be reversed because the original ordering of eigen values is ascending:
// Vector<double> currentRow = evdOfTheta.EigenVectors.Row(idx);
// // the first eigen vector is unnecessary for the following so ...Take(currentRow.Count - 1)...
// List<double> currentRowList = currentRow.Take(currentRow.Count - 1).Reverse().Take(K - 1).ToList();
// string str = "";
// foreach (var item in currentRowList)
// {
// if (item > 0)
// {
// str += "+";
// }
// else
// {
// str += "-";
// }
// }
// List<int> currentElements;
// if (dict.TryGetValue(str, out currentElements))
// {
// currentElements.Add(idx);
// dict[str] = currentElements;
// }
// else
// {
// dict[str] = new List<int>(new int[] { idx });
// }
//}
return dict;
}