class SocialStream::Population::PowerLaw

Public Class Methods

new(array, options = {}) { |i| ... } click to toggle source

Yields each element of array y times given by power law distribution y = ax**k + e

Options: Each constant in the function

# File lib/social_stream/population/power_law.rb, line 10
def initialize(array, options = {})
  options[:a] ||= array.size
  options[:k] ||= -2.5
  options[:e] ||= 1

  array.each do |i|
    value = options[:a] * (array.index(i) + 1) ** options[:k] + options[:e]

    value.round.times do
      yield i
    end
  end
end