本文整理汇总了C++中rcpp::NumericVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::size方法的具体用法?C++ NumericVector::size怎么用?C++ NumericVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rcpp::NumericVector
的用法示例。
在下文中一共展示了NumericVector::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeAllLogLkhd
// [[Rcpp::export]]
NumericVector computeAllLogLkhd(
NumericVector observedCases, NumericVector expectedCases,
List nearestNeighborsList, int nZones, String logLkhdType) {
NumericVector allLogLkhd(nZones);
int nAreas = expectedCases.size(), C = sum(observedCases),
N = sum(expectedCases), index = 0;
int nNeighbors = 0;
double cz = 0.0, nz = 0.0;
for (int i = 0; i < nAreas; ++i) {
cz = 0;
nz = 0;
Rcpp::NumericVector nearestNeighbors = nearestNeighborsList[i];
nNeighbors = nearestNeighbors.size();
// For each area's nearest neighbors
for(int j = 0; j < nNeighbors; ++j) {
// Watch off by 1 vector indexing in C as opposed to R
cz += observedCases[nearestNeighbors[j]-1];
nz += expectedCases[nearestNeighbors[j]-1];
if (logLkhdType=="poisson") {
allLogLkhd[index] = poissonLogLkhd(cz, nz, N, C);
} else if (logLkhdType == "binomial" ) {
allLogLkhd[index] = binomialLogLkhd(cz, nz, N, C);
}
index++;
}
}
return allLogLkhd;
}
示例2: print
static void print(Rcpp::NumericVector a)
{
for (int i = 0; i < a.size(); i++) {
printf("%f ", a[i]);
}
putchar('\n');
}
示例3: innerProduct
double Util::innerProduct(Rcpp::NumericVector x,
Rcpp::NumericVector y) {
double erg=0;
for(int i = 0;i<x.size();i++){
erg = erg+ (x[i]*y[i]);
}
return erg;
}
示例4: trapzRcpp
// [[Rcpp::export]]
double trapzRcpp(const Rcpp::NumericVector X, const Rcpp::NumericVector Y){
if( Y.size() != X.size()){
Rcpp::stop("The input Y-grid does not have the same number of points as input X-grid.");
}
if(is_sorted(X.begin(),X.end())){
double trapzsum = 0;
for (unsigned int ind = 0; ind != X.size()-1; ++ind){
trapzsum += 0.5 * (X[ind + 1] - X[ind]) *(Y[ind] + Y[ind + 1]);
}
return trapzsum;
} else {
Rcpp::stop("The input X-grid is not sorted.");
return std::numeric_limits<double>::quiet_NaN();
}
return std::numeric_limits<double>::quiet_NaN();
}
示例5: lgammap
//' @rdname MultivariateSpecial
//' @return \code{lgammap} is the log multivariate gamma function.
//' @note For \code{lgammp}, warnings of the type \code{"value out of range in
//' 'lgamma'"} is due to evaluation in the half integers below \eqn{(p-1)/2}.
//' @export
// [[Rcpp::export]]
Rcpp::NumericVector lgammap(const Rcpp::NumericVector & x, const int p = 1) {
const double c0 = log(M_PI)*p*(p - 1)/4;
Rcpp::NumericVector ans(x.size(), c0);
for (int j = 0; j < p; ++j) {
ans += Rcpp::lgamma(x - j/2.0f);
}
return ans;
}
示例6: res
// Calculate picewise constant baseline cumulative hazard function at t=(t_1, ..., t_n)
// where h=(h0, h1, ..., hM) with h0=0 and d=(d0, d1, ..., dM) with d0=0, dM=R_PosInf
arma::vec Lambda0tvec(Rcpp::NumericVector t, Rcpp::NumericVector h, Rcpp::NumericVector d){
int n = t.size();
arma::vec res(n);
for (int i=0; i<n; ++i){
res[i] = Lambda0t(t[i],h,d);
}
return(res);
}
示例7: rcpp_sumv
// [[Rcpp::export]]
double rcpp_sumv(Rcpp::NumericVector A)
{ int na= A.size();
double b=0;
for (int i = 0; i < na; i++)
{ b=b+A(i);
}
return b;
}
示例8: kdeDistValue
// kernel Dist function on a Grid
// [[Rcpp::export]]
Rcpp::NumericVector
KdeDist(const Rcpp::NumericMatrix & X
, const Rcpp::NumericMatrix & Grid
, const double h
, const Rcpp::NumericVector & weight
, const bool printProgress
) {
const unsigned sampleNum = X.nrow();
const unsigned dimension = Grid.ncol();
const unsigned gridNum = Grid.nrow();
// first = sum K_h(X_i, X_j), second = K_h(x, x), third = sum K_h(x, X_i)
std::vector< double > firstValue;
const double second = 1.0;
std::vector< double > thirdValue;
double firstmean;
Rcpp::NumericVector kdeDistValue(gridNum);
int counter = 0, percentageFloor = 0;
int totalCount = sampleNum + gridNum;
if (printProgress) {
printProgressFrame(Rprintf);
}
firstValue = computeKernel< std::vector< double > >(
X, X, h, weight, printProgress, Rprintf, counter, totalCount,
percentageFloor);
if (dimension <= 1) {
thirdValue = computeKernel< std::vector< double > >(
X, Grid, h, weight, printProgress, Rprintf, counter, totalCount,
percentageFloor);
}
else {
thirdValue = computeGaussOuter< std::vector< double > >(
X, Grid, h, weight, printProgress, Rprintf, counter, totalCount,
percentageFloor);
}
if (weight.size() == 1) {
firstmean = std::accumulate(firstValue.begin(), firstValue.end(), 0.0) / sampleNum;
}
else {
firstmean = std::inner_product(
firstValue.begin(), firstValue.end(), weight.begin(), 0.0) /
std::accumulate(weight.begin(), weight.end(), 0.0);
}
for (unsigned gridIdx = 0; gridIdx < gridNum; ++gridIdx) {
kdeDistValue[gridIdx] = std::sqrt(firstmean + second - 2 * thirdValue[gridIdx]);
}
if (printProgress) {
Rprintf("\n");
}
return kdeDistValue;
}
示例9:
reModule::reModule(Rcpp::S4 Zt, Rcpp::S4 Lambda, Rcpp::S4 L,
Rcpp::IntegerVector Lind, Rcpp::NumericVector lower)
throw (MatrixNs::wrongS4)
: d_L(L), d_Lambda(Lambda), d_Zt(Zt), d_Lind(Lind),
d_lower(lower), d_theta(lower.size()),
d_u0(d_Lambda.nr(), 0.), d_incr(d_Lambda.nr()),
d_u(d_Lambda.nr()),d_cu(d_Lambda.nr()) {
d_Ut = (CHM_SP)NULL;
}
示例10: setVector
// redis "set a vector" -- without R serialization, without attributes, ...
// this is somewhat experimental
std::string setVector(std::string key, Rcpp::NumericVector x) {
redisReply *reply =
static_cast<redisReply*>(redisCommand(prc_, "SET %s %b",
key.c_str(), x.begin(), x.size()*szdb));
std::string res(reply->str);
freeReplyObject(reply);
return(res);
}
示例11: invlogit
//' @export
//' @rdname logit
// [[Rcpp::export]]
Rcpp::NumericVector invlogit(Rcpp::NumericVector x) {
int n = x.size();
Rcpp::NumericVector result(n);
for (int i=0; i < n; ++i) {
result[i] = 1.0 / (1.0 + exp (-1.0 * x[i]));
}
return result;
}
示例12: logit
//' @title logit and inverse logit functions
//'
//' @description
//' transform \code{x} either via the logit, or inverse logit.
//'
//' @details
//' The loogit and inverse logit functions are part of R via the
//' logistic distribution functions in the stats package.
//' Quoting from the documentation for the logistic distribution
//'
//' "\code{qlogis(p)} is the same as the \code{logit} function, \code{logit(p) =
//' log(p/1-p)}, and \code{plogis(x)} has consequently been called the 'inverse
//' logit'."
//'
//' See the examples for benchmarking these functions. The \code{logit} and
//' \code{invlogit} functions are faster than the \code{qlogis} and \code{plogis}
//' functions.
//'
//' @seealso \code{\link[stats]{qlogis}}
//'
//' @examples
//' library(qwraps2)
//' library(rbenchmark)
//'
//' # compare logit to qlogis
//' p <- runif(1e5)
//' identical(logit(p), qlogis(p))
//' benchmark(logit(p), qlogis(p))
//'
//' # compare invlogit to plogis
//' x <- runif(1e5, -1000, 1000)
//' identical(invlogit(x), plogis(x))
//' benchmark(invlogit(x), plogis(x))
//'
//' @param x a numeric vector
//' @export
//' @rdname logit
// [[Rcpp::export]]
Rcpp::NumericVector logit(Rcpp::NumericVector x) {
int n = x.size();
Rcpp::NumericVector result(n);
for(int i = 0; i < n; ++i) {
result[i] = log( x[i] / (1.0 - x[i]) );
}
return result;
}
示例13: rcpp_sum_
// [[Rcpp::export]]
double rcpp_sum_(Rcpp::NumericVector x)
{
double ret = 0;
#pragma omp parallel for default(shared) reduction(+:ret)
for (int i=0; i<x.size(); i++)
ret += x[i];
return ret;
}
示例14: result
static Rcpp::IntegerVector nz(Rcpp::NumericVector v, double eps)
{
int n = v.size();
Rcpp::IntegerVector result(n);
for(int i=0; i < n; i++){
result[i] = nz(v[i],eps);
}
return result;
}
示例15: isincreasing
bool isincreasing(Rcpp::NumericVector arg){
int length=arg.size();
bool res=true;
for (int n=1; n<(length); n++)
if (arg[n]<=arg[n-1]){
res=false;
break;
}
return res;
}