本文整理汇总了C++中eigen::Matrix::cwiseProduct方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::cwiseProduct方法的具体用法?C++ Matrix::cwiseProduct怎么用?C++ Matrix::cwiseProduct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Matrix
的用法示例。
在下文中一共展示了Matrix::cwiseProduct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
PointCoordinateMatrices ConverterPlaneFromTo3d::projectTo3d(Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> image)
{
PointCoordinateMatrices reshapedCoordinates;
//std::cout << "image: " << std::endl << image << std::endl << std::endl;
//As defined for the example data sets to get the distance in meters Z = depth / 5000 TODO change for kinect data (maybe is the same...)
Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> z = image.array() / 1;// 5000;
Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> x = z.cwiseProduct(xAdjustment_);
Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> y = z.cwiseProduct(yAdjustment_);
//std::cout << "x: " << std::endl << x << std::endl << std::endl;
//std::cout << "y: " << std::endl << y << std::endl << std::endl;
//std::cout << "z: " << std::endl << z << std::endl << std::endl;
reshapedCoordinates.x = Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(x.data(), 1, image.size());
reshapedCoordinates.y = Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(y.data(), 1, image.size());
reshapedCoordinates.z = Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(z.data(), 1, image.size());
return reshapedCoordinates;
}
示例2: calculateGaussPdf
template<int N> void calculateGaussPdf(Eigen::Matrix<double,Eigen::Dynamic,N> X, Eigen::Matrix<double,1,N> mu, Eigen::Matrix<double,N,N> C, double* result){
Eigen::Matrix<double,N,N> L = C.llt().matrixL().transpose(); // cholesky decomposition
Eigen::Matrix<double,N,N> Linv = L.inverse();
double det = L.diagonal().prod(); //determinant of L is equal to square rooot of determinant of C
double lognormconst = -log(2 * M_PI)*X.cols()/2 - log(fabs(det));
Eigen::Matrix<double,1,N> x = mu;
Eigen::Matrix<double,1,N> tmp = x;
for (int i=0; i<X.rows(); i++){
x.noalias() = X.row(i) - mu;
tmp.noalias() = x*Linv;
double exponent = -0.5 * (tmp.cwiseProduct(tmp)).sum();
result[i] = lognormconst+exponent;
}
/*
Eigen::Matrix<double,Eigen::Dynamic,N> X0 = (X.rowwise() - mu)*Linv;
Eigen::Map<Eigen::Matrix<double,Eigen::Dynamic,1> > resultMap(result, X.rows());
resultMap = (X0.rowwise().squaredNorm()).array() * (-0.5) + lognormconst;
*/
fmath::expd_v(result, X.rows());
}
示例3: main
int main()
{
//********************************************************
// Initialization
//********************************************************
double M=0.6;
double Ix=8*1e-3; // moment of inertia in X- Y- and Z-axis
double Iy=7.5*1e-3;
double Iz=13.5*1e-3;
double d=0.2; // displacement of rotors
double kt=0.6;
double km=0.15;
char file[]="/media/fantaosha/Documents/JHU/Summer 2015/quad_rotor_traj/traj_full_12s_1_small.mat";
mxArray *mxR;
mxArray *mxw;
mxArray *mxxq;
mxArray *mxvq;
mxArray *mxU;
mxR=matGetVariable(matOpen(file,"r"),"state_R");
mxw=matGetVariable(matOpen(file,"r"),"state_w");
mxxq=matGetVariable(matOpen(file,"r"),"state_xq");
mxvq=matGetVariable(matOpen(file,"r"),"state_vq");
#ifdef ROT_INPUT
mxU=matGetVariable(matOpen(file,"r"),"U");
#else
mxU=matGetVariable(matOpen(file,"r"),"F");
#endif
size_t N=mxGetN(mxU);
size_t sN=5;
void *pR=mxGetPr(mxR);
void *pw=mxGetPr(mxw);
void *pxq=mxGetPr(mxxq);
void *pvq=mxGetPr(mxvq);
void *pU=mxGetPr(mxU);
std::list<typename quadrotor::State> list_par1;
std::list<typename quadrotor::State> list_par2;
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,3,3> R;
Eigen::Matrix<double,3,1> w,xq,vq;
memcpy(R.data(),pR,sizeof(double)*R.rows()*R.cols());
memcpy(w.data(),pw,sizeof(double)*w.rows()*w.cols());
memcpy(xq.data(),pxq,sizeof(double)*xq.rows()*xq.cols());
memcpy(vq.data(),pvq,sizeof(double)*vq.rows()*vq.cols());
list_par1.emplace_back(R,xq,w,R.transpose()*vq);
if((i+1)%2)
list_par2.emplace_back(R,xq,w,R.transpose()*vq);
pR+=sizeof(double)*R.rows()*R.cols()*sN;
pw+=sizeof(double)*w.rows()*w.cols()*sN;
pxq+=sizeof(double)*xq.rows()*xq.cols()*sN;
pvq+=sizeof(double)*vq.rows()*vq.cols()*sN;
}
sN=10;
std::list<typename quadrotor::U> list_u1;
std::list<typename quadrotor::U> list_u2;
#ifdef ROT_INPUT
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,4,1> u;
memcpy(u.data(),pU,sizeof(double)*u.rows()*u.cols());
list_u1.push_back(u.cwiseProduct(u));
list_u2.push_back(u);
pU+=sizeof(double)*u.rows()*u.cols()*sN;
}
#else
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,4,1> u;
memcpy(u.data(),pU,sizeof(double)*u.rows()*u.cols());
list_u.push_back(u);
pU+=sizeof(double)*u.rows()*u.cols()*sN;
}
#endif
mxDestroyArray(mxR);
mxDestroyArray(mxw);
mxDestroyArray(mxxq);
mxDestroyArray(mxvq);
mxDestroyArray(mxU);
std::srand((unsigned int) time(0));
// initialize SAC
Mat12 PM=2500*Mat12::Identity();
PM.block(0,0,3,3)*=10;
PM.block(3,3,3,3)*=40;
//.........这里部分代码省略.........
示例4: main
int main()
{
double M=0.6;
double d=0.2; // displacement of rotors
double kt=0.6;
double km=0.15;
double K=5;
double Ix1=8*5e-3; // moment of inertia in X- Y- and Z-axis
double Iy1=7.5*5e-3;
double Iz1=13.5*5e-3;
char file1[]="/media/fantaosha/Documents/JHU/Summer 2015/quad_rotor_traj/traj_full_12s_ud_2.mat";
double Ix2=8*1e-3; // moment of inertia in X- Y- and Z-axis
double Iy2=7.5*1e-3;
double Iz2=13.5*1e-3;
char file2[]="/media/fantaosha/Documents/JHU/Summer 2015/quad_rotor_traj/traj_full_12s_ud_small_5.mat";
Eigen::Matrix<double,4,4> B=(Eigen::Matrix<double,4,4>() << 0, kt*d, 0, -kt*d,
-kt*d, 0, kt*d, 0,
km, -km, km, -km,
kt, kt, kt, kt).finished();
Eigen::Matrix<double,4,4> Binv=(Eigen::Matrix<double,4,4>() << 0, -1/(2*d*kt), 1/(4*km), 1/(4*kt),
1/(2*d*kt), 0, -1/(4*km), 1/(4*kt),
0, 1/(2*d*kt), 1/(4*km), 1/(4*kt),
-1/(2*d*kt), 0, -1/(4*km), 1/(4*kt)).finished();
// load control inputs for SAC
mxArray *mxR1;
mxArray *mxw1;
mxArray *mxxq1;
mxArray *mxvq1;
mxArray *mxU1;
mxArray *mxUd1;
mxR1=matGetVariable(matOpen(file1,"r"),"state_R");
mxw1=matGetVariable(matOpen(file1,"r"),"state_w");
mxxq1=matGetVariable(matOpen(file1,"r"),"state_xq");
mxvq1=matGetVariable(matOpen(file1,"r"),"state_vq");
mxU1=matGetVariable(matOpen(file1,"r"),"U");
mxUd1=matGetVariable(matOpen(file1,"r"),"Ud");
size_t N=mxGetN(mxU1);
size_t sN=5;
void *pR1=mxGetPr(mxR1);
void *pw1=mxGetPr(mxw1);
void *pxq1=mxGetPr(mxxq1);
void *pvq1=mxGetPr(mxvq1);
void *pU1=mxGetPr(mxU1);
std::list<typename quadrotor_ext::State> list_ref1;
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,3,3> R;
Eigen::Matrix<double,3,1> w,xq,vq;
Eigen::Matrix<double,4,1> u;
memcpy(R.data(),pR1,sizeof(double)*R.rows()*R.cols());
memcpy(w.data(),pw1,sizeof(double)*w.rows()*w.cols());
memcpy(xq.data(),pxq1,sizeof(double)*xq.rows()*xq.cols());
memcpy(vq.data(),pvq1,sizeof(double)*vq.rows()*vq.cols());
memcpy(u.data(),pU1,sizeof(double)*u.rows()*u.cols());
list_ref1.emplace_back(R,xq,w,R.transpose()*vq,u.cwiseProduct(u));
pR1+=sizeof(double)*R.rows()*R.cols()*sN;
pw1+=sizeof(double)*w.rows()*w.cols()*sN;
pxq1+=sizeof(double)*xq.rows()*xq.cols()*sN;
pvq1+=sizeof(double)*vq.rows()*vq.cols()*sN;
pU1+=sizeof(double)*u.rows()*u.cols()*sN;
}
sN=10;
std::list<typename quadrotor_ext::U> list_ud1;
void *pUd1=mxGetPr(mxUd1)+sizeof(double)*5*4;
for(int i=sN/2;i<N;i+=sN)
{
Eigen::Matrix<double,4,1> ud;
memcpy(ud.data(),pUd1,sizeof(double)*ud.rows()*ud.cols());
list_ud1.push_back(ud.cwiseProduct(ud));
pUd1+=sizeof(double)*ud.rows()*ud.cols()*sN;
}
mxDestroyArray(mxR1);
mxDestroyArray(mxw1);
mxDestroyArray(mxxq1);
mxDestroyArray(mxvq1);
mxDestroyArray(mxU1);
mxDestroyArray(mxUd1);
//.........这里部分代码省略.........
示例5: main
int main()
{
#ifdef TRACK
char file[]="/media/fantaosha/Documents/JHU/Summer 2015/quad_rotor_traj/traj_full_12s_1_small.mat";
mxArray *mxR;
mxArray *mxw;
mxArray *mxxq;
mxArray *mxvq;
mxArray *mxU;
mxR=matGetVariable(matOpen(file,"r"),"state_R");
mxw=matGetVariable(matOpen(file,"r"),"state_w");
mxxq=matGetVariable(matOpen(file,"r"),"state_xq");
mxvq=matGetVariable(matOpen(file,"r"),"state_vq");
mxU=matGetVariable(matOpen(file,"r"),"U");
size_t N=mxGetN(mxU);
size_t sN=10;
void *pR=mxGetPr(mxR);
void *pw=mxGetPr(mxw);
void *pxq=mxGetPr(mxxq);
void *pvq=mxGetPr(mxvq);
void *pU=mxGetPr(mxU);
std::vector<typename quadrotor::State> xrefs;
xrefs.reserve(N/sN+1);
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,3,3> R;
Eigen::Matrix<double,3,1> w,xq,vq;
memcpy(R.data(),pR,sizeof(double)*R.rows()*R.cols());
// R=(Vec3()<<1,-1,-1).finished().asDiagonal();
// w<<0,0,0;
memcpy(w.data(),pw,sizeof(double)*w.rows()*w.cols());
memcpy(xq.data(),pxq,sizeof(double)*xq.rows()*xq.cols());
memcpy(vq.data(),pvq,sizeof(double)*vq.rows()*vq.cols());
xrefs.emplace_back(R,xq,w,R.transpose()*vq);
pR+=sizeof(double)*R.rows()*R.cols()*sN;
pw+=sizeof(double)*w.rows()*w.cols()*sN;
pxq+=sizeof(double)*xq.rows()*xq.cols()*sN;
pvq+=sizeof(double)*vq.rows()*vq.cols()*sN;
}
sN=10;
std::vector<typename quadrotor::U> us;
us.reserve(N/sN+1);
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,4,1> u;
memcpy(u.data(),pU,sizeof(double)*u.rows()*u.cols());
us.push_back(u.cwiseProduct(u));
pU+=sizeof(double)*u.rows()*u.cols()*sN;
}
#else
quadrotor::State xref;
xref.g.block(0,0,3,3)=SO3::exp((Vec3()<<0,0,0).finished());
xref.g.block(0,3,3,1)=(Vec3()<<0,0,0).finished();
std::vector<quadrotor::State> xrefs(4000,xref);
std::vector<quadrotor::U> us(4000, Vec4::Zero());
#endif
std::srand((unsigned int) time(0));
// Set up quadrotor parameters
double m=0.6;
double Ix=8*1e-3; // moment of inertia in X- Y- and Z-axis
double Iy=7.5*1e-3;
double Iz=13.5*1e-3;
double d=0.2; // displacement of rotors
double kt=0.6;
double km=0.15;
quadrotor::System sys(Ix,Iy,Iz,m,d,km,kt);
// Set up cost function
Mat12 Mf=5*Mat12::Identity()/10;
Mf.block(0,0,3,3)*=1;
Mf.block(3,3,3,3)*=6;
// Mf.block(6,6,6,6)=Mf.block(0,0,6,6);
Mat12 M=Mf/2;
Mat4 R=Mat4::Identity()/50;
DDP<quadrotor>::Params params(M,R,Mf);
// Set up initial state
quadrotor::State x0=xrefs[0];
x0.g.block(0,3,3,1)-=(Vec3::Random()).normalized()*3;
x0.g.block(0,0,3,3)*=SO3::exp(Vec3::Random().normalized()*1);
// x0.g.block(0,0,3,3)*=SO3::exp((Vec3()<<3.14,0,0).finished());
x0.v.head(3)-=Vec3::Random().normalized()*0;
x0.v.tail(3)-=Vec3::Random().normalized()*0;
//.........这里部分代码省略.........
示例6: main
int main()
{
//********************************************************
// Initialization
//********************************************************
double M=0.6;
double Ix=8*5e-3; // moment of inertia in X- Y- and Z-axis
double Iy=7.5*5e-3;
double Iz=13.5*5e-3;
double d=0.2; // displacement of rotors
double kt=0.6;
double km=0.15;
char file[]="/media/fantaosha/Documents/JHU/Summer 2015/quad_rotor_traj/traj_full_12s_7.mat";
// double M=2; // mass of quadrotor
// double Ix=1.2; // moment of inertia in X- Y- and Z-axis
// double Iy=1.2;
// double Iz=2.3;
// double d=0.25; // displacement of rotors
// double kt=1;
// double km=0.20;
//
// char file[]="/media/fantaosha/Documents/JHU/Summer 2015/quad_rotor_traj/traj_full_12s_2.mat";
mxArray *mxR;
mxArray *mxw;
mxArray *mxxq;
mxArray *mxvq;
mxArray *mxU;
mxR=matGetVariable(matOpen(file,"r"),"state_R");
mxw=matGetVariable(matOpen(file,"r"),"state_w");
mxxq=matGetVariable(matOpen(file,"r"),"state_xq");
mxvq=matGetVariable(matOpen(file,"r"),"state_vq");
#ifdef ROT_INPUT
mxU=matGetVariable(matOpen(file,"r"),"U");
#else
mxU=matGetVariable(matOpen(file,"r"),"F");
#endif
size_t N=mxGetN(mxU);
size_t sN=5;
void *pR=mxGetPr(mxR);
void *pw=mxGetPr(mxw);
void *pxq=mxGetPr(mxxq);
void *pvq=mxGetPr(mxvq);
void *pU=mxGetPr(mxU);
std::list<typename quadrotor::State> list_PAR1;
std::list<typename quadrotor::State> list_PAR2;
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,3,3> R;
Eigen::Matrix<double,3,1> w,xq,vq;
memcpy(R.data(),pR,sizeof(double)*R.rows()*R.cols());
memcpy(w.data(),pw,sizeof(double)*w.rows()*w.cols());
memcpy(xq.data(),pxq,sizeof(double)*xq.rows()*xq.cols());
memcpy(vq.data(),pvq,sizeof(double)*vq.rows()*vq.cols());
list_PAR1.emplace_back(R,xq,w,R.transpose()*vq);
if((i+1)%2)
list_PAR2.emplace_back(R,xq,w,R.transpose()*vq);
pR+=sizeof(double)*R.rows()*R.cols()*sN;
pw+=sizeof(double)*w.rows()*w.cols()*sN;
pxq+=sizeof(double)*xq.rows()*xq.cols()*sN;
pvq+=sizeof(double)*vq.rows()*vq.cols()*sN;
}
sN=10;
std::list<typename quadrotor::U> list_U1;
std::list<typename quadrotor::U> list_U2;
#ifdef ROT_INPUT
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,4,1> u;
memcpy(u.data(),pU,sizeof(double)*u.rows()*u.cols());
list_U1.push_back(u.cwiseProduct(u));
list_U2.push_back(u);
pU+=sizeof(double)*u.rows()*u.cols()*sN;
}
#else
for(int i=0;i<N;i+=sN)
{
Eigen::Matrix<double,4,1> u;
memcpy(u.data(),pU,sizeof(double)*u.rows()*u.cols());
list_u.push_back(u);
pU+=sizeof(double)*u.rows()*u.cols()*sN;
}
#endif
mxDestroyArray(mxR);
mxDestroyArray(mxw);
//.........这里部分代码省略.........