cs-page-rank 1.0.1

Page Rank

Install-Package cs-page-rank -Version 1.0.1
dotnet add package cs-page-rank --version 1.0.1
<PackageReference Include="cs-page-rank" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add cs-page-rank --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

cs-page-rank

Iterative PageRank implemented in .NET 4.6.1

Install

Install-Package cs-page-rank

Usage

The sample code below shows how to use the page rank to perform link analysis:

using System;
using System.Collections.Generic;

namespace PageRank
{
    class Program
    {
        static void Main(string[] args)
        {
            PageRankByIterativeMethod();
            PageRankByMatrixIterativeMethod();
        }

        private static void PageRankByIterativeMethod()
        {
            Random random = new Random();
            int pageCount = 1000;
            IterativePageRank pr = new IterativePageRank(pageCount);

            List<int> pages = new List<int>();
            for(int pageId = 0; pageId < pageCount; ++pageId)
            {
                pages.Add(pageId);
            }
            for(int fromPageId =0; fromPageId < pageCount; ++fromPageId)
            {
                int outLinkCount = random.Next(pageCount / 50);
                Shuffle(pages, random);
                for(int i=0; i < outLinkCount; ++i)
                {
                    int toPageId = pages[i];
                    pr.AddLink(fromPageId, toPageId);
                }
            }

            double tolerance = 0.00001;
            float[] ranks = pr.RankPages(tolerance);

            for(int pageId = 0; pageId < 50; ++pageId)
            {
                Console.WriteLine("Page: {0}, Score: {1}", pageId, ranks[pageId]);
            }
        }

        private static void PageRankByMatrixIterativeMethod()
        {
            Random random = new Random();
            int pageCount = 1000;
            MatrixIterativePageRank pr = new MatrixIterativePageRank(pageCount);

            List<int> pages = new List<int>();
            for (int pageId = 0; pageId < pageCount; ++pageId)
            {
                pages.Add(pageId);
            }
            for (int fromPageId = 0; fromPageId < pageCount; ++fromPageId)
            {
                int outLinkCount = random.Next(pageCount / 50);
                Shuffle(pages, random);
                for (int i = 0; i < outLinkCount; ++i)
                {
                    int toPageId = pages[i];
                    pr.AddLink(fromPageId, toPageId);
                }
            }

            double tolerance = 0.00001;
            double[] ranks = pr.RankPages(tolerance);

            for (int pageId = 0; pageId < 50; ++pageId)
            {
                Console.WriteLine("Page: {0}, Score: {1}", pageId, ranks[pageId]);
            }
        }

        private static void Shuffle<T>(List<T> a, Random random)
        {
            int i = 0;
            while(i < a.Count)
            {
                int j = random.Next(i + 1);
                Swap(a, i, j);
                i++;
            }
        }

        private static void Swap<T>(List<T> a, int i, int j)
        {
            T temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    }
}

cs-page-rank

Iterative PageRank implemented in .NET 4.6.1

Install

Install-Package cs-page-rank

Usage

The sample code below shows how to use the page rank to perform link analysis:

using System;
using System.Collections.Generic;

namespace PageRank
{
    class Program
    {
        static void Main(string[] args)
        {
            PageRankByIterativeMethod();
            PageRankByMatrixIterativeMethod();
        }

        private static void PageRankByIterativeMethod()
        {
            Random random = new Random();
            int pageCount = 1000;
            IterativePageRank pr = new IterativePageRank(pageCount);

            List<int> pages = new List<int>();
            for(int pageId = 0; pageId < pageCount; ++pageId)
            {
                pages.Add(pageId);
            }
            for(int fromPageId =0; fromPageId < pageCount; ++fromPageId)
            {
                int outLinkCount = random.Next(pageCount / 50);
                Shuffle(pages, random);
                for(int i=0; i < outLinkCount; ++i)
                {
                    int toPageId = pages[i];
                    pr.AddLink(fromPageId, toPageId);
                }
            }

            double tolerance = 0.00001;
            float[] ranks = pr.RankPages(tolerance);

            for(int pageId = 0; pageId < 50; ++pageId)
            {
                Console.WriteLine("Page: {0}, Score: {1}", pageId, ranks[pageId]);
            }
        }

        private static void PageRankByMatrixIterativeMethod()
        {
            Random random = new Random();
            int pageCount = 1000;
            MatrixIterativePageRank pr = new MatrixIterativePageRank(pageCount);

            List<int> pages = new List<int>();
            for (int pageId = 0; pageId < pageCount; ++pageId)
            {
                pages.Add(pageId);
            }
            for (int fromPageId = 0; fromPageId < pageCount; ++fromPageId)
            {
                int outLinkCount = random.Next(pageCount / 50);
                Shuffle(pages, random);
                for (int i = 0; i < outLinkCount; ++i)
                {
                    int toPageId = pages[i];
                    pr.AddLink(fromPageId, toPageId);
                }
            }

            double tolerance = 0.00001;
            double[] ranks = pr.RankPages(tolerance);

            for (int pageId = 0; pageId < 50; ++pageId)
            {
                Console.WriteLine("Page: {0}, Score: {1}", pageId, ranks[pageId]);
            }
        }

        private static void Shuffle<T>(List<T> a, Random random)
        {
            int i = 0;
            while(i < a.Count)
            {
                int j = random.Next(i + 1);
                Swap(a, i, j);
                i++;
            }
        }

        private static void Swap<T>(List<T> a, int i, int j)
        {
            T temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    }
}

Release Notes

Page Rank in .NET 4.6.1

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 346 5/1/2018