显示函数plotpv的2个参数是输入向量和目标函数
1)
>> P=[0 2 3 1 5 0 6
2 9 0 7 1 0 0]
P =
0 2 3 1 5 0 6
2 9 0 7 1 0 0
>> t=[0 1 0 1 1 0 0]
t =
0 1 0 1 1 0 0
>>plotpv(P,T)
2)
>> P=[0 2 3 1 5 0 6
2 9 0 7 1 0 0
0 9 2 1 8 0 9]
P =
0 2 3 1 5 0 6
2 9 0 7 1 0 0
0 9 2 1 8 0 9
>> T=[1 0 0 0 0 1 0]
T =
1 0 0 0 0 1 0
>> plotpv(P,T)
>>
3、plotpc返回分界线控点,根据权W和阈值B的输入绘制一条分界线
plotpc(W,B)
plotpc(W,B,H)包含从前一次调用中返回的控点,在绘制新分界线之前,删除旧线
P=[ -0.3 -0.5 +0.6 -0.1 -0.8
-0.5 +0.6 -0.2 +0.5 -0.6 ]
T=[0 1 1 1 0]
plotpv(P,T)
net=newp([-10 2; -5 20],1)
hold on
linehandle=plotpc(net.iw{1},net.b{1})
net.adaptParam.passes=3
linehandle=plotpc(net.iw{1},net.b{1})
for a=1:25
[net,Y,E]=adapt(net,P,T)
linehandle=plotpc(net.iw{1},net.b{1},linehandle)
drawnow
end
关于 PLOTPC
Plot a classification line on a perceptron vector plot.
绘制一个分类线,根据权矩阵W和阈值矩阵B
Syntax
plotpc(W,b)
plotpc(W,b,h)
Description
PLOTPC(W,B) takes these inputs,
W - SxR weight matrix (R must be 3 or less).
B - Sx1 bias vector.
and returns a handle to a plotted classification line.
PLOTPC(W,B,H) takes these inputs,
H - Handle to last plotted line.
and deletes the last line before plotting the new one.
This function does not change the current axis and is intended
to be called after PLOTPV.
Example
The code below defines and plots the inputs and targets for a
perceptron:
p = [0 0 1 1; 0 1 0 1];
t = [0 0 0 1];
plotpv(p,t)
下面的代码创建一个感知器,感知器是单层神经元,采用阈值激活函数,对一组输入向量的响应达到 元素为0或1的目标输出,实现对输入向量进行分类,下面这个代码创建了这个分类线
The following code creates a perceptron with inputs ranging
over the values in P, assigns values to its weights
and biases, and plots the resulting classification line.
net = newp(minmax(p),1);
net.iw{1,1} = [-1.2 -0.5];
net.b{1} = 1;
plotpc(net.iw{1,1},net.b{1})
我们把这个程序改一下
P=[0 1 0 1 1;1 1 1 0 0]
T=[0 1 0 0 0]
net = newp(minmax(P),1)
plotpv(P,T)
hold on
生成1个神经元的感知器,其中P是输入向量,T是目标函数
>> net.b{1}
ans =
0
>> net.iw{1,1}
ans =
0 0
>>
>> plotpc(net.iw{1,1},net.b{1})
此时执行没有意义,因为权值和阈值初始化为0
我们指定一个正确的权值和阈值
net.b{1}=-2
net.iw{1,1} =[1 1]
plotpc(net.iw{1,1},net.b{1})
注意plotpc必须要在plotpv函数后执行,可以看到分界线正确显示出来
凡在分界线左侧的都是反例,右侧的是正例,即输出值>0