Starting with neural network in MATLAB[ZZ]

Source: Internet
Author: User

Turn from: Http://matlabbyexamples.blogspot.com/2011/03/starting-with-neural-network-in-matlab.htmlThe Neural Networks is A-to-model any-input to output relations based-some input output data when nothing was known about the model. This example shows your a very simple example and its modelling through neural network using MATLAB.


Actual Model

Let's take the US model has three inputs A, B and C and generates an output Y. For data generation purposes, let us take the This model as y=5a+bc+7c;

We are taking the this model for data generation. In actual cases, you dont has the mathematical model and you generate the data by running the real system. Let us first write a small script to generate the data
a= rand (1,1000); B=rand (1,1000); C=rand (1,1000);  N=rand (1,1000) *0.05; y=a*5+b.*c+7*c+n;
n is the noise, we added deliberately to make it more like a real data. The magnitude of the noise is 0.1 and is uniform noise. So we input is set of a, B and C and output is Y.
i=[a; b; c]; o=y;
Understanding Neural NetworksNeural network is like brain full of nerons and made of different layers. The first layer which takes input and put into internal layers or hidden layers is known as input layer. The outer layer which takes the output from inner layers and gives it to outer world is known as output layer. The internal layers can is any number of layers. Each layer was a basically a function which takes some variables (in the form of vector u) and transforms it to another variable (another vector v) by multiplying it with coefficients and adding some biases b. These coefficient is known as weight matrix W.Size of the V vector is known as v-size of the layer. v=sum (w.*u) +bSo we'll make a very simple neural network for our case-1 input and 1 output layer. We'll take the input layer v-size as 5. Since we have three input and our input layer would take uWith three values and transform it to a vector vof size 5. And our output layer now take this 5 element vector as input uand transforms it to a vector of size 1 because we had only on output. Creating A simple neural FF NetworkWe'll use the MATLAB inbuilt function newff for generation of model. First we'll make a matrix R which is of 3 * * size. First column would show the minimum of all three inputs and second would show the maximum of three inputs. In we case all three inputs is from 0 to 1 range, so
R=[0 1; 0 1; 0 1];
Now We make a Size matrix which have the v-size of all the layers.
s=[5 1];
Now call the NEWFF function as following
net = NEWFF ([0 1;0 1; 0 1],s,{' Tansig ', ' Purelin '});
NET is the neural model. {' Tansig ', ' Purelin '}Shows the mapping function of the the layers. Let us not waste time in this. Now as each brain need training, this neural network too need it. We'll train this neural network with the data we generated earlier.
Net=train (net,i,o);
Now-Net is trained. You can see the performance curve, as it gets trained. So is simulate our neural network again on the same data and compare the out.puts.
O1=sim (net,i); plot (1:1000,o,1:1000,o1);
Can observe how closely the the both data green and blue follow each of the other. Let us try scatter plot between simulated output and actual target output.
scatter (o,o1);
Let us observe the weight matrix of the trained model.
Net. Iw{1} -0.3684 0.0308-0.5402
0.4640 0.2340 0.5875
1.9569-1.6887 1.5403
1.1138 1.0841 0.2439
net. lw{2,1} -11.1990 9.4589-1.0006-0.9138
Now test it again in some other data. What about A=1,b=1 and c=1; So input matrix would be [1 1 1] ';
Y1=sim (net,[1 1 1] ');
You'll see 13.0279. Which is close to the actual output (5*1+1*1+12*1); Updates:
1. O and T is same variable. Define o=t or just replace T everywhere with O
2. S=[5 1], so and defining NEWFF you should pass S or [5 1]. [4 1] is incorrect

Starting with neural network in MATLAB[ZZ]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.