Skip to content

Commit b05ecc5

Browse files
committed
fix a bug with IDF
1 parent 10dd161 commit b05ecc5

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/java/util/InvertedImageIndex.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public class InvertedImageIndex {
2525
ListMultimap<String, Image> mainConceptIndex = ArrayListMultimap.create();
2626
ListMultimap<String, Image> mainKeywordIndex = ArrayListMultimap.create();
2727

28-
HashMap<String, Integer> concepts = new HashMap<String, Integer>();
29-
3028
public InvertedImageIndex(){}
3129

3230
public InvertedImageIndex(ImageCollection iCollection){
@@ -44,13 +42,6 @@ public InvertedImageIndex(ImageCollection iCollection){
4442
String conceptId = conceptEntry.getKey();
4543
Concept concept = conceptEntry.getValue();
4644

47-
// maintain a list of TF for concepts
48-
if (!concepts.containsKey(conceptId)) {
49-
concepts.put(conceptId, 0);
50-
} else {
51-
concepts.put(conceptId, concepts.get(conceptId) + 1);
52-
}
53-
5445
// drop concepts where the score is 0
5546
if (concept.getScore() > 0.0) {
5647
this.putConceptImage(conceptId, image);
@@ -202,18 +193,17 @@ public List<Image> get() {
202193
}
203194
});
204195

205-
double numConcepts = concepts.size();
206196
for (String conceptId : conceptList.keySet()) {
207197

208-
double weight = conceptList.get(conceptId) * calculateIDF(numConcepts, concepts.get(conceptId));
198+
double weight = conceptList.get(conceptId) * calculateIDF(mainConceptIndex.size(), mainConceptIndex.get(conceptId).size());
209199
ranking = WeightedScorer.getInstance().combine(ranking, findImageByConcept(conceptId, imageCollection), weight);
210200

211201
}
212202
return ranking;
213203
}
214204

215205
private double calculateIDF(double N, double n_t) {
216-
return Math.log(N/n_t);
206+
return Math.log(N/(n_t+1));
217207
}
218208

219209
/**

0 commit comments

Comments
 (0)