Class: Capricious::SampleSink
- Inherits:
-
Object
- Object
- Capricious::SampleSink
- Defined in:
- lib/capricious/sample_sink.rb
Overview
Records aggregate data about a stream of samples in constant space.
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
-
#<<(sample) ⇒ Object
Adds a sample and updates =min=, =max= and =count= as well as =mean=, and =variance= estimates.
-
#initialize ⇒ SampleSink
constructor
A new instance of SampleSink.
-
#put(sample) ⇒ Object
Adds a sample and updates =min=, =max= and =count= as well as =mean=, and =variance= estimates.
-
#stddev ⇒ Object
Returns the square root of the variance for all witnessed samples.
Constructor Details
#initialize ⇒ SampleSink
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
#count ⇒ Object (readonly)
Returns the value of attribute count.
24 25 26 |
# File 'lib/capricious/sample_sink.rb', line 24 def count @count end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
24 25 26 |
# File 'lib/capricious/sample_sink.rb', line 24 def max @max end |
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
24 25 26 |
# File 'lib/capricious/sample_sink.rb', line 24 def mean @mean end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
24 25 26 |
# File 'lib/capricious/sample_sink.rb', line 24 def min @min end |
#variance ⇒ Object (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 |
#stddev ⇒ Object
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 |