Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

WeightedAndNode.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 //
00014 // WeightedAndNode
00015 //
00016 // 26 January 2004 - tds
00017 //
00018 
00019 #ifndef INDRI_WEIGHTEDANDNODE_HPP
00020 #define INDRI_WEIGHTEDANDNODE_HPP
00021 
00022 #include <vector>
00023 #include "indri/BeliefNode.hpp"
00024 #include "indri/SkippingCapableNode.hpp"
00025 #include "indri/ScoredExtentResult.hpp"
00026 #include <math.h>
00027 
00028 class WeightedAndNode : public SkippingCapableNode {
00029 private:
00030   struct child_type {
00031     struct maxscore_less {
00032     public:
00033       bool operator () ( const child_type& one, const child_type& two ) const {
00034         // think of these two elements as the only two elements in the
00035         // #wand.  What is the threshold of each ordering?  Sort by
00036         // the lowest threshold.
00037 
00038         return (one.backgroundWeightedScore + two.maximumWeightedScore) > 
00039                (one.maximumWeightedScore + two.backgroundWeightedScore);
00040       }
00041     };
00042 
00043     BeliefNode* node;
00044     double weight;
00045     double maximumWeightedScore;
00046     double backgroundWeightedScore;
00047   };
00048 
00049   std::vector<child_type> _children;
00050   greedy_vector<ScoredExtentResult> _scores;
00051   std::string _name;
00052 
00053   double _threshold;
00054   double _recomputeThreshold;
00055   int _quorumIndex;
00056   void _computeQuorum();
00057   double _computeMaxScore( unsigned int start );
00058 
00059 public:
00060   WeightedAndNode( const std::string& name ) : _name(name), _threshold(-DBL_MAX), _quorumIndex(0), _recomputeThreshold(-DBL_MAX) {}
00061 
00062   void addChild( double weight, BeliefNode* node );
00063 
00064   // SkippingCapableNode
00065   void setThreshold( double threshold );
00066 
00067   // InferenceNetworkNode interface
00068   int nextCandidateDocument();
00069   double maximumScore();
00070   double maximumBackgroundScore();
00071   greedy_vector<ScoredExtentResult>& score( int documentID, int begin, int end, int documentLength );
00072   void annotate( class Annotator& annotator, int documentID, int begin, int end );
00073   bool hasMatch( int documentID );
00074   const std::string& getName() const;
00075 };
00076 
00077 #endif // INDRI_WEIGHTEDANDNODE_HPP
00078 

Generated on Wed Nov 3 12:59:07 2004 for Lemur Toolkit by doxygen1.2.18