Class: ExoBasic::MeanAvg
- Inherits:
-
Object
- Object
- ExoBasic::MeanAvg
- Includes:
- AvgTraits
- Defined in:
- lib/exobasic/stats/mean_avg.rb
Instance Attribute Summary collapse
-
#avg ⇒ Object
readonly
Returns the value of attribute avg.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #from_hash(h) ⇒ Object
-
#initialize ⇒ MeanAvg
constructor
A new instance of MeanAvg.
- #offer(x) ⇒ Object
Methods included from AvgTraits
#approx=, #count, #deep_copy, #maximum, #minimum, #offer_many
Constructor Details
Instance Attribute Details
#avg ⇒ Object (readonly)
Returns the value of attribute avg.
5 6 7 |
# File 'lib/exobasic/stats/mean_avg.rb', line 5 def avg @avg end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/exobasic/stats/mean_avg.rb', line 5 def @meta end |
Class Method Details
Instance Method Details
#+(other) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/exobasic/stats/mean_avg.rb', line 37 def +(other) n_prime = @meta.n + other..n MeanAvg.mk({ :avg => n_prime == 0 ? 0.0 : (@avg * @meta.n + other.avg * other..n) / n_prime.to_f, :meta => @meta + other. }) end |
#==(other) ⇒ Object
32 33 34 35 |
# File 'lib/exobasic/stats/mean_avg.rb', line 32 def ==(other) StatsHelpers.double_equals(@avg, other.avg) && @meta == other. end |
#from_hash(h) ⇒ Object
12 13 14 15 |
# File 'lib/exobasic/stats/mean_avg.rb', line 12 def from_hash(h) @avg = h[:avg] @meta = h[:meta] end |
#offer(x) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/exobasic/stats/mean_avg.rb', line 24 def offer(x) n = @meta.n + 1 @meta = @meta.offer(x, @avg, n) n_prime = n.to_f @avg = x / n_prime + (n_prime - 1.0) * @avg / n_prime end |