From 8e2d86414f99bdc869e34a4267b7271a945d6e8e Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Mon, 8 Jun 2015 15:02:39 -0400 Subject: [PATCH] updating function --- scripts-available/CDB_DistType.sql | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts-available/CDB_DistType.sql b/scripts-available/CDB_DistType.sql index 07f685a..b60eb78 100644 --- a/scripts-available/CDB_DistType.sql +++ b/scripts-available/CDB_DistType.sql @@ -10,9 +10,8 @@ -- 1. width_bucket/histograms: http://tapoueh.org/blog/2014/02/21-PostgreSQL-histogram -- 2. R implementation: https://github.com/cran/agrmt - -CREATE OR REPLACE FUNCTION CDB_ClassTest ( in_array NUMERIC[] ) RETURNS text as $$ -DECLARE +CREATE OR REPLACE FUNCTION CDB_DistType ( in_array NUMERIC[] ) RETURNS text as $$ +DECLARE element_count INT4; minv numeric; maxv numeric; @@ -27,7 +26,7 @@ DECLARE BEGIN SELECT min(e), max(e), count(e) INTO minv, maxv, element_count FROM ( SELECT unnest(in_array) e ) x; - IF abs(maxv - minv) < 1e-7 THEN -- if max and min are nearly equal, call if 'F' + IF abs(maxv - minv) < 1e-7 THEN -- if max and min are nearly equal, call if 'F' (make relative to maxv?) signature = 'F'; ELSE -- Calculate bins and count in bins @@ -39,7 +38,7 @@ BEGIN WHERE e is not null ), hist as ( - SELECT width_bucket(e, s.minv, s.maxv, 6) bucket, + SELECT width_bucket(e, s.minv, s.maxv, 7) bucket, count(*) freq FROM (SELECT unnest($1) e) x, stats s WHERE e is not null