AForge.NET

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

Average network weights

The forum is to discuss topics from different artificial intelligence areas, like neural networks, genetic algorithms, machine learning, etc.

Average network weights

Postby Lawrence » Mon May 23, 2016 2:33 pm

Hi,

How can I store network weights to some List structure, such that I can then average the weights and reload this average?

Lawrence
Lawrence
 
Posts: 24
Joined: Tue May 17, 2016 11:32 am

Re: Average network weights

Postby andrew.kirillov » Mon May 23, 2016 2:54 pm

Hello,

You may iterate through all neurons and get their [url=Neuron.Weights]weights[/url] and store those anywhere you wish.
With best regards,
Andrew


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

Re: Average network weights

Postby Lawrence » Thu May 26, 2016 8:39 am

Andrew,

I can easily see weights of neurons now, but I am not trying to store network values to average and reload after several trials. I am trying to create a class "Trial" to hold the Layers and Neurons.

However, your "Layer" is an abstract class! How can I create a constructor something like the code below?

Cannot create an instance of the abstract class or interface 'AForge.Neuro.Layer'


public class Trial
{
public List<Layer> layersL;

Trial(ActivationNetwork trial)
{
layersL = new List<Layer>();

foreach (var tLayer in trial.Layers)
{
Layer layer = new AForge.Neuro.Layer(); //PROBLEM HERE

List<Neuron> neuronL = new List<Neuron>();
foreach (var neuron in tLayer.Neurons)
{
neuronL.Add(neuron);
}

layer.Neurons = neuronL.ToArray<Neuron>();
}

layersL.Add(layersL);
}
}
Lawrence
 
Posts: 24
Joined: Tue May 17, 2016 11:32 am

Re: Average network weights

Postby andrew.kirillov » Thu May 26, 2016 9:19 am

Hello,

Activation network uses ActivationLayer ;)
With best regards,
Andrew


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

Re: Average network weights

Postby Lawrence » Thu May 26, 2016 10:40 am

Thanks Andrew,

That helps, but I now can't assign to "Neurons";

network = new ActivationNetwork(
new BipolarSigmoidFunction(sigmoidAlphaValue),
5,5,1);

foreach (var tLayer in network.Layers)
{
ActivationLayer layer = new ActivationLayer(tLayer.Neurons.Count(),tLayer.InputsCount,null);

layer.Neurons = (AForge.Neuro.Neuron[]) tLayer.Neurons.Clone(); //PROBLEM HERE
}
Lawrence
 
Posts: 24
Joined: Tue May 17, 2016 11:32 am

Re: Average network weights

Postby andrew.kirillov » Thu May 26, 2016 11:37 am

Lawrence wrote:layer.Neurons = (AForge.Neuro.Neuron[]) tLayer.Neurons.Clone(); //PROBLEM HERE

You can not set neurons into layer, only get them. The docs should mention this.
With best regards,
Andrew


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

Re: Average network weights

Postby Lawrence » Thu May 26, 2016 12:01 pm

So I want to set the weight of each Neuron, based on an average of several previous training runs.

Is this not possible?
Lawrence
 
Posts: 24
Joined: Tue May 17, 2016 11:32 am

Re: Average network weights

Postby andrew.kirillov » Thu May 26, 2016 12:25 pm

With best regards,
Andrew


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

Re: Average network weights

Postby Lawrence » Fri May 27, 2016 11:57 am

Andrew,

I am saving neuron weights and later restoring.

I loop through all Layers / Neurons / Weights

But I get different results - is there something else in the Network apart from Neuron weights that I need to store?
Lawrence
 
Posts: 24
Joined: Tue May 17, 2016 11:32 am

Re: Average network weights

Postby andrew.kirillov » Fri May 27, 2016 12:53 pm

Yep. You need to store ActivationNeuron.Threshold. It also updates will learning network.
With best regards,
Andrew


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



Next

Return to Artificial Intelligence

cron