public void Odecti(Vektor x) { for (int i = 0; i < pole.Length; i++) { pole[i] -= x.pole[i]; } }
public Vektor CalculatePageRank(double[,] A) { double[] pom = new double[A.GetLength(0)]; for (int i = 0; i < pom.Length; i++) { pom[i] = 1; } Vektor x = new Vektor(pom); Vektor xprev = x; Vektor y; ////Console.WriteLine(x.pole.Length); //Console.WriteLine(A.GetLength(0)); //Console.Write("{0} : (", 0); x.Vypis(); Console.Write(") -"); Console.WriteLine(); for (int i = 0; i < 20; i++) { y = Pocitej.NasobeniMaticeVektorem(A, x); x = y.Clone(); Pocitej.JednotkovaVelikost(x); //Console.Write("{0} : (", i + 1); //x.Vypis(); //Console.Write(") {0}", String.Format("{0:0.###}", Pocitej.SkalarniSoucin(xprev, y))); //Console.WriteLine(); xprev = x; } return(x); }
public void Pricti(Vektor x) { for (int i = 0; i < pole.Length; i++) { pole[i] += x.pole[i]; } }
public static Vektor OdectiVektory(Vektor x, Vektor y) { for (int i = 0; i < x.pole.Length; i++) { x.pole[i] -= y.pole[i]; } return(x); }
public static double SkalarniSoucin(Vektor x, Vektor y) { double suma = 0; for (int i = 0; i < x.pole.Length; i++) { suma += x.pole[i] * y.pole[i]; } return(suma); }
public void CalculatePercentagesRanked(string lorem) { double[,] matrix = new double[chars.Count, chars.Count]; List <int> pos = new List <int>(); foreach (KeyValuePair <int, int> pair in chars) { pos.Add(pair.Key); } for (int i = 1; i < lorem.Length; i++) { matrix[pos.IndexOf(lorem[i]), pos.IndexOf(lorem[i - 1])]++; } for (int x = 0; x < matrix.GetLength(1); x++) { double sum = 0; for (int y = 0; y < matrix.GetLength(0); y++) { sum += matrix[x, y]; } if (sum != 0) { for (int y = 0; y < matrix.GetLength(0); y++) { matrix[x, y] /= sum; } } } Vektor ranked = CalculatePageRank(matrix); for (int i = 0; i < ranked.pole.Length; i++) { chars[pos[i]] = (int)(ranked.pole[i] * 1000); } basicSum = 0; // lorem.Length; foreach (KeyValuePair <int, int> pair in chars.OrderByDescending(pair => pair.Value)) { basicSum += pair.Value; basicList.Add(new RandValue(pair.Key, pair.Value)); //Console.WriteLine("{0}: {1}", (char)pair.Key, pair.Value); } //foreach (KeyValuePair<int, int> pair in chars.OrderByDescending(pair => pair.Value)) // Console.WriteLine("{0}: {1} = {2}%", (char)pair.Key, pair.Value, (double)pair.Value / lorem.Length * 100); }
public static void JednotkovaVelikost(Vektor x) { double velikost = x.pole.Max();//.AbsolutValue(); if (velikost == 0) { return; } for (int i = 0; i < x.pole.Length; i++) { x.pole[i] = (x.pole[i] / velikost); } }
public static Vektor NasobeniMaticeVektorem(double[,] A, Vektor x) { Vektor y = new Vektor(new double[x.pole.Length]); for (int i = 0; i < x.pole.Length; i++) { for (int j = 0; j < x.pole.Length; j++) { y.pole[i] += (A[j, i] * x.pole[j]); } } return(y); }
public Vektor Clone() { Vektor vratit = new Vektor((double[])this.pole.Clone()); return vratit; }
public static double SkalarniSoucin(Vektor x, Vektor y) { double suma = 0; for (int i = 0; i < x.pole.Length; i++) { suma += x.pole[i] * y.pole[i]; } return suma; }
public static Vektor OdectiVektory(Vektor x, Vektor y) { for (int i = 0; i < x.pole.Length; i++) x.pole[i] -= y.pole[i]; return x; }
public static Vektor NasobeniMaticeVektorem(double[,] A, Vektor x) { Vektor y = new Vektor(new double[x.pole.Length]); for (int i = 0; i < x.pole.Length; i++) { for (int j = 0; j < x.pole.Length; j++) { y.pole[i] += (A[j, i] * x.pole[j]); } } return y; }
public static void JednotkovaVelikost(Vektor x) { double velikost = x.pole.Max();//.AbsolutValue(); if (velikost == 0) return; for (int i = 0; i < x.pole.Length; i++) { x.pole[i] = (x.pole[i] / velikost); } }
public Vektor CalculatePageRank(double[,] A) { double[] pom = new double[A.GetLength(0)]; for (int i = 0; i < pom.Length; i++) pom[i] = 1; Vektor x = new Vektor(pom); Vektor xprev = x; Vektor y; ////Console.WriteLine(x.pole.Length); //Console.WriteLine(A.GetLength(0)); //Console.Write("{0} : (", 0); x.Vypis(); Console.Write(") -"); Console.WriteLine(); for (int i = 0; i < 20; i++) { y = Pocitej.NasobeniMaticeVektorem(A, x); x = y.Clone(); Pocitej.JednotkovaVelikost(x); //Console.Write("{0} : (", i + 1); //x.Vypis(); //Console.Write(") {0}", String.Format("{0:0.###}", Pocitej.SkalarniSoucin(xprev, y))); //Console.WriteLine(); xprev = x; } return x; }
public Vektor Clone() { Vektor vratit = new Vektor((double[])this.pole.Clone()); return(vratit); }