signed

QiShunwang

“诚信为本、客户至上”

是基于局部和全局一致性算法对双月数据进行分类

2021/6/9 4:38:25   来源:

function test
load 2moons;
Y = produce_labelY(y);
%{
for alpha = 0 : 0.1 : 1.0
    for sigma = 1.5 : 0.1 : 2.5;
       LGC(x, Y, sigma, alpha);
    end
end
%}

%{
for sigma = 0.05 : 0.01 : 0.20
LGC(x, Y, sigma, 0.9);
end
%}

%for alpha = 0.0 : 0.1 : 0.9
%{
for alpha = 0.9 : 0.01 : 0.99
LGC(x, Y, 0.11, alpha);
end
%}

%{
for sigma = 0.05 : 0.005 : 0.09
LGC(x, Y, sigma, 0.99);
end
%}

%{
min_error = 200;
best_s = 0;
best_a = 0;
for sigma = 0 : 0.005 : 0.1
    for alpha = 0.9 : 0.01 : 0.99
        error_number = LGC(x, Y, -y, sigma, alpha, 0);
        if error_number < min_error
            min_error = error_number;
            best_s = sigma;
            best_a = alpha;
        end
    end
end
error_number = LGC(x, Y, -y, best_s, best_a, 1);
%}

% The last proper parameter tuning

min_error = 200;
best_s = 0;
best_a = 0;
for sigma = 0.07 : 0.001 : 0.08
    for alpha = 0.95 : 0.001 : 0.999
        %error_number = LGC(x, Y, -y, sigma, alpha, 0, 1);
        error_number = LGC(x, Y, -y, sigma, alpha, 0, 0);
        if error_number < min_error
            min_error = error_number;
            best_s = sigma;
            best_a = alpha;
        end
    end
end
error_number = LGC(x, Y, -y, best_s, best_a, 1, 0)


%error_rate = LGC(x, Y, -y, 0.07, 0.996, 1, 0);


function Y = produce_labelY(y)
n = size(y, 1);
Y = zeros(n, 2);
%{
label_number = 40;
index = find(y == 1);
Y( index(find(index <= label_number)), 1) = 1;
index = find(y == -1);
Y( index(find(index <= label_number)), 2) = 1;
%}

Y(53, 1) = 1;      %Positive example
Y(143, 2) = 1;     %Active exampl