class Evoc::InterestingnessMeasureAggregator
Attributes
max[RW]
mid[RW]
min[RW]
size[RW]
type[RW]
values[RW]
Public Class Methods
new(type,values)
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 5 def initialize(type,values) self.type = type self.min = Evoc::InterestingnessMeasures.get_min(type) self.mid = Evoc::InterestingnessMeasures.get_mid(type) self.max = Evoc::InterestingnessMeasures.get_max(type) self.values = values self.size = values.size end
Public Instance Methods
cg()
click to toggle source
cumulative gain aka sum
# File lib/evoc/interestingness_measure_aggregator.rb, line 35 def cg aggregated = normalize_measures.inject(:+) + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: aggregated) end
dcg()
click to toggle source
discounted CG
# File lib/evoc/interestingness_measure_aggregator.rb, line 41 def dcg agr = normalize_measures.first + normalize_measures[1..-1].each_with_index.inject(0) {|sum,(element,index)| sum + element/Math.log2(index+2)} agr = agr + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr) end
dcg2()
click to toggle source
discounted CG2
# File lib/evoc/interestingness_measure_aggregator.rb, line 48 def dcg2 agr = normalize_measures.first + normalize_measures[1..-1].each_with_index.inject(0) {|sum,(element,index)| sum + (element >= 0 ? (2**element-1)/Math.log2(index+2) : -(2**element.abs-1)/Math.log2(index+2)) } agr = agr + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr) end
hcg()
click to toggle source
Our own aggregation functions
# File lib/evoc/interestingness_measure_aggregator.rb, line 17 def hcg agr = normalize_measures.inject {|tot,i| direction = i > 0 ? self.max-self.mid : self.min-self.mid coefficient = direction.to_f.finite? ? (direction-tot)/direction : 1 tot + coefficient*i } + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr) end
hcg_hc()
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 26 def hcg_hc self.hcg end
normalize_measures()
click to toggle source
def discounted_cg3
agr = normalize_measures.each_with_index.inject(0) {|sum,(element,index)| sum + element >= 0 ? (2**element-1)/Math.log2(index+2) : -(2**element.abs-1)/Math.log2(index+2) } agr = agr + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr)
end
def discounted_cg4
agr = normalize_measures.each_with_index.inject(0) {|sum,(element,index)| sum + (2**element)/Math.log2(index+2) } agr = agr + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr)
end
def discounted_cg5
agr = normalize_measures.each_with_index.inject(0) {|sum,(element,index)| sum + element == 0 ? 0 : (2**element)/Math.log2(index+2) } agr = agr + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr)
end
def discounted_rank_cg
agr = normalize_measures.each_with_index.inject(0) {|sum,(element,index)| sum + element/(index+1) } agr = agr + self.mid Evoc::InterestingnessMeasure.new(type: self.type, min: self.min, mid: self.mid, max: self.max, value: agr)
end
# File lib/evoc/interestingness_measure_aggregator.rb, line 89 def normalize_measures self.values.map {|m| m - self.mid} end
values=(measures)
click to toggle source
values=
set and sort by abs value
# File lib/evoc/interestingness_measure_aggregator.rb, line 97 def values=(measures) if measures.all? {|m| m.is_a?(Evoc::InterestingnessMeasure)} @values = measures.map(&:value) else @values = measures end @values.map!(&:to_f) @values.sort! {|x,y| y.abs<=>x.abs} end
Private Instance Methods
constr_equal_type(other)
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 108 def constr_equal_type other (self.class == other.class ? true : ( raise ArgumentError, "self: #{self.type}: #{self.class} was of different class than other: #{other.class}" ) ) & (self.max == other.max ? true : ( raise ArgumentError, "self: #{self.type}: #{self.max} had a different max than other: #{other.max}" ) ) & (self.mid == other.mid ? true : ( raise ArgumentError, "self: #{self.type}: #{self.mid} had a different mid than other: #{other.mid}" ) ) & (self.min == other.min ? true : ( raise ArgumentError, "self: #{self.type}: #{self.min} had a different min than other: #{other.min}" ) ) & (self.type == other.type ? true : ( raise ArgumentError, "self: #{self.type}: #{self.type}had a different type than other: #{other.type}" ) ) # ((self.value.round(2) >= self.mid) == (other.value.round(2) >= self.mid) ? true : ( raise ArgumentError, "#{self.type}: self: #{self.value} was on another side of the midpoint than other: #{other.value}, midpoint was #{self.mid}" )) end
constr_other_absvalue_smaller_than_self_absvalue(self_value,other_value)
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 140 def constr_other_absvalue_smaller_than_self_absvalue(self_value,other_value) if other_value.abs > self_value.abs #raise ArgumentError.new, "The absolute value of the right hand argument must always be smaller or equal to the absolute value of the left hand side. lhs was #{self_value}, rhs was #{other_value} (possibly normalized around 0)" logger.warn "The absolute value of the right hand argument must always be smaller or equal to the absolute value of the left hand side. lhs was #{self_value}, rhs was #{other_value} (possibly normalized around 0)" end end
constr_other_value_equal_mid(other)
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 132 def constr_other_value_equal_mid(other) satisfied = other.value == self.mid if satisfied logger.warn "other value (#{other.value}) was equal to mid value (#{self.mid}) when aggregating #{self.type} measure, just returning self" end satisfied end
constr_self_value_equal_mid()
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 124 def constr_self_value_equal_mid satisfied = self.value == self.mid if satisfied logger.warn "self value (#{self.value}) was equal to mid value (#{self.mid}) when aggregating #{self.type} measure, just returning other" end satisfied end
constr_value_in_range(agr_val)
click to toggle source
# File lib/evoc/interestingness_measure_aggregator.rb, line 117 def constr_value_in_range(agr_val) if !agr_val.between?(self.min,self.max) #raise Evoc::Exceptions::AggregationError, "#{self.type}: #{agr_val} was not in range: [#{self.min},#{self.max}]" logger.warn "#{self.type}: #{agr_val} was not in range: [#{self.min},#{self.max}]" end end