11//
22// ViewController.m
3- // KRKmeans V2.1
3+ // KRKmeans V2.3
44//
55// Created by Kalvar on 2014/6/29.
66// Copyright (c) 2014 - 2015年 Kalvar Lin, [email protected] . All rights reserved.@@ -51,14 +51,19 @@ - (void)viewDidLoad
5151 KRKmeans *_krKmeans = [KRKmeans sharedKmeans ];
5252 // It means A sets. ( and the centers will be calculated here. )
5353 [_krKmeans addSets: @[@[@1 , @1 ], @[@1 , @2 ], @[@2 , @2 ], @[@3 , @2 ], @[@3 , @1 ]]];
54+
5455 // It means B sets.
5556 [_krKmeans addSets: @[@[@6 , @4 ], @[@7 , @6 ], @[@5 , @6 ], @[@6 , @5 ]]];
57+
5658 // It means C sets and the center.
5759 // [_krKmeans addSets:@[@[@7, @8]]];
60+
5861 // It means D sets.
5962 // [_krKmeans addSets:@[@[@3, @12], @[@5, @20]]];
63+
6064 // It means X sets which wanna be clustered, if you don't setup this, the KRKmeans will cluster the original sets to be new groups.
6165 [_krKmeans addPatterns: @[@[@5 , @4 ], @[@3 , @4 ], @[@2 , @5 ], @[@9 , @8 ], @[@3 , @20 ]]];
66+
6267 [_krKmeans clusteringWithCompletion: ^(BOOL success, NSArray *clusters, NSArray *centers, NSInteger totalTimes)
6368 {
6469 NSLog (@" totalTimes : %li " , totalTimes);
@@ -84,6 +89,26 @@ - (void)viewDidLoad
8489 A Sets : (1, 1) (1, 2) (2, 2) (3, 2) (3, 1) (3, 4) (2, 5) (6, 4) (7, 6) (5, 6) (6, 5) (5, 4)
8590 B Sets : (9, 8) (3, 20)
8691 */
92+
93+ // Multi-Dimensional K-Means
94+ KRKmeans *_multiKmeans = [[KRKmeans alloc ] init ];
95+ [_multiKmeans addSets: @[@[@20 , @9 , @1 , @3 , @6 , @2 ], @[@52 , @32 , @18 , @7 , @0 , @1 ], @[@30 , @18 , @2 , @27 , @18 , @5 ]]];
96+ [_multiKmeans addSets: @[@[@2 , @20 , @15 , @5 , @9 , @16 ], @[@7 , @11 , @2 , @12 , @1 , @0 ]]];
97+
98+ [_multiKmeans addPatterns: @[@[@20 , @1 , @10 , @2 , @12 , @3 ], @[@20 , @8 , @3 , @21 , @8 , @25 ], @[@2 , @30 , @8 , @6 , @33 , @29 ]]];
99+ [_multiKmeans addPatterns: @[@[@10 , @3 , @5 , @12 , @9 , @8 ], @[@2 , @1 , @9 , @30 , @28 , @13 ], @[@22 , @50 , @43 , @22 , @11 , @2 ]]];
100+ [_multiKmeans addPatterns: @[@[@18 , @10 , @20 , @42 , @32 , @13 ], @[@5 , @4 , @28 , @16 , @3 , @9 ]]];
101+
102+ [_multiKmeans clusteringWithCompletion: ^(BOOL success, NSArray *clusters, NSArray *centers, NSInteger totalTimes)
103+ {
104+ NSLog (@" totalTimes : %li " , totalTimes);
105+ NSLog (@" clusters : %@ " , clusters);
106+ NSLog (@" centers : %@ " , centers);
107+ NSLog (@" SSE : %lf " , [_multiKmeans calculateSSE ]);
108+ } eachGeneration: ^(NSInteger times, NSArray *clusters, NSArray *centers)
109+ {
110+ NSLog (@" times : %li " , times);
111+ }];
87112}
88113
89114- (void )didReceiveMemoryWarning
0 commit comments