Advertisement
taksi

Prog2 - Pagerank

Sep 25th, 2012
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package pagerank;
  2.  
  3. /**
  4.  *
  5.  * @author hallgato
  6.  */
  7. public class PageRank {
  8.     /*
  9.      * linkek
  10.      */
  11.  
  12.     double[][] L = {
  13.         {0.0, 0.0, 1.0 / 3.0, 0.0},
  14.         {1.0, 1.0 / 2.0, 1.0 / 3.0, 1.0},
  15.         {0.0, 1.0 / 2.0, 0.0, 0.0},
  16.         {0.0, 0.0, 1.0 / 3.0, 0.0}
  17.     };
  18.     /*
  19.      * PageRank
  20.      */
  21.     double pr[] = {0.0, 0.0, 0.0, 0.0};
  22.     double prv[] = {1.0 / 4.0, 1.0 / 4.0, 1.0 / 4.0, 1.0 / 4.0};
  23.  
  24.     public void kiir() {
  25.         int i, j;
  26.         for (i = 0; i < this.pr.length; i++)
  27.         {
  28.           System.out.println(this.pr[i]);
  29.         }
  30.     }
  31.  
  32.     public double tavolsag(double[] pr, double prv[])
  33.     {
  34.         int i;
  35.         double osszeg = 0;
  36.         for (i = 0; i< this.pr.length; i++)
  37.         {
  38.             osszeg  += (this.prv[i] - this.pr[i]) * (this.prv[i] - this.pr[i]);
  39.         }
  40.        
  41.         return Math.sqrt(osszeg);
  42.     }
  43.  
  44.     public void szamol(double[][]L, double[] pr, double prv[])
  45.     {
  46.         int i;
  47.         int j;
  48.        
  49.         for (;;)
  50.         {
  51.             for (i = 0; i < 4; i++)
  52.             {
  53.                 this.pr[i] = 0.0;
  54.                 for (j = 0; j < 4; j++)
  55.                 {
  56.                     this.pr[i] += (this.L[i][j] * this.prv[j]);
  57.                 }
  58.             }
  59.            
  60.             if (this.tavolsag (this.pr, this.prv) < 0.00000001) { break; }
  61.                
  62.             for (i=0; i<4; i++)
  63.             {
  64.                 this.prv[i] = this.pr[i];
  65.             }
  66.         }
  67.     }
  68.  
  69.     /**
  70.      * @param args the command line arguments
  71.      */
  72.     public static void main(String[] args)
  73.     {
  74.         PageRank prank = new PageRank();
  75.         prank.szamol(prank.L, prank.pr, prank.prv);
  76.         prank.kiir();
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement