diff --git a/KRKNN.podspec b/KRKNN.podspec new file mode 100644 index 0000000..15ec4ac --- /dev/null +++ b/KRKNN.podspec @@ -0,0 +1,18 @@ +Pod::Spec.new do |s| + s.name = "KRKNN" + s.version = "1.0.0" + s.summary = "k-Nearest Neighbor that classficiation method on Machine Learning." + s.description = <<-DESC + Machine Learning (マシンラーニング) in this project, it implemented KNN(k-Nearest Neighbor) that classification method. It can be used on products recommendation (おすすめの商品), user behavior analysis (ユーザーの行動分析), data mining (データマイニング) and data analysis (データ分析). + DESC + s.homepage = "https://github.com/Kalvar/ios-KRKNN" + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { "Kalvar Lin" => "ilovekalvar@gmail.com" } + s.social_media_url = "https://twitter.com/ilovekalvar" + s.source = { :git => "https://github.com/Kalvar/ios-KRKNN.git", :tag => s.version.to_s } + s.platform = :ios, '7.0' + s.requires_arc = true + s.public_header_files = 'ML/**/*.h' + s.source_files = 'ML/**/*.{h,m}' + s.frameworks = 'Foundation' +end diff --git a/KRKNN.xcodeproj/project.pbxproj b/KRKNN.xcodeproj/project.pbxproj new file mode 100644 index 0000000..e5c6d22 --- /dev/null +++ b/KRKNN.xcodeproj/project.pbxproj @@ -0,0 +1,449 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 8E7D0B721B9316B9003C6C50 /* KRKNN.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E7D0B711B9316B9003C6C50 /* KRKNN.m */; }; + 8EA233A41B8C92E3007F03E2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA233A31B8C92E3007F03E2 /* main.m */; }; + 8EA233A71B8C92E3007F03E2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA233A61B8C92E3007F03E2 /* AppDelegate.m */; }; + 8EA233AA1B8C92E3007F03E2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA233A91B8C92E3007F03E2 /* ViewController.m */; }; + 8EA233AD1B8C92E3007F03E2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8EA233AB1B8C92E3007F03E2 /* Main.storyboard */; }; + 8EA233AF1B8C92E3007F03E2 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8EA233AE1B8C92E3007F03E2 /* Images.xcassets */; }; + 8EA233B21B8C92E3007F03E2 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8EA233B01B8C92E3007F03E2 /* LaunchScreen.xib */; }; + 8EA233BE1B8C92E4007F03E2 /* KRKNNTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EA233BD1B8C92E4007F03E2 /* KRKNNTests.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 8EA233B81B8C92E4007F03E2 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8EA233961B8C92E3007F03E2 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8EA2339D1B8C92E3007F03E2; + remoteInfo = KRKNN; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 8E7D0B701B9316A9003C6C50 /* KRKNN.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRKNN.h; sourceTree = ""; }; + 8E7D0B711B9316B9003C6C50 /* KRKNN.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KRKNN.m; sourceTree = ""; }; + 8E7D0B731B931CD4003C6C50 /* KRKNN+Definitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KRKNN+Definitions.h"; sourceTree = ""; }; + 8EA2339E1B8C92E3007F03E2 /* KRKNN.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KRKNN.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 8EA233A21B8C92E3007F03E2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 8EA233A31B8C92E3007F03E2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 8EA233A51B8C92E3007F03E2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 8EA233A61B8C92E3007F03E2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 8EA233A81B8C92E3007F03E2 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 8EA233A91B8C92E3007F03E2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 8EA233AC1B8C92E3007F03E2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 8EA233AE1B8C92E3007F03E2 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 8EA233B11B8C92E3007F03E2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + 8EA233B71B8C92E4007F03E2 /* KRKNNTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KRKNNTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 8EA233BC1B8C92E4007F03E2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 8EA233BD1B8C92E4007F03E2 /* KRKNNTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KRKNNTests.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8EA2339B1B8C92E3007F03E2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8EA233B41B8C92E4007F03E2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 8E7D0B6C1B93166F003C6C50 /* ML */ = { + isa = PBXGroup; + children = ( + 8E7D0B731B931CD4003C6C50 /* KRKNN+Definitions.h */, + 8E7D0B701B9316A9003C6C50 /* KRKNN.h */, + 8E7D0B711B9316B9003C6C50 /* KRKNN.m */, + ); + path = ML; + sourceTree = ""; + }; + 8EA233951B8C92E3007F03E2 = { + isa = PBXGroup; + children = ( + 8E7D0B6C1B93166F003C6C50 /* ML */, + 8EA233A01B8C92E3007F03E2 /* KRKNN */, + 8EA233BA1B8C92E4007F03E2 /* KRKNNTests */, + 8EA2339F1B8C92E3007F03E2 /* Products */, + ); + sourceTree = ""; + }; + 8EA2339F1B8C92E3007F03E2 /* Products */ = { + isa = PBXGroup; + children = ( + 8EA2339E1B8C92E3007F03E2 /* KRKNN.app */, + 8EA233B71B8C92E4007F03E2 /* KRKNNTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 8EA233A01B8C92E3007F03E2 /* KRKNN */ = { + isa = PBXGroup; + children = ( + 8EA233A51B8C92E3007F03E2 /* AppDelegate.h */, + 8EA233A61B8C92E3007F03E2 /* AppDelegate.m */, + 8EA233A81B8C92E3007F03E2 /* ViewController.h */, + 8EA233A91B8C92E3007F03E2 /* ViewController.m */, + 8EA233AB1B8C92E3007F03E2 /* Main.storyboard */, + 8EA233AE1B8C92E3007F03E2 /* Images.xcassets */, + 8EA233B01B8C92E3007F03E2 /* LaunchScreen.xib */, + 8EA233A11B8C92E3007F03E2 /* Supporting Files */, + ); + path = KRKNN; + sourceTree = ""; + }; + 8EA233A11B8C92E3007F03E2 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 8EA233A21B8C92E3007F03E2 /* Info.plist */, + 8EA233A31B8C92E3007F03E2 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 8EA233BA1B8C92E4007F03E2 /* KRKNNTests */ = { + isa = PBXGroup; + children = ( + 8EA233BD1B8C92E4007F03E2 /* KRKNNTests.m */, + 8EA233BB1B8C92E4007F03E2 /* Supporting Files */, + ); + path = KRKNNTests; + sourceTree = ""; + }; + 8EA233BB1B8C92E4007F03E2 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 8EA233BC1B8C92E4007F03E2 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8EA2339D1B8C92E3007F03E2 /* KRKNN */ = { + isa = PBXNativeTarget; + buildConfigurationList = 8EA233C11B8C92E4007F03E2 /* Build configuration list for PBXNativeTarget "KRKNN" */; + buildPhases = ( + 8EA2339A1B8C92E3007F03E2 /* Sources */, + 8EA2339B1B8C92E3007F03E2 /* Frameworks */, + 8EA2339C1B8C92E3007F03E2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = KRKNN; + productName = KRKNN; + productReference = 8EA2339E1B8C92E3007F03E2 /* KRKNN.app */; + productType = "com.apple.product-type.application"; + }; + 8EA233B61B8C92E4007F03E2 /* KRKNNTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 8EA233C41B8C92E4007F03E2 /* Build configuration list for PBXNativeTarget "KRKNNTests" */; + buildPhases = ( + 8EA233B31B8C92E4007F03E2 /* Sources */, + 8EA233B41B8C92E4007F03E2 /* Frameworks */, + 8EA233B51B8C92E4007F03E2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 8EA233B91B8C92E4007F03E2 /* PBXTargetDependency */, + ); + name = KRKNNTests; + productName = KRKNNTests; + productReference = 8EA233B71B8C92E4007F03E2 /* KRKNNTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 8EA233961B8C92E3007F03E2 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0640; + ORGANIZATIONNAME = "Kalvar Lin"; + TargetAttributes = { + 8EA2339D1B8C92E3007F03E2 = { + CreatedOnToolsVersion = 6.4; + }; + 8EA233B61B8C92E4007F03E2 = { + CreatedOnToolsVersion = 6.4; + TestTargetID = 8EA2339D1B8C92E3007F03E2; + }; + }; + }; + buildConfigurationList = 8EA233991B8C92E3007F03E2 /* Build configuration list for PBXProject "KRKNN" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 8EA233951B8C92E3007F03E2; + productRefGroup = 8EA2339F1B8C92E3007F03E2 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8EA2339D1B8C92E3007F03E2 /* KRKNN */, + 8EA233B61B8C92E4007F03E2 /* KRKNNTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8EA2339C1B8C92E3007F03E2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8EA233AD1B8C92E3007F03E2 /* Main.storyboard in Resources */, + 8EA233B21B8C92E3007F03E2 /* LaunchScreen.xib in Resources */, + 8EA233AF1B8C92E3007F03E2 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8EA233B51B8C92E4007F03E2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8EA2339A1B8C92E3007F03E2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8EA233AA1B8C92E3007F03E2 /* ViewController.m in Sources */, + 8EA233A71B8C92E3007F03E2 /* AppDelegate.m in Sources */, + 8E7D0B721B9316B9003C6C50 /* KRKNN.m in Sources */, + 8EA233A41B8C92E3007F03E2 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8EA233B31B8C92E4007F03E2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8EA233BE1B8C92E4007F03E2 /* KRKNNTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 8EA233B91B8C92E4007F03E2 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 8EA2339D1B8C92E3007F03E2 /* KRKNN */; + targetProxy = 8EA233B81B8C92E4007F03E2 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 8EA233AB1B8C92E3007F03E2 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 8EA233AC1B8C92E3007F03E2 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 8EA233B01B8C92E3007F03E2 /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + 8EA233B11B8C92E3007F03E2 /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 8EA233BF1B8C92E4007F03E2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.4; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 8EA233C01B8C92E4007F03E2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.4; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 8EA233C21B8C92E4007F03E2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = KRKNN/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 8EA233C31B8C92E4007F03E2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = KRKNN/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 8EA233C51B8C92E4007F03E2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = KRKNNTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KRKNN.app/KRKNN"; + }; + name = Debug; + }; + 8EA233C61B8C92E4007F03E2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + INFOPLIST_FILE = KRKNNTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KRKNN.app/KRKNN"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 8EA233991B8C92E3007F03E2 /* Build configuration list for PBXProject "KRKNN" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8EA233BF1B8C92E4007F03E2 /* Debug */, + 8EA233C01B8C92E4007F03E2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 8EA233C11B8C92E4007F03E2 /* Build configuration list for PBXNativeTarget "KRKNN" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8EA233C21B8C92E4007F03E2 /* Debug */, + 8EA233C31B8C92E4007F03E2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 8EA233C41B8C92E4007F03E2 /* Build configuration list for PBXNativeTarget "KRKNNTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8EA233C51B8C92E4007F03E2 /* Debug */, + 8EA233C61B8C92E4007F03E2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 8EA233961B8C92E3007F03E2 /* Project object */; +} diff --git a/KRKNN.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/KRKNN.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..7853c6a --- /dev/null +++ b/KRKNN.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/KRKNN/AppDelegate.h b/KRKNN/AppDelegate.h new file mode 100644 index 0000000..bd5762e --- /dev/null +++ b/KRKNN/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// KRKNN +// +// Created by Kalvar Lin on 2015/8/25. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/KRKNN/AppDelegate.m b/KRKNN/AppDelegate.m new file mode 100644 index 0000000..1e5f158 --- /dev/null +++ b/KRKNN/AppDelegate.m @@ -0,0 +1,45 @@ +// +// AppDelegate.m +// KRKNN +// +// Created by Kalvar Lin on 2015/8/25. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/KRKNN/Base.lproj/LaunchScreen.xib b/KRKNN/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..425ab89 --- /dev/null +++ b/KRKNN/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KRKNN/Base.lproj/Main.storyboard b/KRKNN/Base.lproj/Main.storyboard new file mode 100644 index 0000000..d912f9d --- /dev/null +++ b/KRKNN/Base.lproj/Main.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KRKNN/Images.xcassets/AppIcon.appiconset/Contents.json b/KRKNN/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..118c98f --- /dev/null +++ b/KRKNN/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,38 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/KRKNN/Info.plist b/KRKNN/Info.plist new file mode 100644 index 0000000..ab84602 --- /dev/null +++ b/KRKNN/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.kalvar.knn.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/KRKNN/ViewController.h b/KRKNN/ViewController.h new file mode 100644 index 0000000..b02235a --- /dev/null +++ b/KRKNN/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// KRKNN +// +// Created by Kalvar Lin on 2015/8/25. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/KRKNN/ViewController.m b/KRKNN/ViewController.m new file mode 100644 index 0000000..afc6f1d --- /dev/null +++ b/KRKNN/ViewController.m @@ -0,0 +1,69 @@ +// +// ViewController.m +// KRKNN +// +// Created by Kalvar Lin on 2015/8/25. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import "ViewController.h" +#import "KRKNN.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + KRKNN *_knn = [KRKNN sharedInstance]; + + // Features are wording appeared times on a paper as below like : + // Apple, OS, Mobile, Taiwan, Japan, Developer + [_knn addFeatures:@[@20, @9, @1, @3, @6, @2] + group:@"Apple Fans" + identifier:@"Smith"]; + + [_knn addFeatures:@[@52, @32, @18, @7, @0, @1] + group:@"Apple Fans" + identifier:@"John"]; + + [_knn addFeatures:@[@2, @20, @15, @5, @9, @16] + group:@"Linux Fans" + identifier:@"James"]; + + [_knn addFeatures:@[@7, @11, @2, @12, @1, @0] + group:@"Linux Fans" + identifier:@"Terry"]; + + [_knn addFeatures:@[@20, @8, @3, @21, @8, @25] + group:@"Android Fans" + identifier:@"Sam"]; + + [_knn addFeatures:@[@2, @30, @8, @6, @33, @29] + group:@"Android Fans" + identifier:@"Amy"]; + + [_knn classifyFeatures:@[@20, @1, @10, @2, @12, @3] + identifier:@"Bob" + kNeighbor:3 + completion:^(BOOL success, NSString *ownGroup, NSInteger groupCounts, NSDictionary *allData) { + if( success ) + { + NSLog(@"ownGroup : %@", ownGroup); + NSLog(@"groupCounts : %li", groupCounts); + NSLog(@"allData : %@", allData); + } + }]; + +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + +} + +@end diff --git a/KRKNN/main.m b/KRKNN/main.m new file mode 100644 index 0000000..ab48247 --- /dev/null +++ b/KRKNN/main.m @@ -0,0 +1,16 @@ +// +// main.m +// KRKNN +// +// Created by Kalvar Lin on 2015/8/25. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/KRKNNTests/Info.plist b/KRKNNTests/Info.plist new file mode 100644 index 0000000..d643a15 --- /dev/null +++ b/KRKNNTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.kalvar.knn.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/KRKNNTests/KRKNNTests.m b/KRKNNTests/KRKNNTests.m new file mode 100644 index 0000000..8f1d146 --- /dev/null +++ b/KRKNNTests/KRKNNTests.m @@ -0,0 +1,40 @@ +// +// KRKNNTests.m +// KRKNNTests +// +// Created by Kalvar Lin on 2015/8/25. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import +#import + +@interface KRKNNTests : XCTestCase + +@end + +@implementation KRKNNTests + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testExample { + // This is an example of a functional test case. + XCTAssert(YES, @"Pass"); +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 index e408024..988ccc9 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,4 @@ -The MIT License (MIT) - -Copyright (c) 2015 Kuo-Ming Lin +Copyright (c) 2015 Kuo-Ming Lin (http://kalvar-kaki.blogspot.tw/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,14 +7,16 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +... bla bla ... +Just up to you, I don't care what you wanna do. \ No newline at end of file diff --git a/ML/KRKNN+Definitions.h b/ML/KRKNN+Definitions.h new file mode 100644 index 0000000..bd299de --- /dev/null +++ b/ML/KRKNN+Definitions.h @@ -0,0 +1,11 @@ +// +// KRKNN+Definitions.h +// KRKNN +// +// Created by Kalvar Lin on 2015/8/30. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +static NSString *unknown = @"Unknown"; +static NSString *identifierKey = @"identifier"; +static NSString *distanceKey = @"distance"; \ No newline at end of file diff --git a/ML/KRKNN.h b/ML/KRKNN.h new file mode 100644 index 0000000..d680408 --- /dev/null +++ b/ML/KRKNN.h @@ -0,0 +1,27 @@ +// +// KRKNN.h +// KRKNN +// +// Created by Kalvar Lin on 2015/8/30. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import + +typedef void(^KRKNNCompletion)(BOOL success, NSString *ownGroup, NSInteger groupCounts, NSDictionary *allData); + +@interface KRKNN : NSObject + +@property (nonatomic, strong) NSMutableDictionary *allData; +@property (nonatomic, strong) NSMutableDictionary *trainingSets; +@property (nonatomic, strong) NSMutableDictionary *trainingGroups; +@property (nonatomic, copy) KRKNNCompletion completion; + ++(instancetype)sharedInstance; +-(instancetype)init; + +-(void)addFeatures:(NSArray *)_features group:(NSString *)_group identifier:(NSString *)_identifier; +-(void)classifyFeatures:(NSArray *)_features identifier:(NSString *)_identifier kNeighbor:(NSInteger)_kNeighbor completion:(KRKNNCompletion)_doCompletion; + + +@end \ No newline at end of file diff --git a/ML/KRKNN.m b/ML/KRKNN.m new file mode 100644 index 0000000..ce12ab1 --- /dev/null +++ b/ML/KRKNN.m @@ -0,0 +1,177 @@ +// +// KRKNN.m +// KRKNN +// +// Created by Kalvar Lin on 2015/8/30. +// Copyright (c) 2015年 Kalvar Lin. All rights reserved. +// + +#import "KRKNN.h" +#import "KRKNN+Definitions.h" + +@interface KRKNN () + +@end + +@implementation KRKNN (fixCalculations) + +// Calculated by Cosine Similarity method. +-(float)_sumClassifiedFeatures:(NSArray *)_classifiedFeatures trainFeatures:(NSArray *)_trainFeatures +{ + float _sumA = 0.0f; + float _sumB = 0.0f; + float _sumAB = 0.0f; + int _index = 0; + for( NSNumber *_featureValue in _classifiedFeatures ) + { + NSNumber *_trainValue = [_trainFeatures objectAtIndex:_index]; + float _aValue = [_featureValue floatValue]; + float _bValue = [_trainValue floatValue]; + _sumA += ( _aValue * _aValue ); + _sumB += ( _bValue * _bValue ); + _sumAB += ( _aValue * _bValue ); + ++_index; + } + return ( _sumAB / sqrtf( _sumA * _sumB ) ); +} + +-(void)_addClassifiedSetsAtFeatures:(NSArray *)_features group:(NSString *)_group identifier:(NSString *)_identifier +{ + [self.trainingSets setObject:[_features copy] forKey:_identifier]; + [self.trainingGroups setObject:[_group copy] forKey:_identifier]; + [self.allData setObject:@[_group, _identifier, _features] forKey:_identifier]; +} + +@end + +@implementation KRKNN + ++(instancetype)sharedInstance +{ + static dispatch_once_t pred; + static KRKNN *_object = nil; + dispatch_once(&pred, ^ + { + _object = [[KRKNN alloc] init]; + }); + return _object; +} + +-(instancetype)init +{ + self = [super init]; + if( self ) + { + _trainingSets = [NSMutableDictionary new]; + _trainingGroups = [NSMutableDictionary new]; + _allData = [NSMutableDictionary new]; + } + return self; +} + +#pragma --mark Creates Training Sets +// Adding the training sets be the basic patterns to do classfication. +// @param _group means the training-sets own to which group. +-(void)addFeatures:(NSArray *)_features group:(NSString *)_group identifier:(NSString *)_identifier +{ + if( nil == _features || [_features count] < 1 ) + { + return; + } + + if( nil == _group || [_group length] < 1 ) + { + _group = unknown; + } + + if( nil == _identifier || [_identifier length] < 1 ) + { + _identifier = [NSString stringWithFormat:@"%@%li", unknown, [_trainingSets count]]; + } + + // Uses key/value to make the basic training-sets, one key for one point on the hyperplane of classification. + [self _addClassifiedSetsAtFeatures:_features + group:_group + identifier:_identifier]; +} + +-(void)classifyFeatures:(NSArray *)_features identifier:(NSString *)_identifier kNeighbor:(NSInteger)_kNeighbor completion:(KRKNNCompletion)_doCompletion +{ + if( nil == _features || [_features count] < 1 ) + { + return; + } + + if( nil == _trainingSets || [_trainingSets count] < 1 ) + { + return; + } + + if( nil == _identifier || [_identifier length] < 1 ) + { + _identifier = [NSString stringWithFormat:@"%@%li", unknown, [_trainingSets count] + 1]; + } + + NSMutableArray *_sorts = [NSMutableArray new]; + NSString *_idKey = identifierKey; + NSString *_distanceKey = distanceKey; + // Catchs every feature + for( NSArray *_classifiedId in _trainingSets ) + { + float _distance = [self _sumClassifiedFeatures:[_trainingSets objectForKey:_classifiedId] trainFeatures:_features]; + [_sorts addObject:@{_idKey : _classifiedId, _distanceKey : [NSNumber numberWithFloat:_distance]}]; + } + + // Sorting by DESC + NSSortDescriptor *_sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:_distanceKey ascending:NO]; + NSArray *_sortedGroups = [_sorts sortedArrayUsingDescriptors:[NSArray arrayWithObject:_sortDescriptor]]; + + // Catchs K neighbors + NSMutableDictionary *_countingGroups = [NSMutableDictionary new]; + NSInteger _maxCounting = 0; + NSString *_ownGroup = @""; + BOOL _success = NO; + NSInteger _k = 0; + for( NSDictionary *_neighbors in _sortedGroups ) + { + // Its own which group + NSString *_classifiedGrop = [_trainingGroups objectForKey:[_neighbors objectForKey:_idKey]]; + // Counting the group types + NSNumber *_times = [_countingGroups objectForKey:_classifiedGrop]; + NSInteger _counting = 1; + if( nil != _times ) + { + _counting += [_times integerValue]; + } + + if( _counting > _maxCounting ) + { + _maxCounting = _counting; + _ownGroup = _classifiedGrop; + } + + [_countingGroups setObject:[NSNumber numberWithInteger:_counting] forKey:_classifiedGrop]; + + ++_k; + if( _k >= _kNeighbor ) + { + break; + } + } + + if( _maxCounting > 0 ) + { + _success = YES; + [self _addClassifiedSetsAtFeatures:_features + group:_ownGroup + identifier:_identifier]; + } + + if( _doCompletion ) + { + _doCompletion(_success, _ownGroup, _maxCounting, _allData); + } + +} + +@end \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..1a2230f --- /dev/null +++ b/README.md @@ -0,0 +1,75 @@ +ios-KRKNN +================= + +Machine Learning (マシンラーニング) in this project, it implemented KNN(k-Nearest Neighbor) that classification method. It can be used on products recommendation (おすすめの商品), user behavior analysis (ユーザーの行動分析), data mining (データマイニング) and data analysis (データ分析). + +#### Podfile + +```ruby +platform :ios, '7.0' +pod "KRKNN", "~> 1.0.0" +``` + +## How to use + +``` objective-c +#import "KRKNN.h" + +@implementation ViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + KRKNN *_knn = [KRKNN sharedInstance]; + + // Features are wording appeared times on a paper as below like : + // Apple, OS, Mobile, Taiwan, Japan, Developer + [_knn addFeatures:@[@20, @9, @1, @3, @6, @2] + group:@"Apple Fans" + identifier:@"Smith"]; + + [_knn addFeatures:@[@52, @32, @18, @7, @0, @1] + group:@"Apple Fans" + identifier:@"John"]; + + [_knn addFeatures:@[@2, @20, @15, @5, @9, @16] + group:@"Linux Fans" + identifier:@"James"]; + + [_knn addFeatures:@[@7, @11, @2, @12, @1, @0] + group:@"Linux Fans" + identifier:@"Terry"]; + + [_knn addFeatures:@[@20, @8, @3, @21, @8, @25] + group:@"Android Fans" + identifier:@"Sam"]; + + [_knn addFeatures:@[@2, @30, @8, @6, @33, @29] + group:@"Android Fans" + identifier:@"Amy"]; + + [_knn classifyFeatures:@[@20, @1, @10, @2, @12, @3] + identifier:@"Bob" + kNeighbor:3 + completion:^(BOOL success, NSString *ownGroup, NSInteger groupCounts, NSDictionary *allData) { + if( success ) + { + NSLog(@"ownGroup : %@", ownGroup); + NSLog(@"groupCounts : %li", groupCounts); + NSLog(@"allData : %@", allData); + } + }]; + +} + +@end +``` + +## Version + +V1.0.0 + +## License + +MIT.