Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KMeans returns less than k clusters of k input points #179

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -14,6 +14,12 @@ addons:

before_install:
- sudo sh -c "echo /usr/lib/libeatmydata/libeatmydata.so >> /etc/ld.so.preload"
- sudo service postgresql stop 9.6
- sudo find /etc -user postgres | xargs sudo chown travis
- sudo find /var -user postgres | xargs sudo chown travis
- sudo usermod -u 1000 postgres
- sudo adduser travis ssl-cert
- sudo service postgresql start 9.6
- sudo add-apt-repository --yes ppa:ubuntugis/ppa
- sudo add-apt-repository --yes ppa:ubuntugis/ubuntugis-unstable
- sudo apt-get update -qq
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -29,6 +29,8 @@ PostGIS 2.5.0
- #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
Expand Down
1 change: 1 addition & 0 deletions liblwgeom/lwkmeans.c
Expand Up @@ -201,6 +201,7 @@ lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k)
if (seen[j] == closest)
{
closest = (closest + 1) % config.num_objs;
j = 0;
}
else
{
Expand Down
7 changes: 7 additions & 0 deletions regress/lwgeom_regress.sql
Expand Up @@ -169,3 +169,10 @@ SELECT 'ST_Angle_empty' , St_Angle(p1,p2,p3,p4)
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;

1 change: 1 addition & 0 deletions regress/lwgeom_regress_expected
Expand Up @@ -32,3 +32,4 @@ ST_Angle_3_pts|1.5707963267949
ERROR: Operation on mixed SRID geometries
ERROR: Empty geometry
ST_Angle_2_lines|4.71238898038469
#3965|25|25