23#include <gtsam/basis/ParameterMatrix.h>
70using Weights = Eigen::Matrix<double, 1, -1>;
84 Matrix result(M, w.cols() * M);
87 for (
int i = 0; i < w.cols(); i++) {
88 result.block(0, i * M, M, M).diagonal().array() = w(i);
94template <
typename DERIVED>
103 Matrix W(X.size(), N);
104 for (
int i = 0; i < X.size(); i++)
105 W.row(i) = DERIVED::CalculateWeights(N, X(i));
118 static Matrix
WeightMatrix(
size_t N,
const Vector& X,
double a,
double b) {
119 Matrix W(X.size(), N);
120 for (
int i = 0; i < X.size(); i++)
121 W.row(i) = DERIVED::CalculateWeights(N, X(i), a, b);
142 : weights_(DERIVED::CalculateWeights(N, x)) {}
146 : weights_(DERIVED::CalculateWeights(N, x, a, b)) {}
149 double apply(
const typename DERIVED::Parameters& p,
151 if (H) *H = weights_;
152 return (weights_ * p)(0);
161 void print(
const std::string& s =
"")
const {
162 std::cout << s << (s !=
"" ?
" " :
"") << weights_ << std::endl;
175 using VectorM = Eigen::Matrix<double, M, 1>;
176 using Jacobian = Eigen::Matrix<double, M, -1>;
188 H_ = kroneckerProductIdentity<M>(this->weights_);
192 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
212 return P.matrix() * this->weights_.transpose();
232 using Jacobian = Eigen::Matrix<double, 1, -1>;
245 void calculateJacobian(
size_t N) {
246 H_.setZero(1, M * N);
247 for (
int j = 0; j < EvaluationFunctor::weights_.size(); j++)
248 H_(0, rowIndex_ + j * M) = EvaluationFunctor::weights_(j);
258 calculateJacobian(N);
264 calculateJacobian(N);
271 return P.row(rowIndex_) * EvaluationFunctor::weights_.transpose();
309 :
Base(N, x, a, b) {}
315 Eigen::Matrix<double, M, 1> xi = Base::operator()(P, H);
318 Eigen::Matrix<double, M, M> D_result_xi;
319 T result = T::ChartAtOrigin::Retract(xi, H ? &D_result_xi : 0);
324 if (H) *H = D_result_xi * (*H);
347 : weights_(DERIVED::DerivativeWeights(N, x)) {}
349 DerivativeFunctorBase(
size_t N,
double x,
double a,
double b)
350 : weights_(DERIVED::DerivativeWeights(N, x, a, b)) {}
352 void print(
const std::string& s =
"")
const {
353 std::cout << s << (s !=
"" ?
" " :
"") << weights_ << std::endl;
371 DerivativeFunctor(
size_t N,
double x,
double a,
double b)
372 : DerivativeFunctorBase(N, x, a, b) {}
374 double apply(
const typename DERIVED::Parameters& p,
375 OptionalJacobian</*1xN*/ -1, -1> H = boost::none)
const {
376 if (H) *H = this->weights_;
377 return (this->weights_ * p)(0);
397 using VectorM = Eigen::Matrix<double, M, 1>;
398 using Jacobian = Eigen::Matrix<double, M, -1>;
410 H_ = kroneckerProductIdentity<M>(this->weights_);
414 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
433 return P.matrix() * this->weights_.transpose();
453 using Jacobian = Eigen::Matrix<double, 1, -1>;
466 void calculateJacobian(
size_t N) {
467 H_.setZero(1, M * N);
468 for (
int j = 0; j < this->weights_.size(); j++)
469 H_(0, rowIndex_ + j * M) = this->weights_(j);
479 calculateJacobian(N);
485 calculateJacobian(N);
491 return P.row(rowIndex_) * this->weights_.transpose();
501 static double Derivative(
double x,
const Vector& p,
503 return DerivativeFunctor(x)(p.transpose(), H);
typedef and functions to augment Eigen's MatrixXd
Special class for optional Jacobian arguments.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Matrix kroneckerProductIdentity(const Weights &w)
Function for computing the kronecker product of the 1*N Weight vector w with the MxM identity matrix ...
Definition: Basis.h:83
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
free versions of apply
Definition: DecisionTree.h:218
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
CRTP Base class for function bases.
Definition: Basis.h:95
static Matrix WeightMatrix(size_t N, const Vector &X, double a, double b)
Calculate weights for all x in vector X, with interval [a,b].
Definition: Basis.h:118
static Matrix WeightMatrix(size_t N, const Vector &X)
Calculate weights for all x in vector X.
Definition: Basis.h:102
An instance of an EvaluationFunctor calculates f(x;p) at a given x, applied to Parameters p.
Definition: Basis.h:132
EvaluationFunctor(size_t N, double x)
Constructor with interval [a,b].
Definition: Basis.h:141
EvaluationFunctor(size_t N, double x, double a, double b)
Constructor with interval [a,b].
Definition: Basis.h:145
double apply(const typename DERIVED::Parameters &p, OptionalJacobian<-1, -1 > H=boost::none) const
Regular 1D evaluation.
Definition: Basis.h:149
EvaluationFunctor()
For serialization.
Definition: Basis.h:138
double operator()(const typename DERIVED::Parameters &p, OptionalJacobian<-1, -1 > H=boost::none) const
c++ sugar
Definition: Basis.h:156
VectorEvaluationFunctor at a given x, applied to ParameterMatrix<M>.
Definition: Basis.h:173
VectorEvaluationFunctor(size_t N, double x, double a, double b)
Constructor, with interval [a,b].
Definition: Basis.h:203
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VectorEvaluationFunctor()
For serialization.
Definition: Basis.h:195
VectorEvaluationFunctor(size_t N, double x)
Default Constructor.
Definition: Basis.h:198
void calculateJacobian()
Calculate the M*(M*N) Jacobian of this functor with respect to the M*N parameter matrix P.
Definition: Basis.h:187
VectorM operator()(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
c++ sugar
Definition: Basis.h:216
VectorM apply(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
M-dimensional evaluation.
Definition: Basis.h:209
Given a M*N Matrix of M-vectors at N polynomial points, an instance of VectorComponentFunctor compute...
Definition: Basis.h:230
double operator()(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
c++ sugar
Definition: Basis.h:275
VectorComponentFunctor()
For serialization.
Definition: Basis.h:253
VectorComponentFunctor(size_t N, size_t i, double x)
Construct with row index.
Definition: Basis.h:256
VectorComponentFunctor(size_t N, size_t i, double x, double a, double b)
Construct with row index and interval.
Definition: Basis.h:262
double apply(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
Calculate component of component rowIndex_ of P.
Definition: Basis.h:268
Manifold EvaluationFunctor at a given x, applied to ParameterMatrix<M>.
Definition: Basis.h:296
ManifoldEvaluationFunctor(size_t N, double x, double a, double b)
Constructor, with interval [a,b].
Definition: Basis.h:308
ManifoldEvaluationFunctor()
For serialization.
Definition: Basis.h:302
ManifoldEvaluationFunctor(size_t N, double x)
Default Constructor.
Definition: Basis.h:305
Base class for functors below that calculate derivative weights.
Definition: Basis.h:338
DerivativeFunctorBase()
For serialization.
Definition: Basis.h:344
An instance of a DerivativeFunctor calculates f'(x;p) at a given x, applied to Parameters p.
Definition: Basis.h:364
DerivativeFunctor()
For serialization.
Definition: Basis.h:367
double operator()(const typename DERIVED::Parameters &p, OptionalJacobian< -1, -1 > H=boost::none) const
c++ sugar
Definition: Basis.h:380
VectorDerivativeFunctor at a given x, applied to ParameterMatrix<M>.
Definition: Basis.h:395
void calculateJacobian()
Calculate the M*(M*N) Jacobian of this functor with respect to the M*N parameter matrix P.
Definition: Basis.h:409
VectorDerivativeFunctor(size_t N, double x, double a, double b)
Constructor, with optional interval [a,b].
Definition: Basis.h:425
VectorM operator()(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
c++ sugar
Definition: Basis.h:436
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VectorDerivativeFunctor()
For serialization.
Definition: Basis.h:417
VectorDerivativeFunctor(size_t N, double x)
Default Constructor.
Definition: Basis.h:420
Given a M*N Matrix of M-vectors at N polynomial points, an instance of ComponentDerivativeFunctor com...
Definition: Basis.h:451
ComponentDerivativeFunctor(size_t N, size_t i, double x)
Construct with row index.
Definition: Basis.h:477
double operator()(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
c++ sugar
Definition: Basis.h:494
ComponentDerivativeFunctor()
For serialization.
Definition: Basis.h:474
ComponentDerivativeFunctor(size_t N, size_t i, double x, double a, double b)
Construct with row index and interval.
Definition: Basis.h:483
double apply(const ParameterMatrix< M > &P, OptionalJacobian< -1, -1 > H=boost::none) const
Calculate derivative of component rowIndex_ of F.
Definition: Basis.h:488
A matrix abstraction of MxN values at the Basis points.
Definition: ParameterMatrix.h:38