File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change 1616];
1717
1818// create a 2-dimentions space
19- $ space = new Kmeans \Space (2 );
19+ $ space = new Kmeans \Euclidean \ Space (2 );
2020
2121// prepare the points
22- $ points = new Kmeans \PointCollection ($ space );
23-
24- foreach ($ data as $ coordinates ) {
25- $ points ->attach (new Kmeans \Point ($ space , $ coordinates ));
26- }
22+ $ points = new Kmeans \PointCollection ($ space , array_map ([$ space , 'makePoint ' ], $ data ));
2723
2824// prepare the algorithm
29- $ algorithm = new Kmeans \Algorithm (new Kmeans \RandomInitialization ());
25+ $ algorithm = new Kmeans \Euclidean \ Algorithm (new Kmeans \RandomInitialization ());
3026
3127// cluster these 50 points in 3 clusters
3228$ clusters = $ algorithm ->clusterize ($ points , 3 );
3329
3430// display the cluster centers and attached points
3531foreach ($ clusters as $ num => $ cluster ) {
3632 $ coordinates = $ cluster ->getCentroid ()->getCoordinates ();
33+ assert (is_int ($ num ));
3734 printf (
3835 "Cluster #%s [%d,%d] has %d points \n" ,
3936 $ num ,
You can’t perform that action at this time.
0 commit comments