Module: PageRank
- Defined in:
- lib/page_rank.rb,
lib/page_rank/base.rb,
lib/page_rank/dense.rb,
lib/page_rank/sparse.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
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.
35 36 37 38 39 |
# File 'lib/page_rank.rb', line 35 def self.calculate(**, &block) pr = new(**) pr.instance_exec(&block) pr.calculate(**) end |
.new(strategy: :sparse, **options) ⇒ PageRank::Base
28 29 30 |
# File 'lib/page_rank.rb', line 28 def self.new(strategy: :sparse, **) const_get(strategy.to_s.capitalize).new(**) end |