AForge.NET

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

HOW to: SAVE and Load NN and Scale input range? Step by Ste?

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

HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby kpecio » Sat May 16, 2009 11:58 am

I have problem with save and load network.I use AFORGE framework 2.0 so I have this method but I didn't know how to use it. First I write network.Save("network.dat"); after line
double error = teacher.RunEpoch(input, output) / samples; after that I want to Load network so I use Network.Load("network.dat"); before line: while ( !needToStop ) and I add checkbox on the form. When I checked it I have:
// run epoch of learning procedure
if (checkBox1.Checked == false)
{
double error = teacher.RunEpoch(input, output) / samples;
}
Please help me step by step how to save load network and how to load new data for test learned network. I have alos problem with scaling input range. Iwant to leran my NN by 100 points and I use Bipolar activation function. How to do it?
It will be great and save me a lot of time.
Best regards
Kamil
kpecio
 
Posts: 6
Joined: Sat May 16, 2009 11:53 am

Re: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby andrew.kirillov » Sat May 16, 2009 12:31 pm

Hello,

The steps are very simple. Actually there is just one step for both saving and loading ...

Step by step guide for network saving:
Code: Select all
// save neural network to file
network.Save( "my_nn.bin" );

That is all for saving. See docs ...

Step by step guide for network loading:
Code: Select all
// load neural network
Network network = Network.Load( "my_nn.bin" );

That is all for loading. See docs ...

In general you need to train network first and then save it. Then you may load it another application (or in the same application) and use it using Compute() method.
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: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby kpecio » Sun May 17, 2009 9:01 am

Thanks for the replay.
Everything is ok now. Network is saved and Loaded. The second problem is that why there is limitation of 50 points in the input. Is there possible to load 100 points and network will learn it? I have sin function of the range X: 0 - 100 and proper Y for this X. When I load this data (0-50) Network is not able to learn it? How to solve this problem?
kpecio
 
Posts: 6
Joined: Sat May 16, 2009 11:53 am

Re: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby andrew.kirillov » Sun May 17, 2009 2:00 pm

Hello,

There are no limitations in network's size ... If you need more inputs, then just create a network of required size.

If you are using samples from AForge.NET Framework, then you need to understand that these are SAMPLES. They are aimed to show how to use the framework. They are not aimed to be ready to use applications for your needs ...
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: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby kpecio » Sun May 17, 2009 8:24 pm

Hello,
There is no limitation? but arrays are created for 50 points from input. When I load 50 samples (0-50) Network is not able to learn. How to load for example 100 samples?
kpecio
 
Posts: 6
Joined: Sat May 16, 2009 11:53 am

Re: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby kpecio » Tue May 19, 2009 9:13 am

Hello once again,
Now I understand that there are demo samples showing only how to use this framework but I don't know how to rescale this Chart (range) that the NN will be able to learn such big number of learning data. When I change in all arrays 50 to 100 input points it will be works I hope but how to rescale the plot (range of chart). I have to change size og the chart and some how define the double range. How to do it in the best option?
(I need to input 100 points of learning data and 100 points for test data.Generaly I need to know how to define the range of the chart).
Thank You.
kpecio
 
Posts: 6
Joined: Sat May 16, 2009 11:53 am

Re: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby andrew.kirillov » Tue May 19, 2009 6:46 pm

Use Chart.RangeX property ... and check docs before asking.
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: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby kpecio » Tue May 19, 2009 7:43 pm

I know that this method change the range of X or Y but for example I have this set of points:
0,0
1,5
2,7
5,9
6,7
9,-5
10,-7
11,-9
14,-7
15,-5
16,0
23,5
25,-5
26,-7
29,-9
30,-7
32,0
34,7
35,9
37,9
38,7
40,0
41,-5
44,-10
45,-9
47,-5
48,0
49,5

and NN is not able to learn on this set of points. in the range of X I have minX maxX. Where is the problem?
kpecio
 
Posts: 6
Joined: Sat May 16, 2009 11:53 am

Re: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby andrew.kirillov » Tue May 19, 2009 8:02 pm

Of course it will not learn ... You need to make sure that X and Y are in [-1, 1] or [0, 1] range (depends on activation function - bipolar or not). You need to do mapping ... See sample applications where it is done.
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: HOW to: SAVE and Load NN and Scale input range? Step by Ste?

Postby kpecio » Wed May 20, 2009 3:05 pm

I agree that it must be on the range -1 to 1 in case of bipolar function and I have mapping and still it doens't work. It works for 20 points for example. In case of Yours demo application when I load my data (above data from X:0-50 ) the NN is not able to learn. I tried to change number of layers and neurons but it didn't give me positive results. Is there any hope to load this above data? or how to generate points(X and Y cordinates) which will be works?
kpecio
 
Posts: 6
Joined: Sat May 16, 2009 11:53 am




Return to AForge.NET Framework