System documentation of the GNU Image-Finding Tool

CWeightingFunction.h
1 /* -*- mode: c++ -*-
2 */
3 /*
4 
5  GIFT, a flexible content based image retrieval system.
6  Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
7 
8  Copyright (C) 2003, 2004 Bayreuth University
9  2005 Bamberg University
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 
24 */
42 #ifndef _CWEIGHTINGFUNCTION
43 #define _CWEIGHTINGFUNCTION
44 #include "libGIFTQuInvertedFile/include/uses-declarations.h"
45 #include <cmath>
46 #include "libMRML/include/TID.h"
47 #include "libGIFTAcInvertedFile/include/CDocumentFrequencyElement.h"
48 #include "libGIFTAcInvertedFile/include/CAcInvertedFile.h"
49 
50 class CQueryNormalizer;
51 
71 protected:
92 
93  /* A pseudo term frequency calculated from the input
94  at present by calculating the mean.
95 
96  mPositiveTermFrequency/mPositiveRelevanceSum is one term in a
97  a pseudo term frequency used for calculating query weights */
98  double mPositiveTermFrequency;
99  /* A pseudo term frequency calculated from the input
100  at present by calculating the mean.
101 
102  mNegativeTermFrequency/mNegativeRelevanceSum is the other term in a
103  a pseudo term frequency used for calculating query weights */
104  double mNegativeTermFrequency;
105 
112 
114  TID mID;
115 
118 
122 
126 
132  double mQueryFactor;
134  double mDocumentFactor;
135 
136 public:
137 
144  double getQueryFactor()const;
145 
151  virtual void preCalculate();
152 
161  CWeightingFunction(const CAcInvertedFile* inAccessor=0,
162  CQueryNormalizer* inQueryNormalizer=0,
163  CQueryNormalizer* inThisNormalizer=0);
164 
170  void setAccessor(const CAcInvertedFile*);
171 
177  void setNormalizers(CQueryNormalizer* inQueryNormalizer,
178  CQueryNormalizer* inThisNormalizer);
179 
185  void setID(TID);
186 
192  TID getID()const;
193 
204  void setRelevanceSum(double inPositiveRelevanceSum,
205  double inNegativeRelevanceSum);
206 
213  virtual void addQueryFeature(double inRelevanceLevel,
215  inQueryFeature);
216 
222  virtual double getTermFrequency()const;
223 
229  virtual double subApply(const double inDocumentFrequency,
230  const double inNormalizingFactor)const;
231 
237  virtual double apply(const CDocumentFrequencyElement& inResultFeature)const;
238 
245  double applyOnThis()const;
246 
250  virtual CWeightingFunction* constructNew(TID inID)const;
251 
259  virtual CWeightingFunction* clone()const;
260 
265  virtual ~CWeightingFunction();
266 
267  friend class CSortByDFTimesLogICF_WF;
268 };
269 
275 bool operator<(const CWeightingFunction&,
276  const CWeightingFunction&);
277 
280  public binary_function
281 <CWeightingFunction,CWeightingFunction,bool>{
283  inline bool operator()(const CWeightingFunction& l,
284  const CWeightingFunction& t){
285  return l.getID()<t.getID();
286  }
287 };
288 
296  public binary_function
297 <CWeightingFunction,CWeightingFunction,bool>{
299  inline bool operator()(const CWeightingFunction& l,
300  const CWeightingFunction& t){
301  return
302  l.getTermFrequency()
303  *
304  fabs(log(l.mAccessor->FeatureToCollectionFrequency(l.getID())))
305  <
306  t.getTermFrequency()
307  *
308  fabs(log(t.mAccessor->FeatureToCollectionFrequency(t.getID())));
309  };
310 };
311 
318  public binary_function
319 <CWeightingFunction,CWeightingFunction,bool>{
320 public:
322  inline bool operator()(const CWeightingFunction& l,
323  const CWeightingFunction& t){
324  return
325  l.getQueryFactor()
326  <
327  t.getQueryFactor();
328  };
329 };
337  public binary_function
338 <CWeightingFunction,CWeightingFunction,bool>{
339 public:
341  inline bool operator()(const CWeightingFunction& l,
342  const CWeightingFunction& t){
343  return
344  fabs(l.getQueryFactor())
345  <
346  fabs(t.getQueryFactor());
347  };
348 };
349 
355 template<class CSortOp>
357  binary_function<CWeightingFunction*,CWeightingFunction*,bool>{
358 protected:
360  CSortOp mSorter;
361 public:
363  inline CSortPointers_WF(){};
365  inline bool operator()(const CWeightingFunction* l,
366  const CWeightingFunction* t){
367  return mSorter(*l,*t);
368  };
369 };
370 
371 #include "libGIFTQuInvertedFile/include/CQueryNormalizer.h"
372 
373 #endif
374 
375 
virtual CWeightingFunction * constructNew(TID inID) const
For the "prototype pattern": Kinda virtual copy constructor: Gamma/Helm/Johnson/Vlissides p...
double mPositiveRelevanceSum
This value depends on all the elements of the query, which have a positive user-assigned relevance...
Definition: CWeightingFunction.h:81
virtual ~CWeightingFunction()
This virtual destructor is here inorder to call the (inherited) default constructors.
virtual double getTermFrequency() const
Giving a pseudo term frequency for normalization.
CWeightingFunction: Sort by FeatureID.
Definition: CWeightingFunction.h:279
virtual CWeightingFunction * clone() const
For the "prototype pattern": Kinda virtual copy constructor: Gamma/Helm/Johnson/Vlissides p...
CWeightingFunction(const CAcInvertedFile *inAccessor=0, CQueryNormalizer *inQueryNormalizer=0, CQueryNormalizer *inThisNormalizer=0)
Constructor:
double mNegativeRelevanceSum
This value depends on all the elements of the query, which have a negative user-assigned relevance...
Definition: CWeightingFunction.h:91
double mQueryFactor
The query usually will separate into a part which is equal for all the query and a part which is to b...
Definition: CWeightingFunction.h:132
For normalizing weights like in Salton/Buckley we need to now all the features in the query or all th...
Definition: CQueryNormalizer.h:55
TID getID() const
get the ID of this feature
CWeightingFunction: Sort by DocumentFrequency/CollectionFrequency.
Definition: CWeightingFunction.h:317
a universally usable class for weighting.
Definition: CWeightingFunction.h:70
const CAcInvertedFile * mAccessor
The accessor for the file on which the query is performed.
Definition: CWeightingFunction.h:117
CQueryNormalizer * mQueryNormalizer
FIXME THERE IS A GOOD DESCRIPTION MISSING FOR THE NEXT TWO VARIABLES.
Definition: CWeightingFunction.h:121
void setAccessor(const CAcInvertedFile *)
Set the accessor (should not be needed)
double applyOnThis() const
Preparing the right parameters for subApply: Apply this on itself.
An accessor to an inverted file.
Definition: CAcInvertedFile.h:83
virtual double apply(const CDocumentFrequencyElement &inResultFeature) const
Preparing the right parameters for subApply: Apply this on another feature.
CWeightingFunction: Sort by DocumentFrequency/CollectionFrequency.
Definition: CWeightingFunction.h:295
virtual double FeatureToCollectionFrequency(TFeatureID) const =0
Collection frequency for a given feature.
virtual void addQueryFeature(double inRelevanceLevel, const CDocumentFrequencyElement &inQueryFeature)
Add a feature.
CDOCUMENTFREQUENCYELEMENT.
Definition: CDocumentFrequencyElement.h:49
int mFeatureDescription
At present the feature description is a simple integer which expresses if the feature is a histogram ...
Definition: CWeightingFunction.h:111
double getQueryFactor() const
The query factor contains all informatio which depends only on the query.
void setNormalizers(CQueryNormalizer *inQueryNormalizer, CQueryNormalizer *inThisNormalizer)
Set the query normalizer (should not be needed);.
CWeightingFunction: Sort by the absolute value of the query factor.
Definition: CWeightingFunction.h:336
virtual double subApply(const double inDocumentFrequency, const double inNormalizingFactor) const
Apply this on a document frequency.
CQueryNormalizer * mThisNormalizer
A normalizer for apply on self.
Definition: CWeightingFunction.h:125
void setID(TID)
Set the ID of this feature.
virtual void preCalculate()
Calculate the QueryFactor.
Definition: CWeightingFunction.h:356
void setRelevanceSum(double inPositiveRelevanceSum, double inNegativeRelevanceSum)
Setting the relevance sum, that is the sum of the absolute values of all relevance levels of all docu...

Need for discussion? Want to contribute? Contact
help-gift@gnu.org Generated using Doxygen