KRSVM 1.0.0

KRSVM 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2015 年 12 月

Kalvar Lin 更新。



KRSVM 1.0.0

关于

KRSVM 实现了机器学习的 SVM。

Podfile

platform :ios, '7.0'
pod "KRSVM", "~> 1.0.0"

如何开始

导入

#import "KRSVM.h"

使用 SMO

KRSMO *smo = [[KRSVM sharedSVM] useSMO];

使用线性核函数

[smo.kernel useLinear];

使用 RBF 核函数

sigma 可以根据您的意愿进行定制,默认值为 2.0,但有些论文提到 0.5、1.0、3.0、5.0 都可以用于训练。无论如何,请尝试,别无他法。

[smo.kernel useRBF];
smo.kernel.sigma = 2.0f;

使用切线(tanh)核函数

切线的 alpha 可以根据您的意愿进行定制,默认值是 1.0,但在某些情况下,使用 2.0 可能更好,在此示例中,我们使用了 0.8 来进行回归。

[smo.kernel useTangent];
smo.kernel.alpha = 0.8f;

训练样本

smo.toleranceError = 0.001f;
smo.maxIteration   = 1000;
smo.constValue     = 1;
[smo.kernel useLinear];

[smo addPatterns:@[@0.0f, @0.0f] target:-1.0f]; // x1
[smo addPatterns:@[@2.0f, @2.0f] target:-1.0f]; // x2
[smo addPatterns:@[@2.0f, @0.0f] target:1.0f];  // x3
[smo addPatterns:@[@3.0f, @0.0f] target:1.0f];  // x4

// One bias likes a net of neural network
[smo addBias:@0.0f];

// One input value by one weight that likes inputs & weights of neural network
[smo addWeights:@[@0.0f, @0.0f]];

// Setup the groups of classification and the target-value of group
[smo addGroupOfTarget:-1.0f];
[smo addGroupOfTarget:1.0f];

[smo classifyWithPerIteration:^(NSInteger iteration, NSArray *weights, NSArray *biases) {
    //NSLog(@"%li Iteration weights : %@", iteration, weights);
    //NSLog(@"%li Iteration biases : %@", iteration, biases);
} completion:^(BOOL success, NSArray *weights, NSArray *biases, NSDictionary *groups, NSInteger totalIterations) {
    NSLog(@"===============================================");
    NSLog(@"%li Completion weights : %@", totalIterations, weights);
    NSLog(@"%li Completion biases : %@", totalIterations, biases);
    NSLog(@"%li Completion groups : %@", totalIterations, groups);
    NSLog(@"===============================================");
    // Verify & Directly Output
    [smo classifyPatterns:@[@[@2.0f, @2.0f], @[@3.0f, @0.0f]] completion:^(NSArray *weights, NSArray *biases, NSArray *results, NSDictionary *allGroups) {
        for( KRSVMPattern *pattern in results )
        {
            NSLog(@"direct classify to target %@", pattern.classifiedTarget);
        }
        NSLog(@"all groups : %@", allGroups);
    }];
}];

版本

V1.0.0

许可证

MIT。