int main() { FileReader* pointCloudReader = new FileReader("Jiangtailgong.pcd"); Visualizer* visualizer = new Visualizer(pointCloudReader->getPointCloud()); visualizer->visualize(); return 0; }
void plotLearningCurves(NNModel* model, DataParser* trainingSet, DataParser* cvSet, double lambda){ /* getting training set and cross validation set */ mat& xTrain = trainingSet->getExampleSet(); mat& yTrain = trainingSet->getLabelSet(); mat& xCross = cvSet->getExampleSet(); mat& yCross = cvSet->getLabelSet(); /* Initializing some usefull variables */ int m = xTrain.n_rows; int numEvaluations = ((m-stepSize) / stepSize)+1; /* Initializing data containers */ double* errorCV = new double[numEvaluations]; double* errorT = new double[numEvaluations]; double* foldSizes = new double[numEvaluations]; int currentFoldSize = stepSize; mat predictions; for (int i = 0; i < numEvaluations; i++) { /* Initializing example fold(size is dependent on iteration) */ mat xFold = xTrain.head_rows(currentFoldSize); mat yFold = yTrain.head_rows(currentFoldSize); /* Training model over current example fold */ NNBackPropagation * backPropagation = new NNBackPropagation(model, xFold, yFold, lambda); backPropagation->optimize(numTrainingIterations); model = backPropagation->getUpdatedModel(); /* Getting error over current fold and cross validation set */ predictions = model->predict(xFold); errorT[i] = model->getCostOver(predictions, yFold); predictions = model->predict(xCross); errorCV[i] = model->getCostOver(predictions, yCross); foldSizes[i] = currentFoldSize; /* Showing the results of iteration */ cout << " Cost for crossVal. set: " << errorCV[i] << endl; cout << " Cost for training fold: " << errorT[i] << endl; cout << " Training finished for fold of: " << currentFoldSize << endl << endl; /* Changing variables */ currentFoldSize += stepSize; model->randomlyInitialize(); delete backPropagation; } cout << " == Computation finished." << endl; cout << " == Visualizing data." << endl; /* ================== Plotting the results ================== */ ostringstream plotNameStream; plotNameStream << "\"" << "Learning curves: lambda = " << lambda << "\""; string plotName = plotNameStream.str(); Visualizer *visualizer = new Visualizer(""); visualizer->addSeries("\"Crossvalidation set\"", numEvaluations, foldSizes, errorCV); visualizer->addSeries("\"Training set\"", numEvaluations, foldSizes, errorT); visualizer->visualize("\"Learning curves\"", (char*)plotName.c_str(), "\"Fold size\"", "error"); }