Methods
public class
public instance
Public class methods
from_json
(str)
[show source]
# File lib/stella/core_ext.rb, line 443 def self.from_json(str) Yajl::Parser.parse(str, :check_utf8 => false) end
Public instance methods
deviation
()
[show source]
# File lib/stella/core_ext.rb, line 413 def deviation ; Math::sqrt( self.variance ) ; end
dump
(format)
[show source]
# File lib/stella/core_ext.rb, line 436 def dump(format) respond_to?(:"to_#{format}") ? send(:"to_#{format}") : raise("Unknown format: #{format}") end
histogram
()
[show source]
# File lib/stella/core_ext.rb, line 405 def histogram ; self.sort.inject({}){|a,x|a[x]=a[x].to_i+1;a} ; end
mean
()
[show source]
# File lib/stella/core_ext.rb, line 398 def mean; self.sum.to_f/self.size ; end
median
()
[show source]
# File lib/stella/core_ext.rb, line 399 def median case self.size % 2 when 0 then self.sort[self.size/2-1,2].mean when 1 then self.sort[self.size/2].to_f end if self.size > 0 end
mode
()
[show source]
# File lib/stella/core_ext.rb, line 406 def mode map = self.histogram max = map.values.max map.keys.select{|x|map[x]==max} end
percentile
(perc)
[show source]
# File lib/stella/core_ext.rb, line 426 def percentile(perc) self.sort[percentile_index(perc)] end
percentile_index
(perc)
[show source]
# File lib/stella/core_ext.rb, line 429 def percentile_index(perc) (perc * self.length).ceil - 1 end
permute
()
[show source]
# File lib/stella/core_ext.rb, line 415 def permute ; self.dup.permute! ; end
permute!
()
[show source]
# File lib/stella/core_ext.rb, line 416 def permute! (1...self.size).each do |i| ; j=rand(i+1) self[i],self[j] = self[j],self[i] if i!=j end;self end
random
()
[show source]
# File lib/stella/core_ext.rb, line 423 def random self[rand(self.size)] end
sample
(n=1 ;)
[show source]
# File lib/stella/core_ext.rb, line 421 def sample n=1 ; (0...n).collect{ self[rand(self.size)] } ; end
squares
()
[show source]
# File lib/stella/core_ext.rb, line 411 def squares ; self.inject(0){|a,x|x.square+a} ; end
sum
()
[show source]
# File lib/stella/core_ext.rb, line 397 def sum ; self.inject(0){|a,x| next if x.nil? || a.nil?; x+a} ; end
to_json
()
[show source]
# File lib/stella/core_ext.rb, line 440 def to_json Yajl::Encoder.encode(self) end
variance
()
[show source]
# File lib/stella/core_ext.rb, line 412 def variance ; self.squares.to_f/self.size - self.mean.square; end