本文整理汇总了C++中eigen::Map::all方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::all方法的具体用法?C++ Map::all怎么用?C++ Map::all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Map
的用法示例。
在下文中一共展示了Map::all方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mu
Eigen::MatrixXd RmullwlskCCsort2( const Eigen::Map<Eigen::VectorXd> & bw, const std::string kernel_type, const Eigen::Map<Eigen::MatrixXd> & tPairs, const Eigen::Map<Eigen::MatrixXd> & cxxn, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::VectorXd> & xgrid, const Eigen::Map<Eigen::VectorXd> & ygrid, const bool & bwCheck){
// Assumes the first row of tPairs is sorted in increasing order.
// tPairs : xin (in MATLAB code)
// cxxn : yin (in MATLAB code)
// xgrid: out1 (in MATLAB code)
// ygrid: out2 (in MATLAB code)
// bwCheck : boolean/ cause the function to simply run the bandwidth check.
const double invSqrt2pi= 1./(sqrt(2.*M_PI));
// Map the kernel name so we can use switches
std::map<std::string,int> possibleKernels;
possibleKernels["epan"] = 1; possibleKernels["rect"] = 2;
possibleKernels["gauss"] = 3; possibleKernels["gausvar"] = 4;
possibleKernels["quar"] = 5;
// The following test is here for completeness, we mightwant to move it up a
// level (in the wrapper) in the future.
// If the kernel_type key exists set KernelName appropriately
int KernelName = 0;
if ( possibleKernels.count( kernel_type ) != 0){
KernelName = possibleKernels.find( kernel_type )->second; //Set kernel choice
} else {
// otherwise use "epan"as the kernel_type
//Rcpp::Rcout << "Kernel_type argument was not set correctly; Epanechnikov kernel used." << std::endl;
Rcpp::warning("Kernel_type argument was not set correctly; Epanechnikov kernel used.");
KernelName = possibleKernels.find( "epan" )->second;;
}
// Check that we do not have zero weights // Should do a try-catch here
// Again this might be best moved a level-up.
if ( !(win.all()) ){ //
Rcpp::Rcout << "Cases with zero-valued windows are not yet implemented" << std::endl;
return (tPairs);
}
// ProfilerStart("sort.log");
// Start the actual smoother here
const unsigned int xgridN = xgrid.size();
const unsigned int ygridN = ygrid.size();
const unsigned int n = tPairs.cols();
// For sorted x1
Eigen::VectorXd x1(tPairs.row(0).transpose());
const double* tDat = x1.data();
Eigen::MatrixXd mu(xgrid.size(), ygrid.size());
mu.setZero();
for (unsigned int i = 0; i != xgridN; ++i) {
const double xl = xgrid(i) - bw(0) - 1e-6,
xu = xgrid(i) + bw(0) + 1e-6;
unsigned int indl = std::lower_bound(tDat, tDat + n, xl) - tDat,
indu = std::upper_bound(tDat, tDat + n, xu) - tDat;
// sort the y index
std::vector<valIndPair> yval(indu - indl);
for (unsigned int k = 0; k < yval.size(); ++k){
yval[k] = std::make_pair(tPairs(1, k + indl), k + indl);
}
std::sort<std::vector<valIndPair>::iterator>(yval.begin(), yval.end(), compPair);
std::vector<valIndPair>::iterator ylIt = yval.begin(),
yuIt = yval.begin();
for (unsigned int j = 0; j != ygridN; ++j) {
const double yl = ygrid(j) - bw(1) - 1e-6,
yu = ygrid(j) + bw(1) + 1e-6;
//locating local window (LOL) (bad joke)
std::vector <unsigned int> indx;
//if the kernel is not Gaussian
if ( KernelName != 3) {
// Search the lower and upper bounds increasingly.
ylIt = std::lower_bound(ylIt, yval.end(), valIndPair(yl, 0), compPair);
yuIt = std::upper_bound(yuIt, yval.end(), valIndPair(yu, 0), compPair);
// The following works nice for the Gaussian
// but for very small samples it complains
//} else {
// ylIt = yval.begin();
// yuIt = yval.end();
//}
for (std::vector<valIndPair>::iterator y = ylIt; y != yuIt; ++y){
indx.push_back(y->second);
}
} else { //When we finally get c++11 we will use std::iota
for( unsigned int y = 0; y != n; ++y){
indx.push_back(y);
}
}
// for (unsigned int y = 0; y != indx.size(); ++y){
// Rcpp::Rcout << "indx.at(y): " << indx.at(y)<< ", ";
// }
//.........这里部分代码省略.........
示例2: RmullwlskCC
Eigen::MatrixXd RmullwlskCC( const Eigen::Map<Eigen::VectorXd> & bw, const std::string kernel_type, const Eigen::Map<Eigen::MatrixXd> & tPairs, const Eigen::Map<Eigen::MatrixXd> & cxxn, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::VectorXd> & xgrid, const Eigen::Map<Eigen::VectorXd> & ygrid, const bool & bwCheck){
// tPairs : xin (in MATLAB code)
// cxxn : yin (in MATLAB code)
// xgrid: out1 (in MATLAB code)
// ygrid: out2 (in MATLAB code)
// bwCheck : boolean/ cause the function to simply run the bandwidth check.
const double invSqrt2pi= 1./(sqrt(2.*M_PI));
// Map the kernel name so we can use switches
std::map<std::string,int> possibleKernels;
possibleKernels["epan"] = 1; possibleKernels["rect"] = 2;
possibleKernels["gauss"] = 3; possibleKernels["gausvar"] = 4;
possibleKernels["quar"] = 5;
// The following test is here for completeness, we mightwant to move it up a
// level (in the wrapper) in the future.
// If the kernel_type key exists set KernelName appropriately
int KernelName = 0;
if ( possibleKernels.count( kernel_type ) != 0){
KernelName = possibleKernels.find( kernel_type )->second; //Set kernel choice
} else {
// otherwise use "epan"as the kernel_type
//Rcpp::Rcout << "Kernel_type argument was not set correctly; Epanechnikov kernel used." << std::endl;
Rcpp::warning("Kernel_type argument was not set correctly; Epanechnikov kernel used.");
KernelName = possibleKernels.find( "epan" )->second;;
}
// Check that we do not have zero weights // Should do a try-catch here
// Again this might be best moved a level-up.
if ( !(win.all()) ){ //
Rcpp::Rcout << "Cases with zero-valued windows are not yet implemented" << std::endl;
return (tPairs);
}
// Start the actual smoother here
unsigned int xgridN = xgrid.size();
unsigned int ygridN = ygrid.size();
Eigen::MatrixXd mu(xgrid.size(), ygrid.size());
mu.setZero();
const double bufSmall = 1e-6; // pow(double(10),-6);
for (unsigned int j = 0; j != ygridN; ++j) {
for (unsigned int i = 0; i != xgridN; ++i) {
//locating local window (LOL) (bad joke)
std::vector <unsigned int> indx;
//if the kernel is not Gaussian
if ( KernelName != 3) {
//construct listX as vectors / size is unknown originally
for (unsigned int y = 0; y != tPairs.cols(); y++){
if ( (std::abs( tPairs(0,y) - xgrid(i) ) <= (bw(0)+ bufSmall ) && std::abs( tPairs(1,y) - ygrid(j) ) <= (bw(1)+ bufSmall)) ) {
indx.push_back(y);
}
}
} else{ // just get the whole deal
for (unsigned int y = 0; y != tPairs.cols(); ++y){
indx.push_back(y);
}
}
// for (unsigned int y = 0; y != indx.size(); ++y){
// Rcpp::Rcout << "indx.at(y): " << indx.at(y)<< ", ";
// }
unsigned int indxSize = indx.size();
Eigen::VectorXd lw(indxSize);
Eigen::VectorXd ly(indxSize);
Eigen::MatrixXd lx(2,indxSize);
for (unsigned int u = 0; u !=indxSize; ++u){
lx.col(u) = tPairs.col(indx[u]);
lw(u) = win(indx[u]);
ly(u) = cxxn(indx[u]);
}
// check enough points are in the local window
unsigned int meter=1;
for (unsigned int u =0; u< indxSize; ++u) {
for (unsigned int t = u + 1; t < indxSize; ++t) {
if ( (lx(0,u) != lx(0,t) ) || (lx(1,u) != lx(1,t) ) ) {
meter++;
}
}
if (meter >= 3) {
break;
}
}
//computing weight matrix
if (meter >= 3 && !bwCheck) {
Eigen::VectorXd temp(indxSize);
Eigen::MatrixXd llx(2, indxSize );
llx.row(0) = (lx.row(0).array() - xgrid(i))/bw(0);
llx.row(1) = (lx.row(1).array() - ygrid(j))/bw(1);
//.........这里部分代码省略.........
示例3: Rrotatedmullwlsk
Eigen::VectorXd Rrotatedmullwlsk( const Eigen::Map<Eigen::VectorXd> & bw, const std::string kernel_type, const Eigen::Map<Eigen::MatrixXd> & tPairs, const Eigen::Map<Eigen::MatrixXd> & cxxn, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::MatrixXd> & xygrid, const unsigned int npoly, const bool & bwCheck){
// tPairs : xin (in MATLAB code)
// cxxn : yin (in MATLAB code)
// xygrid: d (in MATLAB code)
// npoly: redundant?
const double invSqrt2pi= 1./(sqrt(2.*M_PI));
// Map the kernel name so we can use switches
std::map<std::string,int> possibleKernels;
possibleKernels["epan"] = 1; possibleKernels["rect"] = 2;
possibleKernels["gauss"] = 3; possibleKernels["gausvar"] = 4;
possibleKernels["quar"] = 5;
// The following test is here for completeness, we mightwant to move it up a
// level (in the wrapper) in the future.
// If the kernel_type key exists set KernelName appropriately
int KernelName = 0;
if ( possibleKernels.count( kernel_type ) != 0){
KernelName = possibleKernels.find( kernel_type )->second; //Set kernel choice
} else {
// otherwise use "epan"as the kernel_type
// Rcpp::Rcout << "Kernel_type argument was not set correctly; Epanechnikov kernel used." << std::endl;
Rcpp::warning("Kernel_type argument was not set correctly; Epanechnikov kernel used.");
KernelName = possibleKernels.find( "epan" )->second;;
}
// Check that we do not have zero weights // Should do a try-catch here
// Again this might be best moved a level-up.
if ( !(win.all()) ){ //
Rcpp::Rcout << "Cases with zero-valued windows are not yet implemented" << std::endl;
return (tPairs);
}
Eigen::Matrix2d RC; // Rotation Coordinates
RC << 1, -1, 1, 1;
RC *= sqrt(2.)/2.;
Eigen::MatrixXd rtPairs = RC * tPairs;
Eigen::MatrixXd rxygrid = RC * xygrid;
unsigned int xygridN = rxygrid.cols();
Eigen::VectorXd mu(xygridN);
mu.setZero();
for (unsigned int i = 0; i != xygridN; ++i){
//locating local window (LOL) (bad joke)
std::vector <unsigned int> indx;
//if the kernel is not Gaussian or Gaussian-like
if ( KernelName != 3 && KernelName != 4 ) {
//construct listX as vectors / size is unknown originally
std::vector <unsigned int> list1, list2;
for (unsigned int y = 0; y != tPairs.cols(); y++){
if ( std::abs( rtPairs(0,y) - rxygrid(0,i) ) <= bw(0) ) {
list1.push_back(y);
}
if ( std::abs( rtPairs(1,y) - rxygrid(1,i) ) <= bw(1) ) {
list2.push_back(y);
}
}
//get intersection between the two lists
std::set_intersection(list1.begin(), list1.begin() + list1.size(), list2.begin(), list2.begin() + list2.size(), std::back_inserter(indx));
} else { // just get the whole deal
for (unsigned int y = 0; y != tPairs.cols(); ++y){
indx.push_back(y);
}
}
unsigned int indxSize = indx.size();
Eigen::VectorXd lw(indxSize);
Eigen::VectorXd ly(indxSize);
Eigen::MatrixXd lx(2,indxSize);
for (unsigned int u = 0; u !=indxSize; ++u){
lx.col(u) = rtPairs.col(indx[u]);
lw(u) = win(indx[u]);
ly(u) = cxxn(indx[u]);
}
if (ly.size()>=npoly+1 && !bwCheck ){
//computing weight matrix
Eigen::VectorXd temp(indxSize);
Eigen::MatrixXd llx(2, indxSize );
llx.row(0) = (lx.row(0).array() - rxygrid(0,i))/bw(0);
llx.row(1) = (lx.row(1).array() - rxygrid(1,i))/bw(1);
//define the kernel used
switch (KernelName){
case 1: // Epan
temp= ((1-llx.row(0).array().pow(2))*(1- llx.row(1).array().pow(2))).array() *
((9./16)*lw).transpose().array();
break;
case 2 : // Rect
//.........这里部分代码省略.........