本文整理汇总了C++中eigen::Ref类的典型用法代码示例。如果您正苦于以下问题:C++ Ref类的具体用法?C++ Ref怎么用?C++ Ref使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ref类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:gitter-badger,项目名称:gpuR,代码行数:7,代码来源:eigen_helpers.hpp
示例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));
}
开发者ID:graiola,项目名称:dmpbbo,代码行数:35,代码来源:FunctionApproximatorGPR.cpp
示例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;
}
开发者ID:pgebhardt,项目名称:libdistmesh,代码行数:30,代码来源:utils.cpp
示例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());
}
开发者ID:graiola,项目名称:dmpbbo,代码行数:26,代码来源:FunctionApproximatorGPR.cpp
示例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;
}
开发者ID:stereomatchingkiss,项目名称:ocv_libs,代码行数:10,代码来源:softmax.hpp
示例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;
}
开发者ID:pgebhardt,项目名称:libdistmesh,代码行数:56,代码来源:utils.cpp
示例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;
}
开发者ID:stereomatchingkiss,项目名称:ocv_libs,代码行数:11,代码来源:softmax.hpp
示例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;
}
开发者ID:pgebhardt,项目名称:libdistmesh,代码行数:51,代码来源:utils.cpp
示例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();
}
开发者ID:liuwei000000,项目名称:codyco-modules,代码行数:16,代码来源:wholeBodyReachUtils.cpp
示例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
}
开发者ID:stulp,项目名称:dmpbbo,代码行数:7,代码来源:FunctionApproximatorGMR.cpp
示例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);
}
开发者ID:jturner65,项目名称:ParticleSim,代码行数:26,代码来源:glFuncs.cpp
示例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;
}
开发者ID:pgebhardt,项目名称:mpflow,代码行数:30,代码来源:mathematics.cpp
示例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;
}
开发者ID:liuwei000000,项目名称:codyco-modules,代码行数:18,代码来源:wholeBodyReachUtils.cpp
示例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);
}
}
开发者ID:ubi-agni,项目名称:rviz_cbf_plugin,代码行数:9,代码来源:run_cbf.cpp
示例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_;//*/
}
}
开发者ID:stereomatchingkiss,项目名称:ocv_libs,代码行数:40,代码来源:softmax.hpp
示例16: polygon
// check whether points lies inside or outside of polygon
Eigen::ArrayXd distmesh::utils::pointsInsidePoly(
Eigen::Ref<Eigen::ArrayXXd const> const points,
Eigen::Ref<Eigen::ArrayXXd const> const polygon) {
Eigen::ArrayXd inside = Eigen::ArrayXd::Zero(points.rows());
for (int i = 0, j = polygon.rows() - 1; i < polygon.rows(); j = i++) {
inside = (((points.col(1) < polygon(i, 1)) != (points.col(1) < polygon(j, 1))) &&
(points.col(0) < (polygon(j, 0) - polygon(i, 0)) * (points.col(1) - polygon(i, 1)) /
(polygon(j, 1) - polygon(i, 1)) + polygon(i, 0))).select(1.0 - inside, inside);
}
return inside;
}
开发者ID:pgebhardt,项目名称:libdistmesh,代码行数:14,代码来源:utils.cpp
示例17: predict
void FunctionApproximatorGPR::predict(const Eigen::Ref<const Eigen::MatrixXd>& inputs, MatrixXd& outputs)
{
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();
outputs.resize(n_samples,1);
MatrixXd ks(n_samples,n_samples);
model_parameters_gpr->kernelActivations(inputs, ks);
VectorXd weights = model_parameters_gpr->weights();
for (unsigned int ii=0; ii<n_samples; ii++)
outputs(ii) = ks.row(ii).dot(weights);
}
开发者ID:graiola,项目名称:dmpbbo,代码行数:24,代码来源:FunctionApproximatorGPR.cpp
示例18: C
void LinearElasticIsotropic<DisplacementDim>::computeConstitutiveRelation(
double const t,
ProcessLib::SpatialPosition const& x,
double const aperture0,
Eigen::Ref<Eigen::VectorXd const>
sigma0,
Eigen::Ref<Eigen::VectorXd const>
/*w_prev*/,
Eigen::Ref<Eigen::VectorXd const>
w,
Eigen::Ref<Eigen::VectorXd const>
/*sigma_prev*/,
Eigen::Ref<Eigen::VectorXd>
sigma,
Eigen::Ref<Eigen::MatrixXd>
C,
typename FractureModelBase<DisplacementDim>::MaterialStateVariables&
material_state_variables)
{
material_state_variables.reset();
const int index_ns = DisplacementDim - 1;
C.setZero();
for (int i = 0; i < index_ns; i++)
C(i, i) = _mp.shear_stiffness(t, x)[0];
sigma.noalias() = C * w;
double const aperture = w[index_ns] + aperture0;
sigma.coeffRef(index_ns) =
_mp.normal_stiffness(t, x)[0] * w[index_ns] *
logPenalty(aperture0, aperture, _penalty_aperture_cutoff);
C(index_ns, index_ns) =
_mp.normal_stiffness(t, x)[0] *
logPenaltyDerivative(aperture0, aperture, _penalty_aperture_cutoff);
sigma.noalias() += sigma0;
// correction for an opening fracture
if (_tension_cutoff && sigma[index_ns] > 0)
{
C.setZero();
sigma.setZero();
material_state_variables.setTensileStress(true);
}
}
开发者ID:OlafKolditz,项目名称:ogs,代码行数:48,代码来源:LinearElasticIsotropic.cpp
示例19: drawShapeTriangulation
/** Draw shape triangles */
void drawShapeTriangulation(cv::Mat& canvas, Eigen::Ref<RowVectorX const> shape, Eigen::Ref<RowVectorXi const> triangleIds, const cv::Scalar &color)
{
const auto &s = shape.cast<float>();
for (int j = 0; j < triangleIds.cols() / 3; j++) {
int id1 = triangleIds(0, j * 3 + 0);
int id2 = triangleIds(0, j * 3 + 1);
int id3 = triangleIds(0, j * 3 + 2);
float x1 = s(0, id1 * 2 + 0);
float y1 = s(0, id1 * 2 + 1);
float x2 = s(0, id2 * 2 + 0);
float y2 = s(0, id2 * 2 + 1);
float x3 = s(0, id3 * 2 + 0);
float y3 = s(0, id3 * 2 + 1);
cv::line(canvas, cv::Point2f(x1, y1), cv::Point2f(x2, y2), color, 1, CV_AA);
cv::line(canvas, cv::Point2f(x2, y2), cv::Point2f(x3, y3), color, 1, CV_AA);
cv::line(canvas, cv::Point2f(x3, y3), cv::Point2f(x1, y1), color, 1, CV_AA);
}
}
开发者ID:cheind,项目名称:aam,代码行数:25,代码来源:show.cpp
示例20: jacobian
void jacobian(const Eigen::Ref<const Eigen::VectorXd> &x, Eigen::Ref<Eigen::MatrixXd> out) const override
{
const unsigned int offset = 3 * links_ * chainNum_;
out.setZero();
Eigen::VectorXd plus(3 * (links_ + 1));
plus.head(3 * links_) = x.segment(offset, 3 * links_);
plus.tail(3) = Eigen::VectorXd::Zero(3);
Eigen::VectorXd minus(3 * (links_ + 1));
minus.head(3) = offset_;
minus.tail(3 * links_) = x.segment(offset, 3 * links_);
const Eigen::VectorXd diagonal = plus - minus;
for (unsigned int i = 0; i < links_; i++)
out.row(i).segment(3 * i + offset, 3) = diagonal.segment(3 * i, 3).normalized();
out.block(1, offset, links_ - 1, 3 * links_ - 3) -= out.block(1, offset + 3, links_ - 1, 3 * links_ - 3);
}
开发者ID:ompl,项目名称:ompl,代码行数:20,代码来源:ConstrainedPlanningImplicitParallel.cpp
注:本文中的eigen::Ref类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论