override WeightMatrix for Chebyshev2

release/4.3a0
Varun Agrawal 2023-10-28 11:24:31 -04:00
parent fe7d877352
commit 36dc04d126
3 changed files with 21 additions and 2 deletions

View File

@ -59,6 +59,15 @@ Weights Chebyshev2::CalculateWeights(size_t N, double x, double a, double b) {
return weights / d; return weights / d;
} }
Matrix Chebyshev2::WeightMatrix(size_t N, const Vector& X, double a, double b) {
// Chebyshev points go from 0 to N, hence N+1 points.
Matrix W(X.size(), N + 1);
for (int i = 0; i < X.size(); i++) {
W.row(i) = CalculateWeights(N, X(i), a, b);
}
return W;
}
Weights Chebyshev2::DerivativeWeights(size_t N, double x, double a, double b) { Weights Chebyshev2::DerivativeWeights(size_t N, double x, double a, double b) {
// Allocate space for weights // Allocate space for weights
Weights weightDerivatives(N + 1); Weights weightDerivatives(N + 1);

View File

@ -102,6 +102,16 @@ class GTSAM_EXPORT Chebyshev2 : public Basis<Chebyshev2> {
static Weights CalculateWeights(size_t N, double x, double a = -1, static Weights CalculateWeights(size_t N, double x, double a = -1,
double b = 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,
double b = 1);
/** /**
* Evaluate derivative of barycentric weights. * Evaluate derivative of barycentric weights.
* This is easy and efficient via the DifferentiationMatrix. * This is easy and efficient via the DifferentiationMatrix.

View File

@ -11,10 +11,9 @@ Author: Frank Dellaert & Gerry Chen (Python)
import unittest import unittest
import numpy as np import numpy as np
from gtsam.utils.test_case import GtsamTestCase
import gtsam import gtsam
from gtsam.utils.test_case import GtsamTestCase
from gtsam.symbol_shorthand import B
class TestBasis(GtsamTestCase): class TestBasis(GtsamTestCase):
@ -26,6 +25,7 @@ class TestBasis(GtsamTestCase):
Chebyshev bases, the line y=x is used to generate the data while for Fourier, 0.7*cos(x) is Chebyshev bases, the line y=x is used to generate the data while for Fourier, 0.7*cos(x) is
used. used.
""" """
def setUp(self): def setUp(self):
self.N = 2 self.N = 2
self.x = [0., 0.5, 0.75] self.x = [0., 0.5, 0.75]