本文整理汇总了C++中MatrixXi::col方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXi::col方法的具体用法?C++ MatrixXi::col怎么用?C++ MatrixXi::col使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixXi
的用法示例。
在下文中一共展示了MatrixXi::col方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: v
TEST(TestEigenHelper, TestSelectColumns) {
unsigned int rows = 4;
unsigned int cls = 5;
MatrixXi v(rows, cls);
v << 1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15,
16, 17, 18, 19, 20;
std::vector<int> cols = {0,1,4};
MatrixXi z = select_columns<int, Ints >(v, cols);
EXPECT_EQ(v.col(0), z.col(0));
EXPECT_EQ(v.col(1), z.col(1));
EXPECT_EQ(v.col(4), z.col(2));
MatrixXd q = v.cast<double>() / 2;
Ints more_cols = {1,0,2};
MatrixXd t = select_columns<double, Ints >(q, more_cols);
for(unsigned int i = 0; i < rows; i++) {
EXPECT_DOUBLE_EQ(q(i, 1), t(i, 0));
EXPECT_DOUBLE_EQ(q(i, 0), t(i, 1));
EXPECT_DOUBLE_EQ(q(i, 2), t(i, 2));
}
}
示例2: sparseSubsets
// function used internally, which computes lasso fits for subsets containing a
// small number of observations (typically only 3) and returns the indices of
// the respective h observations with the smallest absolute residuals
MatrixXi sparseSubsets(const MatrixXd& x, const VectorXd& y,
const double& lambda, const int& h, const MatrixXi& subsets,
const bool& normalize, const bool& useIntercept,
const double& eps, const bool& useGram) {
const int nsamp = subsets.cols();
MatrixXi indices(h, nsamp);
for(int k = 0; k < nsamp; k++) {
// compute lasso fit
double intercept, crit;
VectorXd coefficients, residuals;
fastLasso(x, y, lambda, true, subsets.col(k), normalize, useIntercept,
eps, useGram, false, intercept, coefficients, residuals, crit);
// find h observations with smallest absolute residuals
indices.col(k) = findSmallest(residuals.cwiseAbs(), h);
}
return indices;
}
示例3:
parameters::parameters(datafile dat, model nv_mod, model ref_mod,parameters ref_param,int compo,int iter){
const MatrixXi & omega=nv_mod.Get_model(),ref_omega=ref_mod.Get_model(),mat=dat.Get_mat_datafile();
const int g=omega.rows(),unique=mat.rows();
m_proba=ref_param.m_proba;
m_proba_block.resize(g);
m_param.resize(g);
for (int k=0;k<g;k++){
if (k!=compo){
m_param[k].resize(omega.rowwise().maxCoeff()(k)+1);
m_param[k]=ref_param.m_param[k];
m_proba_block[k].resize(unique,omega.rowwise().maxCoeff()(k)+1);
m_proba_block[k]=ref_param.m_proba_block[k];
for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){
if ((omega.row(k).array()==b).any()){
m_param[k][b]=ref_param.m_param[k][b];
}
}
}else{
m_param[k].resize(omega.rowwise().maxCoeff()(k)+1);
m_proba_block[k].resize(unique,omega.rowwise().maxCoeff()(k)+1);
for (int b=0;b<(omega.rowwise().maxCoeff()(k)+1) ;b++){
if ((omega.row(k).array()==b).any()){
if ((((omega.row(k).array()==b)==(ref_omega.row(k).array()==b)).prod())==1){
m_param[k][b]=ref_param.m_param[k][b];
}else{
m_param[k][b]=param_block(k,b,dat,nv_mod,m_proba.col(k).array()/m_proba.rowwise().sum().array(),1);
if ((omega.row(k).array()==b).count()>1){
int prem=0;
while(omega(k,prem)!=b){prem++;}
if (mat.col(prem).maxCoeff()>5){
m_param[k][b]=m_param[k][b].Optimise_gamma(k,b,dat,nv_mod,5,m_proba.col(k).array()/m_proba.rowwise().sum().array(),dat.Get_eff_datafile());
}
}
}
}
}
}
}
m_propor=uniforme(g);
Probapost( nv_mod , mat );
Compte_nbparam(dat,nv_mod);
Likelihood(dat.Get_eff_datafile());
Estimation(1,0,iter,dat,nv_mod);
}
示例4: skip
int
NMS::nms3x3 (MatrixXd &im_, MatrixXd &om_, vector<int> &id_om_)
{
//Sizes
int h_ = im_.rows();
int w_ = im_.cols();
lmn_ = 0;
om_.fill (0); // binary output image
MatrixXi skip (h_,2);
skip.fill (0);
int cur = 0;
int next = 1;
int r, tmp;
for (int c=1; c<w_-1; c++)
{
r = 1;
while (r<h_-1)
{
if (skip(r,cur))
{
// skip current pixel
r=r+1;
continue;
}
if (im_(r,c) <= im_(r+1,c)) // compare to pixel on the left
{
r=r+1;
while ((r<h_-1) && (im_(r,c) <= im_(r+1,c)))
r=r+1; //rising
if (r==h_-1)
break; // reach scanline's local maximum
}
else // compare to pixel on the right
{
if (im_(r,c) <= im_(r-1,c))
{
r=r+1;
continue;
}
}
skip(r+1,cur) = 1; // skip next pixel in the scanline
//compare to 3 future then 3 past neighbors
if (im_(r,c) <= im_(r-1,c+1))
{
r=r+1;
continue;
}
skip(r-1,next) = 1; // skip future neighbors only
if (im_(r,c) <= im_(r ,c+1))
{
r=r+1;
continue;
}
skip(r ,next) = 1;
if (im_(r,c) <= im_(r+1,c+1))
{
r=r+1;
continue;
}
skip(r+1,next) = 1;
if (im_(r,c) <= im_(r-1,c-1))
{
r=r+1;
continue;
}
if (im_(r,c) <= im_(r ,c-1))
{
r=r+1;
continue;
}
if (im_(r,c) <= im_(r+1,c-1))
{
r=r+1;
continue;
}
// a new local maximum is found
om_(r,c) = 1;
id_om_.push_back (r * im_.cols () + c);
lmn_++;
r=r+1;
}
// swap mask indices
tmp = cur;
cur = next;
next = tmp;
// reset next scanline mask
skip.col(next).fill(0);
//.........这里部分代码省略.........
示例5: mexFunction
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
// This is useful for debugging whether Matlab is caching the mex binary
//mexPrintf("%s %s\n",__TIME__,__DATE__);
igl::matlab::MexStream mout;
std::streambuf *outbuf = std::cout.rdbuf(&mout);
#else
int main(int argc, char * argv[])
{
#endif
using namespace std;
using namespace Eigen;
using namespace igl;
using namespace igl::matlab;
using namespace igl::cgal;
MatrixXd V;
MatrixXi F;
igl::cgal::RemeshSelfIntersectionsParam params;
string prefix;
bool use_obj_format = false;
#ifdef MEX
if(nrhs < 2)
{
mexErrMsgTxt("nrhs < 2");
}
parse_rhs_double(prhs,V);
parse_rhs_index(prhs+1,F);
mexErrMsgTxt(V.cols()==3,"V must be #V by 3");
mexErrMsgTxt(F.cols()==3,"F must be #F by 3");
if(nrhs>2)
{
int i = 2;
while(i<nrhs)
{
if(!mxIsChar(prhs[i]))
{
mexErrMsgTxt("Parameter names should be char strings");
}
// Cast to char
const char * name = mxArrayToString(prhs[i]);
if(strcmp("DetectOnly",name) == 0)
{
validate_arg_scalar(i,nrhs,prhs,name);
validate_arg_logical(i,nrhs,prhs,name);
mxLogical * v = (mxLogical *)mxGetData(prhs[++i]);
params.detect_only = *v;
}else if(strcmp("FirstOnly",name) == 0)
{
validate_arg_scalar(i,nrhs,prhs,name);
validate_arg_logical(i,nrhs,prhs,name);
mxLogical * v = (mxLogical *)mxGetData(prhs[++i]);
params.first_only = *v;
}else
{
mexErrMsgTxt(C_STR("Unsupported parameter: "<<name));
}
i++;
}
}
#else
if(argc <= 1)
{
cerr<<"Usage:"<<endl<<" selfintersect [path to .off/.obj mesh] "
"[0 or 1 for detect only]"<<endl;
return 1;
}
// Apparently CGAL doesn't have a good data structure triangle soup. Their
// own examples use (V,F):
// http://www.cgal.org/Manual/latest/doc_html/cgal_manual/AABB_tree/Chapter_main.html#Subsection_64.3.7
//
// Load mesh
string filename(argv[1]);
if(!read_triangle_mesh(filename,V,F))
{
//cout<<REDRUM("Reading "<<filename<<" failed.")<<endl;
return false;
}
cout<<GREENGIN("Read "<<filename<<" successfully.")<<endl;
{
// dirname, basename, extension and filename
string dirname,b,ext;
pathinfo(filename,dirname,b,ext,prefix);
prefix = dirname + "/" + prefix;
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
use_obj_format = ext == "obj";
}
if(argc>2)
{
//http://stackoverflow.com/a/9748431/148668
char *p;
long d = strtol(argv[2], &p, 10);
if (errno != 0 || *p != '\0')
{
cerr<<"detect only param should be 0 or 1"<<endl;
}else
//.........这里部分代码省略.........