summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/svm/src/matlab/getAlphaFromTrainSet.m
blob: bd2bec72ff376d7a68d838d6f102576f82ba8d7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [a,b,C,d,dim,e,eps,a_result,b_result,X,tolerance,Y,ret]=getAlphaFromTrainSet(N, d16trn_1, d16trn_2, Iterations)


tolerance=0.001;
C=0.05;
d = -1;
dim=256;
eps=0.001;
a_result=zeros(Iterations,N);
b_result=zeros(Iterations,1);
ret = 0;
Y = 0;

X=usps_read_partial(d16trn_1, d16trn_2,1,1,N/Iterations, Iterations);

for iter=1:Iterations
    Y=usps_read_partial(d16trn_1,d16trn_2,iter,0,N/Iterations, Iterations);
    if iter==1
    fWriteMatrix(Y, './');
    end

    a=zeros(N,1);
    b=0;
    e=zeros(N,1);
    ExamineAll=1;  
    cnt=0;
    NumChanged=0;
    while (NumChanged>0 || ExamineAll == 1)
        cnt=cnt+1;
        NumChanged=0;
        if ExamineAll==1
            for i=1:N
                [a,b,e,ret] = examineExample(i, a, b, C, e, X, Y, tolerance, N, eps, dim);
                NumChanged=NumChanged+ret;
            end
        else
            for i=1:N
                if a(i,1) > 0 && a(i,1) < C
                    [a,b,e,ret] = examineExample(i, a, b, C, e, X, Y, tolerance, N, eps, dim);
                    NumChanged=NumChanged+ret;
                end
            end
        end
        if ExamineAll==1
            ExamineAll=0;
        elseif NumChanged==0 
            ExamineAll=1;
        end
    end
    
    for r = 1:N
        a_result(iter,r) = a(r,1);
    end
    
%    a_result=transpose(a); %KVS: Problem using transpose function here. So wrote the code above
    b_result(iter,1)=b;
end