AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Silly question i guess

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Silly question i guess

Postby Abner77 » Sun Feb 08, 2009 11:18 am

I am trying to use AForge to do a simple Approximation. I have tried the example of the codeproject source. The train is good, but now i want to use it to predict one value. How can i do it? I have used the Compute method of the activation network but the result passing one value in the input vector to the network gives exactly the same result as the output property without the input. It looks like is not computing the input to give the result. Whats going on? What would be the code to use the network after the train?

Probably a silly question but i am kind lost.
Thanks in advance and sorry for my english.
Abner77
 
Posts: 4
Joined: Sun Feb 08, 2009 11:09 am

Re: Silly question i guess

Postby andrew.kirillov » Sun Feb 08, 2009 12:59 pm

Hello,

One a neural network is trained, you may use Network.Compute() method to compute network's output for a given input.

Abner77 wrote:I have used the Compute method of the activation network but the result passing one value in the input vector to the network gives exactly the same result as the output property without the input.


After calling Compute(), the Output property will have the same result as returned by Compute(). The Output property keeps the last computed output.

Abner77 wrote: It looks like is not computing the input to give the result.


Network should not compute input. It should compute output.

With best regards,
Andrew
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Silly question i guess

Postby Abner77 » Sun Feb 08, 2009 1:15 pm

But the result is not right then. The input data comes from one of the sample data, and the output vector training are always positive values. However the result giving a 2 value in the input vector to the compute method returns as output a -0.77 value. it does not correspond with the function to be approximated. What am i doing wrong?
Thank you very much for your help.
Abner77
 
Posts: 4
Joined: Sun Feb 08, 2009 11:09 am

Re: Silly question i guess

Postby andrew.kirillov » Sun Feb 08, 2009 1:21 pm

What is the function? How many inputs/outputs does it have?

With best regards,
Andrew
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Silly question i guess

Postby Abner77 » Sun Feb 08, 2009 1:27 pm

these are the vectors of the csv file in the sample.
1,0
2,4
3,7
4,9
5,10
6,9
7,7
8,4
9,0
It's a parabolic function. I was expecting that if i give to the compute method a value of for example "1,5" or "2" the result will be of courde between 0 and 4, but it isnt. The result of the compute method is about -0,78.
Abner77
 
Posts: 4
Joined: Sun Feb 08, 2009 11:09 am

Re: Silly question i guess

Postby andrew.kirillov » Sun Feb 08, 2009 3:10 pm

OK, so you have network with one input and one output. This means that after training you need to use something like this:
Code: Select all
double[] output = network.Compute( new double[] { 0.5 } )


If you use Approximation sample application, than you need to notice that there is normalization done before training for both input and output. This means that after training, you will need to normalize input as well. And this will a produce output, which also requires converting to original space. Take a look at normalization procedure in Approximation sample:
Code: Select all
for ( int i = 0; i < samples; i++ )
{
   input[i] = new double[1];
   output[i] = new double[1];

   // set input
   input[i][0] = ( data[i, 0] - xMin ) * xFactor - 1.0;
   // set output
   output[i][0] = ( data[i, 1] - yMin ) * yFactor - 0.85;
}


Such normalization is OK for approximation inside of the range, but not outside. If you need to predict, then you may try different normalization range. Also you may try Time Series prediction sample application.

With best regards,
Andrew
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Silly question i guess

Postby Abner77 » Sun Feb 08, 2009 3:18 pm

I'll take an eye at this.
thank you very much for your help Andrew.

the library is a Nice work by the way.
David.
Abner77
 
Posts: 4
Joined: Sun Feb 08, 2009 11:09 am




Return to AForge.NET Framework