%产生指定类别的样本点,并在图中绘出
X = [0 1; 0 1]; % 限制类中心的范围
clusters = 5; % 指定类别数目
points = 10; % 指定每一类的点的数目
std_dev = 0.05; % 每一类的标准差
P = nngenc(X,clusters,points,std_dev);
plot(P(1,:),P(2,:),'+r');
title('输入样本向量');
xlabel('p(1)');
ylabel('p(2)');
%建立网络
net=newc([0 1;0 1],5,0.1); %设置神经元数目为5
%得到网络权值,并在图上绘出
figure;
plot(P(1,:),P(2,:),'+r');
w=net.iw{1}
hold on;
plot(w(:,1),w(:,2),'ob');
hold off;
title('输入样本向量及初始权值');
xlabel('p(1)');
ylabel('p(2)');
figure;
plot(P(1,:),P(2,:),'+r');
hold on;
%训练网络
net.trainParam.epochs=7;
net=init(net);
net=train(net,P);
%得到训练后的网络权值,并在图上绘出
w=net.iw{1}
plot(w(:,1),w(:,2),'ob');
hold off;
title('输入样本向量及更新后的权值');
xlabel('p(1)');
ylabel('p(2)');
a=0;
p = [0.6 ;0.8];
a=sim(net,p)