ForceIdentityDistance::ForceIdentityDistance(const PointLayout& layout, const ParameterMap& params) : DistanceFunction(layout, params) { validParams = QStringList() << "distance" << "params"; _dist = MetricFactory::create(params.value("distance"), layout, params.value("params", ParameterMap()).toParameterMap()); }
int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); gaia2::verbose = true; // get command-line options ParameterMap options = parseOptions(argc, argv); yaml::Node filelist = yaml::loadFromFile(options.value("inputFiles")); const yaml::Mapping& tracks = filelist.mapping(); // convert our yaml::Map to a QMap we can give to mergeFiles QMap<QString, QString> sigfiles; yaml::Mapping::const_iterator it = tracks.constBegin(); for (; it != tracks.constEnd(); ++it) { sigfiles.insert(it.key().toString(), it.value().toString()); } //qDebug() << "Found" << tracks.size() << "in filelist"; // do the actual merging DataSet* dataset = DataSet::mergeFiles(sigfiles, descs_select, descs_exclude, options.value("start").toInt(), options.value("end").toInt(), layout); // save dataset & clean up stuff qDebug() << "Saving dataset..."; dataset->save(options.value("dataset")); qDebug() << "Dataset successfully saved!"; // let the OS reclaim the memory itself, much faster than deleting the dataset here... //delete dataset; return 0; }
int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); ParameterMap options = parseOptions(argc, argv); gaia2::init(); gaia2::verbose = true; if (options.value("verbose").toBool()) { setDebugLevel(GTools); } DataSet dataset; int npoints; int dimension; try { G_INFO("Loading dataset: " << options.value("dataset")); dataset.load(options.value("dataset")); npoints = dataset.size(); dimension = dataset.layout().correspondingRegion().dimension(); } catch (GaiaException& e) { G_ERROR(e.msg()); exit(1); } G_INFO("DataSet name: " << dataset.name()); G_INFO("Total number of points: " << npoints); G_INFO("Dimension: " << dimension); G_INFO(""); // --------------------------------------------------------------------------- G_INFO("Copying data into SuperMatrix (naive FrozenDataset)..."); G_INFO("fixed real data dimension = " << dataset[0]->frealData().size()); G_INFO("(note: should be 175 for gaiabench)"); G_INFO(""); float* frozenDataSet = new float[npoints*dimension]; for (int i=0; i<npoints; i++) { const int offset = i*dimension; const RealDescriptor& d = dataset[i]->frealData(); for (int j=0; j<dimension; j++) { frozenDataSet[offset+j] = d[j]; } } float* frozenDataSet2 = new float[npoints*25]; for (int i=0; i<npoints; i++) { const int offset = i*25; const RealDescriptor& d = dataset[i]->frealData(); for (int j=0; j<25; j++) { frozenDataSet2[offset+j] = d[150+j]; } } G_INFO("Copying data into gaia::FrozenDataSet..."); FrozenDataSet frozenDS; frozenDS.fromDataSet(dataset); gaia2::verbose = false; ParameterMap eucp; eucp.insert("descriptorNames", "pca"); DataSet* eucds = transform(&dataset, "select", eucp); FrozenDataSet frozeuc; frozeuc.fromDataSet(*eucds); delete eucds; gaia2::verbose = true; G_INFO("FrozenDataSets ready"); G_INFO(""); // --------------------------------------------------------------------------- G_INFO(G_HLINE "\n"); const char* hybridDistanceParams = "colfilter: \n" " weight: 0.4 \n" " distance: cosineangle \n" " params: \n" " descriptorNames: colfilter \n" " defaultValue: 0.0 \n" " \n" "context: \n" " weight: 0.4 \n" " distance: cosineangle \n" " params: \n" " descriptorNames: context \n" " defaultValue: 0.0 \n" " \n" "content: \n" " weight: 0.2 \n" " distance: euclidean \n" " params: \n" " descriptorNames: pca \n" " \n"; // pick a point for doing all the queries const Point& query = *dataset.at(1234); const float* fquery = query.frealData().constBegin(); G_DEBUG(GTools, "query point: " << query.name() << '\n'); // --------------------------------------------------------------------------- G_INFO('\n' << G_TITLE("USING HYBRID DISTANCE") << '\n'); ParameterMap params = toParameterMap(yaml::load(hybridDistanceParams)); DistanceFunction* dist = MetricFactory::create("LinearCombination", dataset.layout(), params); normalSearch(dataset, dist, query, N); // --------------------------------------------------------------------------- frozenSearch(dataset, frozenDataSet, 175, fquery, N, BmatDistance(0.4, 0.4, 0.2)); // --------------------------------------------------------------------------- deepFreeze(frozenDS, FrozenBmatDistance(frozenDS), Eigen::RowVectorXf::Map(fquery, 175), N); // --------------------------------------------------------------------------- G_INFO("(Folding data so that it can fit into L2 cache, but doing the\n" " exact same amount of computation as the previous line)"); G_DEBUG(GTools, "[[[ Note that the results here will be incorrect ]]]"); deepFoldedFreeze(frozenDS, FrozenBmatDistance(frozenDS), Eigen::RowVectorXf::Map(fquery, 175), N); // --------------------------------------------------------------------------- multiQuery<FrozenBmatDistance, 0, 175>(frozenDS, 2); multiQuery<FrozenBmatDistance, 0, 175>(frozenDS, 5); multiQuery<FrozenBmatDistance, 0, 175>(frozenDS, 10); multiQuery<FrozenBmatDistance, 0, 175>(frozenDS, 20); // --------------------------------------------------------------------------- G_INFO('\n' << G_TITLE("USING ONLY EUCLIDEAN DISTANCE") << '\n'); N = 100; DistanceFunction* content = MetricFactory::create("Euclidean", dataset.layout(), params["content"].toParameterMap()["params"].toParameterMap()); normalSearch(dataset, content, query, N); // --------------------------------------------------------------------------- frozenSearch(dataset, frozenDataSet+150, 175, fquery+150, N, EuclideanDistance(25)); // --------------------------------------------------------------------------- G_INFO("(Using compacted datasets without context/colfilt data)"); frozenSearch(dataset, frozenDataSet2, 25, fquery+150, N, EuclideanDistance(25)); // --------------------------------------------------------------------------- deepFreeze(frozeuc, FrozenEuclideanDistance(frozeuc, 0, 25), Eigen::RowVectorXf::Map(fquery+150, 25), N); // --------------------------------------------------------------------------- G_INFO("(Folding data so that it can fit into L2 cache, but doing the\n" " exact same amount of computation as the previous line)"); G_DEBUG(GTools, "[[[ Note that the results here will be incorrect ]]]"); deepFoldedFreeze(frozeuc, FrozenEuclideanDistance(frozeuc, 0, 25), Eigen::RowVectorXf::Map(fquery+150, 25), N); // --------------------------------------------------------------------------- multiQuery<FrozenEuclideanDistance, 0, 25>(frozeuc, 2); multiQuery<FrozenEuclideanDistance, 0, 25>(frozeuc, 5); multiQuery<FrozenEuclideanDistance, 0, 25>(frozeuc, 10); // --------------------------------------------------------------------------- delete dist; delete content; delete[] frozenDataSet; delete[] frozenDataSet2; gaia2::shutdown(); return 0; }