{"id":17920591,"url":"https://github.com/nem035/page-rank-fun","last_synced_at":"2025-04-03T08:32:33.986Z","repository":{"id":92966022,"uuid":"77321022","full_name":"nem035/page-rank-fun","owner":"nem035","description":"Simple Demonstration of the PageRank Algorithm","archived":false,"fork":false,"pushed_at":"2016-12-27T08:12:05.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"gh-pages","last_synced_at":"2025-02-08T22:12:47.186Z","etag":null,"topics":["algorithm","html","javascript","pagerank-algorithm"],"latest_commit_sha":null,"homepage":"https://nem035.github.io/page-rank-fun/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nem035.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-25T10:29:10.000Z","updated_at":"2021-04-04T17:28:02.000Z","dependencies_parsed_at":"2023-04-13T20:08:16.907Z","dependency_job_id":null,"html_url":"https://github.com/nem035/page-rank-fun","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fpage-rank-fun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fpage-rank-fun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fpage-rank-fun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fpage-rank-fun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nem035","download_url":"https://codeload.github.com/nem035/page-rank-fun/tar.gz/refs/heads/gh-pages","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246966005,"owners_count":20861979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","html","javascript","pagerank-algorithm"],"created_at":"2024-10-28T20:26:15.778Z","updated_at":"2025-04-03T08:32:33.963Z","avatar_url":"https://github.com/nem035.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PageRank in JavaScript\n\nPageRank essentially works by counting the number of links to a page to obtain a rough estimate of website's importance.\nThe base assumption in PageRank is that more important websites are likely to receive more links from other websites.\n\n[Demo Page](https://nem035.github.io/page-rank-fun/)\n\n## Algorithm\n\nWe have 4 pages A.html, B.html, C.html, D.html\n\nPageRank is initialized to the same value for all pages, with a probability distribution between 0 and 1. Hence the initial value for each page in this example is 0.25.\n\n```js\nconst pages = ['A', 'B', 'C', 'D'];\nconst initialRanks = pages.map(() =\u003e 1 / pages.length); // [0.25, 0.25, 0.25, 0.25]\n```\n\nThe PageRank of a given page gets equally distributed through its outbound links on each iteration of the algorithm.\n\nIf the only links we had were `A`, `B`, and `C` to `D`, each link would transfer 0.25 PageRank to `D` upon the next iteration, for a total of 0.75.\n\n`PR('D') = PR('A') + PR('B') + PR('C')`\n\nSuppose instead that page `B` had a link to pages `C` and `A`, page `C` had a link to page `A`, and page `D` had links to all three pages.\n\n```html\n\u003c!-- B.html --\u003e\n\u003ca href=\"A.html\"\u003eA\u003c/a\u003e\n\u003ca href=\"C.html\"\u003eC\u003c/a\u003e\n\n\u003c!-- C.html --\u003e\n\u003ca href=\"A.html\"\u003eA\u003c/a\u003e\n\n\u003c!-- D.html --\u003e\n\u003ca href=\"A.html\"\u003eA\u003c/a\u003e\n\u003ca href=\"B.html\"\u003eB\u003c/a\u003e\n\u003ca href=\"C.html\"\u003eC\u003c/a\u003e\n```\n\nIn this example, upon the first iteration, page `B` would transfer half of its existing rank, or 0.125, to page `A` and the other half, to page `C`. Page `C` would transfer all of its existing rank, 0.25, to the only page it links to, `A`. Since `D` had three outbound links, it would transfer one third of its rank, or approximately 0.083, to `A`.\n\nAt the end of this iteration, page `A` will have a PageRank of approximately 0.458.\n\n```js\npageRankA = PR('B') / 2 + PR('C') + PR('D') / 3` // (0.25 / 2) + (0.25 / 1) + (0.25 / 3) ~= 0.458\n```\n\nIn other words, the PageRank conferred by an outbound link is equal to the document's own PageRank score divided by the number of outbound links `L`.\n\n```js\npageRankA = PR('B') / L('B') +\n            PR('C') / L('C') +\n            PR('D') / L('D')`\n```\n\nIn the general case, the PageRank value for any page `X` can be expressed as:\n\n```js\npageRankX = sum(\n  pagesLinkingTo('X').\n    map(page =\u003e\n      getPageRank(page) / countOutgoingLinks(page)\n    )\n)\n```\n\nIt is important to note that the original algorithm ignores repeated links as well as self-links.\n\n### Damping Factor\n\n- Original Paper\n\n\u003e The parameter d is a damping factor which can be set between 0 and 1. We usually set d to 0.85.\n\n- Wikipedia\n\n\u003e The PageRank theory holds that an imaginary random surfer who is randomly clicking on links will eventually stop clicking. The probability, at any step, that the person will continue is a damping factor `d`. Various studies have tested different damping factors, but it is generally assumed that the damping factor will be set around 0.85.\n\n```js\npageRankX = (1 - d) + d * sum(\n  pagesLinkingTo('X').\n    map(page =\u003e\n      PR(page) / L(page)\n    )\n);\n```\n\nHere's the full algorithm:\n\n```js\nconst getRanksOverNumberOfBackLinks = (url) =\u003e {\n  return getBackLinkedPages(url).map(backLinkPage =\u003e {\n    return backLinkPage.rank / countOutLinks(backLinkPage.url)\n  });\n};\n\nconst normalizedSum = (ranksOverNumberOfBackLinks) =\u003e {\n  return (1 - d) + d * sum(ranksOverNumberOfBackLinks);\n};\n\nconst pageRank = normalizedSum(\n  getRanksOverNumberOfBackLinks(\n    url\n  )\n);\n```\n\n## Sources\n\n- [Wikipedia](https://en.wikipedia.org/wiki/PageRank)\n- [Princeton's Ian Rogers](http://www.cs.princeton.edu/~chazelle/courses/BIB/pagerank.htm)\n\n## Libraries\n\n- [dragula](https://github.com/bevacqua/dragula)\n- [highlight](https://github.com/isagalaev/highlight.js)\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnem035%2Fpage-rank-fun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnem035%2Fpage-rank-fun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnem035%2Fpage-rank-fun/lists"}