当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.Evd方法代码示例

本文整理汇总了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;
 }
开发者ID:szalaigj,项目名称:TilingApplication,代码行数:46,代码来源:ThetaMatrixFormation.cs

示例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);
 }
开发者ID:szalaigj,项目名称:TilingApplication,代码行数:21,代码来源:ThetaMatrixFormation.cs

示例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;
 }
开发者ID:szalaigj,项目名称:TilingApplication,代码行数:20,代码来源:NormCutUtils.cs

示例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);
 }
开发者ID:szalaigj,项目名称:TilingApplication,代码行数:19,代码来源:ThetaMatrixFormation.cs

示例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;
 }
开发者ID:szalaigj,项目名称:TilingApplication,代码行数:62,代码来源:PartitioningBasedOnSpectrumAlgo.cs


注:本文中的Matrix.Evd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。