Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Code for Neural Network Simulation

25 views
Skip to first unread message

Fernando Henrique

unread,
Apr 9, 2010, 4:18:04 PM4/9/10
to
Hello,

I have trained a neural network using 'nprtool', which is supposed to use "sigmoid hidden and output neurons". I am trying to use the results of this training (weights and biases) to implement a neural network from scratch. Unfortunately, I cannot get the right results. Could anyone point what I am doing wrong? The code follows below.

Thanks in advance,
Fernando H.

%Neural Network training
numHiddenNeurons = 40;
net = newpr(P,T,numHiddenNeurons); %The network has two inputs and one output
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,P,T);

%Neural Network implementation
inputsInput=[A;B];
weightsInput=net.IW{1,1};
weightsLayer=net.LW{2,1};
biasesInput=net.B{1,1};
biasesLayer=net.B{2,1};
inputsLayer=tansig(weightsInput*inputsInput+biasesInput);
Output=tansig(weightsLayer*inputsLayer+biasesLayer);

Greg Heath

unread,
Apr 9, 2010, 7:46:42 PM4/9/10
to
On Apr 9, 4:18 pm, "Fernando Henrique" <fernandoh...@gmail.com> wrote:
> Hello,
>
> I have trained a neural network using 'nprtool', which is supposed to use "sigmoid hidden and output neurons". I am trying to use the results of this training (weights and biases) to implement a neural network from scratch. Unfortunately, I cannot get the right results. Could anyone point what I am doing wrong? The code follows below.
>
> Thanks in advance,
> Fernando H.
>
> %Neural Network training
> numHiddenNeurons = 40;
> net = newpr(P,T,numHiddenNeurons); %The network has two inputs and one output

sizeP = size(P) % ?
sizeT = size(T) % ?

Does H = 40 make sense for the size of the data base?
Search

greg heath Neq Nw

> net.divideParam.trainRatio = 70/100;
> net.divideParam.valRatio = 15/100;
> net.divideParam.testRatio = 15/100;
> [net,tr] = train(net,P,T);
>
> %Neural Network implementation
> inputsInput=[A;B];

size(A) % ?
size(B) % ?


> weightsInput=net.IW{1,1};
> weightsLayer=net.LW{2,1};
> biasesInput=net.B{1,1};
> biasesLayer=net.B{2,1};
> inputsLayer=tansig(weightsInput*inputsInput+biasesInput);
> Output=tansig(weightsLayer*inputsLayer+biasesLayer);

Please explain EXACTLY what you mean by

"Unfortunately, I cannot get the right results."

Do you get the right results when you use SIM?

Hope this helps.

Greg

Fernando Henrique

unread,
Apr 12, 2010, 8:46:04 AM4/12/10
to
size(P) = 2 10000
size(T) = 1 10000
size(A) = 1 1
size(B) = 1 1

I'm using the neural network as a classifier, so by right results I mean results that correspond to reality (when I use an input vector with known output). I think the number of neurons makes sense, as the network results are OK when I use SIM.

Thank you for your time,
Fernando H

Greg Heath <he...@alumni.brown.edu> wrote in message <610901f7-804b-4fea...@x7g2000vbc.googlegroups.com>...

Greg Heath

unread,
Apr 13, 2010, 4:29:04 AM4/13/10
to

CORRECTED FOR THE HEINOUS SIN OF TOP-POSTING!

On Apr 12, 8:46 am, "Fernando Henrique" <fernandoh...@gmail.com>
wrote:
> Greg Heath <he...@alumni.brown.edu> wrote in message <610901f7-804b-4fea-aff7-236a8bc6b...@x7g2000vbc.googlegroups.com>...

> size(P) = 2 10000
> size(T) = 1 10000
> size(A) = 1 1
> size(B) = 1 1
>
> I'm using the neural network as a classifier, so by right results I mean results > that correspond to reality (when I use an input vector with known output).

Considering the size of your training set you are probably OK.

However, it is better to partition the data into training, validation
and test sets. So that you can select training parameters and
predict future performance by using nontraining data. In addition,
you can reduce training times by not using an excessive amount
of training data.

I think the number of neurons makes sense, as the network results
are OK when I use SIM.

On nontraining data?


> Thank you for your time,
> Fernando H

You are welcome.
Hope this helps.

Greg

Fernando Henrique

unread,
Apr 13, 2010, 7:32:20 AM4/13/10
to
I am dividing it, as in:

net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

And yes, I'm testing with data outside the training set. The network performs correctly with SIM. I really think the problem is in the implementation "from scratch", but from the definition, I can't find what's wrong:

inputsInput=[A;B];

weightsInput=net.IW{1,1};
weightsLayer=net.LW{2,1};
biasesInput=net.B{1,1};
biasesLayer=net.B{2,1};

inputsLayer=tansig(weightsInput*inputsInput+biasesInput);
Output=tansig(weightsLayer*inputsLayer+biasesLayer);

Thank you,
Fernando Henrique

Greg Heath <he...@alumni.brown.edu> wrote in message <5d1c324d-e956-4be9...@r18g2000yqd.googlegroups.com>...

Greg Heath

unread,
Apr 13, 2010, 7:43:15 PM4/13/10
to
On Apr 13, 7:32 am, "Fernando Henrique" <fernandoh...@gmail.com>
wrote:

> I am dividing it, as in:
>
> net.divideParam.trainRatio = 70/100;
> net.divideParam.valRatio = 15/100;
> net.divideParam.testRatio = 15/100;
>
> And yes, I'm testing with data outside the training set. The network performs correctly with SIM. I really think the problem is in the implementation "from scratch", but from the definition, I can't find what's wrong:
>
> inputsInput=[A;B];
>
> weightsInput=net.IW{1,1};
> weightsLayer=net.LW{2,1};
> biasesInput=net.B{1,1};
> biasesLayer=net.B{2,1};
>
> inputsLayer=tansig(weightsInput*inputsInput+biasesInput);
> Output=tansig(weightsLayer*inputsLayer+biasesLayer);
>
> Thank you,
> Fernando Henrique
>
>
>
> Greg Heath <he...@alumni.brown.edu> wrote in message <5d1c324d-e956-4be9-8e2e-280b93fbd...@r18g2000yqd.googlegroups.com>...

Check algorithm defaults.

In particular, mapminmax and 'purelin'

Hope this helps.

Greg

Amol Mahurkar

unread,
Feb 25, 2012, 2:42:30 PM2/25/12
to
Hello,

I am trying to do the same since long time... but the output result does not match with the result we get by using SIM command...

Did anyone found solution to this problem??

Please guys suggest something... I tried using all parameters mentioned in 'net' object variable... such as range of input, hidden and output... used 'tansig' for hidden and 'purelin' for output.. but it didn't help..

Thanks in advance... :)



"Fernando Henrique" wrote in message <hpo21s$jd2$1...@fred.mathworks.com>...

he...@alumni.brown.edu

unread,
Aug 5, 2015, 2:07:02 AM8/5/15
to
Typically, the analytic result does not match the net result because of
the default normalization of input and target followed by the denormalization of the output.

Hope this helps.

Greg
0 new messages