主要内容

学习向量量化

LVQ 网络训练为根据给定目标对输入向量进行分类。

令 X 为 10 个二元素样本输入向量,C 为这些向量所属的类。这些类可以通过 IND2VEC 变换为用作目标 T 的向量。

x = [-3 -2 -2  0  0  0  0 +2 +2 +3;
      0 +1 -1 +2 +1 -1 -2 +1 -1  0];
c = [1 1 1 2 2 2 2 1 1 1];
t = ind2vec(c);

下面绘制了这些数据点。红色 = 第 1 类,青色 = 第 2 类。LVQ 网络表示具有隐藏神经元的向量聚类,并将这些聚类与输出神经元组合在一起以形成期望的类。

colormap(hsv);
plotvec(x,c)
title('Input Vectors');
xlabel('x(1)');
ylabel('x(2)');

Figure contains an axes object. The axes object with title Input Vectors, xlabel x(1), ylabel x(2) contains 10 objects of type line. One or more of the lines displays its values using only markers

在以下代码中,LVQNET 创建了一个具有四个隐藏神经元的 LVQ 层,学习率为 0.1。然后针对输入 X 和目标 T 配置网络。(配置通常不是必要步骤,因为 TRAIN 会自动完成配置。)

net = lvqnet(4,0.1);
net = configure(net,x,t);

按如下方式绘制竞争神经元权重向量。

hold on
w1 = net.IW{1};
plot(w1(1,1),w1(1,2),'ow')
title('Input/Weight Vectors');
xlabel('x(1), w(1)');
ylabel('x(2), w(2)');

Figure contains an axes object. The axes object with title Input/Weight Vectors, xlabel x(1), w(1), ylabel x(2), w(2) contains 11 objects of type line. One or more of the lines displays its values using only markers

要训练网络,首先改写默认的训练轮数,然后训练网络。训练完成后,重新绘制输入向量“+”和竞争神经元的权重向量“o”。红色 = 第 1 类,青色 = 第 2 类。

net.trainParam.epochs=150;
net=train(net,x,t);

Figure Neural Network Training (14-Jul-2025 06:31:27) contains an object of type uigridlayout.

cla;
plotvec(x,c);
hold on;
plotvec(net.IW{1}',vec2ind(net.LW{2}),'o');

Figure contains an axes object. The axes object with title Input/Weight Vectors, xlabel x(1), w(1), ylabel x(2), w(2) contains 14 objects of type line. One or more of the lines displays its values using only markers

现在使用 LVQ 网络作为分类器,其中每个神经元都对应于一个不同的类别。提交输入向量 [0.2; 1]。红色 = 第 1 类,青色 = 第 2 类。

x1 = [0.2; 1];
y1 = vec2ind(net(x1))
y1 = 
2