Exemple #1
0
        private double Compute()
        {
            SortedSet <Weight>       links;
            Dictionary <int, double> dlink = new Dictionary <int, double>();
            double dscore = 0.0d;

            double[] tempscore = new double[score.Length];
            double   sum;

            // initialize temp score vector
            for (int i = 0; i < tempscore.Length; i++)
            {
                tempscore[i] = 0.0d;
            }

            for (int i = 0; i < score.Length; i++)
            {
                // get outlinks
                links = graph.GetOutlinks(i);

                if (links == null)
                {
                    double s = (double)(score[i] / (double)(score.Length - 1));
                    dlink.Add(i, s);
                    dscore += s;
                    continue;
                }
                else
                {
                    sum = 0.0d;
                    // get sum of out-link weights
                    foreach (Weight j in links)
                    {
                        sum += j.w;
                    }
                    // give score
                    foreach (Weight j in links)
                    {
                        tempscore[j.id] += (double)(score[i] * (j.w / sum));
                    }
                }
            }

            double stderr = 0, tmpscore;

            for (int i = 0; i < score.Length; i++)
            {
                if (dlink.ContainsKey(i))
                {
                    tmpscore = ((tempscore[i] + dscore - dlink[i]) * D) + (restart[i] * (1.0d - D));
                }
                else
                {
                    tmpscore = ((tempscore[i] + dscore) * D) + (restart[i] * (1.0d - D));
                }
                stderr  += Math.Pow(score[i] - tmpscore, 2);
                score[i] = tmpscore;
            }
            return(stderr);
        }
Exemple #2
0
        private double Compute()
        {
            double[] bal       = graph.balance;
            int      user_size = graph.user_size;

            double[] ptempscore = new double[user_size];
            double[] ntempscore = new double[user_size];

            for (int i = 0; i < user_size; i++)
            {
                SortedSet <Weight> links = graph.GetOutlinks(i);
                if (links == null)
                {
                    continue;
                }

                int    sum = links.Count();
                double wgt = (double)1 / (double)sum;


                double b0 = wgt * bal[0];
                double b1 = wgt * bal[1];
                double b2 = wgt * bal[2];
                double b3 = wgt * bal[3];


                double b0_conjugate = wgt - b0;
                double b1_conjugate = wgt - b1;
                double b2_conjugate = wgt - b2;
                double b3_conjugate = wgt - b3;

                foreach (Weight j in links)
                {
                    if (j.id < user_size)
                    {
                        if (j.w > 0)
                        {
                            ptempscore[j.id] += pscore[i] * b0 + nscore[i] * b2_conjugate;
                            ntempscore[j.id] += pscore[i] * b0_conjugate + nscore[i] * b2;
                        }
                        else
                        {
                            ptempscore[j.id] += pscore[i] * b1_conjugate + nscore[i] * b3;
                            ntempscore[j.id] += pscore[i] * b1 + nscore[i] * b3_conjugate;
                        }
                    }
                }
            }

            for (int i = 0; i < user_size; i++)
            {
                pscore[i] = ptempscore[i] * D;
                nscore[i] = ntempscore[i] * D;
            }
            pscore[init_node] += 1.0d - D;

            double stderr = 0, tmpscore;

            for (int i = 0; i < score.Length; i++)
            {
                tmpscore = pscore[i] - nscore[i];
                stderr  += Math.Pow(score[i] - tmpscore, 2);
                score[i] = tmpscore;
            }
            return(stderr);
        }
Exemple #3
0
        private double Compute()
        {
            HashSet <Weight>         links;
            Dictionary <int, double> pdlink = new Dictionary <int, double>(); // 뎅글링링크 관련 데이터 저장
            Dictionary <int, double> ndlink = new Dictionary <int, double>();
            double pdscore = 0.0d;                                            // 뎅글링링크에 의해 파급된 스코어 계
            double ndscore = 0.0d;

            double[] ptempscore = new double[score.Length];
            double[] ntempscore = new double[score.Length];
            double   sum;

            // initialize temp score vector
            for (int i = 0; i < ptempscore.Length; i++)
            {
                ptempscore[i] = 0.0d;
                ntempscore[i] = 0.0d;
            }

            for (int i = 0; i < score.Length; i++)
            {
                // get outlinks
                links = graph.GetOutlinks(i);

                // 아웃링크 없는 경우(뎅글링링크)
                if (links == null)
                {
                    double s = (double)(pscore[i] / (double)(pscore.Length - 1)); // 네트워크 전반에 파급시킬 값
                    double n = (double)(nscore[i] / (double)(nscore.Length - 1));
                    pdlink.Add(i, s);                                             // dlink에 자신이 네트워크 전반에 파급시킨 값을 저장
                    ndlink.Add(i, n);
                    pdscore += s;
                    ndscore += n;
                    continue;
                }
                // 아웃링크를 따라 파급
                else
                {
                    sum = 0.0d;
                    // get sum of out-link weights
                    foreach (Weight j in links)
                    {
                        if (j.w > 0)
                        {
                            sum += j.w;
                        }
                        else
                        {
                            sum -= j.w;
                        }
                    }
                    // give score
                    foreach (Weight j in links)
                    {
                        if (j.w > 0)
                        {
                            ptempscore[j.id] += (double)(pscore[i] * (j.w / sum));
                            ptempscore[j.id] += (1 - gamma) * (double)(nscore[i] * (j.w / sum));
                            ntempscore[j.id] += (gamma) * (double)(nscore[i] * (j.w / sum));
                        }
                        else
                        {
                            ptempscore[j.id] += (beta) * (double)(nscore[i] * (-j.w / sum));
                            ntempscore[j.id] += (double)(pscore[i] * (-j.w / sum));
                            ntempscore[j.id] += (1 - beta) * (double)(nscore[i] * (-j.w / sum));
                        }
                    }
                }
            }

            // 계산결과 적용
            double stderr = 0, ptmpscore, ntmpscore, tmpscore;

            for (int i = 0; i < score.Length; i++)
            {
                if (pdlink.ContainsKey(i))
                {
                    ptmpscore = ((ptempscore[i] + pdscore - pdlink[i]) * D) + (restart[i] * (1.0d - D));
                    ntmpscore = ((ntempscore[i] + ndscore - ndlink[i]) * D);
                }
                else
                {
                    ptmpscore = ((ptempscore[i] + pdscore) * D) + (restart[i] * (1.0d - D));
                    ntmpscore = ((ntempscore[i] + ndscore) * D);
                }
                tmpscore  = ptmpscore - ntmpscore;
                stderr   += Math.Pow(score[i] - tmpscore, 2);
                pscore[i] = ptmpscore;
                nscore[i] = ntmpscore;
                score[i]  = tmpscore;
            }
            return(stderr);
        }