-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chebyshev2 Improvements #1660
Chebyshev2 Improvements #1660
Changes from 6 commits
b766093
79272bf
3bff8ad
9ee652c
fe7d877
36dc04d
e952a31
8312a71
fb49579
10f75a0
e56e9b5
7aa6e57
bc1b949
7799fd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,27 +51,30 @@ class GTSAM_EXPORT Chebyshev2 : public Basis<Chebyshev2> { | |
using Parameters = Eigen::Matrix<double, /*Nx1*/ -1, 1>; | ||
using DiffMatrix = Eigen::Matrix<double, /*NxN*/ -1, -1>; | ||
|
||
/// Specific Chebyshev point | ||
static double Point(size_t N, int j) { | ||
assert(j >= 0 && size_t(j) < N); | ||
const double dtheta = M_PI / (N > 1 ? (N - 1) : 1); | ||
// We add -PI so that we get values ordered from -1 to +1 | ||
// sin(- M_PI_2 + dtheta*j); also works | ||
return cos(-M_PI + dtheta * j); | ||
} | ||
|
||
/// Specific Chebyshev point, within [a,b] interval | ||
static double Point(size_t N, int j, double a, double b) { | ||
assert(j >= 0 && size_t(j) < N); | ||
const double dtheta = M_PI / (N - 1); | ||
/** | ||
* @brief Specific Chebyshev point, within [a,b] interval. | ||
* Default interval is [-1, 1] | ||
* | ||
* @param N The degree of the polynomial | ||
* @param j The index of the Chebyshev point | ||
* @param a Lower bound of interval (default: -1) | ||
* @param b Upper bound of interval (default: 1) | ||
* @return double | ||
*/ | ||
static double Point(size_t N, int j, double a = -1, double b = 1) { | ||
assert(j >= 0 && size_t(j) <= N); | ||
const double dtheta = M_PI / (N > 1 ? N : 1); | ||
// We add -PI so that we get values ordered from -1 to +1 | ||
// sin(-M_PI_2 + dtheta*j); also works | ||
return a + (b - a) * (1. + cos(-M_PI + dtheta * j)) / 2; | ||
} | ||
|
||
/// All Chebyshev points | ||
static Vector Points(size_t N) { | ||
Vector points(N); | ||
for (size_t j = 0; j < N; j++) points(j) = Point(N, j); | ||
Vector points(N + 1); | ||
for (size_t j = 0; j <= N; j++) { | ||
points(j) = Point(N, j); | ||
} | ||
return points; | ||
} | ||
|
||
|
@@ -83,8 +86,13 @@ class GTSAM_EXPORT Chebyshev2 : public Basis<Chebyshev2> { | |
return points; | ||
} | ||
|
||
/// Return a zero initialized Parameter matrix. | ||
static Parameters ParameterMatrix(size_t N) { | ||
return Parameters::Zero(N + 1); | ||
} | ||
|
||
/** | ||
* Evaluate Chebyshev Weights on [-1,1] at any x up to order N-1 (N values) | ||
* Evaluate Chebyshev Weights on [-1,1] at any x up to order N (N+1 values) | ||
* These weights implement barycentric interpolation at a specific x. | ||
* More precisely, f(x) ~ [w0;...;wN] * [f0;...;fN], where the fj are the | ||
* values of the function f at the Chebyshev points. As such, for a given x we | ||
|
@@ -94,6 +102,16 @@ class GTSAM_EXPORT Chebyshev2 : public Basis<Chebyshev2> { | |
static Weights CalculateWeights(size_t N, double x, double a = -1, | ||
double b = 1); | ||
|
||
/** | ||
* Calculate weights for all x in vector X. | ||
* Returns M*N matrix where M is the size of the vector X, | ||
* and N is the number of basis functions. | ||
* | ||
* Overriden for Chebyshev2. | ||
*/ | ||
static Matrix WeightMatrix(size_t N, const Vector& X, double a = -1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used? Just being worried about this MxN matrix being confused with the other MxN matrix that is used for VectorEvaluators. But I remember we talked about this as a speedup in some scenarios? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be removed too. |
||
double b = 1); | ||
|
||
/** | ||
* Evaluate derivative of barycentric weights. | ||
* This is easy and efficient via the DifferentiationMatrix. | ||
|
@@ -134,8 +152,8 @@ class GTSAM_EXPORT Chebyshev2 : public Basis<Chebyshev2> { | |
template <size_t M> | ||
static Matrix matrix(std::function<Eigen::Matrix<double, M, 1>(double)> f, | ||
size_t N, double a = -1, double b = 1) { | ||
Matrix Xmat(M, N); | ||
for (size_t j = 0; j < N; j++) { | ||
Matrix Xmat(M, N + 1); | ||
for (size_t j = 0; j <= N; j++) { | ||
Xmat.col(j) = f(Point(N, j, a, b)); | ||
} | ||
return Xmat; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we can't just say Zero(N) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this needs to be removed since it was added for the previous change of
N
toN+1
. Removing.