public static List <TrainingDataDto> GetTestingSet(NeuralNetworkTrainingConfig trainingConfig) { List <TrainingDataDto> trainingSet = new List <TrainingDataDto>(); string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(System.IO.Path.Combine(trainingConfig.TrainingDatabaseFileRoute, trainingConfig.TrainingDatabaseTestFileName)); while ((line = file.ReadLine()) != null) { var trainingRow = new TrainingDataDto(); var lines = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); trainingRow.XEntries = Array.ConvertAll(lines.Take(trainingConfig.InputSize).ToArray(), System.Convert.ToDouble) .ToList(); trainingRow.YExpected = Array.ConvertAll(lines.Skip(trainingConfig.InputSize) .Take(trainingConfig.PredictedObjects.Count).ToArray(), System.Convert.ToDouble) .ToList(); trainingSet.Add(trainingRow); } file.Close(); return(trainingSet); }
public static PredictedObjectResultDto GetNetworkPredictionOptimized(IList <NeuronForManipulation> HiddenLayer, IList <NeuronForManipulation> OutputLayer, NeuralNetworkTrainingConfig neuralNetworkConfig, IList <double> input) { List <double> hiddenOutput = new List <double>(); foreach (NeuronForManipulation hiddenNeuron in HiddenLayer) { CalculateNeuronOutput(hiddenNeuron, neuralNetworkConfig.HiddenActivationFunction, Alpha, input); hiddenOutput.Add(hiddenNeuron.Output); } foreach (NeuronForManipulation outputNeuron in OutputLayer) { CalculateNeuronOutput(outputNeuron, neuralNetworkConfig.OutputActivationFunction, Alpha, hiddenOutput); } var maxNeuralNetwork = OutputLayer.OrderByDescending(s => s.Output).FirstOrDefault(); var predictedObject = neuralNetworkConfig.PredictedObjects.Where(po => po.Index == maxNeuralNetwork.Index).FirstOrDefault(); return(new PredictedObjectResultDto { ObjectName = predictedObject.ObjectName, Index = maxNeuralNetwork.Index, Accuracy = maxNeuralNetwork.Output }); }