/// <summary> /// Constructor for the neural network class /// </summary> /// <param name="numberInputs"> /// The number of nodes in the input layer /// </param> /// <param name="numberHiddenNodes"> /// An array of the number of hidden nodes in each hidden layer /// </param> /// <param name="numberOutputs"> /// The number of nodes in the output layer /// </param> /// <param name="learningRate"> /// The learning rate of the network /// </param> /// <param name="momentumFactor"> /// The momentum factor of the network /// </param> public NeuralNetwork(int numberInputs, int[] numberHiddenNodes, int numberOutputs, float learningRate, float momentumFactor) { this.numberHiddenLayers = numberHiddenNodes.Length; allLayers = new NeuronLayer[numberHiddenLayers + 2]; for (int i = 0; i < numberHiddenLayers + 2; i++) { if (i == 0) { inputLayer = allLayers[i] = new NeuronLayer(numberInputs, numberHiddenNodes[i], 0, learningRate, momentumFactor); } else if (i < numberHiddenLayers) { allLayers[i] = new NeuronLayer(numberHiddenNodes[i - 1], numberHiddenNodes[i], allLayers[i - 1].GetNumberNodes(), learningRate, momentumFactor); } else if (i < numberHiddenLayers + 1) { allLayers[i] = new NeuronLayer(numberHiddenNodes[i - 1], numberOutputs, allLayers[i - 1].GetNumberNodes(), learningRate, momentumFactor); } else { outputLayer = allLayers[i] = new NeuronLayer(numberOutputs, 0, allLayers[i - 1].GetNumberNodes(), learningRate, momentumFactor); } } inputLayer.Initialise(null, allLayers[1]); for (int i = 1; i < numberHiddenLayers + 1; i++) { allLayers[i].Initialise(allLayers[i - 1], allLayers[i + 1]); } outputLayer.Initialise(allLayers[numberHiddenLayers], null); }
/// <summary> /// Constructor for the neural network class /// </summary> /// <param name="numberInputs"> /// The number of nodes in the input layer /// </param> /// <param name="numberHiddenNodes"> /// An array of the number of hidden nodes in each hidden layer /// </param> /// <param name="numberOutputs"> /// The number of nodes in the output layer /// </param> /// <param name="learningRate"> /// The learning rate of the network /// </param> /// <param name="momentumFactor"> /// The momentum factor of the network /// </param> public NeuralNetwork(int numberInputs, int[] numberHiddenNodes, int numberOutputs, float learningRate, float momentumFactor) { this.numberHiddenLayers = numberHiddenNodes.Length; allLayers = new NeuronLayer[numberHiddenLayers + 2]; for (int i = 0; i < numberHiddenLayers + 2; i++) { if (i == 0) inputLayer = allLayers[i] = new NeuronLayer(numberInputs, numberHiddenNodes[i], 0, learningRate, momentumFactor); else if (i < numberHiddenLayers) allLayers[i] = new NeuronLayer(numberHiddenNodes[i - 1], numberHiddenNodes[i], allLayers[i - 1].GetNumberNodes(), learningRate, momentumFactor); else if (i < numberHiddenLayers + 1) allLayers[i] = new NeuronLayer(numberHiddenNodes[i - 1], numberOutputs, allLayers[i - 1].GetNumberNodes(), learningRate, momentumFactor); else outputLayer = allLayers[i] = new NeuronLayer(numberOutputs, 0, allLayers[i - 1].GetNumberNodes(), learningRate, momentumFactor); } inputLayer.Initialise(null, allLayers[1]); for (int i = 1; i < numberHiddenLayers + 1; i++) allLayers[i].Initialise(allLayers[i - 1], allLayers[i + 1]); outputLayer.Initialise(allLayers[numberHiddenLayers], null); }
/// <summary> /// Register the previous and next layers with the current layer /// </summary> /// <param name="parentLayer"> /// The previous layer /// </param> /// <param name="childLayer"> /// The next layer /// </param> public void Initialise(NeuronLayer parentLayer, NeuronLayer childLayer) { this.parentLayer = parentLayer; this.childLayer = childLayer; }