void testNormalize() { BOOST_LOG(rdInfoLog) << "-----------------------\n test normalize" << std::endl; Normalizer normalizer; // Test sulfoxide normalization. std::string smi1 = "CS(C)=O"; std::shared_ptr<ROMol> m1(SmilesToMol(smi1)); ROMOL_SPTR normalized(normalizer.normalize(*m1)); TEST_ASSERT(MolToSmiles(*normalized) == "C[S+](C)[O-]"); // normalize sulfone. std::string smi2 = "C[S+2]([O-])([O-])C"; std::shared_ptr<ROMol> m2(SmilesToMol(smi2)); ROMOL_SPTR normalized2(normalizer.normalize(*m2)); TEST_ASSERT(MolToSmiles(*normalized2) == "CS(C)(=O)=O"); BOOST_LOG(rdInfoLog) << "Finished" << std::endl; }
int main() { cout << ">> TEST DATA SET (k=3)" << endl; rowvec inX = randu<rowvec>(4); mat dataSet = randu<mat>(4, 4); ucolvec labels; labels << 1 << endr << 3 << endr << 2 << endr << 3 << endr; inX.print("inX"); dataSet.print("dataSet:"); labels.print("labels:"); cout << "answer: " << knn(inX, dataSet, labels, 3) << endl << endl; cout << ">> RAND DATA SET (k=10)" << endl; srand ( time(NULL) ); inX = randu<rowvec>(100); dataSet = randu<mat>(1000000, 100); labels = arma::conv_to<ucolvec>::from(4 * randu<colvec>(1000000)); cout << "0s: " << count(labels.begin(), labels.end(), 0) << endl; cout << "1s: " << count(labels.begin(), labels.end(), 1) << endl; cout << "2s: " << count(labels.begin(), labels.end(), 2) << endl; cout << "3s: " << count(labels.begin(), labels.end(), 3) << endl; cout << "answer: " << knn(inX, dataSet, labels, 10) << endl << endl; cout << ">> FILE-BASED DATA SET (k=10)" << endl; mat data; data.load("datingTestSet2.txt"); dataSet = data.submat(0, 0, data.n_rows-1, data.n_cols-2); Normalizer <double> normalizer; dataSet = normalizer.normalize(dataSet); labels = arma::conv_to<ucolvec>::from(data.submat(0, data.n_cols-1, data.n_rows-1, data.n_cols-1)); rowvec inX1, inX2, inX3; inX1 << 58732 << 2.454285 << 0.222380 << endr; inX2 << 6121 << 8.339588 << 1.443357 << endr; inX3 << 36800 << 12.45 << 0.64 << endr; cout << "example from the 1st class:" << inX1 << "answer: " << knn(normalizer.normalize(inX1), dataSet, labels, 10) << endl << endl; cout << "example from the 2nd class:" << inX2 << "answer: " << knn(normalizer.normalize(inX2), dataSet, labels, 10) << endl << endl; cout << "example from the 3rd class:" << inX3 << "answer: " << knn(normalizer.normalize(inX3), dataSet, labels, 10) << endl << endl; return 0; }