/// <summary> /// Gets (and removes) a random example from the 'presentlyProcessed' /// </summary> /// <param name="index"></param> /// <returns></returns> public NeuralNetworkExample GetExample(int index) { NeuralNetworkExample obj = presentlyProcessed.Get(index); presentlyProcessed.Remove(obj); return(obj); }
/// <summary> /// Induces the layer of this perceptron from the specified set of examples /// </summary> /// <param name="innds">a set of training examples for constructing the layer of this perceptron.</param> /// <param name="numberofEpochs">the number of training epochs to be used.</param> public void TrainOn(NeuralNetworkDataSet innds, int numberofEpochs) { for (int i = 0; i < numberofEpochs; ++i) { innds.RefreshDataset(); while (innds.HasMoreExamples()) { NeuralNetworkExample nne = innds.GetExampleAtRandom(); ProcessInput(nne.GetInput()); Vector error = layer.ErrorVectorFrom(nne.GetTarget()); ProcessError(error); } } }
/// <summary> /// Returns the accuracy of the hypothesis on the specified set of examples /// </summary> /// <param name="nnds">the neural network data set to be tested on.</param> /// <returns>the accuracy of the hypothesis on the specified set of examples</returns> public int[] TestOnDataSet(NeuralNetworkDataSet nnds) { int[] result = new int[] { 0, 0 }; nnds.RefreshDataset(); while (nnds.HasMoreExamples()) { NeuralNetworkExample nne = nnds.GetExampleAtRandom(); Vector prediction = Predict(nne); if (nne.IsCorrect(prediction)) { result[0] = result[0] + 1; } else { result[1] = result[1] + 1; } } return(result); }
/// <summary> /// Returns the outcome predicted for the specified example /// </summary> /// <param name="nne">an example</param> /// <returns>the outcome predicted for the specified example</returns> public Vector Predict(NeuralNetworkExample nne) { return(ProcessInput(nne.GetInput())); }