eigen

Trilateration in Android using iBeacons

五迷三道 提交于 2019-12-04 21:20:11
问题 We want to implement some kind of indoor position determination using iBeacons. This article seems really interesting, in which the author implemented the Non-linear Least Squares Triangulation, using the Eigen C++ library and the Levenberg Marquardt algorithm. Since Eigen is written in C++, I tried to use JNI and Android NDK in order to use it but it throws a lot of errors that I have no idea how to solve and I couldn´t find anything online. I also tried to use Jeigen, but it does not have

Compare Eigen matrices in Google Test or Google Mock

家住魔仙堡 提交于 2019-12-04 21:14:23
问题 I was wondering if there is a good way to test two Eigen matrices for approximate equality using Google Test, or Google Mock. Take the following test-case as a simplified example: I am multiplying two complex valued matrices A , and B , and expect a certain result C_expect . I calculate the numerical result C_actual = A * B , using Eigen. Now, I want to compare C_expect , and C_actual . Right now, the corresponding code looks like this: #include <complex> #include <Eigen/Dense> #include

evaluate multivariate Normal/Gaussian Density in c++

点点圈 提交于 2019-12-04 19:45:14
Right now I have the following function to evaluate the Gaussian density: double densities::evalMultivNorm(const Eigen::VectorXd &x, const Eigen::VectorXd &meanVec, const Eigen::MatrixXd &covMat) { double inv_sqrt_2pi = 0.3989422804014327; double quadform = (x - meanVec).transpose() * covMat.inverse() * (x-meanVec); double normConst = pow(inv_sqrt_2pi, covMat.rows()) * pow(covMat.determinant(), -.5); return normConst * exp(-.5* quadform); } This is just transcribing the formula . However I get a lot of 0, nans and infs. I suspect it's coming from the covMat.determinant() portion being very

Rcpp equivalent for rowsum [closed]

一曲冷凌霜 提交于 2019-12-04 19:09:43
I am looking for a fast alternative for the R function rowsum in C++ / Rcpp / Eigen or Armadillo. The purpose is to get the sum of elements in a vector a according to a grouping vector b . For example: > a [1] 2 2 2 2 2 2 2 2 2 2 > b [1] 1 1 1 1 1 2 2 2 2 2 > rowsum(a,b) [,1] 1 10 2 10 Writing a simple for loop in Rcpp is very slow, but maybe my code was just inefficient. I tried also to call the function rowsum in Rcpp , however, rowsum is not very fast. Here's my attempt at doing this using Rcpp (first time using the package, so do point out my inefficiencies): library(inline) library(Rcpp)

Making a reshape function in Eigen

二次信任 提交于 2019-12-04 15:30:24
Here's the code for a reshape function in Eigen. It works. typedef MatrixXd mat; typedef VectorXd vec; Map<mat> reshape (vec b, const uint n, const uint m) { return Map<mat>(b.data(), n, m); } I was trying to decide the right type for the first argument. vec & b still works, but I get strange errors with const vec & b or const vec b : error: invalid conversion from 'const Scalar* {aka const double*}' to 'Eigen::Map<Eigen::Matrix<double, -1, -1> >::PointerArgType {aka double*}' [-fpermissive] return Map<mat>(b.data(), n, m); ~~~~~~^~ I suspect this is due to mutability and the fact that the

Thin QR decomposition in c++

倖福魔咒の 提交于 2019-12-04 14:43:20
Is there an easy to use c++ library for "thin" QR decomposition of a rectangular matrix? Eigen seems to only support full Q matrices. I can take a full Q and discard some columns, but would it be more efficient to not compute them to begin with? Newmat does exactly what you want. To decompose A into QR, you can do: Matrix Q = A; UpperTriangularMatrix R; QRZ(Q, R) If A is a 3x5 matrix, R will be 3x3 and Q will be 3x5 as well. Even though this question is a bit old, for the record: Eigen does not explicitly compute the Q matrix, but a sequence of Householder vectors, which can directly be

Eigen3 matrix multiplication performance

橙三吉。 提交于 2019-12-04 14:36:26
Note: I've posted this also on Eigen forum here I want to premultiply 3xN matrices by a 3x3 matrix, i.e., to transform 3D points, like p_dest = T * p_source after initializing the matrices: Eigen::Matrix<double, 3, Eigen::Dynamic> points = Eigen::Matrix<double, 3, Eigen::Dynamic>::Random(3, NUMCOLS); Eigen::Matrix<double, 3, Eigen::Dynamic> dest = Eigen::Matrix<double, 3, Eigen::Dynamic>(3, NUMCOLS); int NT = 100; I have evaluated this two versions // eigen direct multiplication for (int i = 0; i < NT; i++){ Eigen::Matrix3d T = Eigen::Matrix3d::Random(); dest.noalias() = T * points; } and //

Link the R Package Depending on RcppEigen with MKL in Microsoft R Open

*爱你&永不变心* 提交于 2019-12-04 13:43:49
I have built a custom package with some functions written in RcppEigen. I also have Microsoft R open with Intel MKL enabled. How could I link the R package to the Intel MKL feature? Setup 1 : Below are procedures that I have tried to link the package with MKL in the normal R, but failed: The Eigen documents says I need: 1. #define EIGEN_USE_MKL_ALL 2. link your program to MKL libraries ( the MKL linking advisor ) Based on 2, in my file Makevars PKG_CXXFLAGS = -I/opt/intel/mkl/include PKG_LIBS = ${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} -L/opt/intel/mkl/lib/intel64 -Wl,--no-as-needed -lmkl_intel

Using Eigen::VectorXd (Eigen 3.3.4) as a state type in boost::numeric::odeint (Boost 1.65.1)

时光毁灭记忆、已成空白 提交于 2019-12-04 12:06:37
During my work, it would be a requirement for me to use Eigen::VectorXcd as state type, to solve a huge linear ODE system. In that project, the matrix in the ODE system is sparse. Multiplying a it with a dense vector can be computed in parallel in a simple way using Eigen. However, I have faced some problems in that situation that I will tell in details below. Currently I am applying a not-so efficient solution, namely, I use arma::cx_vec as state type, and declare the matrix corresponding the ode arma::cx_mat, which is a dense matrix type. Unfortunately, sparse-matrix-dense vector

机械臂末端参数(x y z rx ry rz)

蓝咒 提交于 2019-12-04 10:34:32
对于六轴机械臂而言,在控制器端通常会有六个参数表征当前机械臂末端的状态(x, y, z, rx, ry, rz),其中(x, y, z)表示以机械臂的基座为原点(0, 0, 0)的OXYZ坐标系的坐标值,其中地面为xoy面,垂直方向为z轴,而(rx, ry, rz)表示末端工具分别围绕基座的x、y以及z轴旋转的角度,即欧拉角(eular)。 此时我们定义机械臂末端存在另一个坐标系O'X'Y‘Z',可以知道从OXYZ坐标系经过Rt的坐标变换会得到O'X'YZ'。 其中t=[x, y, z], 为一个3*1的列向量。 对于旋转矩阵R而言,可以通过欧拉角转换成旋转矩阵,使用opencv以及eigen程序实现如下: 1. opencv实现 /** opencv实现欧拉角计算对应的旋转矩阵 cv::Vec3d &theta 必须是弧度值 : cv::Vec3d eular(0.2*M_PI, 0.3*M_PI, 0.4*M_PI); **/ cv::Mat eulerAnglesToRotationMatrix(cv::Vec3d &theta) { // 计算旋转矩阵的X分量 cv::Mat R_x = (cv::Mat_<double>(3, 3) << 1, 0, 0, 0, cos(theta[0]), -sin(theta[0]), 0, sin(theta[0]), cos