/// <summary> /// Copies this NeuralLayer including its weights. /// </summary> /// <returns>A deep copy of this NeuralLayer</returns> public NeuralLayer DeepCopy() { //Copy weights var copiedWeights = new float[Weights.GetLength(0), Weights.GetLength(1)]; for (var x = 0; x < Weights.GetLength(0); x++) { for (var y = 0; y < Weights.GetLength(1); y++) { copiedWeights[x, y] = Weights[x, y]; } } //Create copy var newLayer = new NeuralLayer(NeuronCount, OutputCount); newLayer.Weights = copiedWeights; newLayer.NeuronActivationFunctionType = NeuronActivationFunctionType; return(newLayer); }
/// <summary> /// Initialises a new fully connected feedforward neural network with given topology. /// </summary> /// <param name="topology"> /// An array of unsigned integers representing the node count of each layer from input to output /// layer. /// </param> public NeuralNetwork(ActivationFunctionType activationFunction, params uint[] topology) { Topology = topology; //Calculate overall weight count WeightCount = 0; for (var i = 0; i < topology.Length - 1; i++) { WeightCount += (int)((topology[i] + 1) * topology[i + 1]); // + 1 for bias node } //Initialise layers Layers = new NeuralLayer[topology.Length - 1]; for (var i = 0; i < Layers.Length; i++) { Layers[i] = new NeuralLayer(topology[i], topology[i + 1]) { NeuronActivationFunctionType = activationFunction } } ; }