Added Boost program options for command line for allknn
This commit is contained in:
@@ -46,6 +46,18 @@
|
||||
#include <fastlib/fastlib.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/serialization/string.hpp>
|
||||
#include <boost/serialization/utility.hpp>
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
using namespace std;
|
||||
namespace boost_po = boost::program_options;
|
||||
|
||||
boost_po::variables_map vm;
|
||||
|
||||
/**
|
||||
* Forward declaration for the tester class
|
||||
*/
|
||||
@@ -69,12 +81,20 @@ class AllkNN {
|
||||
|
||||
// Defines many useful things for a class, including a pretty
|
||||
// printer and copy constructor
|
||||
OT_DEF_BASIC(QueryStat) {
|
||||
friend class boost::serialization::access; // Should be removed later
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, QueryStat & query)
|
||||
{
|
||||
ar & query.max_distance_so_far_;
|
||||
}
|
||||
|
||||
/* OT_DEF_BASIC(QueryStat) {
|
||||
// Include this line for all non-pointer members
|
||||
// There are other versions for arrays and pointers, see base/otrav.h
|
||||
OT_MY_OBJECT(max_distance_so_far_);
|
||||
} // OT_DEF_BASIC
|
||||
|
||||
*/
|
||||
private:
|
||||
|
||||
/**
|
||||
@@ -476,8 +496,13 @@ class AllkNN {
|
||||
number_of_prunes_ = 0;
|
||||
|
||||
mode_=fx_param_str(module_, "mode", "dual");
|
||||
//mode_ = vm["mode"].as<std::string>();
|
||||
cout << "Mode successful:" << mode_;
|
||||
|
||||
// Get the leaf size from the module
|
||||
leaf_size_ = fx_param_int(module_, "leaf_size", 20);
|
||||
//leaf_size_ = vm["leaf_size"].as<int>();
|
||||
|
||||
// Make sure the leaf size is valid
|
||||
DEBUG_ASSERT(leaf_size_ > 0);
|
||||
|
||||
@@ -490,7 +515,8 @@ class AllkNN {
|
||||
|
||||
// K-nearest neighbors initialization
|
||||
knns_ = fx_param_int(module_, "knns", 5);
|
||||
|
||||
//knns_ = vm["knns"].as<int>();
|
||||
|
||||
// Initialize the list of nearest neighbor candidates
|
||||
neighbor_indices_.Init(queries_.n_cols() * knns_);
|
||||
|
||||
@@ -527,12 +553,15 @@ class AllkNN {
|
||||
module_ = module_in;
|
||||
|
||||
mode_=fx_param_str(module_, "mode", "dual");
|
||||
|
||||
//mode_ = vm["mode"].as<std::string>();
|
||||
|
||||
// track the number of prunes
|
||||
number_of_prunes_ = 0;
|
||||
|
||||
// Get the leaf size from the module
|
||||
leaf_size_ = fx_param_int(module_, "leaf_size", 20);
|
||||
//leaf_size_ = vm["leaf_size"].as<int>();
|
||||
|
||||
// Make sure the leaf size is valid
|
||||
DEBUG_ASSERT(leaf_size_ > 0);
|
||||
|
||||
@@ -541,7 +570,8 @@ class AllkNN {
|
||||
queries_.Alias(references_);
|
||||
// K-nearest neighbors initialization
|
||||
knns_ = fx_param_int(module_, "knns", 5);
|
||||
|
||||
//knns_ = vm["knns_"].as<int>();
|
||||
|
||||
// Initialize the list of nearest neighbor candidates
|
||||
neighbor_indices_.Init(references_.n_cols() * knns_);
|
||||
|
||||
|
||||
@@ -126,6 +126,26 @@ class TestAllkNN {
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
boost_po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help", "Display options")
|
||||
("reference_file", boost_po::value<std::string>(), " The reference file name")
|
||||
("result_file", boost_po::value<std::string>(), " The result file name")
|
||||
("query_file", boost_po::value<std::string>(), "Number of nearest neighbours" )
|
||||
("leaf_size", boost_po::value<index_t>(), "The number of points in a leaf")
|
||||
("mode", boost_po::value<std::string>() , "This can be either single or dual referring to dual tree and single tree algorithm")
|
||||
("knns", boost_po::value<int>(), "Number of nearest neighbours" );
|
||||
|
||||
boost_po::store(boost_po::parse_command_line(argc, argv, desc), vm);
|
||||
boost_po::notify(vm);
|
||||
|
||||
if( vm.count("help"))
|
||||
{
|
||||
cout << desc << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fx_module *module = fx_init(argc, argv, NULL);
|
||||
TestAllkNN test;
|
||||
test.TestAll();
|
||||
|
||||
@@ -55,19 +55,36 @@
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
fx_module *module = fx_init(argc, argv, NULL);
|
||||
std::string result_file = fx_param_str(module, "result_file", "result.txt");
|
||||
std::string reference_file = fx_param_str_req(module, "reference_file");
|
||||
//std::string result_file = fx_param_str(module, "result_file", "result.txt");
|
||||
//std::string reference_file = fx_param_str_req(module, "reference_file");
|
||||
Matrix reference_data;
|
||||
ArrayList<index_t> neighbors;
|
||||
ArrayList<double> distances;
|
||||
std::string result_file;
|
||||
std::string reference_file;
|
||||
std::string query_file;
|
||||
|
||||
boost_po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help", "Display options")
|
||||
("reference_file", boost_po::value<std::string>(&reference_file), " The reference file name")
|
||||
("result_file", boost_po::value<std::string>(&result_file), " The result file name")
|
||||
("query_file", boost_po::value<std::string>(&query_file), "Number of nearest neighbours" )
|
||||
("knns", boost_po::value<int>(), "Number of nearest neighbours" );
|
||||
|
||||
boost_po::store(boost_po::parse_command_line(argc, argv, desc), vm);
|
||||
boost_po::notify(vm);
|
||||
|
||||
if (data::Load(reference_file.c_str(), &reference_data)==SUCCESS_FAIL) {
|
||||
FATAL("Reference file %s not found", reference_file.c_str());
|
||||
}
|
||||
NOTIFY("Loaded reference data from file %s", reference_file.c_str());
|
||||
|
||||
AllkNN allknn;
|
||||
if (fx_param_exists(module, "query_file")) {
|
||||
std::string query_file=fx_param_str_req(module, "query_file");
|
||||
// if (fx_param_exists(module, "query_file")) {
|
||||
// std::string query_file=fx_param_str_req(module, "query_file");
|
||||
if ( 0 != vm.count("query_file")) {
|
||||
std::string query_file = vm["query_file"].as<std::string>();
|
||||
Matrix query_data;
|
||||
if (data::Load(query_file.c_str(), &query_data)==SUCCESS_FAIL) {
|
||||
FATAL("Query file %s not found", query_file.c_str());
|
||||
@@ -80,7 +97,8 @@ int main(int argc, char *argv[]) {
|
||||
allknn.Init(reference_data, module);
|
||||
}
|
||||
NOTIFY("Tree(s) built");
|
||||
index_t knns=fx_param_int_req(module, "knns");
|
||||
//index_t knns=fx_param_int_req(module, "knns");
|
||||
index_t knns = vm["knns"].as<index_t>();
|
||||
NOTIFY("Computing %"LI"d nearest neighbors", knns);
|
||||
allknn.ComputeNeighbors(&neighbors, &distances);
|
||||
NOTIFY("Neighbors computed");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user