AForge.NET

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

Networks weights and biases

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

Networks weights and biases

Postby Arms_deir » Mon Jul 13, 2015 2:52 pm

Dear C# Friends,

I am using AForge to make an estimation of a function (Interpolation). After a successful training of the ANN, I would like to dig the weights and biases of the developed network. How can I do that?

In following is the section of the code where the network is made and then trained. But I don't know how to dig through the network after training!!!

Code: Select all
// create multi-layer neural network
ActivationNetwork network = new ActivationNetwork(new BipolarSigmoidFunction(sigmoidAlphaValue), 1, 20, 20, 1);
// create teacher
BackPropagationLearning teacher = new BackPropagationLearning(network);

regards
AM
Arms_deir
 
Posts: 13
Joined: Mon Jul 13, 2015 2:47 pm

Re: Networks weights and biases

Postby andrew.kirillov » Tue Jul 14, 2015 7:10 am

Hello,

1) Using Network.Layers property you can get access to network's layers.
2) Using Layer.Neurons property you can get access to layer's neurons.
3) And finally you get to Neuron.Weights.

Check the docs.
With best regards,
Andrew


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

Re: Networks weights and biases

Postby Arms_deir » Tue Jul 14, 2015 8:06 am

Hello,

Thanks for your answer. However, when I write the network. in my program, automatically, it should give possible choices which I can not find the layers or any similar methods, the only methods are Compute, Equals, InputCount and so on. If you could expand your example to how implement them I will be grateful.

Thanks a world in advance
AM

andrew.kirillov wrote:Hello,

1) Using Network.Layers property you can get access to network's layers.
2) Using Layer.Neurons property you can get access to layer's neurons.
3) And finally you get to Neuron.Weights.

Check the docs.
Arms_deir
 
Posts: 13
Joined: Mon Jul 13, 2015 2:47 pm

Re: Networks weights and biases

Postby andrew.kirillov » Tue Jul 14, 2015 8:26 am

Not sure what is the problem you have. Below works for me:
Code: Select all
ActivationNetworw network = new ActivationNetwork( ... );

double weight = network.Layers[0].Neurons[1].Weights[0];
With best regards,
Andrew


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

Re: Networks weights and biases

Postby Arms_deir » Tue Jul 14, 2015 8:58 am

Hi,

The error was:

Error 1 'AForge.Neuro.ActivationNetwork' does not contain a definition for 'Layers' and no extension method 'Layers' accepting a first argument of type 'AForge.Neuro.ActivationNetwork' could be found (are you missing a using directive or an assembly reference?)

Then I replaced the reference with the updated AForge framework, thus new error comes due to Error2 Cannot implicitly convert type 'AForge.DoubleRange' to 'AForge.Range'

regards
AM

andrew.kirillov wrote:Not sure what is the problem you have. Below works for me:
Code: Select all
ActivationNetworw network = new ActivationNetwork( ... );

double weight = network.Layers[0].Neurons[1].Weights[0];
Arms_deir
 
Posts: 13
Joined: Mon Jul 13, 2015 2:47 pm

Re: Networks weights and biases

Postby andrew.kirillov » Tue Jul 14, 2015 9:23 am

I am not sure what you do exactly on your side. Here is what you can do:
1) Take XORProblem sample application (provided with the framework);
2) in MainForm.cs, on line 545 - add this:
Code: Select all
double weight = network.Layers[0].Neurons[0].Weights[0];

3) Hit "Build Solution" - it works, isn't it?
4) If step #3 works, then search for the problem in your solution (what you do differently).
With best regards,
Andrew


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

Re: Networks weights and biases

Postby Arms_deir » Mon Aug 24, 2015 2:36 pm

Sorry for the late response, I see when I changed my Framework to the newest version (2.2.5), it worked then correctly.

Thanks for your helps.
arms_deir

andrew.kirillov wrote:I am not sure what you do exactly on your side. Here is what you can do:
1) Take XORProblem sample application (provided with the framework);
2) in MainForm.cs, on line 545 - add this:
Code: Select all
double weight = network.Layers[0].Neurons[0].Weights[0];

3) Hit "Build Solution" - it works, isn't it?
4) If step #3 works, then search for the problem in your solution (what you do differently).
Arms_deir
 
Posts: 13
Joined: Mon Jul 13, 2015 2:47 pm




Return to AForge.NET Framework