/// <summary> Creates a new <see cref="WeightLayer"/> for the given <paramref name="neuralNetwork"/> with the given <paramref name="index"/> and linked to the given <paramref name="nextNeuronLayer"/> and <paramref name="previousNeuronLayer"/>. </summary> /// <param name="neuralNetwork"> The <see cref="IReadOnlyNeuralNetwork"/> this <see cref="WeightLayer"/> is for. </param> /// <param name="index"> The index of this new <see cref="WeightLayer"/>. </param> /// <param name="previousNeuronLayer"> The previous <see cref="NeuronLayer"/> that this <see cref="WeightLayer"/> is linked to. </param> /// <param name="nextNeuronLayer"> The next <see cref="NeuronLayer"/> that this <see cref="WeightLayer"/> is linked to. </param> public WeightLayer(IReadOnlyNeuralNetwork neuralNetwork, uint index, ILinkableNeuronLayer previousNeuronLayer, ILinkableNeuronLayer nextNeuronLayer) { // Set the index. Index = index; // Set references. NeuralNetwork = neuralNetwork; PreviousNeuronLayer = previousNeuronLayer; NextNeuronLayer = nextNeuronLayer; // Link the previous and next layers to this layer. previousNeuronLayer.NextWeightLayer = this; nextNeuronLayer.PreviousWeightLayer = this; // Initialise dictionaries. previousNeuronConnectionsByID = new Dictionary <uint, Dictionary <uint, weightConnection> >(previousNeuronLayer.Count); nextNeuronConnectionsByID = new Dictionary <uint, Dictionary <uint, weightConnection> >(nextNeuronLayer.Count); }
/// <summary> Creates, loads, links up, and returns a <see cref="WeightLayer"/> from the given <paramref name="networkLoader"/>. </summary> /// <param name="neuralNetwork"> The neural network for which this layer is created. </param> /// <param name="networkLoader"> The <see cref="INetworkLoader"/> used to load this <see cref="WeightLayer"/>. </param> /// <param name="index"> The index of this new <see cref="WeightLayer"/>. </param> /// <param name="previousNeuronLayer"> The previous <see cref="NeuronLayer"/> that this <see cref="WeightLayer"/> is linked to. </param> /// <param name="nextNeuronLayer"> The next <see cref="NeuronLayer"/> that this <see cref="WeightLayer"/> is linked to. </param> /// <returns> A new <see cref="WeightLayer"/> loaded from the given parameters. </returns> public static WeightLayer Load(IReadOnlyNeuralNetwork neuralNetwork, INetworkLoader networkLoader, uint index, ILinkableNeuronLayer previousNeuronLayer, ILinkableNeuronLayer nextNeuronLayer) { // Create the weight layer to return. WeightLayer weightLayer = new WeightLayer(neuralNetwork, index, previousNeuronLayer, nextNeuronLayer); // Get all defined connections from the file. Tuple <uint, float, uint>[] connections = networkLoader.GetAllWeightConnections(index); // Link the layers together based on the given connections. for (int i = 0; i < connections.Length; i++) { weightLayer.LinkNeurons(previousNeuronLayer[connections[i].Item1], nextNeuronLayer[connections[i].Item3], connections[i].Item2); } // Return the weight layer. return(weightLayer); }