Module: PageRank
- Defined in:
- lib/page_rank.rb,
lib/page_rank/base.rb,
lib/page_rank/dense.rb,
lib/page_rank/sparse.rb,
lib/page_rank/sparse_native.rb
Overview
A module for supporting Ruby implementations of PageRank. Rather than rely on one single implementation, this module allows for multiple implementations that may be beneficial in different scenarios.
= Example
PageRank.calculate(strategy: :dense, damping: 0.8, max_iterations: 100) do add('nodeA', 'nodeC', weight: 4.3) add('nodeA', 'nodeE', weight: 2.1) add('nodeB', 'nodeC', weight: 3.6) add('nodeE', 'nodeD', weight: 1.9) add('nodeA', 'nodeC', weight: 5.3) end
Defined Under Namespace
Classes: Base, Dense, Sparse, SparseNative
Class Method Summary collapse
-
.calculate(**options, &block) ⇒ Hash<Object, Float>
Convenience method to quickly calculate PageRank.
- .new(strategy: :sparse, **options) ⇒ PageRank::Base
Class Method Details
.calculate(**options, &block) ⇒ Hash<Object, Float>
Convenience method to quickly calculate PageRank. In the calling block, graph edges can be added.
36 37 38 39 40 |
# File 'lib/page_rank.rb', line 36 def self.calculate(**, &block) pr = new(**) pr.instance_exec(&block) pr.calculate(**) end |
.new(strategy: :sparse, **options) ⇒ PageRank::Base
29 30 31 |
# File 'lib/page_rank.rb', line 29 def self.new(strategy: :sparse, **) const_get(strategy.to_s.split('_').map(&:capitalize).join).new(**) end |