Class: Capricious::SampleSink

Inherits:
Object
  • Object
show all
Defined in:
lib/capricious/sample_sink.rb

Overview

Records aggregate data about a stream of samples in constant space.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSampleSink

Returns a new instance of SampleSink.



26
27
28
29
30
31
32
33
# File 'lib/capricious/sample_sink.rb', line 26

def initialize
  @min = nil
  @max = nil
  @count = 0
  @variance = 0.0
  @mean = 0.0
  @sum_x2 = 0.0
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



24
25
26
# File 'lib/capricious/sample_sink.rb', line 24

def count
  @count
end

#maxObject (readonly)

Returns the value of attribute max.



24
25
26
# File 'lib/capricious/sample_sink.rb', line 24

def max
  @max
end

#meanObject (readonly)

Returns the value of attribute mean.



24
25
26
# File 'lib/capricious/sample_sink.rb', line 24

def mean
  @mean
end

#minObject (readonly)

Returns the value of attribute min.



24
25
26
# File 'lib/capricious/sample_sink.rb', line 24

def min
  @min
end

#varianceObject (readonly)

Returns the value of attribute variance.



24
25
26
# File 'lib/capricious/sample_sink.rb', line 24

def variance
  @variance
end

Instance Method Details

#<<(sample) ⇒ Object

Adds a sample and updates =min=, =max= and =count= as well as =mean=, and =variance= estimates.



45
46
47
48
# File 'lib/capricious/sample_sink.rb', line 45

def <<(sample)
  self.put(sample)
  self
end

#put(sample) ⇒ Object

Adds a sample and updates =min=, =max= and =count= as well as =mean=, and =variance= estimates.



37
38
39
40
41
# File 'lib/capricious/sample_sink.rb', line 37

def put(sample)
  update_stats(sample)
  update_estimates(sample)
  nil
end

#stddevObject

Returns the square root of the variance for all witnessed samples.



51
52
53
# File 'lib/capricious/sample_sink.rb', line 51

def stddev
  Math::sqrt(@variance)
end