class Evoc::HyperRule
Attributes
hyper_coefficient[RW]
hyper_confidence[RW]
lhs[RW]
rhs[RW]
Public Class Methods
new(rules,aggregator,measures)
click to toggle source
# File lib/evoc/hyper_rule.rb, line 5 def initialize(rules,aggregator,measures) if measures.nil? || measures.empty? raise ArgumentError, "At least one measure must be provided when defining a new hyper rule" end self.lhs = rules.map(&:lhs).array_union self.rhs = rules.map(&:rhs).array_union self.tx_store = rules.first.tx_store self.hyper_coefficient = rules.size # aggregate measures measures.each do |m| logger.debug "Aggregating #{self.hyper_coefficient} rules on #{m}" # check if its the hyper confidence if m == 'm_hyper_confidence' antecedent = self.tx_store.transactions_of_list(self.lhs) consequent = self.tx_store.transactions_of_list(self.rhs) numerator = (antecedent & consequent).size denominator = antecedent.size hyper_confidence = numerator/denominator self.set_measure(m,hyper_confidence,hyper_measure: true) else begin # get the 'm' measure of each rule m_measures = rules.map {|rule| rule.get_measure(m)} # remove undefined measures m_measures.reject! {|a| a.value.nil?} # group the measures into negative and positive correlations pos_correlation = m_measures.group_by {|a| a.value > Evoc::Rule.get_mid(m)} positive_correlation = pos_correlation[true].nil? ? 0 : Evoc::InterestingnessMeasureAggregator.new(m,pos_correlation[true]).method(aggregator).call.value # add the agggregated measure self.set_measure(m,positive_correlation,hyper_measure: true) # add the hyper coefficient as a measure for aggregators called with '.._hc' if !(aggregator =~ /_hc\z/).nil? self.set_measure('m_hyper_coefficient',hyper_coefficient,hyper_measure: true) end rescue Evoc::Exceptions::InterestingnessMeasure::NonFinite logger.debug "Could not aggregate #{m} using #{aggregator}, aggregation produced a non-finite value, probably a range problem, setting measure value to nil" self.set_measure(m,nil, hyper_measure: true) end end end end
Public Instance Methods
name()
click to toggle source
# File lib/evoc/hyper_rule.rb, line 49 def name self.lhs.join(',') + " => " + self.rhs.join(',') end