Advertisement
Hamikadze

Untitled

Dec 6th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. private static void ProcedureGrammaShmita(ref Vector<double> lambda, ref Matrix<double> d)
  2.         {
  3.             List<Vector<double>> a = new List<Vector<double>>();
  4.             List<Vector<double>> b = new List<Vector<double>>();
  5.  
  6.             for (int i = 0; i < n + 1; i++)
  7.             {
  8.                 if (lambda[i].Equals(0))
  9.                 {
  10.                     a.Add(d.Row(i));
  11.                 }
  12.                 else
  13.                 {
  14.                     Vector<double> temp = Vector<double>.Build.Dense(n + 1, 0.0);
  15.  
  16.                     for (int j = i; j < n + 1; j++)
  17.                     {
  18.                         temp = temp.Add(d.Row(j).Multiply(lambda[j]));
  19.                     }
  20.  
  21.                     a.Add(temp);
  22.                 }
  23.             }
  24.  
  25.             for (int i = 0; i < n + 1; i++)
  26.             {
  27.                 if (i != 0)
  28.                 {
  29.                     Vector<double> temp = Vector<double>.Build.Sparse(n + 1);
  30.  
  31.                     for (int j = 0; j < i; j++)
  32.                     {
  33.                         temp = temp.Add(d.Row(j).Multiply(a[i].ConjugateDotProduct(d.Row(j))));
  34.                     }
  35.  
  36.                     temp = a[i].Subtract(temp);
  37.                     b.Add(temp);
  38.                 }
  39.                 else
  40.                 {
  41.                     b.Add(a[i]);
  42.                 }
  43.  
  44.                 d.SetRow(i,b[i].Divide(b[i].L2Norm()));
  45.             }
  46.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement