# Pastebin ZNAys3Bc #include #include #include #include using namespace mlpack; using namespace std; using namespace dlib; // Information about the program itself. PROGRAM_INFO("KMEANS Clustering", "This program will perform KMEANS clustering with the DLib-ml " "library."); // Define our input parameters that this program will take. PARAM_STRING_IN("reference_file", "File containing the reference dataset.", "r", ""); PARAM_INT_IN("k", "Value of K", "k", 0); PARAM_STRING_IN("query_file", "File containing query points (optional).", "q", ""); PARAM_STRING_OUT("assignments_file", "File to output assignments into.", "a"); int main(int argc, char** argv) { // Parse command line options. CLI::ParseCommandLine(argc, argv); // Get all the parameters. const string referenceFile = CLI::GetParam("reference_file"); const string queryFile = CLI::GetParam("query_file"); size_t k = CLI::GetParam("k"); arma::mat referenceData; arma::mat queryData; // So it doesn't go out of scope. data::Load(referenceFile, referenceData, true); Log::Info << "Loaded reference data from '" << referenceFile << "' (" << referenceData.n_rows << " x " << referenceData.n_cols << ")." << endl; if (queryFile != "") { data::Load(queryFile, queryData, true); Log::Info << "Loaded query data from '" << queryFile << "' (" << queryData.n_rows << " x " << queryData.n_cols << ")." << endl; } typedef matrix sample_type; typedef radial_basis_kernel kernel_type; kcentroid kc(kernel_type(0.1),0.01, 8); kkmeans test(kc); std::vector samples = referenceData; std::vector initial_centers; test.set_number_of_centers(k); pick_initial_centers(k, initial_centers, samples, test.get_kernel()); Timer::Start("clustering"); test.train(samples,initial_centers); std::vector assignments = spectral_cluster(kernel_type(0.1), samples, k); Timer::Stop("clustering"); // Save output, if desired. if (CLI::HasParam("assignments_file")) data::Save(CLI::GetParam("assignments_file"), assignments); return 0; }