Last active
March 13, 2017 07:51
-
-
Save MikeLing/b6c7d0a38ce6079c42e4717582d322cc to your computer and use it in GitHub Desktop.
fix an issue in mlpack decision tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "armadillo" | |
using namespace arma; | |
using namespace std; | |
/* | |
*This one will output " 3 1 2 9 0 1 8 2 5" | |
*/ | |
int test1() { | |
arma::Mat<double> labels = {"2 1 5 3 8 9 2 0 1"}; | |
arma::uvec sortedIndices = arma::sort_index(labels); | |
arma::Row<size_t> sortedLabels(labels.n_elem); | |
for (size_t i = 0; i < sortedLabels.n_elem; ++i) | |
sortedLabels[sortedIndices[i]] = labels[i]; | |
std::cout << sortedIndices << std::endl; | |
std::cout << '\n' << std::endl; | |
std::cout << sortedLabels << std::endl; | |
return 0; | |
} | |
/* | |
*This one will output " 0 1 1 2 2 3 5 8 9" which is right(I think :)) | |
*/ | |
int test2() { | |
arma::Mat<double> labels = {"2 1 5 3 8 9 2 0 1"}; | |
arma::uvec sortedIndices = arma::sort_index(labels); | |
arma::Row<size_t> sortedLabels(labels.n_elem); | |
for (size_t i = 0; i < sortedLabels.n_elem; ++i) | |
sortedLabels[i] = labels[sortedIndices[i]]; | |
std::cout << sortedIndices << std::endl; | |
std::cout << '\n' << std::endl; | |
std::cout << sortedLabels << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment