indii/ml/aux/MedianPartitioner.cpp

00001 #include "MedianPartitioner.hpp"
00002 
00003 using namespace indii::ml::aux;
00004 
00005 MedianPartitioner::~MedianPartitioner() {
00006   //
00007 }
00008 
00009 bool MedianPartitioner::init(DiracMixturePdf* p,
00010       const std::vector<unsigned int>& is) {
00011   /* pre-condition */
00012   assert (is.size() >= 2);
00013 
00014   unsigned int i, j;
00015   vector lower(p->get(is[0]));
00016   vector upper(p->get(is[0]));
00017   vector length(p->getDimensions());
00018   
00019   /* calculate bounds */
00020   for (i = 1; i < is.size(); i++) {
00021     for (j = 0; j < p->getDimensions(); j++) {
00022       vector& x = p->get(is[i]);
00023       if (x(j) < lower(j)) {
00024         lower(j) = x(j);
00025       } else if (x(j) > upper(j)) {
00026         upper(j) = x(j);
00027       }
00028     }
00029   }
00030 
00031   /* select longest dimension */
00032   noalias(length) = upper - lower;
00033   this->index = index_norm_inf(length);   
00034 
00035   /* split on median of this dimension */
00036   std::vector<double> projection(is.size());
00037   unsigned int median = projection.size() / 2;
00038 
00039   for (i = 0; i < is.size(); i++) {
00040     projection[i] = p->get(is[i])(this->index);
00041   }
00042   std::nth_element(projection.begin(), projection.begin() + median,
00043       projection.end());
00044   this->value = projection[median];
00045 
00046   return length(this->index) > 0.0;
00047 }
00048 

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