class ExoBasic::AvgMeta
Attributes
averageChange[R]
averageDirectional[R]
change[R]
maxPossibility[R]
minPossibility[R]
n[R]
squareOfChange[R]
variance[R]
Public Class Methods
append_helper(n1, d1, n2, d2, nAll)
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 82 def self.append_helper(n1, d1, n2, d2, nAll) d1 * n1 / nAll + d2 * n2 / nAll end
mk(h)
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 34 def self.mk(h) x = AvgMeta.new x.from_hash(h) x end
new()
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 12 def initialize @n = 0 @change = 0.0 @averageChange = 0.0 @squareOfChange = 0.0 @variance = 0.0 @averageDirectional = 0.0 @minPossibility = Float::MAX @maxPossibility = Float::MIN end
zero()
click to toggle source
Monoid
# File lib/exobasic/stats/avg_meta.rb, line 78 def self.zero AvgMeta.new end
Public Instance Methods
+(other)
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 86 def +(other) n_prime = @n + other.n nd = n_prime.to_f n1 = @n.to_f n2 = other.n.to_f x = { :n => n_prime } if n1 <= 0 x[:change] = other.change x[:averageChange] = other.averageChange x[:squareOfChange] = other.squareOfChange x[:variance] = other.variance x[:averageDirectional] = other.averageDirectional elsif n2 <= 0 x[:change] = @change x[:averageChange] = @averageChange x[:squareOfChange] = @squareOfChange x[:variance] = @variance x[:averageDirectional] = @averageDirectional else x[:change] = AvgMeta.append_helper(n1, @change, n2, other.change, nd), x[:averageChange] = AvgMeta.append_helper(n1, @averageChange, n2, other.averageChange, nd), x[:squareOfChange] = AvgMeta.append_helper(n1, @squareOfChange, n2, other.squareOfChange, nd), x[:variance] = AvgMeta.append_helper(n1, @variance, n2, other.variance, nd), x[:averageDirectional] = AvgMeta.append_helper(n1, @averageDirectional, n2, other.averageDirectional, nd) end x[:minPossibility] = [@minPossibility, other.minPossibility].min x[:maxPossibility] = [@maxPossibility, other.maxPossibility].max AvgMeta.mk(x) end
==(other)
click to toggle source
Equal
# File lib/exobasic/stats/avg_meta.rb, line 69 def ==(other) StatsHelpers.double_equals(@change, other.change) && StatsHelpers.double_equals(@variance, other.variance) && StatsHelpers.double_equals(@averageDirectional, other.averageDirectional) && StatsHelpers.double_equals(@minPossibility, other.minPossibility) && StatsHelpers.double_equals(@maxPossibility, other.maxPossibility) end
deep_copy()
click to toggle source
Copy
# File lib/exobasic/stats/avg_meta.rb, line 64 def deep_copy Marshal.load(Marshal.dump(self)) end
empty?()
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 41 def empty? @n == 0 end
from_hash(h)
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 23 def from_hash(h) @n = h[:n] @change = h[:change] @averageChange = h[:averageChange] @squareOfChange = h[:squareOfChange] @variance = h[:variance] @averageDirectional = h[:averageDirectional] @minPossibility = h[:minPossibility] @maxPossibility = h[:maxPossibility] end
offer(x, prev_mean, d)
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 45 def offer(x, prev_mean, d) delta = x - prev_mean d2 = d <= 0 ? 1.0 : d.to_f change_prime = delta.abs square_of_change_prime = delta * delta AvgMeta.mk({ :n => @n + 1, :change => change_prime, :averageChange => change_prime / d2 + (d2 - 1.0) * @averageChange / d2, :squareOfChange => square_of_change_prime, :variance => square_of_change_prime / d2 + (d2 - 1.0) * @variance / d2, :averageDirectional => delta, :minPossibility => [x, @minPossibility].min, :maxPossibility => [x, @maxPossibility].max }) end
possibilityRange()
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 136 def possibilityRange [@minPossibility, @maxPossibility] end
standardDeviation()
click to toggle source
# File lib/exobasic/stats/avg_meta.rb, line 132 def standardDeviation Math.sqrt(@variance) end