SOFM-Matlab实例

run.m

% sofm网络会进行数据的聚类分析,
% 比如说使用newsom([-1 1; -1 1],[5 6])
% 会产生5x6=30个集合点

% 把大的程序拆成很多个小的程序是一个很好的习惯

close all;clear;clc

% P=rands(2,100);
A_define; % define a "Nx2" matrix
P=A';
% P=[rands(2,50)*0.2+0.6, rands(2,50)*0.1-0.6];
plot(P(1,:),P(2,:),'+r')

net=newsom([min(P(1,:)) max(P(1,:)); min(P(2,:)) max(P(2,:))],[2 1]);
w1_init=net.iw{1,1};

figure
plotsom(w1_init,net.layers{1}.distances)
title('初始权值分布图')

% 训练一个神经网络
for i=100:30:100
    net.trainParam.epochs=i;
    net=train(net,P);
    figure;
    plotsom(net.iw{1,1},net.layers{1}.distances)
end

% 网络测试与应用
find(sim(net,[0.3072;0.7490])==1)


colorit;

colorit.m

% color original point by its class:
point_class=net.iw{1,1};
figure
hold on
num1=0;
num2=0;
for i=1:size(P,2)
    dis=inf;
    for j=1:size(point_class,1)
        now_dis=sqrt( (P(1,i)-point_class(j,1))^2+(P(2,i)-point_class(j,2))^2 );
        if now_dis<dis
            dis=now_dis;
            class=j;
        end
    end
    if class==1
        plot(P(1,i),P(2,i),'r+');
        num1=num1+1;
    elseif class==2
        plot(P(1,i),P(2,i),'g+');
        num2=num2+1;
    elseif  class==3
        plot(P(1,i),P(2,i),'b+');
    end
end
hold off
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

inksci

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值