Class: ANTLR3::Profile::DataSet

Inherits:
Array
  • Object
show all
Includes:
Math
Defined in:
lib/antlr3/profile.rb

Instance Method Summary collapse

Methods inherited from Array

#pad, #pad!

Instance Method Details

#averageObject


81
82
83
# File 'lib/antlr3/profile.rb', line 81

def average
  length > 0 ? ( total.to_f / length ) : 0
end

#standard_deviationObject


89
90
91
# File 'lib/antlr3/profile.rb', line 89

def standard_deviation
  sqrt( variance )
end

#totalObject


78
79
80
# File 'lib/antlr3/profile.rb', line 78

def total
  inject( :+ )
end

#varianceObject


84
85
86
87
88
# File 'lib/antlr3/profile.rb', line 84

def variance
  length.zero? and return( 0.0 )
  mean = average
  inject( 0.0 ) { |t, i| t + ( i - mean )**2 } / ( length - 1 )
end