Class: Array
Instance Method Summary collapse
- #as_chain ⇒ Object
- #average_growth ⇒ Object
- #geometric_mean ⇒ Object
- #growth ⇒ Object
- #mean ⇒ Object
- #product ⇒ Object
- #rank ⇒ Object
- #stability ⇒ Object
- #standard_deviation ⇒ Object
- #sum ⇒ Object
- #total ⇒ Object
- #variance ⇒ Object
Instance Method Details
#as_chain ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/kuku.rb', line 61 def as_chain self.size.times{|i| a = self[i+1] b = self[i-1] (self[i].next = a) if a (self[i].previous = b) if (b && i > 0) } self[0] end |
#average_growth ⇒ Object
102 103 104 |
# File 'lib/kuku.rb', line 102 def average_growth growth.mean end |
#geometric_mean ⇒ Object
79 80 81 |
# File 'lib/kuku.rb', line 79 def geometric_mean product ** (1/size.to_f) end |
#growth ⇒ Object
97 98 99 100 101 |
# File 'lib/kuku.rb', line 97 def growth result = Array.new (size-1).times {|i| result << ((self[i].to_f - self[i+1].to_f)/self[i+1].to_f) * 100 } result end |
#mean ⇒ Object
85 86 87 |
# File 'lib/kuku.rb', line 85 def mean sum / size end |
#product ⇒ Object
76 77 78 |
# File 'lib/kuku.rb', line 76 def product reduce{|k,v| k*v} end |
#stability ⇒ Object
94 95 96 |
# File 'lib/kuku.rb', line 94 def stability mean / (standard_deviation > 1.0 ? standard_deviation : 1) end |
#standard_deviation ⇒ Object
88 89 90 |
# File 'lib/kuku.rb', line 88 def standard_deviation Math.sqrt variance end |
#sum ⇒ Object
82 83 84 |
# File 'lib/kuku.rb', line 82 def sum reduce{|k,v| k+v} end |
#total ⇒ Object
73 74 75 |
# File 'lib/kuku.rb', line 73 def total Totaler.new self end |
#variance ⇒ Object
91 92 93 |
# File 'lib/kuku.rb', line 91 def variance ((reduce(0){|k,v| k+(v-mean)**2})) / size.to_f end |