diff --git a/.index b/.index index b935324c..1270f238 100644 --- a/.index +++ b/.index @@ -67,7 +67,7 @@ paths: - lib/standard name: facets title: Ruby Facets -version: 3.1.0 +version: 3.1.1 summary: The orginal well curated collection of extension methods for Ruby. slogan: ALL YOUR BASE ARE BELONG TO RUBY! description: Facets is the premier collection of extension methods for the Ruby programming diff --git a/lib/standard/facets/math/gini_coefficient.rb b/lib/standard/facets/math/gini_coefficient.rb index b0e4d713..ac1601aa 100644 --- a/lib/standard/facets/math/gini_coefficient.rb +++ b/lib/standard/facets/math/gini_coefficient.rb @@ -1,4 +1,5 @@ require 'facets/math/approx_equal' +require 'facets/math/mean' module Math @@ -13,11 +14,11 @@ module Math # GC = \frac{\sum_{i=1}^N (2i-N-1)x_i}{N^2-\bar{x}} # def self.gini_coefficient(array) - return -1 if size <= 0 or any? { |x| x < 0 } - return 0 if size < 2 or all? { |x| approx_equal(x,0) } + return -1 if array.size <= 0 or array.any? { |x| x < 0 } + return 0 if array.size < 2 or array.all? { |x| approx_equal(x,0) } s = 0 - sort.each_with_index { |li,i| s += (2*i+1-size)*li } - s.to_f/(size**2*mean).to_f + array.sort.each_with_index { |li,i| s += (2*i+1-array.size)*li } + s.to_f/(array.size**2*mean(array)).to_f end ## OLD WAY