System documentation of the GNU Image-Finding Tool

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class 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      Copyright (C) 2003, 2004 Bayreuth University
00009       2005 Bamberg University
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 
00024 */
00042 #ifndef _CWEIGHTINGFUNCTION
00043 #define _CWEIGHTINGFUNCTION
00044 #include "libGIFTQuInvertedFile/include/uses-declarations.h"
00045 #include <cmath>
00046 #include "libMRML/include/TID.h"
00047 #include "libGIFTAcInvertedFile/include/CDocumentFrequencyElement.h"
00048 #include "libGIFTAcInvertedFile/include/CAcInvertedFile.h"
00049 
00050 class CQueryNormalizer;
00051 
00070 class CWeightingFunction{
00071 protected:
00081   double mPositiveRelevanceSum;
00091   double mNegativeRelevanceSum;
00092 
00093   /* A pseudo term frequency calculated from the input
00094      at present by calculating the mean.
00095 
00096      mPositiveTermFrequency/mPositiveRelevanceSum is one term in a 
00097      a pseudo term frequency used for calculating query weights */
00098   double mPositiveTermFrequency;
00099   /* A pseudo term frequency calculated from the input
00100      at present by calculating the mean.
00101 
00102      mNegativeTermFrequency/mNegativeRelevanceSum is the other term in a 
00103      a pseudo term frequency used for calculating query weights */
00104   double mNegativeTermFrequency;
00105 
00111   int mFeatureDescription;
00112 
00114   TID mID;
00115 
00117   const CAcInvertedFile* mAccessor;
00118 
00121   mutable CQueryNormalizer* mQueryNormalizer;
00122 
00125   mutable CQueryNormalizer* mThisNormalizer;
00126 
00132   double mQueryFactor;
00134   double mDocumentFactor;
00135 
00136 public:
00137 
00144   double getQueryFactor()const;
00145 
00151   virtual void preCalculate();
00152 
00161   CWeightingFunction(const CAcInvertedFile* inAccessor=0,
00162                      CQueryNormalizer* inQueryNormalizer=0,
00163                      CQueryNormalizer* inThisNormalizer=0);
00164 
00170   void setAccessor(const CAcInvertedFile*);
00171 
00177   void setNormalizers(CQueryNormalizer* inQueryNormalizer,
00178                       CQueryNormalizer* inThisNormalizer);
00179 
00185   void setID(TID);
00186 
00192   TID getID()const;
00193 
00204   void setRelevanceSum(double inPositiveRelevanceSum,
00205                        double inNegativeRelevanceSum);
00206 
00213   virtual void addQueryFeature(double inRelevanceLevel,
00214                                const CDocumentFrequencyElement& 
00215                                inQueryFeature);
00216 
00222   virtual double getTermFrequency()const;
00223 
00229   virtual double subApply(const double inDocumentFrequency,
00230                           const double inNormalizingFactor)const;
00231 
00237   virtual double apply(const CDocumentFrequencyElement& inResultFeature)const;
00238 
00245   double applyOnThis()const;
00246 
00250   virtual CWeightingFunction* constructNew(TID inID)const;
00251 
00259   virtual CWeightingFunction* clone()const;
00260 
00265   virtual ~CWeightingFunction();
00266   
00267   friend class CSortByDFTimesLogICF_WF;
00268 };
00269 
00275 bool operator<(const CWeightingFunction&,
00276                const CWeightingFunction&);
00277 
00279 class CSortByFeatureID_WF:
00280   public binary_function
00281 <CWeightingFunction,CWeightingFunction,bool>{
00283   inline bool operator()(const CWeightingFunction& l,
00284                          const CWeightingFunction& t){
00285     return l.getID()<t.getID();
00286   }
00287 };
00288 
00295 class CSortByDFTimesLogICF_WF:
00296   public binary_function
00297 <CWeightingFunction,CWeightingFunction,bool>{
00299   inline bool operator()(const CWeightingFunction& l,
00300                          const CWeightingFunction& t){
00301     return 
00302       l.getTermFrequency()
00303       *
00304       fabs(log(l.mAccessor->FeatureToCollectionFrequency(l.getID())))
00305       <
00306       t.getTermFrequency()
00307       *
00308       fabs(log(t.mAccessor->FeatureToCollectionFrequency(t.getID())));
00309   };
00310 };
00311 
00317 class CSortByQueryFactor_WF:
00318   public binary_function
00319 <CWeightingFunction,CWeightingFunction,bool>{
00320 public:
00322   inline bool operator()(const CWeightingFunction& l,
00323                          const CWeightingFunction& t){
00324     return 
00325       l.getQueryFactor()
00326       <
00327       t.getQueryFactor();
00328   };
00329 };
00336 class CSortByAbsQueryFactor_WF:
00337   public binary_function
00338 <CWeightingFunction,CWeightingFunction,bool>{
00339 public:
00341   inline bool operator()(const CWeightingFunction& l,
00342                          const CWeightingFunction& t){
00343     return 
00344       fabs(l.getQueryFactor())
00345       <
00346       fabs(t.getQueryFactor());
00347   };
00348 };
00349 
00355 template<class CSortOp>
00356 class CSortPointers_WF:
00357   binary_function<CWeightingFunction*,CWeightingFunction*,bool>{
00358 protected:
00360   CSortOp mSorter;
00361 public:
00363   inline CSortPointers_WF(){};
00365   inline bool operator()(const CWeightingFunction* l,
00366                          const CWeightingFunction* t){
00367     return mSorter(*l,*t);
00368   };
00369 };
00370 
00371 #include "libGIFTQuInvertedFile/include/CQueryNormalizer.h"
00372 
00373 #endif
00374 
00375 

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