Sha256: a2ccb3ed65313eb2664f0c857a80de7823842c3bf1af8ce4cf90d01a5f085984

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

module Query

  # Calculates weights for certain combinations.
  #
  class Weights # :nodoc:all
    
    #
    #
    def initialize weights = {}
      @weights_cache = {}
      @weights = prepare weights
    end
    
    # Get the category indexes for the given bonuses.
    #
    def prepare weights
      weights
    end
    
    # Get the weight of an allocation.
    #
    def weight_for clustered
      @weights[clustered] || 0
    end
    
    # Returns an energy term E for allocation. this turns into a probability
    # by P(allocation) = 1/Z * exp (-1/T * E(allocation)),
    # where Z is the normalizing partition function
    # sum_allocations exp(-1/T *E(allocation)), and T is a temperature constant.
    # If T is high the distribution will be close to equally distributed.
    # If T is low, the distribution will be the indicator function
    # for min (E(allocation))…
    #
    # ...
    #
    # Just kidding. It's far more complicated than that. Ha ha ha ha ;)
    #
    # Note: Cache this if more complicated weighings become necessary.
    #
    def score combinations
      # TODO Beautify? Use categories for weights?
      #
      # weight_for combinations.map(&:category).clustered_uniq_fast.map!(&:name)
      
      # TODO combinations could cluster uniq as combinations are added (since combinations don't change).
      #
      weight_for combinations.map(&:category_name).clustered_uniq_fast
    end
    
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
picky-1.2.4 lib/picky/query/weights.rb
picky-1.2.3 lib/picky/query/weights.rb
picky-1.2.2 lib/picky/query/weights.rb
picky-1.2.1 lib/picky/query/weights.rb
picky-1.2.0 lib/picky/query/weights.rb
picky-1.1.7 lib/picky/query/weights.rb
picky-1.1.6 lib/picky/query/weights.rb
picky-1.1.5 lib/picky/query/weights.rb
picky-1.1.4 lib/picky/query/weights.rb
picky-1.1.3 lib/picky/query/weights.rb
picky-1.1.2 lib/picky/query/weights.rb
picky-1.1.1 lib/picky/query/weights.rb
picky-1.1.0 lib/picky/query/weights.rb