Sha256: 00c7873ecf4fa1d5495c82c89408aa6d0bc130a53be81cd7ec3f8ec722d3e40c

Contents?: true

Size: 698 Bytes

Versions: 15

Compression:

Stored size: 698 Bytes

Contents

module Picky

  module Generators

    module Weights

      # Uses a logarithmic weight.
      # If for a key k we have x ids, the weight is:
      # w(x): log(x)
      # Special case: If x < 1, then we use 0.
      #
      class Logarithmic < Strategy

        # Sets the weight value.
        #
        # If the size is 0 or one, we would get -Infinity or 0.0.
        # Thus we do not set a value if there is just one. The default, dynamically, is 0.
        #
        # BUT: We need the value, even if 0. To designate that there is a weight!
        #
        def weight_for amount
          return 0 if amount < 1
          Math.log(amount).round 3
        end

      end

    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
picky-4.0.0pre1 lib/picky/generators/weights/logarithmic.rb
picky-3.6.16 lib/picky/generators/weights/logarithmic.rb
picky-3.6.15 lib/picky/generators/weights/logarithmic.rb
picky-3.6.14 lib/picky/generators/weights/logarithmic.rb
picky-3.6.13 lib/picky/generators/weights/logarithmic.rb
picky-3.6.12 lib/picky/generators/weights/logarithmic.rb
picky-3.6.11 lib/picky/generators/weights/logarithmic.rb
picky-3.6.10 lib/picky/generators/weights/logarithmic.rb
picky-3.6.9 lib/picky/generators/weights/logarithmic.rb
picky-3.6.8 lib/picky/generators/weights/logarithmic.rb
picky-3.6.7 lib/picky/generators/weights/logarithmic.rb
picky-3.6.6 lib/picky/generators/weights/logarithmic.rb
picky-3.6.4 lib/picky/generators/weights/logarithmic.rb
picky-3.6.3 lib/picky/generators/weights/logarithmic.rb
picky-3.6.2 lib/picky/generators/weights/logarithmic.rb