本文整理汇总了C++中eigen::Ref类的典型用法代码示例。如果您正苦于以下问题:C++ Ref类的具体用法?C++ Ref怎么用?C++ Ref使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ref类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
SEXP
GetMatCol(const SEXP data, const int idx)
{
Eigen::Ref<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > A = EigenXPtrToMapEigen<T>(data);
Eigen::Matrix<T, Eigen::Dynamic, 1> Am = A.col(idx-1);
return(wrap(Am));
}
示例2: train
void FunctionApproximatorGPR::train(const Eigen::Ref<const Eigen::MatrixXd>& inputs, const Eigen::Ref<const Eigen::MatrixXd>& targets)
{
if (isTrained())
{
cerr << "WARNING: You may not call FunctionApproximatorGPR::train more than once. Doing nothing." << endl;
cerr << " (if you really want to retrain, call reTrain function instead)" << endl;
return;
}
assert(inputs.rows() == targets.rows());
assert(inputs.cols()==getExpectedInputDim());
const MetaParametersGPR* meta_parameters_gpr =
dynamic_cast<const MetaParametersGPR*>(getMetaParameters());
double max_covar = meta_parameters_gpr->maximum_covariance();
VectorXd sigmas = meta_parameters_gpr->sigmas();
// Compute the gram matrix
// In a gram matrix, every input point is itself a center
MatrixXd centers = inputs;
// Replicate sigmas, because they are the same for each data point/center
MatrixXd widths = sigmas.transpose().colwise().replicate(centers.rows());
MatrixXd gram(inputs.rows(),inputs.rows());
bool normalize_activations = false;
bool asymmetric_kernels = false;
BasisFunction::Gaussian::activations(centers,widths,inputs,gram,normalize_activations,asymmetric_kernels);
gram *= max_covar;
setModelParameters(new ModelParametersGPR(inputs,targets,gram,max_covar,sigmas));
}
示例3: edgeIndices
Eigen::ArrayXXi distmesh::utils::findUniqueEdges(Eigen::Ref<Eigen::ArrayXXi const> const triangulation) {
// find all unique combinations
auto const combinations = nOverK(triangulation.cols(), 2);
// find unique edges for all combinations
// guarantee direction of edges with lower node index to higher index
std::set<std::array<int, 2>> uniqueEdges;
std::array<int, 2> edge = {{0, 0}};
for (int combination = 0; combination < combinations.rows(); ++combination)
for (int triangle = 0; triangle < triangulation.rows(); ++triangle) {
edge[0] = triangulation(triangle, combinations(combination, 0));
edge[1] = triangulation(triangle, combinations(combination, 1));
edge = edge[1] < edge[0] ? std::array<int, 2>{edge[1], edge[0]} : edge;
uniqueEdges.insert(edge);
}
// copy set to eigen array
Eigen::ArrayXXi edgeIndices(uniqueEdges.size(), 2);
int index = 0;
for (auto const& edge : uniqueEdges) {
edgeIndices(index, 0) = edge[0];
edgeIndices(index, 1) = edge[1];
index++;
}
return edgeIndices;
}
示例4: predictVariance
void FunctionApproximatorGPR::predictVariance(const Eigen::Ref<const Eigen::MatrixXd>& inputs, MatrixXd& variances)
{
if (!isTrained())
{
cerr << "WARNING: You may not call FunctionApproximatorLWPR::predict if you have not trained yet. Doing nothing." << endl;
return;
}
const ModelParametersGPR* model_parameters_gpr = static_cast<const ModelParametersGPR*>(getModelParameters());
assert(inputs.cols()==getExpectedInputDim());
unsigned int n_samples = inputs.rows();
variances.resize(n_samples,1);
MatrixXd ks;
model_parameters_gpr->kernelActivations(inputs, ks);
double maximum_covariance = model_parameters_gpr->maximum_covariance();
MatrixXd gram_inv = model_parameters_gpr->gram_inv();
for (unsigned int ii=0; ii<n_samples; ii++)
variances(ii) = maximum_covariance - (ks.row(ii)*gram_inv).dot(ks.row(ii).transpose());
}
示例5:
double softmax<T>::compute_cost(const Eigen::Ref<const EigenMat> &train,
const Eigen::Ref<const EigenMat> &weight,
const Eigen::Ref<const EigenMat> &ground_truth)
{
compute_hypothesis(train, weight);
double const NSamples = static_cast<double>(train.cols());
return -1.0 * (hypothesis_.array().log() *
ground_truth.array()).sum() / NSamples +
weight.array().pow(2.0).sum() * params_.lambda_ / 2.0;
}
示例6: pointsPerDimension
// create initial points distribution
Eigen::ArrayXXd distmesh::utils::createInitialPoints(
Functional const& distanceFunction, double const initialPointDistance,
Functional const& elementSizeFunction, Eigen::Ref<Eigen::ArrayXXd const> const boundingBox,
Eigen::Ref<Eigen::ArrayXXd const> const fixedPoints) {
// extract dimension of mesh
unsigned const dimension = boundingBox.cols();
// initially distribute points evenly in complete bounding box
Eigen::ArrayXi pointsPerDimension(dimension);
for (int dim = 0; dim < dimension; ++dim) {
pointsPerDimension(dim) = ceil((boundingBox(1, dim) - boundingBox(0, dim)) /
(initialPointDistance * (dim == 0 ? 1.0 : sqrt(3.0) / 2.0)));
}
Eigen::ArrayXXd points(pointsPerDimension.prod(), dimension);
for (int point = 0; point < points.rows(); ++point)
for (int dim = 0; dim < dimension; ++dim) {
int const pointIndex = (point / std::max(pointsPerDimension.topRows(dim).prod(), 1)) %
pointsPerDimension(dim);
points(point, dim) = boundingBox(0, dim) + (double)pointIndex * initialPointDistance *
(dim == 0 ? 1.0 : sqrt(3.0) / 2.0);
if (dim > 0) {
points(point, dim - 1) += pointIndex % 2 != 0 ? initialPointDistance / 2.0 : 0.0;
}
}
// reject points outside of region defined by distance function
points = selectMaskedArrayElements<double>(points,
distanceFunction(points) < constants::geometryEvaluationThreshold * initialPointDistance);
// clear duplicate points
Eigen::Array<bool, Eigen::Dynamic, 1> isUniquePoint =
Eigen::Array<bool, Eigen::Dynamic, 1>::Constant(points.rows(), true);
for (int i = 0; i < fixedPoints.rows(); ++i)
for (int j = 0; j < points.rows(); ++j) {
isUniquePoint(j) &= !(fixedPoints.row(i) == points.row(j)).all();
}
points = selectMaskedArrayElements<double>(points, isUniquePoint);
// calculate probability to keep points
Eigen::ArrayXd probability = 1.0 / elementSizeFunction(points).pow(dimension);
probability /= probability.maxCoeff();
// reject points with wrong probability
points = selectMaskedArrayElements<double>(points,
0.5 * (1.0 + Eigen::ArrayXd::Random(points.rows())) < probability);
// combine fixed and variable points to one array
Eigen::ArrayXXd finalPoints(points.rows() + fixedPoints.rows(), dimension);
finalPoints << fixedPoints, points;
return finalPoints;
}
示例7: rowwise
int softmax<T>::predict(Eigen::Ref<const EigenMat> const &input)
{
CV_Assert(input.cols() == 1);
compute_hypothesis(input, weight_);
probability_ = (hypothesis_ * input.transpose()).
rowwise().sum();
EigenMat::Index max_row = 0, max_col = 0;
probability_.maxCoeff(&max_row, &max_col);
return max_row;
}
示例8: boundary
// determine boundary edges of given triangulation
Eigen::ArrayXi distmesh::utils::boundEdges(
Eigen::Ref<Eigen::ArrayXXi const> const triangulation,
Eigen::Ref<Eigen::ArrayXXi const> const _edges,
Eigen::Ref<Eigen::ArrayXXi const> const _edgeIndices) {
// create a new edge list, if none was given
Eigen::ArrayXXi edges;
if (_edges.rows() == 0) {
edges = utils::findUniqueEdges(triangulation);
}
else {
edges = _edges;
}
// get edge indices for each triangle in triangulation
Eigen::ArrayXXi edgeIndices;
if (_edgeIndices.rows() == 0) {
edgeIndices = utils::getTriangulationEdgeIndices(triangulation, edges);
}
else {
edgeIndices = _edgeIndices;
}
// find edges, which only appear once in triangulation
std::set<int> uniqueEdges;
std::vector<int> boundaryEdges;
for (int triangle = 0; triangle < triangulation.rows(); ++triangle)
for (int edge = 0; edge < triangulation.cols(); ++edge) {
auto const edgeIndex = edgeIndices(triangle, edge);
// insert edge in set to get info about multiple appearance
if (!std::get<1>(uniqueEdges.insert(edgeIndex))) {
// find edge in vector and delete it
auto const it = std::find(boundaryEdges.begin(), boundaryEdges.end(), edgeIndex);
if (it != boundaryEdges.end()) {
boundaryEdges.erase(it);
}
}
else {
boundaryEdges.push_back(edgeIndex);
}
}
// convert stl vector to eigen array
Eigen::ArrayXi boundary(boundaryEdges.size());
for (int edge = 0; edge < boundary.rows(); ++edge) {
boundary(edge) = boundaryEdges[edge];
}
return boundary;
}
示例9: pinvDampedEigen
//**************************************************************************************************
Eigen::MatrixRXd wholeBodyReach::pinvDampedEigen(const Eigen::Ref<Eigen::MatrixRXd> &A, double damp)
{
// allocate memory
int m = A.rows(), n = A.cols(), k = m<n?m:n;
VectorXd SpinvD = VectorXd::Zero(k);
// compute decomposition
JacobiSVD<MatrixRXd> svd(A, ComputeThinU | ComputeThinV); // default Eigen SVD
VectorXd sv = svd.singularValues();
// compute pseudoinverse of singular value matrix
double damp2 = damp*damp;
for (int c=0;c<k; c++)
SpinvD(c) = sv(c) / (sv(c)*sv(c) + damp2);
// compute damped pseudoinverse
return svd.matrixV() * SpinvD.asDiagonal() * svd.matrixU().transpose();
}
示例10: predictVariance
void FunctionApproximatorGMR::predictVariance(const Eigen::Ref<const Eigen::MatrixXd>& inputs, Eigen::MatrixXd& variances)
{
ENTERING_REAL_TIME_CRITICAL_CODE
variances.resize(inputs.rows(),getExpectedOutputDim());
predict(inputs,empty_prealloc_,variances);
EXITING_REAL_TIME_CRITICAL_CODE
}
示例11: DrawArrow
void DrawArrow(const Eigen::Ref<const Eigen::Vector3d>& pt, const Eigen::Ref<const Eigen::Vector3d>& dir, double length, double thickness, double arrowthickness) {
Eigen::Vector3d normDir = dir.normalized();
if(arrowthickness==-1) arrowthickness=2*thickness;
double arrowlength = 2*arrowthickness;
GLUquadricObj *c;
c = gluNewQuadric();
gluQuadricDrawStyle(c, GLU_FILL);
gluQuadricNormals(c, GLU_SMOOTH);
glPushMatrix();
glTranslated(pt[0], pt[1], pt[2]);
glRotated(acos(normDir[2])*180/M_PI, -normDir[1], normDir[0], 0);
gluCylinder(c, thickness, thickness, length-arrowlength, 16, 16);
// arrowhed
glPushMatrix();
glTranslated(0, 0, length-arrowlength);
gluCylinder(c, arrowthickness, 0.0, arrowlength, 10, 10);
glPopMatrix();
glPopMatrix();
gluDeleteQuadric(c);
}
示例12: if
// convert kartesian to polar coordinates
Eigen::ArrayXd mpFlow::math::polar(Eigen::Ref<Eigen::ArrayXd const> const point) {
// calc radius
double angle = 0.0;
double radius = sqrt(point.square().sum());
// calc angle
if (point(0) > 0.0) {
angle = atan(point(1) / point(0));
}
else if ((point(0) < 0.0) && (point(1) >= 0.0)) {
angle = atan(point(1) / point(0)) + M_PI;
}
else if ((point(0) < 0.0) && (point(1) < 0.0)) {
angle = atan(point(1) / point(0)) - M_PI;
}
else if ((point(0) == 0.0) && (point(1) > 0.0)) {
angle = M_PI / 2.0;
}
else if ((point(0) == 0.0) && (point(1) < 0.0)) {
angle = - M_PI / 2.0;
}
else {
angle = 0.0;
}
Eigen::ArrayXd result(2);
result << radius, angle;
return result;
}
示例13: nullSpaceProjector
//**************************************************************************************************
Eigen::MatrixRXd wholeBodyReach::nullSpaceProjector(const Eigen::Ref<MatrixRXd> A, double tol)
{
// allocate memory
int m = A.rows(), n = A.cols(), k = m<n?m:n;
MatrixRXd Spinv = MatrixRXd::Zero(k,k);
// compute decomposition
JacobiSVD<MatrixRXd> svd(A, ComputeThinU | ComputeThinV); // default Eigen SVD
VectorXd sv = svd.singularValues();
// compute pseudoinverse of singular value matrix
for (int c=0;c<k; c++)
if ( sv(c)> tol)
Spinv(c,c) = 1/sv(c);
// compute pseudoinverse
MatrixRXd N = MatrixRXd::Identity(n,n);
N -= svd.matrixV() * Spinv * svd.matrixU().transpose() * A;
return N;
}
示例14: assign
void assign (Eigen::Ref<Eigen::Vector3d> result, const geometry_msgs::Quaternion &q) {
result << q.x, q.y, q.z;
if (result.isMuchSmallerThan(1)) {
result = Eigen::Vector3d::Zero();
} else {
double angle = 2. * acos(q.w);
result *= angle / sin(0.5 * angle);
}
}
示例15: re
void softmax<T>::train(const Eigen::Ref<const EigenMat> &train,
const std::vector<int> &labels)
{
#ifdef OCV_TEST_SOFTMAX
gradient_check();
#endif
auto const UniqueLabels = get_unique_labels(labels);
auto const NumClass = UniqueLabels.size();
weight_ = EigenMat::Random(NumClass, train.rows());
grad_ = EigenMat::Zero(NumClass, train.rows());
auto const TrainCols = static_cast<int>(train.cols());
EigenMat const GroundTruth = get_ground_truth(static_cast<int>(NumClass),
TrainCols,
UniqueLabels,
labels);
std::random_device rd;
std::default_random_engine re(rd());
int const Batch = (get_batch_size(TrainCols));
int const RandomSize = TrainCols != Batch ?
TrainCols - Batch - 1 : 0;
std::uniform_int_distribution<int>
uni_int(0, RandomSize);
for(size_t i = 0; i != params_.max_iter_; ++i){
auto const Cols = uni_int(re);
auto const &TrainBlock =
train.block(0, Cols, train.rows(), Batch);
auto const >Block =
GroundTruth.block(0, Cols, NumClass, Batch);
auto const Cost = compute_cost(TrainBlock, weight_, GTBlock);
if(std::abs(params_.cost_ - Cost) < params_.epsillon_ ||
Cost < 0){
break;
}
params_.cost_ = Cost;
compute_gradient(TrainBlock, weight_, GTBlock);
weight_.array() -= grad_.array() * params_.lrate_;//*/
}
}