竞争网络权值分析

 

 

%竞争网络权值分析
clc;
clear;
P=[0.7071 0.6402 0.000 -0.1961 0.1961 -0.9285 -0.8762 -0.8192;
0.7071 0.7682 -1.000 -0.9806 -0.9806 0.3714 0.4819 0.5735];
S=4;
[R,Q]=size(P);
net=newc(minmax(P),S); %创建竞争网络
% Create a competitive layer
%
% Competitive layers are used to solve classification problems.
% net = newc creates a new network with a dialog box.
% net = newc(PR,S,KLR,CLR) takes these inputs,
% PR -- R x 2 matrix of min and max values for R input elements
% S -- Number of neurons
% KLR -- Kohonen learning rate, default = 0.01
% CLR -- Conscience learning rate, default = 0.001
% and returns a new competitive layer.
net.iw{1,1}=randnr(S,2); %赋归一化后的权值
w1=net.iw{1,1} %输出权值
b1=w1';
%%%%%%%%画圆开始
x=0:0.1:3.1416*2;
plot(sin(x),cos(x));
%%%%%%%%画圆结束
axis('equal')
xlabel('P(1,q)..+ W(i,1)..o')
ylabel('P(2,q) W(i,2)')
hold on
plot(P(1,:),P(2,:),'r+') %画输入状态点
plot(b1(1,:),b1(2,:),'o') %画初始权值点
%%%%%%%%%%%%%画输入点和原点的连线
for i=1:Q
plot([P(1,i) 0],[P(2,i) 0])
end
%%%%%%%%%%%%%画输入点和原点的连线
hold off
% disp('按任一键继续 ')
% pause
%%%%%%%%%%%%%%%%%%网络训练开始
net.trainParam.epochs=320; %最大训练次数
net.trainParam.show=100; %显示间隔
lp.lr=0.05;
net=train(net,P); %训练竞争网络
%%%%%%%%%%%%%%%%%%网络训练结束
w2=net.iw{1,1} %输出训练后的权值
b2=w2';
a=zeros(4,Q)+compet(net.iw{1,1}*P) %输出训练后的结果
% compet is a transfer function.
% Transfer functions calculate a layer's output from its net input.
% compet(N) takes one input argument,
% N - S x Q matrix of net input (column) vectors.
% and returns output vectors with 1
% where each net input vector has its maximum value,
% and 0 elsewhere.
% n = [0; 1; -0.5; 0.5];
% a = compet(n);
% subplot(2,1,1), plot(n), ylabel('n')
% subplot(2,1,2), plot(a), ylabel('a')
% a =
%
% (2,1) 1
x=0:0.1:3.1416*2;
figure(2)
plot(sin(x),cos(x)); %画圆
axis('equal')
xlabel('P(1,q)..+ W(i,1)..o')
ylabel('P(2,q) W(i,2)')
hold on
plot(P(1,:),P(2,:),'r+')
plot(b2(1,:),b2(2,:),'o') %作训练后的权值点
for i=1:Q
plot([P(1,i) 0],[P(2,i) 0])
end
hold off

 

 

输出如下:

 

 

w1 =
-0.7318 -0.6815
-0.8692 0.4944
-0.1281 -0.9918
0.4407 -0.8977
TRAINR, Epoch 0/320
TRAINR, Epoch 100/320
TRAINR, Epoch 200/320
TRAINR, Epoch 300/320
TRAINR, Epoch 320/320
TRAINR, Maximum epoch reached.

w2 =
-0.0671 0.6655
-0.8995 0.4316
-0.0892 -0.9900
0.4553 -0.1103

a =
1 1 0 0 0 0 0 0
0 0 0 0 0 1 1 1
0 0 1 1 1 0 0 0
0 0 0 0 0 0 0 0