public void BatchTrain() { int trainCnt = 0; Random rnd = new Random(); double [][] inputSet = new double[_trainSetSize][]; double[][] labelSet = new double[_trainSetSize][]; while (!stopCriteria()) { for (int i = 0; i < _trainSetSize; i++) { int index = rnd.Next(_dataMgr.count - 1); inputSet[i] = _dataMgr.GetInputData(index); if (!_normalizeOuput) { labelSet[i] = _dataMgr.GetIntLabelData(index); } } _network.BatchTrain(inputSet, labelSet); Test(); trainCnt++; Console.WriteLine("TRAINING TIME " + trainCnt + " with successrate " + _successRate + " and mse " + _mse); } }
public void Test() { int successTime = 0; double mse = 0; for (int i = 0; i < _testSetSize; i++) { double labelData = _dataMgr.GetDoubleLabelData(i); double [] inputData = _dataMgr.GetNormalizedInputData(i); double[] labelData2 = _dataMgr.GetIntLabelData(i); _mlp.SetInput(inputData); _mlp.Feedfowrad(); double maxIndex = _mlp.GetMaxOutputIndex(); if (labelData == maxIndex) { successTime++; } double[] outputData = _mlp.GetIntOutput(); mse += GetMSE(outputData, labelData2); } _mse = mse / (double)_testSetSize; _successRate = (double)successTime / (double)_testSetSize; Console.WriteLine("Test set - success rate : " + _successRate + " - mse : " + _mse); }
public void OnlineTrain() { int trainCnt = 0; Random rnd = new Random(); while (!stopCriteria(trainCnt)) { Console.Write("\n"); for (int i = 0; i < _trainSetSize; i++) { int index = rnd.Next(_dataMgr.count - 1); //Console.WriteLine(i); //Console.Write("-"); if (!_normalizeOuput) { double[] input; if (_normalizeInput) { input = _dataMgr.GetNormalizedInputData(index); } else { input = _dataMgr.GetInputData(index); } double[] label = _dataMgr.GetIntLabelData(index); _network.OnlineTrain(input, label); } } //Console.Write("\n"); Test(); trainCnt++; if (trainCnt % 5 == 0) { _network.DumpToFile(); } Console.WriteLine("TRAINING TIME " + trainCnt + " with successrate " + _successRate + " and mse " + _mse); } }