0

Can somebody help me to find the error of not having the following code converge on MATLAB? Please note that k means kernel and has its own function.

I tried to implement it using the algorithm in the picture:

enter image description here

My implementation:

while 1

    num_changed_alphas = 0;
    %step 4
     if (Y .* alphas < B)   
    [Yigi , i_WS] = max(Y .* g)
     end
     %step 5
     if (A < Y .* alphas)   
    [Yjgj , j_WS] = max(Y .* g)
     end
     %step 6
     if ( (Yigi - Yjgj ) <= eps )
         num_changed_alphas = num_changed_alphas + 1;
         break;

     end
     %step 7
     lambda = min (B(i_WS) - Y(i_WS) .* alphas(i_WS), Y(j_WS) .* alphas(j_WS) - A(j_WS) );
     lambda = min (lambda, (Yigi - Yjgj) ./ (K(i_WS,i_WS) + K(j_WS,j_WS) - 2* K(j_WS,i_WS)) );

     g = sum (g - lambda .* Y .* K (:,i_WS) + lambda .* Y .* K (:,j_WS));

     alphas = alphas + Y * lambda;

    fprintf('.');
    dots = dots + 1;
    if dots > 75
        dots = 0;
        fprintf('\n');
    end
    if exist('OCTAVE_VERSION')
        fflush(stdout);
    end
end %while
1
  • The smo tag is for SQL Server Management Objects. I don't think that applies to your question. I removed it, and added a tag for MatLab. Commented Nov 7, 2016 at 17:06

1 Answer 1

1

One big mistake is that

a=f(x) subject to g(x)

does not mean "if g(x) then a=f(x)", but rather "a=f(x) considering only such x's that g(x) is true".

so

if (Y .* alphas < B)   
    [Yigi , i_WS] = max(Y .* g)
end

(as well as next if) is not a valid implementation of operation

i = arg max SOMETHING   subject to CONSTRAINTS

You should do something among the lines of

selected = (Y .* alphas < B) 
[Yigi , i_WS] = max(Y(selected) .* g(selected))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.