public SetWeight ( int fromLayer, int fromNeuron, int toNeuron, double v ) : void | ||
fromLayer | int | The from layer. |
fromNeuron | int | The from neuron. |
toNeuron | int | The to neuron. |
v | double | The to value. |
return | void |
public void SetWeight(int fromLayer, int fromNeuron,
int toNeuron, double v)
{
_structure.RequireFlat();
int fromLayerNumber = LayerCount - fromLayer - 1;
int toLayerNumber = fromLayerNumber - 1;
if (toLayerNumber < 0)
{
throw new NeuralNetworkError(
"The specified layer is not connected to another layer: "
+ fromLayer);
}
int weightBaseIndex = _structure.Flat.WeightIndex[toLayerNumber];
int count = _structure.Flat.LayerCounts[fromLayerNumber];
int weightIndex = weightBaseIndex + fromNeuron
+ (toNeuron*count);
_structure.Flat.Weights[weightIndex] = v;
}
/// <summary> /// Randomize one level of a neural network. /// </summary> /// /// <param name="network">The network to randomize</param> /// <param name="fromLayer">The from level to randomize.</param> public override void Randomize(BasicNetwork network, int fromLayer) { int fromCount = network.GetLayerTotalNeuronCount(fromLayer); int toCount = network.GetLayerNeuronCount(fromLayer + 1); for (int fromNeuron = 0; fromNeuron < fromCount; fromNeuron++) { for (int toNeuron = 0; toNeuron < toCount; toNeuron++) { double v = CalculateValue(toCount); network.SetWeight(fromLayer, fromNeuron, toNeuron, v); } } }