class SAAL::OutlierCache

Constants

COMP_CACHE_SIZE

By feeding values into this cache the outliers are identified. The cache is conservative and only flags down values that it is sure are outliers. The cache considers itself “live” when the values in the cache are all within a few percent of each other and will then flag down outliers. When the cache is not live all values will be considered good.

MAX_CACHE_DEVIATION

These are conservative settings that can be made stricted if the cache is not rejecting enough values or is often not “live” Sets how close the central values have to be for the cache to be “live”

MAX_VALUE_DEVIATION

Sets how off the read value can be from the cache median to be accepted

Public Class Methods

new() click to toggle source
   # File lib/outliercache.rb
18 def initialize
19   @compcache = []
20 end

Public Instance Methods

live() click to toggle source
   # File lib/outliercache.rb
22 def live
23   @compcache.size == COMP_CACHE_SIZE && valid_cache
24 end
validate(value) click to toggle source
   # File lib/outliercache.rb
26 def validate(value)
27   ret = compare_with_cache(value)
28   @compcache.shift if @compcache.size == COMP_CACHE_SIZE
29   @compcache.push value
30   ret
31 end

Private Instance Methods

compare_with_cache(value) click to toggle source
   # File lib/outliercache.rb
34 def compare_with_cache(value)
35   return true if !live
36   @compcache.sort!
37   median = @compcache[COMP_CACHE_SIZE/2]
38   (value.to_f/median.to_f - 1.0).abs < MAX_VALUE_DEVIATION 
39 end
valid_cache() click to toggle source
   # File lib/outliercache.rb
41 def valid_cache
42   @compcache.sort!
43   central = @compcache[1..(@compcache.size-2)]
44   sum = central.inject(0.0){|csum,el| csum+el}
45   return false if sum == 0.0
46   average = sum/central.size
47   central.each do |el|
48     return false if (el.to_f/average.to_f - 1.0).abs > MAX_CACHE_DEVIATION
49   end
50   true
51 end