Sha256: 239c7a878f606d38f540c02bb16b5eb2d0d09fcb2c86740a03891b9ca4d8623b
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
module Picky module Query # Calculates weights for certain combinations. # class Weights # :nodoc:all attr_reader :weights delegate :empty?, :to => :weights # # def initialize weights = {} @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 Or it could use actual combinations? Could it? Or make combinations comparable to Symbols. # weight_for combinations.map(&:category_name).clustered_uniq_fast end def == other @weights == other.weights end # Prints out a nice representation of the configured weights. # def to_s "#{self.class}(#{@weights})" end end end end
Version data entries
5 entries across 5 versions & 1 rubygems