Class: ExoBasic::AvgMeta
- Inherits:
-
Object
- Object
- ExoBasic::AvgMeta
- Defined in:
- lib/exobasic/stats/avg_meta.rb
Instance Attribute Summary collapse
-
#averageChange ⇒ Object
readonly
Returns the value of attribute averageChange.
-
#averageDirectional ⇒ Object
readonly
Returns the value of attribute averageDirectional.
-
#change ⇒ Object
readonly
Returns the value of attribute change.
-
#maxPossibility ⇒ Object
readonly
Returns the value of attribute maxPossibility.
-
#minPossibility ⇒ Object
readonly
Returns the value of attribute minPossibility.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#squareOfChange ⇒ Object
readonly
Returns the value of attribute squareOfChange.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#==(other) ⇒ Object
Equal.
-
#deep_copy ⇒ Object
Copy.
- #empty? ⇒ Boolean
- #from_hash(h) ⇒ Object
-
#initialize ⇒ AvgMeta
constructor
A new instance of AvgMeta.
- #offer(x, prev_mean, d) ⇒ Object
- #possibilityRange ⇒ Object
- #standardDeviation ⇒ Object
Constructor Details
#initialize ⇒ AvgMeta
Returns a new instance of AvgMeta.
12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#averageChange ⇒ Object (readonly)
Returns the value of attribute averageChange.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def averageChange @averageChange end |
#averageDirectional ⇒ Object (readonly)
Returns the value of attribute averageDirectional.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def averageDirectional @averageDirectional end |
#change ⇒ Object (readonly)
Returns the value of attribute change.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def change @change end |
#maxPossibility ⇒ Object (readonly)
Returns the value of attribute maxPossibility.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def maxPossibility @maxPossibility end |
#minPossibility ⇒ Object (readonly)
Returns the value of attribute minPossibility.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def minPossibility @minPossibility end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def n @n end |
#squareOfChange ⇒ Object (readonly)
Returns the value of attribute squareOfChange.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def squareOfChange @squareOfChange end |
#variance ⇒ Object (readonly)
Returns the value of attribute variance.
3 4 5 |
# File 'lib/exobasic/stats/avg_meta.rb', line 3 def variance @variance end |
Class Method Details
.append_helper(n1, d1, n2, d2, nAll) ⇒ Object
82 83 84 |
# 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 |
Instance Method Details
#+(other) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# 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) ⇒ Object
Equal
69 70 71 72 73 74 75 |
# 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 ⇒ Object
Copy
64 65 66 |
# File 'lib/exobasic/stats/avg_meta.rb', line 64 def deep_copy Marshal.load(Marshal.dump(self)) end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/exobasic/stats/avg_meta.rb', line 41 def empty? @n == 0 end |
#from_hash(h) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 ⇒ Object
136 137 138 |
# File 'lib/exobasic/stats/avg_meta.rb', line 136 def possibilityRange [@minPossibility, @maxPossibility] end |
#standardDeviation ⇒ Object
132 133 134 |
# File 'lib/exobasic/stats/avg_meta.rb', line 132 def standardDeviation Math.sqrt(@variance) end |