MATLAB Code of Artificial Neural Networks Estimation: February 2016
MATLAB Code of Artificial Neural Networks Estimation: February 2016
MATLAB Code of Artificial Neural Networks Estimation: February 2016
net/publication/292970981
CITATIONS READS
0 12,644
1 author:
Aymen Ammari
Ecole de Management Strasbourg
17 PUBLICATIONS 10 CITATIONS
SEE PROFILE
All content following this page was uploaded by Aymen Ammari on 04 February 2016.
Aymen AMMARI *
High Business School of Tunis, University of Manouba, Tunisia
Article history: Neural networks are very appropriate at function fit problems. A neural
Received 00 December 00 network with enough features (called neurons) can fit any data with
Received in revised form 00 January 00 arbitrary accuracy. They are for the most part well-matched in focusing
Accepted 00 February 00 on non-linear questions. In view of the non-linear nature of real world
events, neural networks are an effective runner for resolving the
Keywords: Artificial Neural Network
problem. This article provides a MATLAB code for numerically
simulating Artificial Neural Networks Estimation. An example of
corporate governance data (as input) linked to their Accounting and
Market performance (as output) of 80 French publicly traded firms from
2000 to 2013 was introduced just to generate results. This article is
written for the developers of MATLAB programming language. The
code was written for flexibility so as to be easily modified to many other
applications for educational purposes.
assumptions implicitly as in most usual statistical Neural networks are considered universal
methodologies. As an alternative for regression approximators (Kolmogorov, 1957). Based on
techniques, ANNs are used. ANNs are applied in this theorem, it was proven that regardless of the
many fields such as financial services, activation function and the dimension of the
biomedical applications, time-series prediction, input space, a neural network with one hidden
text mining, decision making and many others. layer can approximate any continuous function
Although the applications of ANNs are arbitrarily well (Hornik et al., 1989). The
numerous, they all share an important common different input (the possible contributing
aspect: the processes to be predicted are variables) are weighed and combined into a final
correlated with a large number of explanatory model. The network is trained to estimate the and
variables and there may exist high-level non- this training implies that the different
linear relationships between those variables. One interconnection weights will be adapted every
of the main goals of ANNs is to detect those time a new part is fed to the network.
high-level non-linear relationships to enable a Adaptation of the weights will be done based on
better modeling of the process. ANNs are in fact a punishment/reward principle: if the
computer systems that simulate the learning interconnection did well during estimation of the
effect of the human brain and are typically previous part, this variable will be rewarded by
composed of a number of neurons, grouped in increasing the weight of its interconnection to the
one or more hidden layers connected by means of output. If the interconnection performed badly,
synapse connections. The output of each neuron the interconnection weights will be decreased in
will be a weighted function of the different the next iteration step. By minimizing the
incoming signals. The weight of an squared error (MSE) between the estimate and
interconnection between different neurons will the desired output (in our case firm
depend on the contribution performance of that performance), the network is trained and as more
neuron to the final output. parts are fed, the learning effect increases.
Fig. 1 shows the combination of different However, one cannot keep on training the
neurons (perceptron) into an artificial neural network into infinity. When new parts, not
network (multi-layer perceptron). included in the training set, are fed to the
network, inaccurate estimates can be generated.
It can indeed happen that the network has
focused too much on the specific data of the
training set (i.e. overfitting), but fails to
generalize when unknown parts are fed to the
network (i.e. generalization ability of ANNs). To
ensure that ANNs also generate accurate
estimates for parts not included in the training
set, a separate testing and validation set are used.
The network will be trained until the error of the
testing and validation set increases. At that point,
training will be stopped to avoid overfitting.
Neural networks are typically characterised by
the number of hidden layers, the number of
hidden neurons and the training algorithm. Those
design parameters determine to a large extent the
performance of the ANN and will differ
depending on the field of application. If the
number of hidden neurons is too small, not all
necessary dependencies between the variables
might be captured, resulting in a poor modelling
of the observed process. On the other hand, if the
number of hidden neurons is too large, spurious
relations and noise are included in the model. By
a trial–error process the number of hidden
neurons that best fits the specific purpose is
determined. The training algorithm will be
chosen in function of the specific application.
The biggest advantage of neural networks is the
fact that they can approximate functions very
3
well without explaining them. This means that an Data for function fitting problems are set up for a
output is generated based on different input neural network by organizing the data into two
signals and by training those networks, accurate
estimates can be generated. ANNs are considered matrices, the input matrix “in” and the target
black box approaches (Smith and Mason, 1999), matrix “out”.
(Kim et al., 2004).To overcome this problem of corrplot(data): was introduced to verify
neural networks being black boxes, research has the problems of multicollinearity which means
been conducted to try and explain their that there is a nearly perfect linear relationship
behaviour. Equivalence between ANNs and
fuzzy-rule-based systems can be found, allowing between explanatory variables, we introduced the
to interpret the neural network. Benitez et al. Cross correlation Matrix. The correlation plot Fig
(1997) offer such a fuzzy-based interpretation of 2 shows that our independent variables
neural networks to translate the knowledge (corporate governance data) are not correlated.
embedded in the ANN into more understandable
fuzzy rules. However, despite the efforts in trying
to explain the complex relationships found by the
network, ANNs are still mainly considered black
boxes. Even if one were to extract the CER by
examining the weights, architecture and nodal
transfer functions, the equation is difficult to
explain. Fitting the data to a particular parametric
form is possible with regression but not practical
with neural networks (Smith and Mason, 1999).
% net1.trainparam.lr=0.1;
% net1.trainParam.epochs=500;
% Training Network
it=20;
% Max Number of Iteration
ii=0;
netopt{:}=1:nnnf;
for nnn=nnn1:nnnj:nnnf Fig 3: Error plot for different n: 5, 10, 15 and 20
ii=ii+1; nnn
net1=newff(p,t,[nnn nnn]); % For Network Output
more functions see: 'Function
Reference' in 'Neural Network Toolbox'
of Matlab help ***************************************
evalopt(ii)=100; %% Output
for i=1:it clear; close all;
[net1,tr,y,et]=train(net1,p,t); load('run_log_2');
% Training
nn=4
5
ptrain=p(:,tropt(nn).trainInd);
ttrain=t(:,tropt(nn).trainInd);
esttrain=sim(netopt{nn},ptrain);
ptest=p(:,tropt(nn).testInd);
ttest=t(:,tropt(nn).testInd);
esttest=sim(netopt{nn},ptest);
pval=p(:,tropt(nn).valInd);
tval=t(:,tropt(nn).valInd);
estval=sim(netopt{nn},pval);
estwhole=sim(netopt{nn},p);
% ttrain=exp(ttrain); ttest=exp(ttest);
tval=exp(tval); t=exp(t);
% esttrain=exp(esttrain);
esttest=exp(esttest);
estval=exp(estval);
estwhole=exp(estwhole);
figure; plot(ttrain,esttrain,'.b'); %
train data: ttrain: real and esttrain:
estimated
figure; plot(tval,estval,'.g'); %
validation
figure; plot(ttest,esttest,'.r'); % Fig 4: Plot of training, validation, and testing
test data of accounting performance.
figure; plot(t,estwhole,'.k') %
whole
figure;
plotregression(ttrain,esttrain,'Train',
tval,estval,'Validation',ttest,esttest,
'Test',t,estwhole,'Whole Data');
***************************************
Conclusion:
Based on a chapter of my Ph.D dissertation
which analyses the French corporate governance
linked to their firm performance, this paper
present the MATLAB code used and clarifies
step by step the implanting of Artificial Neural
Networks Estimation. The code was written for
flexibility so as to be easily modified to many
other applications for educational purposes.
Acknowledgement:
I acknowledge Verlinden, B. et al 2007, “Cost
estimation for sheet metal parts using multiple
regression and artificial neural networks: A case
study” for getting his background support.