• 大小: 3KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: Matlab
  • 标签: SOM  分类  代码  

资源简介

Discuss the influence of the following factors (plot the results and quantify the test error and the training error): 1. # of training samples

资源截图

代码片段和文件信息

clc;clear;clf;
load data_D2_C2.mat
%%
% [DNp]=size(p.value);
% for i=1:Np
%     if p.class(i)==1
%         plot(p.value(1i)p.value(2i)‘r.‘);hold on;
%     else
%         plot(p.value(1i)p.value(2i)‘b.‘);hold on;
%     end  
% end

[DNt]=size(t.value);
for i=1:Nt
    if t.class(i)==1
        plot(t.value(1i)t.value(2i)‘r.‘);hold on;
    else
        plot(t.value(1i)t.value(2i)‘b.‘);hold on;
    end  
end

no_neurons1=8;
no_neurons2=8;
total_neurons=no_neurons1*no_neurons2;

samples=10:10:300;

for n=1:30
        ind_rand=randperm (300);  ind =ind_rand(1:samples(n));
        train_data=zeros(2samples(n));
        train_class=zeros(1samples(n));
        for a=1:samples(n)
            train_data(:a)=p.value(:ind(a));
            train_class(a)=p.class(:ind(a));
        end
        
        som1=selforgmap([no_neurons1 no_neurons2]);
        som1=train(som1train_data);
        plotsom(som1.iw{11}som1.layers{1}.distances);

        ynp=sim(som1train_data);
        ynpind=vec2ind(ynp);

n1=zeros(1total_neurons);
n2=zeros(1total_neurons);
for i=1:samples(n)
    if train_class(i)==1
        for j=1:total_neurons
            if ynpind(i)==j
                n1(1j)=n1(1j)+1;
            end   
        end
    else
        for j=1:total_neurons
            if ynpind(i)==j
                n2(1j)=n2(1j)+1;
            end
        end
    end
end 
%observe the va

评论

共有 条评论