medianpartitioner.cpp

来自「dysii is a C++ library for distributed p」· C++ 代码 · 共 49 行

CPP
49
字号
#include "MedianPartitioner.hpp"using namespace indii::ml::aux;MedianPartitioner::~MedianPartitioner() {  //}bool MedianPartitioner::init(DiracMixturePdf* p,      const std::vector<unsigned int>& is) {  /* pre-condition */  assert (is.size() >= 2);  unsigned int i, j;  vector lower(p->get(is[0]));  vector upper(p->get(is[0]));  vector length(p->getDimensions());    /* calculate bounds */  for (i = 1; i < is.size(); i++) {    for (j = 0; j < p->getDimensions(); j++) {      vector& x = p->get(is[i]);      if (x(j) < lower(j)) {        lower(j) = x(j);      } else if (x(j) > upper(j)) {        upper(j) = x(j);      }    }  }  /* select longest dimension */  noalias(length) = upper - lower;  this->index = index_norm_inf(length);     /* split on median of this dimension */  std::vector<double> projection(is.size());  unsigned int median = projection.size() / 2;  for (i = 0; i < is.size(); i++) {    projection[i] = p->get(is[i])(this->index);  }  std::nth_element(projection.begin(), projection.begin() + median,      projection.end());  this->value = projection[median];  return length(this->index) > 0.0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?