1.构建
使用newp函数
功能:
创建一个感知器神经网络的函数
格式:
net = newp(PR,S,TF,LF)
说明:
net为生成的感知机神经网络;PR为一个R2的矩阵,由R组输入向量中的最大值和最小值组成;S表示神经元的个数;TF表示感知器的激活函数,缺省值为硬限幅激活函数hardlim;LF表示网络的学习函数,缺省值为learnp 。
hardlim:
硬限幅激活函数,A = hardlim(N) 。
函数hardlim(N)在给定网络的输入矢量矩阵N时,返回该层的输出矢量矩阵A。当N中的元素大于等于零时,返回的值为l;否则为0。也就是说,如果网络的输入达到阈值,则硬限幅传输函数的输出为1;否则,为0。
learnp:
感知机的权值和阈值学习函数
2.实验
>> net = newp([-2 2;-2 2],1) %创建一个神经元,输入为二维,大小都是-2~2net =
Neural Network object:
architecture:
numInputs: 1
numLayers: 1
biasConnect: [1]
inputConnect: [1]
layerConnect: [0]
outputConnect: [1]
targetConnect: [1]
numOutputs: 1 (**read**-only)
numTargets: 1 (**read**-only)
numInputDelays: 0 (**read**-only)
numLayerDelays: 0 (**read**-only)
subobject structures:
inputs: {1x1 cell} of inputs
layers: {1x1 cell} of layers
outputs: {1x1 cell} containing 1 output
targets: {1x1 cell} containing 1 target
biases: {1x1 cell} containing 1 bias
inputWeights: {1x1 cell} containing 1 input weight
layerWeights: {1x1 cell} containing no layer weights
functions:
adaptFcn: 'trains'
initFcn: 'initlay'
performFcn: 'mae'
trainFcn: 'trainc'
parameters:
adaptParam: .passes
initParam: (none)
performParam: (none)
trainParam: .epochs, .goal, .show, .time
weight and bias values:
IW: {1x1 cell} containing 1 input weight matrix
LW: {1x1 cell} containing no layer weight matrices
b: {1x1 cell} containing 1 bias vector
other:
userdata: (user stuff)
>> net.IW{1,1} = [-1 1]; % w1,1 设置
>> net.b{1} = [1]; % b1 设置
>> p1 = [1;1]; % p1 输入
>> a1 = sim(net,p1) % 运行a1 =
1 % 输出结果
a = hardlim(wp+b)
计算p1输入时
wp+b = [-1 1][1;1]+1 = 1
hardlim(1) = 1
所以输出为1