Class: Elastic::Stats::KS
- Inherits:
-
Object
- Object
- Elastic::Stats::KS
- Includes:
- ElasticClient
- Defined in:
- lib/elastic/stats/ks.rb
Overview
Utility to determine the KolmogorovSmirnov difference between to sets of data fetched from Elasticsearch
Constant Summary collapse
- MULTIPLIERS =
{ 0.001 => 1.95, 0.005 => 1.73, 0.01 => 1.63, 0.025 => 1.48, 0.05 => 1.36, 0.10 => 1.22 }
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#query ⇒ Object
Returns the value of attribute query.
-
#span ⇒ Object
readonly
Returns the value of attribute span.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Attributes included from ElasticClient
Instance Method Summary collapse
- #calculate(current, previous, confidence) ⇒ Object
- #fetch(confidence = 0.05) ⇒ Object
-
#initialize(indices, options = {}) ⇒ KS
constructor
indices should include all possible indices.
Methods included from ElasticClient
#analyze, #client_options, #client_options=, #search
Constructor Details
#initialize(indices, options = {}) ⇒ KS
indices should include all possible indices.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/elastic/stats/ks.rb', line 25 def initialize(indices, = {}) @indices = indices = .update() @to = .delete(:to) @span = .delete(:span) @interval = .delete(:interval) @field = .delete(:field) @offset = .delete(:offset) @indices = [indices] unless @indices.is_a? Array @from = @to - @span end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
13 14 15 |
# File 'lib/elastic/stats/ks.rb', line 13 def field @field end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
13 14 15 |
# File 'lib/elastic/stats/ks.rb', line 13 def from @from end |
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
13 14 15 |
# File 'lib/elastic/stats/ks.rb', line 13 def indices @indices end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
13 14 15 |
# File 'lib/elastic/stats/ks.rb', line 13 def interval @interval end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/elastic/stats/ks.rb', line 12 def logger @logger end |
#query ⇒ Object
Returns the value of attribute query.
12 13 14 |
# File 'lib/elastic/stats/ks.rb', line 12 def query @query end |
#span ⇒ Object (readonly)
Returns the value of attribute span.
13 14 15 |
# File 'lib/elastic/stats/ks.rb', line 13 def span @span end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
13 14 15 |
# File 'lib/elastic/stats/ks.rb', line 13 def to @to end |
Instance Method Details
#calculate(current, previous, confidence) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/elastic/stats/ks.rb', line 55 def calculate(current, previous, confidence) MULTIPLIERS[confidence] * Math.sqrt( ( (current.count + previous.count).to_f / (current.count * previous.count) ) ) end |
#fetch(confidence = 0.05) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elastic/stats/ks.rb', line 40 def fetch(confidence = 0.05) current = range(@from, @to) previous = range(@from - @offset, @to - @offset) difference = Statsample::Test::KolmogorovSmirnov.new( current, previous ).d comparison = calculate(current, previous, confidence) { confidence: confidence, comparison: comparison, difference: difference, different?: (difference > comparison) } end |