System documentation of the GNU Image-Finding Tool

Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members

CWeightingFunction.h

00001 /* -*- mode: c++ -*- 
00002 */
00003 /* 
00004 
00005     GIFT, a flexible content based image retrieval system.
00006     Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 */
00040 #ifndef _CWEIGHTINGFUNCTION
00041 #define _CWEIGHTINGFUNCTION
00042 #include "libGIFTQuInvertedFile/include/uses-declarations.h"
00043 #include <cmath>
00044 #include "libMRML/include/TID.h"
00045 #include "libGIFTAcInvertedFile/include/CDocumentFrequencyElement.h"
00046 #include "libGIFTAcInvertedFile/include/CAcInvertedFile.h"
00047 
00048 class CQueryNormalizer;
00049 
00068 class CWeightingFunction{
00069 protected:
00079   double mPositiveRelevanceSum;
00089   double mNegativeRelevanceSum;
00090 
00091   /* A pseudo term frequency calculated from the input
00092      at present by calculating the mean.
00093 
00094      mPositiveTermFrequency/mPositiveRelevanceSum is one term in a 
00095      a pseudo term frequency used for calculating query weights */
00096   double mPositiveTermFrequency;
00097   /* A pseudo term frequency calculated from the input
00098      at present by calculating the mean.
00099 
00100      mNegativeTermFrequency/mNegativeRelevanceSum is the other term in a 
00101      a pseudo term frequency used for calculating query weights */
00102   double mNegativeTermFrequency;
00103 
00109   int mFeatureDescription;
00110 
00112   TID mID;
00113 
00115   const CAcInvertedFile* mAccessor;
00116 
00119   mutable CQueryNormalizer* mQueryNormalizer;
00120 
00123   mutable CQueryNormalizer* mThisNormalizer;
00124 
00130   double mQueryFactor;
00132   double mDocumentFactor;
00133 
00134 public:
00135 
00142   double getQueryFactor()const;
00143 
00149   virtual void preCalculate();
00150 
00159   CWeightingFunction(const CAcInvertedFile* inAccessor=0,
00160                      CQueryNormalizer* inQueryNormalizer=0,
00161                      CQueryNormalizer* inThisNormalizer=0);
00162 
00168   void setAccessor(const CAcInvertedFile*);
00169 
00175   void setNormalizers(CQueryNormalizer* inQueryNormalizer,
00176                       CQueryNormalizer* inThisNormalizer);
00177 
00183   void setID(TID);
00184 
00190   TID getID()const;
00191 
00202   void setRelevanceSum(double inPositiveRelevanceSum,
00203                        double inNegativeRelevanceSum);
00204 
00211   virtual void addQueryFeature(double inRelevanceLevel,
00212                                const CDocumentFrequencyElement& 
00213                                inQueryFeature);
00214 
00220   virtual double getTermFrequency()const;
00221 
00227   virtual double subApply(const double inDocumentFrequency,
00228                           const double inNormalizingFactor)const;
00229 
00235   virtual double apply(const CDocumentFrequencyElement& inResultFeature)const;
00236 
00243   double applyOnThis()const;
00244 
00248   virtual CWeightingFunction* constructNew(TID inID)const;
00249 
00257   virtual CWeightingFunction* clone()const;
00258 
00263   virtual ~CWeightingFunction();
00264   
00265   friend class CSortByDFTimesLogICF_WF;
00266 };
00267 
00273 bool operator<(const CWeightingFunction&,
00274                const CWeightingFunction&);
00275 
00277 class CSortByFeatureID_WF:
00278   public binary_function
00279 <CWeightingFunction,CWeightingFunction,bool>{
00281   inline bool operator()(const CWeightingFunction& l,
00282                          const CWeightingFunction& t){
00283     return l.getID()<t.getID();
00284   }
00285 };
00286 
00293 class CSortByDFTimesLogICF_WF:
00294   public binary_function
00295 <CWeightingFunction,CWeightingFunction,bool>{
00297   inline bool operator()(const CWeightingFunction& l,
00298                          const CWeightingFunction& t){
00299     return 
00300       l.getTermFrequency()
00301       *
00302       fabs(log(l.mAccessor->FeatureToCollectionFrequency(l.getID())))
00303       <
00304       t.getTermFrequency()
00305       *
00306       fabs(log(t.mAccessor->FeatureToCollectionFrequency(t.getID())));
00307   };
00308 };
00309 
00315 class CSortByQueryFactor_WF:
00316   public binary_function
00317 <CWeightingFunction,CWeightingFunction,bool>{
00318 public:
00320   inline bool operator()(const CWeightingFunction& l,
00321                          const CWeightingFunction& t){
00322     return 
00323       l.getQueryFactor()
00324       <
00325       t.getQueryFactor();
00326   };
00327 };
00334 class CSortByAbsQueryFactor_WF:
00335   public binary_function
00336 <CWeightingFunction,CWeightingFunction,bool>{
00337 public:
00339   inline bool operator()(const CWeightingFunction& l,
00340                          const CWeightingFunction& t){
00341     return 
00342       fabs(l.getQueryFactor())
00343       <
00344       fabs(t.getQueryFactor());
00345   };
00346 };
00347 
00353 template<class CSortOp>
00354 class CSortPointers_WF:
00355   binary_function<CWeightingFunction*,CWeightingFunction*,bool>{
00356 protected:
00358   CSortOp mSorter;
00359 public:
00361   inline CSortPointers_WF(){};
00363   inline bool operator()(const CWeightingFunction* l,
00364                          const CWeightingFunction* t){
00365     return mSorter(*l,*t);
00366   };
00367 };
00368 
00369 #include "libGIFTQuInvertedFile/include/CQueryNormalizer.h"
00370 
00371 #endif
00372 
00373 

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