From a953163f8d480c45a4a7687e55d3c0e827ab706b Mon Sep 17 00:00:00 2001 From: The Stranjer <791672+TheStranjer@users.noreply.github.com> Date: Tue, 22 Mar 2022 14:02:07 -0600 Subject: [PATCH 1/2] Fix Math.gini_coefficient(array) --- lib/standard/facets/math/gini_coefficient.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 From 6ef8e63b9f71977c5b7e46f3cd229e0d8977dc36 Mon Sep 17 00:00:00 2001 From: The Stranjer <791672+TheStranjer@users.noreply.github.com> Date: Tue, 22 Mar 2022 14:14:36 -0600 Subject: [PATCH 2/2] Bump version --- .index | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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