Demo entry 6362718

competition

   

Submitted by anonymous on May 10, 2017 at 08:45
Language: Matlab. Code size: 859 Bytes.

load('test3_train_w.mat')
alpha = 0.1;    %学习率
tor = 0.0000001; %收敛条件
%输入向量归一化
inputs = train_inputs';
for i = 1:1:7
    inputs(:,i) = inputs(:,i) / norm(inputs(:,i));
end    
wtemp = zeros(7,8);
for i = 1:1:100
    for p = inputs
        a = compet(w*p);
        for j = 1:1:7
            if a(j) == 1
                break
            end
        end
        %更新权值
        w(j,:) = w(j,:) + alpha*(p'-w(j,:));
    end
    %记录第一次及第十次权值
    if i ==1 
         w1 = roundn(w,-3);
    elseif i ==10
        w10 = roundn(w,-3);
    end
    %满足收敛条件退出循环
    e = wtemp - w;
    E = var(e(:));
    if E < tor
        break
    else
        wtemp = w;
    end
end
%测试样本分类
test = [0.625,1.75,1.875,0.5,-0.375,-1.5,-13.5,-0.875;1,2.375,1.5,0.375,-0.25,-4.875,-4.125,-0.25]';
for in = test
    a = compet(w*in);
    disp(a);
end

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).