Page 1 of 2

Average network weights

PostPosted: Mon May 23, 2016 2:33 pm
by Lawrence
Hi,

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

Lawrence

Re: Average network weights

PostPosted: Mon May 23, 2016 2:54 pm
by andrew.kirillov
Hello,

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

Re: Average network weights

PostPosted: Thu May 26, 2016 8:39 am
by Lawrence
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);
}
}

Re: Average network weights

PostPosted: Thu May 26, 2016 9:19 am
by andrew.kirillov
Hello,

Activation network uses ActivationLayer ;)

Re: Average network weights

PostPosted: Thu May 26, 2016 10:40 am
by Lawrence
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
}

Re: Average network weights

PostPosted: Thu May 26, 2016 11:37 am
by andrew.kirillov
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.

Re: Average network weights

PostPosted: Thu May 26, 2016 12:01 pm
by Lawrence
So I want to set the weight of each Neuron, based on an average of several previous training runs.

Is this not possible?

Re: Average network weights

PostPosted: Thu May 26, 2016 12:25 pm
by andrew.kirillov

Re: Average network weights

PostPosted: Fri May 27, 2016 11:57 am
by Lawrence
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?

Re: Average network weights

PostPosted: Fri May 27, 2016 12:53 pm
by andrew.kirillov
Yep. You need to store ActivationNeuron.Threshold. It also updates will learning network.