本文整理汇总了Java中net.semanticmetadata.lire.indexing.tools.ProximityHashingIndexor类的典型用法代码示例。如果您正苦于以下问题:Java ProximityHashingIndexor类的具体用法?Java ProximityHashingIndexor怎么用?Java ProximityHashingIndexor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProximityHashingIndexor类属于net.semanticmetadata.lire.indexing.tools包,在下文中一共展示了ProximityHashingIndexor类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHashing
import net.semanticmetadata.lire.indexing.tools.ProximityHashingIndexor; //导入依赖的package包/类
private void testHashing(Class featureClass, String fieldName) throws IOException, InstantiationException, IllegalAccessException {
String hashesFile = "hashes.obj";
String hashesFileL = "l_hashes.obj";
int numResults = 50;
int maxQueries = 20;
int queryOffset = 100;
File file = new File(hashesFile);
if (file.exists()) file.delete();
file = new File(hashesFileL);
if (file.exists()) file.delete();
BitSampling.generateHashFunctions(hashesFile);
LocalitySensitiveHashing.generateHashFunctions(hashesFileL);
// HashingIndexor hi = new HashingIndexor();
ProximityHashingIndexor hi = new ProximityHashingIndexor();
BitSampling.readHashFunctions(new FileInputStream(hashesFile));
LocalitySensitiveHashing.readHashFunctions(new FileInputStream(hashesFileL));
hi.setFeatureClass(featureClass);
hi.addInputFile(new File(dataSetDataOut));
hi.setIndexPath(testIndex);
hi.run();
System.out.println();
IndexReader reader = DirectoryReader.open(new RAMDirectory(FSDirectory.open(new File(testIndex)), IOContext.READONCE));
// generating ground truth for all queries ...
ImageSearcher groundTruth = new GenericFastImageSearcher(numResults, featureClass, fieldName);
ArrayList<ImageSearchHits> trueHitsList = new ArrayList<ImageSearchHits>(maxQueries);
long time = System.currentTimeMillis();
for (int q = 0; q < maxQueries; q++) {
trueHitsList.add(q, groundTruth.search(reader.document(q + queryOffset), reader));
}
time = System.currentTimeMillis() - time;
// header
System.out.println(featureClass.getName().substring(featureClass.getName().lastIndexOf('.') + 1));
System.out.println("Number of queries: " + maxQueries);
System.out.println("Time taken for linear search: " + (time / maxQueries));
System.out.printf("numFunctionBundles: %d, numBits: %d, w: %2.2f, dimensions: %d\n", BitSampling.getNumFunctionBundles(), BitSampling.getBits(), BitSampling.getW(), BitSampling.dimensions);
System.out.println("#hashedResults\ttrue pos.\t#results\tms per search\tprecision");
for (int j = 100; j <= 3000; j += 100) {
ImageSearcher hashed = new BitSamplingImageSearcher(numResults, fieldName, fieldName + "_hash", (LireFeature) featureClass.newInstance(), new FileInputStream(hashesFile), j);
long ms = 0;
long msSum = 0;
int posSum = 0;
for (int q = 0; q < maxQueries; q++) {
ms = System.currentTimeMillis();
ImageSearchHits hashedHits = hashed.search(reader.document(q + queryOffset), reader);
assert(hashedHits.length()<=numResults);
msSum += System.currentTimeMillis() - ms;
HashSet<Integer> t = new HashSet<Integer>(hashedHits.length());
HashSet<Integer> h = new HashSet<Integer>(hashedHits.length());
for (int i = 0; i < trueHitsList.get(q).length(); i++) {
t.add(((SimpleImageSearchHits) trueHitsList.get(q)).readerID(i));
h.add(((SimpleImageSearchHits) hashedHits).readerID(i));
}
assert (t.size() == h.size());
int intersect = 0;
for (Iterator<Integer> iterator = h.iterator(); iterator.hasNext(); ) {
if (t.contains(iterator.next())) {
intersect++;
}
}
posSum += intersect;
}
if (j > 1400) j += 100;
double truePositives = ((double) posSum) / ((double) maxQueries);
System.out.printf("%4d\t%4.1f\t%4d\t%6.1f\t%1.3f\n", j, truePositives, numResults, ((double) msSum) / ((double) maxQueries), truePositives / (double) numResults);
if (posSum / maxQueries == numResults) break;
}
}