Skip to content

Commit 1f0fd28

Browse files
committed
Updated V2.3
Added Cosine Similarity method to do Multi-Dimensional clustering.
1 parent 75febb3 commit 1f0fd28

File tree

14 files changed

+219
-84
lines changed

14 files changed

+219
-84
lines changed

KRKmeans.xcodeproj/project.xcworkspace/xcshareddata/KRKmeans.xccheckout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<key>IDESourceControlProjectIdentifier</key>
88
<string>E57A2907-A074-4106-B530-22DF2BC0D9E7</string>
99
<key>IDESourceControlProjectName</key>
10-
<string>KRKmeans</string>
10+
<string>project</string>
1111
<key>IDESourceControlProjectOriginsDictionary</key>
1212
<dict>
1313
<key>0FD47910F037E012AA6F179F93F7DFEC0BB80E7B</key>
1414
<string>https://github.com/Kalvar/ios-KRKmeans-Algorithm.git</string>
1515
</dict>
1616
<key>IDESourceControlProjectPath</key>
17-
<string>KRKmeans.xcodeproj</string>
17+
<string>KRKmeans.xcodeproj/project.xcworkspace</string>
1818
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
1919
<dict>
2020
<key>0FD47910F037E012AA6F179F93F7DFEC0BB80E7B</key>

KRKmeans/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// AppDelegate.h
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.

KRKmeans/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// AppDelegate.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.

KRKmeans/ViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ViewController.h
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.

KRKmeans/ViewController.m

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

KRKmeans/main.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// main.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.

KRKmeansTests/KRKmeansTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// KRKmeans V2.1Tests.m
3-
// KRKmeans V2.1Tests
2+
// KRKmeans V2.3Tests.m
3+
// KRKmeans V2.3Tests
44
//
55
// Created by Kalvar on 2014/6/29.
66
// Copyright (c) 2014 - 2015年 Kalvar Lin, [email protected]. All rights reserved.

ML/KRKmeans.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// KRKmeans.h
3-
// KRKmeans V2.1
3+
// KRKmeans V2.3
44
//
55
// Created by Kalvar on 2014/6/30.
66
// Copyright (c) 2014 - 2015年 Kalvar Lin, [email protected]. All rights reserved.
@@ -49,15 +49,14 @@ typedef void(^KRKmeansClusteringCompletion)(BOOL success, NSArray *clusters, NSA
4949
*/
5050
typedef void(^KRKmeansEachGeneration)(NSInteger times, NSArray *clusters, NSArray *centers);
5151

52-
5352
@interface KRKmeans : NSObject
5453

5554
//要訓練分群用的集合樣本
5655
@property (nonatomic, strong) NSMutableArray *sets;
5756
//每一群的中心點
5857
@property (nonatomic, strong) NSMutableArray *centers;
5958
//要分群的集合數據
60-
@property (nonatomic, strong) NSArray *patterns;
59+
@property (nonatomic, strong) NSMutableArray *patterns;
6160
//分群結果
6261
@property (nonatomic, strong) NSMutableArray *results;
6362
//收斂誤差

0 commit comments

Comments
 (0)