Skip to content

Commit

Permalink
override WeightMatrix for Chebyshev2
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Oct 28, 2023
1 parent fe7d877 commit 36dc04d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions gtsam/basis/Chebyshev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ Weights Chebyshev2::CalculateWeights(size_t N, double x, double a, double b) {
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) {
// Allocate space for weights
Weights weightDerivatives(N + 1);
Expand Down
10 changes: 10 additions & 0 deletions gtsam/basis/Chebyshev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,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,
double b = 1);

/**
* Evaluate derivative of barycentric weights.
* This is easy and efficient via the DifferentiationMatrix.
Expand Down
4 changes: 2 additions & 2 deletions python/gtsam/tests/test_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import unittest

import numpy as np
from gtsam.utils.test_case import GtsamTestCase

import gtsam
from gtsam.utils.test_case import GtsamTestCase
from gtsam.symbol_shorthand import B


class TestBasis(GtsamTestCase):
Expand All @@ -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
used.
"""

def setUp(self):
self.N = 2
self.x = [0., 0.5, 0.75]
Expand Down

0 comments on commit 36dc04d

Please sign in to comment.