当前位置: 首页>>代码示例>>C++>>正文


C++ Mat::min方法代码示例

本文整理汇总了C++中Mat::min方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::min方法的具体用法?C++ Mat::min怎么用?C++ Mat::min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


在下文中一共展示了Mat::min方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eT

inline
void
interp1_helper_nearest(const Mat<eT>& XG, const Mat<eT>& YG, const Mat<eT>& XI, Mat<eT>& YI, const eT extrap_val)
  {
  arma_extra_debug_sigprint();
  
  const eT XG_min = XG.min();
  const eT XG_max = XG.max();
  
  YI.copy_size(XI);
  
  const eT* XG_mem = XG.memptr();
  const eT* YG_mem = YG.memptr();
  const eT* XI_mem = XI.memptr();
        eT* YI_mem = YI.memptr();
  
  const uword NG = XG.n_elem;
  const uword NI = XI.n_elem;
  
  uword best_j = 0;
  
  for(uword i=0; i<NI; ++i)
    {
    eT best_err = Datum<eT>::inf;
    
    const eT XI_val = XI_mem[i];
    
    if((XI_val < XG_min) || (XI_val > XG_max))
      {
      YI_mem[i] = extrap_val;
      }
    else
      {
      // XG and XI are guaranteed to be sorted in ascending manner,
      // so start searching XG from last known optimum position 
      
      for(uword j=best_j; j<NG; ++j)
        {
        const eT tmp = XG_mem[j] - XI_val;
        const eT err = (tmp >= eT(0)) ? tmp : -tmp;
        
        if(err >= best_err)
          {
          // error is going up, so we have found the optimum position
          break;
          }
        else
          {
          best_err = err;
          best_j   = j;   // remember the optimum position
          }
        }
      
      YI_mem[i] = YG_mem[best_j];
      }
    }
  }
开发者ID:Aeryltic,项目名称:labirynth,代码行数:57,代码来源:fn_interp1.hpp

示例2: parse_matrices

void parse_matrices(string file, Mat<double> & M, Mat<double> & P0, Mat<double> & P1, Mat<int> & C, int nrows) {
  ifstream ifs;
  ifs.open(file.c_str());
  if(!ifs.good()) {
    cerr << "Error: couldn't open " << file << endl;
    exit(1);
  }
  string str;
  vector<string> tokens;
  int m=-1,i=0;
  int P0reducedcols=0;
  int P1reducedcols=0;
  while(true) {
    bool spacer=false;
    do {
      if(!ifs.eof()) {
        getline(ifs,str);
      } else {
        str="";
      }
      str=str.substr(0, str.find_first_of("#"));
      tokens.clear();
      tokenise(str, tokens, " ");
      if(tokens.size() < 1) spacer=true;
    } while(!ifs.eof() && tokens.size() < 1);
    if(str.size()==0 && ifs.eof()) break;
    if(spacer) {
      m++;
      i=0;
    }
    if(m==-1) m=0;

    if(m==0) M.resize(nrows,tokens.size());
    if(m==1) C.resize(nrows,tokens.size());
    if(m==2) P0.resize(nrows,tokens.size());
    if(m==3) P1.resize(nrows,tokens.size());
    if(i >= nrows) {
      cerr << "Error: number of rows of matrices greater than number of samples.\n";
      exit(1);
    }
    for(int t=0; t < tokens.size(); t++) {
      if(m==0) M(i,t) = atof(tokens[t].c_str());
      if(m==1) C(i,t) = atoi(tokens[t].c_str());
      if(m==2) {
        for(int j=0; j < nrows; j++) {
          if(i > max(C.col(0))) { 
              cerr << "Error: more distinct rows of P than classes for model 0 (" << i << " > " << max(C.col(0)) << ").\n";
              exit(1);
          }
          if(C(j,0)==i) {
            P0(j,t)= atof(tokens[t].c_str());
          }
        }
        P0reducedcols = max(P0reducedcols, i);
      }
      if(m==3) {
        for(int j=0; j < nrows; j++) {
          if(i > max(C.col(1))) { 
              cerr << "Error: more distinct rows of P than classes for model 1 (" << i << " > " << max(C.col(1)) << ").\n";
              exit(1);
          }
          if(C(j,1)==i) {
            P1(j,t)= atof(tokens[t].c_str());
          }
        }
        P1reducedcols = max(P1reducedcols, i);
      }
    }
    i++;
  }
  if(C.min() != 0) {
    cerr << "Error: need at least one class in each model labelled 0." << endl;
    exit(1);
  }
  if(max(C.col(0)) != P0reducedcols) {
    cerr << "Error: number of classes does not correspond to number of disinct rows of P for model 0.\n";
    exit(1);
  }
  if(max(C.col(1)) != P1reducedcols) {
    cerr << "Error: number of classes does not correspond to number of disinct rows of P for  model 1.\n";
    exit(1);
  }

}
开发者ID:fawnshao,项目名称:mmseq,代码行数:84,代码来源:mmdiff.cpp


注:本文中的Mat::min方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。