Sha256: 7bfa9e44c84f91ad6f1dc25ca2e6db3312ebc81a0640831f2304f82947cd9e94

Contents?: true

Size: 617 Bytes

Versions: 201

Compression:

Stored size: 617 Bytes

Contents

module SocialStream
  module Populate

    class << self
      # Yields each element of array y times given by 
      # {power law distribution}[http://en.wikipedia.org/wiki/Power_law]
      # y = ax**k + e
      # 
      # Options: Each constant in the function
      #
      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
    end
  end
end

Version data entries

201 entries across 201 versions & 4 rubygems

Version Path
social_stream-0.26.0 base/lib/social_stream/populate.rb
social_stream-base-0.20.0 lib/social_stream/populate.rb
social_stream-0.25.2 base/lib/social_stream/populate.rb
social_stream-base-0.19.2 lib/social_stream/populate.rb
social_stream-0.25.1 base/lib/social_stream/populate.rb
social_stream-base-0.19.1 lib/social_stream/populate.rb
social_stream-0.25.0 base/lib/social_stream/populate.rb
social_stream-base-0.19.0 lib/social_stream/populate.rb
social_stream-0.24.1 base/lib/social_stream/populate.rb
social_stream-base-0.18.1 lib/social_stream/populate.rb
social_stream-0.24.0 base/lib/social_stream/populate.rb
social_stream-base-0.18.0 lib/social_stream/populate.rb
social_stream-0.23.4 base/lib/social_stream/populate.rb
social_stream-base-0.17.3 lib/social_stream/populate.rb
social_stream-0.23.3 base/lib/social_stream/populate.rb
social_stream-base-0.17.2 lib/social_stream/populate.rb
social_stream-0.23.2 base/lib/social_stream/populate.rb
social_stream-base-0.17.1 lib/social_stream/populate.rb
social_stream-0.23.1 base/lib/social_stream/populate.rb
social_stream-base-0.17.0 lib/social_stream/populate.rb