本文整理汇总了C++中Benchmark::getAnswer方法的典型用法代码示例。如果您正苦于以下问题:C++ Benchmark::getAnswer方法的具体用法?C++ Benchmark::getAnswer怎么用?C++ Benchmark::getAnswer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Benchmark
的用法示例。
在下文中一共展示了Benchmark::getAnswer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[])
{
string prefix;
unsigned K;
float R;
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message.")
(",K", po::value<unsigned>(&K)->default_value(100), "number of nearest neighbors.")
("prefix,D", po::value<string>(&prefix), "")
("threshold,R", po::value<float>(&R)->default_value(std::numeric_limits<float>::max()), "radius of search.")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help") || (vm.count("prefix") < 1))
{
cout << help << endl;
cout << desc;
return 0;
}
Matrix<float> train(prefix + ".train");
Matrix<float> test(prefix + ".test");
Benchmark<unsigned> bench;
bench.init(test.getSize(), test.getSize() * 100);
boost::timer timer;
timer.restart();
metric::l2<float> l2(train.getDim());
boost::progress_display progress(test.getSize());
int totalSize = 0;
for (unsigned i = 0; i < test.getSize(); ++i)
{
Topk<unsigned> &topk = bench.getAnswer(i);
topk.reset(K,R);
for (unsigned j = 0; j < train.getSize(); ++j)
{
topk << Topk<unsigned>::Element(j, l2(test[i],
train[j]));
}
++progress;
totalSize += topk.numElements();
}
cout << boost::format("QUERY TIME: %1%s.") % timer.elapsed() << endl;
cout << "Average List Size: " << float(totalSize)/test.getSize() << endl;
if (R < std::numeric_limits<float>::max())
bench.save(prefix + ".bench-eps");
else
bench.save(prefix + ".bench");
return 0;
}
示例2: main
//.........这里部分代码省略.........
index.init(param, rng, L);
// The accessor.
// Initialize the index structure. Note L is passed here.
cout << "CONSTRUCTING INDEX..." << endl;
timer.restart();
{
boost::progress_display progress(data.getSize());
for (int i = 0; i < data.getSize(); ++i)
{
// Insert an item to the hash table.
// Note that only the key is passed in here.
// MPLSH will get the feature from the accessor.
index.insert(i, data[i]);
++progress;
}
}
cout << boost::format("CONSTRUCTION TIME: %1%s.") % timer.elapsed() << endl;
if (use_index) {
timer.restart();
cout << "SAVING INDEX..." << endl;
{
ofstream os(index_file.c_str(), ios_base::binary);
os.exceptions(ios_base::eofbit | ios_base::failbit | ios_base::badbit);
index.save(os);
}
cout << boost::format("SAVING TIME: %1%s") % timer.elapsed() << endl;
}
}
if (do_benchmark) {
Benchmark<> bench;
cout << "LOADING BENCHMARK..." << endl;
bench.load(benchmark);
bench.resize(Q, K);
cout << "DONE." << endl;
for (unsigned i = 0; i < Q; ++i)
{
for (unsigned j = 0; j < K; ++j)
{
assert(bench.getAnswer(i)[j].key < data.getSize());
}
}
cout << "RUNNING QUERIES..." << endl;
Stat recall;
Stat cost;
metric::l2sqr<float> l2sqr(data.getDim());
TopkScanner<FloatMatrix::Accessor, metric::l2sqr<float> > query(accessor, l2sqr, K, R);
vector<Topk<unsigned> > topks(Q);
timer.restart();
if (do_recall)
// Specify the required recall
// and let MPLSH to guess how many bins to probe.
{
boost::progress_display progress(Q);
for (unsigned i = 0; i < Q; ++i)
{
// Query for one point.
query.reset(data[bench.getQuery(i)]);
index.query_recall(data[bench.getQuery(i)], desired_recall, query);
cost << double(query.cnt())/double(data.getSize());
topks[i].swap(query.topk());
++progress;
}
}
else
// specify how many bins to probe.
{
boost::progress_display progress(Q);
for (unsigned i = 0; i < Q; ++i)
{
query.reset(data[bench.getQuery(i)]);
index.query(data[bench.getQuery(i)], T, query);
cost << double(query.cnt())/double(data.getSize());
topks[i].swap(query.topk());
++progress;
}
}
for (unsigned i = 0; i < Q; ++i) {
recall << bench.getAnswer(i).recall(topks[i]);
}
cout << boost::format("QUERY TIME: %1%s.") % timer.elapsed() << endl;
cout << "[RECALL] " << recall.getAvg() << " +/- " << recall.getStd() << endl;
cout << "[COST] " << cost.getAvg() << " +/- " << cost.getStd() << endl;
}
return 0;
}
示例3: main
//.........这里部分代码省略.........
if (!index_loaded) {
// We define a short name for the MPLSH index.
float min = numeric_limits<float>::max();
float max = -numeric_limits<float>::max();
for (unsigned i = 0; i < data.getSize(); ++i) {
for (unsigned j = 0; j < data.getDim(); ++j) {
if (data[i][j] > max) max = data[i][j];
if (data[i][j] < min) min = data[i][j];
}
}
*/
Index::Parameter param;
// Setup the parameters. Note that L is not provided here.
param.W = W;
param.dim = data.getDim();
DefaultRng rng;
index.init(param, rng, L, H);
// The accessor.
// Initialize the index structure. Note L is passed here.
cout << "CONSTRUCTING INDEX..." << endl;
timer.restart();
{
boost::progress_display progress(data.getSize());
for (unsigned i = 0; i < data.getSize(); ++i)
{
// Insert an item to the hash table.
// Note that only the key is passed in here.
// MPLSH will get the feature from the accessor.
index.insert(i, accessor);
++progress;
}
}
cout << boost::format("CONSTRUCTION TIME: %1%s.") % timer.elapsed() << endl;
/*
if (use_index) {
timer.restart();
cout << "SAVING INDEX..." << endl;
{
ofstream os(index_file.c_str(), ios_base::binary);
os.exceptions(ios_base::eofbit | ios_base::failbit | ios_base::badbit);
index.save(os);
verify(os);
}
cout << boost::format("SAVING TIME: %1%s") % timer.elapsed() << endl;
}
}
*/
if (do_benchmark) {
Benchmark<> bench;
cout << "LOADING BENCHMARK..." << endl;
bench.load(benchmark);
bench.resize(Q, K);
cout << "DONE." << endl;
for (unsigned i = 0; i < Q; ++i)
{
for (unsigned j = 0; j < K; ++j)
{
assert(bench.getAnswer(i)[j].key < data.getSize());
}
}
cout << "RUNNING QUERIES..." << endl;
Stat recall;
Stat cost;
timer.restart();
{
TopkScanner<FloatMatrix::Accessor, metric::l2<float> > query(accessor, l2, K, R);
boost::progress_display progress(Q);
for (unsigned i = 0; i < Q; ++i)
{
query.reset(data[bench.getQuery(i)]);
index.query(data[bench.getQuery(i)], c * L, query);
recall << bench.getAnswer(i).recall(query.topk());
cost << double(query.cnt())/double(data.getSize());
++progress;
}
}
cout << boost::format("QUERY TIME: %1%s.") % timer.elapsed() << endl;
cout << "[RECALL] " << recall.getAvg() << " +/- " << recall.getStd() << endl;
cout << "[COST] " << cost.getAvg() << " +/- " << cost.getStd() << endl;
}
return 0;
}