Class: RankAggregation::MarkovChain
- Inherits:
-
Object
- Object
- RankAggregation::MarkovChain
- Defined in:
- lib/rank-aggregation/markov.rb
Instance Method Summary collapse
-
#initialize(items, transitions, logger) ⇒ MarkovChain
constructor
A new instance of MarkovChain.
- #stationary_distribution ⇒ Object
Constructor Details
#initialize(items, transitions, logger) ⇒ MarkovChain
Returns a new instance of MarkovChain.
3 4 5 6 7 |
# File 'lib/rank-aggregation/markov.rb', line 3 def initialize(items, transitions, logger) @logger = logger @transitions = transitions @items = items end |
Instance Method Details
#stationary_distribution ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rank-aggregation/markov.rb', line 9 def stationary_distribution dist = {} @items.each{|x| dist[x] = 1.0 / @items.size } 3.times{ |i| @logger.debug "markov chain iteration #{i}" new_dist = Hash.new(0.0) dist.each{|x, p| @transitions[x].each{|y, q| new_dist[y] += p * q } } dist = new_dist } dist end |