file: ~/courses/spring2002/434/perceptron_setup.txt RWN 02/07-10/02 The steps to follow, with an example, using MatLab NNET programs for handling perceptrons: 1. setup the network: net1 = newp([0 1; -2 1; 3 9; -0.8 0.8; -3 3],2); This uses the new_perceptron call to set up a double neuron perceptron with five inputs, for which weights will be generated; the five entries in an input vector are in the five ranges indicated. 2. setup the training set of inputs P and corresponding outputs T: P1=[0 0.1 0.2 0.8; 1 -1 -2 2; 3 4 5 6; -0.6 -0.5 0.5 0.6; ... -3 -2 -1 2] T1=[1 0 0 1; 0 1 1 1] 3. check the initial weight and bias values: net1.IW{1,1} net1.b{1} These should return two rows each all with zeros 3. next check, by simulating the net, that P1 works with net1: Y=sim(net1,P1) This returns Y = 1 1 1 1 1 1 1 1 These values are as expected since the inputs to the hardlimit activation functions are all zero. 4. next train via the adapt function on P1 & T1: first set how many epochs=passes to use net1.adaptParam.passes = 10; then adapt the weights and bias net1= adapt(net1,P1,T1); then check if T1 results as the output now Y = sim(net1,P1) Note that this returns Y that is T1. 5. To see the final weights and bias repeat 3.: net1.IW{1,1} ans = 0.5000 6.0000 0 0 2.0000 1.1000 -4.0000 6.0000 2.4000 8.0000 net1.b{1} ans = 0 0 6. try out on a new input vector: P2=[0.3; -1.2; 4; 0.6; 2]; Y=sim(net1,P2) This returns Y = 0 1 7. next we use the train program to do the same thing: First reset the weights and bias to zero net1 = init(net1); to check that zero results use net1.IW{1,1} Y = sim(net1,P2) This returns: Y = 1 1 1 1 1 1 1 1 Set the upper limit of the number of epochs=passes net1.trainParam.epochs = 20; Now do the training net1 = train(net1,P2,T2); Y = sim(net1,P2) The result is TRAINC, Epoch 0/20 TRAINC, Epoch 4/20 TRAINC, Performance goal met. Y = 1 0 0 1 0 1 1 1 along with a plot of the performance showing the error behavior. 8. With this perceptron defined it can be put into simulink. For that the weight vectors and biases can be set into gain blocks which call their gains from the "command window." For the weight-gain for the first neuron one can enter the gain as W1net1 and enter in the command window W1net1=net1.IW{1,1}(1,:) and then for the second neuron W2net1=net1.IW{1,1}(2,:) while for the gain of bias blocks B1net1=net1.b{1}(1) B2net1=net1.b{1}(2) 4'. To see what is available for this net1: net1= adapt(net1,P1,T1) entered without the ; This returns: net1 = 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) 4''. Now one can find various data: net1.trainParam.epochs ans = 20 net1.trainParam.goal ans = 0 net1.layers{1}.transferFcn ans = hardlim