[postgis-tickets] r16212 - Fix KMeans initialization issue that lost clusters sometimes.

Darafei komzpa at gmail.com
Tue Jan 2 05:59:19 PST 2018


Author: komzpa
Date: 2018-01-02 05:59:19 -0800 (Tue, 02 Jan 2018)
New Revision: 16212

Modified:
   trunk/NEWS
   trunk/liblwgeom/lwkmeans.c
   trunk/regress/lwgeom_regress.sql
   trunk/regress/lwgeom_regress_expected
Log:
Fix KMeans initialization issue that lost clusters sometimes.

Closes #3965
Closes https://github.com/postgis/postgis/pull/179



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2018-01-02 13:50:12 UTC (rev 16211)
+++ trunk/NEWS	2018-01-02 13:59:19 UTC (rev 16212)
@@ -29,6 +29,8 @@
   - #3097, Really allow MULTILINESTRING blades in ST_Split() (Paul Ramsey)
   - #3942, geojson: Do not include private header for json-c >= 0.13 (Björn Esser)
   - #3954, ST_GeometricMedian now supports point weights (Darafei Praliaskouski)
+  - #3965, ST_ClusterKMeans used to lose some clusters on initialization
+           (Darafei Praliaskouski)
 
 
 PostGIS 2.4.0

Modified: trunk/liblwgeom/lwkmeans.c
===================================================================
--- trunk/liblwgeom/lwkmeans.c	2018-01-02 13:50:12 UTC (rev 16211)
+++ trunk/liblwgeom/lwkmeans.c	2018-01-02 13:59:19 UTC (rev 16212)
@@ -201,6 +201,7 @@
 			if (seen[j] == closest)
 			{
 				closest = (closest + 1) % config.num_objs;
+				j = 0;
 			}
 			else
 			{

Modified: trunk/regress/lwgeom_regress.sql
===================================================================
--- trunk/regress/lwgeom_regress.sql	2018-01-02 13:50:12 UTC (rev 16211)
+++ trunk/regress/lwgeom_regress.sql	2018-01-02 13:59:19 UTC (rev 16212)
@@ -169,3 +169,10 @@
 SELECT 'ST_Angle_2_lines', St_Angle(l1,l2)
 	FROM ST_GeomFromtext('LINESTRING(0 1,0 0)') AS l1
 	, ST_GeomFromtext('LINESTRING(1 0, 2 0)') AS l2 ;
+
+--- ST_ClusterKMeans
+select '#3965', count(distinct cid), count(*) from (
+	with points as (select ST_MakePoint(x,y) geom from generate_series(1,5) x, generate_series(1,5) y)
+  select ST_ClusterKMeans(geom, 25) over () as cid, geom
+  from points) z;
+

Modified: trunk/regress/lwgeom_regress_expected
===================================================================
--- trunk/regress/lwgeom_regress_expected	2018-01-02 13:50:12 UTC (rev 16211)
+++ trunk/regress/lwgeom_regress_expected	2018-01-02 13:59:19 UTC (rev 16212)
@@ -32,3 +32,4 @@
 ERROR:  Operation on mixed SRID geometries
 ERROR:  Empty geometry
 ST_Angle_2_lines|4.71238898038469
+#3965|25|25



More information about the postgis-tickets mailing list