Class: StreamStat::V
- Inherits:
-
Object
- Object
- StreamStat::V
- Defined in:
- lib/stream_stat/v.rb
Overview
Accumrator.
This holds :avg, :variance & :sd.
Instance Attribute Summary collapse
-
#avg ⇒ Object
readonly
Returns the value of attribute avg.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
-
#initialize(count = 0, avg = 0.0, square_avg = 0.0, min = Float::INFINITY, max = -Float::INFINITY)) ⇒ V
constructor
A new instance of V.
- #next(item) ⇒ Object
- #sd ⇒ Object
- #variance ⇒ Object
Constructor Details
#initialize(count = 0, avg = 0.0, square_avg = 0.0, min = Float::INFINITY, max = -Float::INFINITY)) ⇒ V
Returns a new instance of V.
10 11 12 13 14 15 16 |
# File 'lib/stream_stat/v.rb', line 10 def initialize(count = 0, avg = 0.0, square_avg = 0.0, min = Float::INFINITY, max = -Float::INFINITY) @count = count @avg = avg @square_avg = square_avg @min = min @max = max end |
Instance Attribute Details
#avg ⇒ Object (readonly)
Returns the value of attribute avg.
8 9 10 |
# File 'lib/stream_stat/v.rb', line 8 def avg @avg end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
8 9 10 |
# File 'lib/stream_stat/v.rb', line 8 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
8 9 10 |
# File 'lib/stream_stat/v.rb', line 8 def min @min end |
Instance Method Details
#next(item) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stream_stat/v.rb', line 18 def next(item) item = item.to_f next_length = @count + 1 self.class.new( next_length, next_avg(next_length, item), next_square_avg(next_length, item), [@min, item].min, [@max, item].max ) end |
#sd ⇒ Object
34 35 36 |
# File 'lib/stream_stat/v.rb', line 34 def sd Math.sqrt variance end |
#variance ⇒ Object
30 31 32 |
# File 'lib/stream_stat/v.rb', line 30 def variance @square_avg - @avg**2 end |