Sha256: 4c5e72942110b2583fdc176a00701a0606a801173d25dea96101cbe8dcaba164

Contents?: true

Size: 698 Bytes

Versions: 32

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

32 entries across 32 versions & 1 rubygems

Version Path
picky-4.5.6 lib/picky/generators/weights/logarithmic.rb
picky-4.5.5 lib/picky/generators/weights/logarithmic.rb
picky-4.5.4 lib/picky/generators/weights/logarithmic.rb
picky-4.5.3 lib/picky/generators/weights/logarithmic.rb
picky-4.5.2 lib/picky/generators/weights/logarithmic.rb
picky-4.5.1 lib/picky/generators/weights/logarithmic.rb
picky-4.5.0 lib/picky/generators/weights/logarithmic.rb
picky-4.4.2 lib/picky/generators/weights/logarithmic.rb
picky-4.4.1 lib/picky/generators/weights/logarithmic.rb
picky-4.4.0 lib/picky/generators/weights/logarithmic.rb
picky-4.3.2 lib/picky/generators/weights/logarithmic.rb
picky-4.3.1 lib/picky/generators/weights/logarithmic.rb
picky-4.3.0 lib/picky/generators/weights/logarithmic.rb
picky-4.2.4 lib/picky/generators/weights/logarithmic.rb
picky-4.2.3 lib/picky/generators/weights/logarithmic.rb
picky-4.2.2 lib/picky/generators/weights/logarithmic.rb
picky-4.2.1 lib/picky/generators/weights/logarithmic.rb
picky-4.2.0 lib/picky/generators/weights/logarithmic.rb
picky-4.1.0 lib/picky/generators/weights/logarithmic.rb
picky-4.0.9 lib/picky/generators/weights/logarithmic.rb