@@ -284,6 +284,7 @@ void Algorithm::classify_perceptrons_MSE(Eigen::MatrixXd weights) {
284284 }
285285}
286286
287+ /* Taken from https://stackoverflow.com/questions/2704521/generate-random-double-numbers-in-c */
287288double fRand (double fMin , double fMax )
288289{
289290 double f = (double )rand () / RAND_MAX;
@@ -365,13 +366,42 @@ void Algorithm::train_perceptrons_BPG(Eigen::MatrixXd &weights) {
365366}
366367
367368void Algorithm::classify_perceptrons_BPG (Eigen::MatrixXd weights) {
368-
369+ std::cout << " \t -> Classifying..." << std::endl;
370+
371+ /* Build the testing elements matrix */
372+ int n = 0 ;
373+ Eigen::MatrixXd testing_elements_matrix (input_data->getVectorSize (), input_data->getTestingElements ().size ());
374+ for (auto const &testing_element : input_data->getTestingElements ()) {
375+ testing_elements_matrix.col (n) = testing_element.data ;
376+ n++;
377+ }
378+
379+ /* Augment the data */
380+ Eigen::MatrixXd augmented_test_elements (testing_elements_matrix);
381+ augmented_test_elements.conservativeResize (augmented_test_elements.rows () + 1 , Eigen::NoChange);
382+ augmented_test_elements.row (augmented_test_elements.rows () - 1 ).setZero ();
383+
384+ /* Compute classification */
385+ Eigen::MatrixXd computed_elements (weights.transpose () * augmented_test_elements);
386+ n = 0 ;
387+ for (auto const &training_class : input_data->getTrainingElements ()) {
388+ for (int i = 0 ; i < computed_elements.cols (); i++) {
389+ if (computed_elements.row (n)(i) > 0 )
390+ input_data->getTestingElements ().at (i).given_class = training_class.first ;
391+
392+ }
393+ n++;
394+ }
369395}
370396
371397void Algorithm::perceptronBPG () {
372398 std::cout << " * Running a neural network of perceptrons using Back-Propagation..." << std::endl;
373399
374400 Eigen::MatrixXd weights;
401+ train_perceptrons_BPG (weights);
402+ classify_perceptrons_BPG (weights);
403+
404+ std::cout << std::endl << " * Done ! => Accuracy: " << calculateAccuracy () * 100 << " %" << std::endl << std::endl;
375405}
376406
377407
0 commit comments