Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/charlie/etc/minireport.rb,
lib/charlie/etc/monkey.rb
Overview
This was handled by ruport earlier, but that turned out to be overkill and give a huge amount of dependencies.
Direct Known Subclasses
Instance Method Summary collapse
- #at_rand ⇒ Object
- #average ⇒ Object
- #dot_product(v) ⇒ Object
-
#map_with_index ⇒ Object
TODO 1.9.
- #rand_index ⇒ Object
- #shuffle ⇒ Object
-
#stats ⇒ Object
TODO 1.9, use minmax.
- #stddev ⇒ Object
- #to_table(colnames = nil) ⇒ Object
Instance Method Details
#at_rand ⇒ Object
50 51 52 |
# File 'lib/charlie/etc/monkey.rb', line 50 def at_rand self[rand(size)] end |
#average ⇒ Object
59 60 61 |
# File 'lib/charlie/etc/monkey.rb', line 59 def average sum.to_f / size end |
#dot_product(v) ⇒ Object
40 41 42 43 44 |
# File 'lib/charlie/etc/monkey.rb', line 40 def dot_product(v) r=0.0 each_with_index{|e,i| r+=e*v[i] } r end |
#map_with_index ⇒ Object
TODO 1.9
68 69 70 71 72 |
# File 'lib/charlie/etc/monkey.rb', line 68 def map_with_index # TODO 1.9 r=[] each_with_index{|e,i| r << yield(e,i) } r end |
#rand_index ⇒ Object
46 47 48 |
# File 'lib/charlie/etc/monkey.rb', line 46 def rand_index rand(size) end |
#shuffle ⇒ Object
36 37 38 |
# File 'lib/charlie/etc/monkey.rb', line 36 def shuffle sort_by{ rand } end |
#stats ⇒ Object
TODO 1.9, use minmax
54 55 56 57 |
# File 'lib/charlie/etc/monkey.rb', line 54 def stats # TODO 1.9, use minmax return transpose.map(&:stats).transpose if at(0).is_a?(Array) # return stats of each component if elements are arrays [min,max,average,stddev] end |
#stddev ⇒ Object
63 64 65 66 |
# File 'lib/charlie/etc/monkey.rb', line 63 def stddev mu = average Math.sqrt( map{|x| (x-mu)*(x-mu) }.sum / size ) end |