indii/ml/aux/MedianPartitioner.hpp

00001 #ifndef INDII_ML_AUX_MEDIANPARTITIONER_HPP
00002 #define INDII_ML_AUX_MEDIANPARTITIONER_HPP
00003 
00004 #include "Partitioner.hpp"
00005 
00006 namespace indii {
00007   namespace ml {
00008     namespace aux {
00009 /**
00010  * Partitions a set of weighted points into two sets at the median of
00011  * the dimension with greatest range.
00012  *
00013  * @author Lawrence Murray <lawrence@indii.org>
00014  * @version $Rev: 489 $
00015  * @date $Date: 2008-07-31 12:13:05 +0100 (Thu, 31 Jul 2008) $
00016  */
00017 class MedianPartitioner : public Partitioner {
00018 public:
00019   /**
00020    * Destructor.
00021    */
00022   virtual ~MedianPartitioner();
00023 
00024   virtual bool init(DiracMixturePdf* p,
00025       const std::vector<unsigned int>& is);
00026   
00027   virtual Partitioner::Partition assign(const vector& x);
00028 
00029 private:
00030   /**
00031    * Index of the dimension on which to split.
00032    */
00033   unsigned int index;
00034   
00035   /**
00036    * Value along which to split.
00037    */
00038   double value;
00039 
00040 };
00041  
00042     }
00043   }
00044 }
00045 
00046 inline indii::ml::aux::Partitioner::Partition
00047     indii::ml::aux::MedianPartitioner::assign(const vector& x) {
00048   if (x(index) < value) { // <, not <=, important given how median is selected
00049     return Partitioner::LEFT;
00050   } else {
00051     return Partitioner::RIGHT;
00052   }
00053 }
00054 
00055 #endif
00056 

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3