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 

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