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


C++ NumericVector::end方法代码示例

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


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

示例1: compPvals3

// [[Rcpp::export]]
SEXP compPvals3(NumericVector nullvec, NumericVector vec) { //A fancyer version using iterators. Actually runs much slower!!!!
  
  int n = nullvec.size();
  int m = vec.size();
  Rcpp::NumericVector pvalVec(m);
  
  typedef Rcpp::NumericVector::iterator vec_iterator;
  //vec_iterator it_nv = nullvec.begin();
  //vec_iterator it_v = vec.begin();
  //vec_iterator it_pv = pvalVec.begin();
  
  for(vec_iterator it_v = vec.begin(), it_pv = pvalVec.begin(); it_v != vec.end(); ++it_v, ++it_pv) {
    int count = 0;
    for(vec_iterator it_nv = nullvec.begin(); it_nv != nullvec.end(); ++it_nv) {
      count = count + ( *it_nv >= *it_v );
      //cout<<count<<endl;
    }
    double val = ((double)count)/((double)n);
    //cout<<val<<endl;
    *it_pv = val;
  }
  
  return pvalVec;
  
}
开发者ID:npetraco,项目名称:fdrID,代码行数:26,代码来源:empirical_pvalues.cpp

示例2: ddirichlet

// [[Rcpp::export]]
NumericVector ddirichlet(NumericVector xx , NumericVector alphaa){
  
  if (is_true(any(alphaa<=0))){
    return wrap(-1e20);
  }

  if (is_true(any( (xx <=0) ))){
    return wrap(-1e20);
  }

  double alpha_sum = std::accumulate(alphaa.begin(), alphaa.end(), 0.0); 
  
  // this will return alpha_sum = 0 0 0
  //return (alpha_sum);


  NumericVector log_gamma_alpha = lgamma(alphaa);
  NumericVector log_alpha_sum = lgamma(wrap(alpha_sum));


  double sum_log_gamma_alpha = std::accumulate(log_gamma_alpha.begin(), log_gamma_alpha.end(), 0.0); 
  
  double logD = sum_log_gamma_alpha - as<double>(log_alpha_sum);


  NumericVector a = ( alphaa - 1.0 ) * log(xx);
  return wrap( std::accumulate(a.begin(), a.end(), 0.0) - logD ); 
}
开发者ID:ctszkin,项目名称:simmen,代码行数:29,代码来源:function.cpp

示例3: lowerBound

// Quick and dirty implementation of lowerBound, the complement to R's
// findInterval
// [[Rcpp::export]]
IntegerVector lowerBound(const NumericVector& x, const NumericVector& breaks) {
  int n = x.size();
  IntegerVector out(n);

  for (int i = 0; i < n; i++) {
    NumericVector::const_iterator it =
      std::lower_bound(breaks.begin(), breaks.end(), x[i]);
    if (it == breaks.end()) --it;
    out[i] = it - breaks.begin() + 1;
  }
  return out;
}
开发者ID:dmellop,项目名称:bigvis,代码行数:15,代码来源:lowerBound.cpp

示例4: pairSort

//' Sorted vector index.
//'
//' The sorted vector is returned along with the original index of the vector it belonged to.
//'
//' @param x A real-valued vector to be sorted.
//'
//' @return A list with two components:
//' \itemize{
//' \item sorted: The sorted version of \code{x}.
//' \item index: The index of the \eqn{i^{th}} element in \code{x}.
//' }
//'
//' @examples
//' pairSort(c(5, 2, 6))
//' @export
//[[Rcpp::export]]
List pairSort(NumericVector x)
{
int n = x.size();
NumericVector x_sorted(n);
IntegerVector x_index(n);

std::vector<double> arr(x.begin(), x.end());
std::vector<std::pair<double,int> >V;

for (int i=0; i<x.size(); i++)
{
std::pair<double,int>P = std::make_pair(arr[i], i);
V.push_back(P);
}

std::sort(V.begin(), V.end());

for (int i=0; i<x.size(); i++)
{
x_sorted[i] = V[i].first;
x_index[i] = V[i].second;
}

return List::create(_["sorted"] = x_sorted,
_["index"] = x_index);
}
开发者ID:mtloots,项目名称:alR,代码行数:42,代码来源:utilities.cpp

示例5: ptsThresh

// [[Rcpp::export]]
NumericVector ptsThresh(NumericVector values,NumericVector endDates,int window){
  int valuesLen = values.length();
  NumericVector out = clone(values);
  NumericVector startDates = endDates - window;

  for (int i = 0; i < valuesLen; ++i){
    LogicalVector idx = (endDates <= endDates[i]) & (endDates >= startDates[i]);
    NumericVector valuesWindow = values[idx];
    int lenCur = valuesWindow.length();

    if (lenCur == 1){
      out[i] = (1.4 / 1.3) * valuesWindow[i];
    }
    if (lenCur == 2){
      out[i] = (1.5 / 2.4) * sum(valuesWindow);
    }
    if (lenCur == 3){
      out[i] = (1.5 / 3.3) * sum(valuesWindow);
    }
    if (lenCur == 4){
      out[i] = (1.5 / 4.0) * sum(valuesWindow);
    }
    if (lenCur >= 5){
      std::nth_element(valuesWindow.begin(),valuesWindow.begin() + 5,valuesWindow.end());
      out[i] = valuesWindow[4];
    }
  }

  return out;
}
开发者ID:joranE,项目名称:statskier2,代码行数:31,代码来源:cummean_bestn.cpp

示例6: GoFBHK

// [[Rcpp::export]]
double GoFBHK(NumericVector x,double a) { 
  
  double s = 0;
  double n = x.size();
  double  e = n/sum(x);    
  NumericMatrix k(2,n);
  double res=0;
  NumericVector k1(n);
  NumericVector k2(n);
  NumericVector y = e*x;
  std::sort(y.begin(),y.end());
  k(0,0) = y[1];
  k(1,0) = 0;
  for(int i=0; i<(n-1);i++){
     s = 0;
     s = sum(y[Range(0,i)]);
     k(0,(i+1)) = s/n + y[i+1]*(1-(i+1)/n) - (i+1)/n;
     k(1,(i+1)) = (i+1)/n - s/n - y[i]*(1-(i+1)/n);
}
  k1 = k(0,_);
  k2 = k(1,_);
  s=k1[which_max(k1)];
  e=k2[which_max(k2)];
  res= sqrt(n)*std::max(s,e);
return res;
}
开发者ID:cran,项目名称:EWGoF,代码行数:27,代码来源:GoFBHK.cpp

示例7: loopC

// [[Rcpp::export]]
NumericVector loopC(NumericVector nodelist,int al,IntegerVector x, IntegerVector x2, List pm_lc, NumericMatrix Lix, int finind){
  NumericVector::iterator k;
  LogicalVector res;
  IntegerVector daughter;
  int temp1, temp2;
  int k2;
  int l = 0;
  int g = 0;
  int n = x.size();
  LogicalVector in1(x2.size());
  LogicalVector in2(x2.size());
  IntegerVector indices = seq_len(n); //from 1 to n...
  for(k = nodelist.begin(); k != nodelist.end(); ++k) {
    k2  = nodelist[l];
    res = x == k2;
    daughter = x2[res];
    in1 = x2==daughter[0];
    in2 = x2==daughter[1];
    temp1 = as<int>(indices[in1]);
    temp2 = as<int>(indices[in2]);
    NumericMatrix pmtmp1 = pm_lc[temp1 - 1];
    NumericMatrix pmtmp2 = pm_lc[temp2 - 1];
    for(g = 0; g<al; ++g){
      Lix(k2 - 1, g) = sum(Lix.row(daughter[0] - 1) * pmtmp1.row(g)) *
      sum(Lix.row(daughter[1] - 1) * pmtmp2.row(g));
    }
    l=l+1;
  }
  NumericVector res2 = Lix(finind,_);
  return res2;
}
开发者ID:cran,项目名称:markophylo,代码行数:32,代码来源:loopC-general4.cpp

示例8: instrumented_count_positive_threaded

// [[Rcpp::export]]
List instrumented_count_positive_threaded(NumericVector data, int nthreads){
  int n = data.size() ;
  int chunk_size = n / nthreads ; 
  
  std::vector<Timer> timers(nthreads) ; 
  std::vector<std::future<int>> futures(nthreads-1) ;
  std::vector<std::thread> threads(nthreads-1) ;
  timers[0].step("data structures") ;
  
  double* it = data.begin() ;
  for( int i=0; i<nthreads-1; i++){
    InstrumentedTask instr_task(timers[i+1]) ;
    Task task(instr_task) ;
    futures[i] = task.get_future();
    threads[i] = std::thread( std::move(task), it, it + chunk_size ) ;
    it += chunk_size ;
    timers[0].step( "spawning" ) ;
  }
  timers[0].step( "spawning" ) ;
  int result = InstrumentedTask(timers[0])(it, data.end()); 
  
  for( int i=0; i<nthreads-1; i++) {
    threads[i].join() ;
    timers[0].step("fusion") ;
    result += futures[i].get() ;  
  }
  timers[0].step( "fusion" ) ;
    
  return List::create( _["res"] = result, _["timers"] = timers );
}
开发者ID:Lunalo,项目名称:Rcpp-book,代码行数:31,代码来源:count_positive.cpp

示例9: appendRcpp

// [[Rcpp::export]]
void appendRcpp(  List fillVecs, NumericVector newLengths, NumericMatrix retmat, NumericVector retmatLengths ) {
  /* appendRcpp
	Fills numeric matrix
	Loop through rows, filling retmat in with the vectors in list
	then update return matrix size to index the next free
	*/
	
	// Declare vars
	NumericVector fillTmp;
	int sizeOld, sizeNew;
    
	// Pull out dimensions of return matrix to fill
	int nrow = retmat.nrow();
  int ncol = retmat.ncol();
    
	// Check that dimensions match
	if ( nrow != retmatLengths.size() || nrow != fillVecs.size() ) { 
        throw std::range_error("In appendC(): dimension mismatch");
    }
    
	// Traverse ddimensions
	for (int ii=0; ii<ncol; ii++) {
        throw std::range_error("In appendC(): exceeded max cols");
		
	// Iterator for row to fill
        NumericMatrix::Row retRow = retmat(ii, _);
	
  // Fill row of return matrix, starting at first non-zero element
        std::copy( fillTmp.begin(), fillTmp.end(), retRow.begin() + sizeOld );
  
  // Update size of return matrix
        retmatLengths[ii] = sizeNew;
		}
	}
开发者ID:codecompletion,项目名称:fhcrcExamples,代码行数:35,代码来源:cppHelpers.cpp

示例10: sqrtWrkWt

    Rcpp::NumericVector glmerResp::sqrtWrkWt() const {
	NumericVector me = muEta();
#ifdef USE_RCPP_SUGAR
	return sqrt(d_weights * me * me / variance());
#else
	NumericVector vv = variance();
	std::transform(me.begin(), me.end(), me.begin(), me.begin(),
		       std::multiplies<double>());
	std::transform(me.begin(), me.end(), d_weights.begin(),
		       me.begin(), std::multiplies<double>());
	std::transform(me.begin(), me.end(), vv.begin(), me.begin(),
		       std::divides<double>());
	std::transform(me.begin(), me.end(), me.begin(), &::sqrt);
	return me;
#endif	
    }
开发者ID:rforge,项目名称:lme4,代码行数:16,代码来源:respModule.cpp

示例11: split_runs_numeric

// [[Rcpp::export]]
List split_runs_numeric( NumericVector X ) {

	List out( X.size() );

	std::vector< std::vector< double > > all_nums;
	std::vector< double > curr_nums;

	// initial stuff
	curr_nums.push_back( X[0] );

	for( NumericVector::iterator it = X.begin()+1; it != X.end(); ++it ) {
		if( (*it) != (*(it-1)) ) {
			all_nums.push_back( curr_nums );
			curr_nums.clear();
			curr_nums.push_back( *it );
		} else {
			curr_nums.push_back( *it );
		}
	}

	// push the final vector in
	all_nums.push_back( curr_nums );

	return wrap( all_nums );

}
开发者ID:Libardo1,项目名称:Kmisc,代码行数:27,代码来源:split_runs.cpp

示例12: updateWts

    double glmResp::updateWts() {
	d_sqrtrwt = sqrt(d_weights/d_fam.variance(d_mu));
	NumericVector muEta = d_fam.muEta(d_eta);
	std::transform(muEta.begin(), muEta.end(), d_sqrtrwt.begin(),
		       d_sqrtXwt.begin(), std::multiplies<double>());
	return updateWrss();
    }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例13: append

 void append(  List fillVecs) {
     // "append" fill oldmat w/  
     // we will loop through cols, filling retmat in with the vectors in list
     // then update retmat_size to index the next free
     // newLenths isn't used, added for compatibility
     std::size_t sizeOld, sizeAdd, sizeNew, icol;
     NumericVector fillTmp;
     // check that number of vectors match
     if ( nvec != fillVecs.size()) {
         throw std::range_error("In append(): dimension mismatch");
     }
     for (icol = 0; icol<nvec; icol++){
         // vector to append
         fillTmp = fillVecs[icol];
         // compute lengths
         sizeOld = lengths[icol];
         sizeAdd = fillTmp.size();
         sizeNew = sizeOld + sizeAdd;
         // grow data matrix as needed
         if ( sizeNew > allocLen) {
             grow(sizeNew);
         }
         // iterator for col to fill
         NumericMatrix::Column dataCol = data(_, icol);
         // fill row of return matrix, starting at first non-zero elem
         std::copy( fillTmp.begin(), fillTmp.end(), dataCol.begin() + sizeOld);
         // update size of retmat
         lengths[icol] = sizeNew;
     }
 }
开发者ID:helmingstay,项目名称:RaggedArray,代码行数:30,代码来源:classdef.cpp

示例14: sum2

// [[Rcpp::export]]
double sum2(NumericVector x) {
    double total = 0;

    for(NumericVector::iterator it = x.begin(); it != x.end(); it++) {
        total += *it;
    }
    return total;
}
开发者ID:CJGodfrey,项目名称:adv-r,代码行数:9,代码来源:sum.cpp

示例15: Cquant

// [[Rcpp::export]]
NumericVector Cquant(NumericVector A, NumericVector probs) {

    NumericVector q(probs) ;
    NumericVector y = wrap(na_omit(A)) ;

    std::sort(y.begin(), y.end());
    return y[y.size()*(q - 0.000000001)];
}
开发者ID:lyggd,项目名称:openair,代码行数:9,代码来源:Cquantile.cpp


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