Module: SocialStream::Populate

Defined in:
lib/social_stream/populate.rb

Class Method Summary collapse

Class Method Details

.power_law(array, options = {}) ⇒ Object

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

Options: Each constant in the function



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/social_stream/populate.rb', line 11

def power_law(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