Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
searchivarius committed May 24, 2019
2 parents 658214d + 535fa79 commit 16a7209
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
29 changes: 24 additions & 5 deletions similarity_search/apps/report_intr_dim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void TestSpace(
string dataFile,
bool compMuDeffect,
unsigned maxNumData,
unsigned sampleQty
unsigned sampleQty,
string sampleFile
) {
string spaceType;
vector<string> vSpaceArgs;
Expand All @@ -90,9 +91,21 @@ void TestSpace(
vector<string> tmp;
unique_ptr<DataFileInputState> inpState(space->ReadDataset(data, tmp, dataFile, maxNumData));
space->UpdateParamsFromFile(*inpState);
vector<double> dist;

// Prints the report
ReportIntrinsicDimensionality("********", *space, data, sampleQty);
ReportIntrinsicDimensionality("********", *space, data, dist, sampleQty);
if (!sampleFile.empty()) {
ofstream of(sampleFile);
CHECK_MSG(of, "Cannot open for writing file: " + sampleFile);
of.exceptions ( std::ifstream::failbit | std::ifstream::badbit );

for (size_t i = 0; i < dist.size(); ++i) {
if (i) of << ",";
of << dist[i];
}
of << std::endl;
}
if (compMuDeffect) {
double dleft, dright;
ComputeMuDeffect<dist_t>(
Expand All @@ -108,6 +121,7 @@ void TestSpace(
int main(int argc, char* argv[]) {
string spaceDesc, distType;
string dataFile;
string sampleFile;
unsigned maxNumData;
unsigned sampleQty;
bool compMuDeffect;
Expand All @@ -126,6 +140,8 @@ int main(int argc, char* argv[]) {
&sampleQty, false, defaultSampleQty));
cmd_options.Add(new CmdParam("muDeffect,m", "estimate the left and the right mu deffectiveness",
&compMuDeffect, false, false));
cmd_options.Add(new CmdParam("sampleFile", "optional output sample file",
&sampleFile, false, ""));

try {
cmd_options.Parse(argc, argv);
Expand All @@ -143,23 +159,26 @@ int main(int argc, char* argv[]) {
dataFile,
compMuDeffect,
maxNumData,
sampleQty
sampleQty,
sampleFile
);
} else if (DIST_TYPE_FLOAT == distType) {
TestSpace<float>(
spaceDesc,
dataFile,
compMuDeffect,
maxNumData,
sampleQty
sampleQty,
sampleFile
);
} else if (DIST_TYPE_DOUBLE == distType) {
TestSpace<double>(
spaceDesc,
dataFile,
compMuDeffect,
maxNumData,
sampleQty
sampleQty,
sampleFile
);
}

Expand Down
5 changes: 4 additions & 1 deletion similarity_search/include/report_intr_dim.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ void ComputeIntrinsicDimensionality(const Space<dist_t>& space,
double& IntrDim,
double& DistMean,
double& DistSigma,
std::vector<double>& dist,
size_t SampleQty = 1000000) {
std::vector<double> dist;
DistMean = 0;
dist.clear();
for (size_t n = 0; n < SampleQty; ++n) {
size_t r1 = RandomInt() % dataset.size();
size_t r2 = RandomInt() % dataset.size();
Expand Down Expand Up @@ -70,13 +71,15 @@ template <typename dist_t>
void ReportIntrinsicDimensionality(const string& reportName,
const Space<dist_t>& space,
const ObjectVector& dataset,
std::vector<double>& dist,
size_t SampleQty = 1000000) {
double DistMean, DistSigma, IntrDim;

ComputeIntrinsicDimensionality(space, dataset,
IntrDim,
DistMean,
DistSigma,
dist,
SampleQty);

LOG(LIB_INFO) << "### " << reportName;
Expand Down
3 changes: 2 additions & 1 deletion similarity_search/src/method/perm_bin_vptree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void PermBinVPTree<dist_t, RankCorrelDistFunc>::CreateIndex(const AnyParams& Ind
BinPermData_[i] = VPTreeSpace_->CreateObjFromVect(i, -1, binPivot);
}

ReportIntrinsicDimensionality("Set of permutations" , *VPTreeSpace_, BinPermData_);
vector<double> dist;
ReportIntrinsicDimensionality("Set of permutations" , *VPTreeSpace_, BinPermData_, dist);
VPTreeIndex_.reset(new VPTree<int, PolynomialPruner<int>>(
PrintProgress_,
*VPTreeSpace_,
Expand Down
3 changes: 2 additions & 1 deletion similarity_search/src/method/proj_vptree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ void ProjectionVPTree<dist_t>::CreateIndex(const AnyParams& IndexParams) {
projData_[id] = ProjectOneVect(id, NULL, this->data_[id]);
}

ReportIntrinsicDimensionality("Set of projections" , *VPTreeSpace_, projData_);
vector<double> dist;
ReportIntrinsicDimensionality("Set of projections" , *VPTreeSpace_, projData_, dist);

VPTreeIndex_.reset(new VPTree<float, PolynomialPruner<float>>(
PrintProgress_,
Expand Down

0 comments on commit 16a7209

Please sign in to comment.