-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathGaussianProcess.hpp
1564 lines (1240 loc) · 51.4 KB
/
GaussianProcess.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <iostream>
#include <fstream>
#include <filesystem>
#include <algorithm> // Include this header for std::max
#include <Eigen/Dense>
// Sophus
#include <sophus/se3.hpp>
#include <SophusExtras.hpp>
typedef Sophus::SO3<double> SO3d;
typedef Sophus::SE3<double> SE3d;
typedef Vector3d Vec3;
typedef Matrix3d Mat3;
using namespace std;
using namespace Eigen;
/* #region Define the states for convenience in initialization and copying ------------------------------------------*/
#define STATE_DIM 18
template <class T = double>
class GPState
{
public:
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
double t;
SO3T R;
Vec3T O;
Vec3T S;
Vec3T P;
Vec3T V;
Vec3T A;
// Destructor
~GPState(){};
// Constructor
GPState()
: t(0), R(SO3T()), O(Vec3T(0, 0, 0)), S(Vec3T(0, 0, 0)), P(Vec3T(0, 0, 0)), V(Vec3T(0, 0, 0)), A(Vec3T(0, 0, 0)) {}
GPState(double t_)
: t(t_), R(SO3T()), O(Vec3T()), S(Vec3T()), P(Vec3T()), V(Vec3T()), A(Vec3T()) {}
GPState(double t_, const SE3d &pose)
: t(t_), R(pose.so3().cast<T>()), O(Vec3T(0, 0, 0)), S(Vec3T(0, 0, 0)), P(pose.translation().cast<T>()), V(Vec3T(0, 0, 0)), A(Vec3T(0, 0, 0)) {}
GPState(double t_, const SO3d &R_, const Vec3 &O_, const Vec3 &S_, const Vec3 &P_, const Vec3 &V_, const Vec3 &A_)
: t(t_), R(R_.cast<T>()), O(O_.cast<T>()), S(S_.cast<T>()), P(P_.cast<T>()), V(V_.cast<T>()), A(A_.cast<T>()) {}
GPState(const GPState<T> &other)
: t(other.t), R(other.R), O(other.O), S(other.S), P(other.P), V(other.V), A(other.A) {}
GPState(double t_, const GPState<T> &other)
: t(t_), R(other.R), O(other.O), S(other.S), P(other.P), V(other.V), A(other.A) {}
GPState &operator=(const GPState &Xother)
{
this->t = Xother.t;
this->R = Xother.R;
this->O = Xother.O;
this->S = Xother.S;
this->P = Xother.P;
this->V = Xother.V;
this->A = Xother.A;
return *this;
}
Matrix<double, STATE_DIM, 1> boxminus(const GPState &Xother) const
{
Matrix<double, STATE_DIM, 1> dX;
dX << (Xother.R.inverse()*R).log(),
O - Xother.O,
S - Xother.S,
P - Xother.P,
V - Xother.V,
A - Xother.A;
return dX;
}
double yaw()
{
Eigen::Vector3d n = R.matrix().col(0);
Eigen::Vector3d ypr(3);
double y = atan2(n(1), n(0));
return y / M_PI * 180.0;
}
double pitch()
{
Eigen::Vector3d n = R.matrix().col(0);
Eigen::Vector3d ypr(3);
double y = atan2(n(1), n(0));
double p = atan2(-n(2), n(0) * cos(y) + n(1) * sin(y));
return p / M_PI * 180.0;
}
double roll()
{
Eigen::Vector3d n = R.matrix().col(0);
Eigen::Vector3d o = R.matrix().col(1);
Eigen::Vector3d a = R.matrix().col(2);
Eigen::Vector3d ypr(3);
double y = atan2(n(1), n(0));
double p = atan2(-n(2), n(0) * cos(y) + n(1) * sin(y));
double r = atan2(a(0) * sin(y) - a(1) * cos(y), -o(0) * sin(y) + o(1) * cos(y));
return r / M_PI * 180.0;
}
};
/* #endregion Define the states for convenience in initialization and copying ---------------------------------------*/
/* #region Utility for propagation and interpolation matrices, elementary jacobians dXt/dXk, J_r, H_r, Hprime_r.. ---*/
class GPMixer
{
private:
// Knot length
double dt = 0.0;
// identity matrix
const Mat3 Eye = Mat3::Identity();
// Covariance of angular jerk
Mat3 SigGa = Eye;
// Covariance of translational jerk
Mat3 SigNu = Eye;
public:
// Destructor
~GPMixer() {};
// Constructor
GPMixer(double dt_, const Mat3 SigGa_, const Mat3 SigNu_) : dt(dt_), SigGa(SigGa_), SigNu(SigNu_) {};
double getDt() const { return dt; }
Mat3 getSigGa() const { return SigGa; }
Mat3 getSigNu() const { return SigNu; }
template <typename MatrixType1, typename MatrixType2>
MatrixXd kron(const MatrixType1& A, const MatrixType2& B) const
{
MatrixXd result(A.rows() * B.rows(), A.cols() * B.cols());
for (int i = 0; i < A.rows(); ++i)
for (int j = 0; j < A.cols(); ++j)
result.block(i * B.rows(), j * B.cols(), B.rows(), B.cols()) = A(i, j) * B;
return result;
}
void setSigGa(const Mat3 &m)
{
SigGa = m;
}
void setSigNu(const Mat3 &m)
{
SigNu = m;
}
// Transition Matrix, PHI(tau, 0)
MatrixXd Fbase(const double dtau, int N) const
{
std::function<int(int)> factorial = [&factorial](int n) -> int {return (n <= 1) ? 1 : n * factorial(n - 1);};
MatrixXd Phi = MatrixXd::Identity(N, N);
for(int n = 0; n < N; n++)
for(int m = n + 1; m < N; m++)
Phi(n, m) = pow(dtau, m-n)/factorial(m-n);
return Phi;
}
// Gaussian Process covariance, Q = \int{Phi*F*SigNu*F'*Phi'}
MatrixXd Qbase(const double dtau, int N) const
{
std::function<int(int)> factorial = [&factorial](int n) -> int {return (n <= 1) ? 1 : n * factorial(n - 1);};
MatrixXd Q(N, N);
for(int n = 0; n < N; n++)
for(int m = 0; m < N; m++)
Q(n, m) = pow(dtau, 2*N-1-n-m)/double(2*N-1-n-m)/double(factorial(N-1-n))/double(factorial(N-1-m));
// cout << "MyQ: " << Q << endl;
return Q;
}
MatrixXd Qga(const double s, int N) const
{
double dtau = s*dt;
std::function<int(int)> factorial = [&factorial](int n) -> int {return (n <= 1) ? 1 : n * factorial(n - 1);};
MatrixXd Q(N, N);
for(int n = 0; n < N; n++)
for(int m = 0; m < N; m++)
Q(n, m) = pow(dtau, 2*N-1-n-m)/double(2*N-1-n-m)/double(factorial(N-1-n))/double(factorial(N-1-m));
return kron(Qbase(dt, 3), SigGa);
}
MatrixXd Qnu(const double s, int N) const
{
double dtau = s*dt;
std::function<int(int)> factorial = [&factorial](int n) -> int {return (n <= 1) ? 1 : n * factorial(n - 1);};
MatrixXd Q(N, N);
for(int n = 0; n < N; n++)
for(int m = 0; m < N; m++)
Q(n, m) = pow(dtau, 2*N-1-n-m)/double(2*N-1-n-m)/double(factorial(N-1-n))/double(factorial(N-1-m));
return kron(Qbase(dt, 3), SigNu);
}
Matrix<double, STATE_DIM, STATE_DIM> PropagateFullCov(Matrix<double, STATE_DIM, STATE_DIM> P0) const
{
Matrix<double, STATE_DIM, STATE_DIM> F; F.setZero();
Matrix<double, STATE_DIM, STATE_DIM> Q; Q.setZero();
F.block<9, 9>(0, 0) = kron(Fbase(dt, 3), Eye);
F.block<9, 9>(9, 9) = kron(Fbase(dt, 3), Eye);
Q.block<9, 9>(0, 0) = kron(Qbase(dt, 3), SigGa);
Q.block<9, 9>(9, 9) = kron(Qbase(dt, 3), SigNu);
return F*P0*F.transpose() + Q;
}
MatrixXd PSI(const double dtau, const Mat3 &Q) const
{
if (dtau < 1e-4)
return kron(MatrixXd::Zero(3, 3), Eye);
MatrixXd Phidtaubar = kron(Fbase(dt - dtau, 3), Eye);
MatrixXd Qdtau = kron(Qbase(dtau, 3), Q);
MatrixXd Qdt = kron(Qbase(dt, 3), Q);
return Qdtau*Phidtaubar.transpose()*Qdt.inverse();
}
MatrixXd PSI_ROS(const double dtau) const
{
return PSI(dtau, SigGa);
}
MatrixXd PSI_PVA(const double dtau) const
{
return PSI(dtau, SigNu);
}
MatrixXd LAMDA(const double dtau, const Mat3 &Q) const
{
MatrixXd PSIdtau = PSI(dtau, Q);
MatrixXd Fdtau = kron(Fbase(dtau, 3), Eye);
MatrixXd Fdt = kron(Fbase(dt, 3), Eye);
return Fdtau - PSIdtau*Fdt;
}
MatrixXd LAMDA_ROS(const double dtau) const
{
return LAMDA(dtau, SigGa);
}
MatrixXd LAMDA_PVA(const double dtau) const
{
return LAMDA(dtau, SigNu);
}
template <class T = double>
static Eigen::Matrix<T, 3, 3> Jr(const Eigen::Matrix<T, 3, 1> &phi)
{
if (phi.norm() < 1e-4)
return Eigen::Matrix<T, 3, 3>::Identity() - Sophus::SO3<T>::hat(phi);
Eigen::Matrix<T, 3, 3> Jr;
Sophus::rightJacobianSO3(phi, Jr);
return Jr;
}
template <class T = double>
static Eigen::Matrix<T, 3, 3> JrInv(const Eigen::Matrix<T, 3, 1> &phi)
{
if (phi.norm() < 1e-4)
return Eigen::Matrix<T, 3, 3>::Identity() + Sophus::SO3<T>::hat(phi);
Eigen::Matrix<T, 3, 3> JrInv;
Sophus::rightJacobianInvSO3(phi, JrInv);
return JrInv;
}
template <class T = double>
void MapParamToState(T const *const *parameters, int base, GPState<T> &X) const
{
X.R = Eigen::Map<Sophus::SO3<T> const>(parameters[base + 0]);
X.O = Eigen::Map<Eigen::Matrix<T, 3, 1> const>(parameters[base + 1]);
X.S = Eigen::Map<Eigen::Matrix<T, 3, 1> const>(parameters[base + 2]);
X.P = Eigen::Map<Eigen::Matrix<T, 3, 1> const>(parameters[base + 3]);
X.V = Eigen::Map<Eigen::Matrix<T, 3, 1> const>(parameters[base + 4]);
X.A = Eigen::Map<Eigen::Matrix<T, 3, 1> const>(parameters[base + 5]);
}
template <class T = double>
Eigen::Matrix<T, 3, 3> Fu(const Eigen::Matrix<T, 3, 1> &U, const Eigen::Matrix<T, 3, 1> &V) const
{
// Extract the elements of input
T ux = U(0); T uy = U(1); T uz = U(2);
T vx = V(0); T vy = V(1); T vz = V(2);
Eigen::Matrix<T, 3, 3> Fu_;
Fu_ << uy*vy + uz*vz, ux*vy - 2.0*uy*vx, ux*vz - 2.0*uz*vx,
uy*vx - 2.0*ux*vy, ux*vx + uz*vz, uy*vz - 2.0*uz*vy,
uz*vx - 2.0*ux*vz, uz*vy - 2.0*uy*vz, ux*vx + uy*vy;
return Fu_;
}
template <class T = double>
Eigen::Matrix<T, 3, 3> Fv(const Eigen::Matrix<T, 3, 1> &U, const Eigen::Matrix<T, 3, 1> &V) const
{
return Sophus::SO3<T>::hat(U)*Sophus::SO3<T>::hat(U);
}
template <class T = double>
Eigen::Matrix<T, 3, 3> Fuu(const Eigen::Matrix<T, 3, 1> &U, const Eigen::Matrix<T, 3, 1> &V, const Eigen::Matrix<T, 3, 1> &A) const
{
// Extract the elements of input
// T ux = U(0); T uy = U(1); T uz = U(2);
T vx = V(0); T vy = V(1); T vz = V(2);
T ax = A(0); T ay = A(1); T az = A(2);
Eigen::Matrix<T, 3, 3> Fuu_;
Fuu_ << ay*vy + az*vz, ax*vy - 2.0*ay*vx, ax*vz - 2.0*az*vx,
ay*vx - 2.0*ax*vy, ax*vx + az*vz, ay*vz - 2.0*az*vy,
az*vx - 2.0*ax*vz, az*vy - 2.0*ay*vz, ax*vx + ay*vy;
return Fuu_;
}
template <class T = double>
Eigen::Matrix<T, 3, 3> Fuv(const Eigen::Matrix<T, 3, 1> &U, const Eigen::Matrix<T, 3, 1> &V, const Eigen::Matrix<T, 3, 1> &A) const
{
// Extract the elements of input
T ux = U(0); T uy = U(1); T uz = U(2);
// T vx = V(0); T vy = V(1); T vz = V(2);
T ax = A(0); T ay = A(1); T az = A(2);
Eigen::Matrix<T, 3, 3> Fuv_;
Fuv_ << -2.0*ay*uy - 2.0*az*uz, ax*uy + ay*ux, ax*uz + az*ux,
ax*uy + ay*ux, -2.0*ax*ux - 2.0*az*uz, ay*uz + az*uy,
ax*uz + az*ux, ay*uz + az*uy, -2.0*ax*ux - 2.0*ay*uy;
return Fuv_;
}
template <class T = double>
Eigen::Matrix<T, 3, 3> DJrXV_DX(const Eigen::Matrix<T, 3, 1> &X, const Eigen::Matrix<T, 3, 1> &V) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
T Xn = X.norm();
if(Xn < 1e-4)
return 0.5*SO3T::hat(V);
T Xnp2 = Xn*Xn;
T Xnp3 = Xnp2*Xn;
T Xnp4 = Xnp3*Xn;
T sXn = sin(Xn);
// T sXnp2 = sXn*sXn;
T cXn = cos(Xn);
// T cXnp2 = cXn*cXn;
T gXn = (1.0 - cXn)/Xnp2;
T DgXn_DXn = sXn/Xnp2 - 2.0*(1.0 - cXn)/Xnp3;
T hXn = (Xn - sXn)/Xnp3;
T DhXn_DXn = (1.0 - cXn)/Xnp3 - 3.0*(Xn - sXn)/Xnp4;
Vec3T Xb = X/Xn;
Vec3T XsksqV = SO3T::hat(X)*SO3T::hat(X)*V;
Mat3T DXsksqV_DX = Fu<T>(X, V);
return SO3T::hat(V)*gXn + SO3T::hat(V)*X*DgXn_DXn*Xb.transpose() + DXsksqV_DX*hXn + XsksqV*DhXn_DXn*Xb.transpose();
}
template <class T = double>
Eigen::Matrix<T, 3, 3> DDJrXVA_DXDX(const Eigen::Matrix<T, 3, 1> &X, const Eigen::Matrix<T, 3, 1> &V, const Eigen::Matrix<T, 3, 1> &A) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
T Xn = X.norm();
if(Xn < 1e-4)
return Fuu(X, V, A)/6.0;
T Xnp2 = Xn*Xn;
T Xnp3 = Xnp2*Xn;
T Xnp4 = Xnp3*Xn;
T Xnp5 = Xnp4*Xn;
T sXn = sin(Xn);
// T sXnp2 = sXn*sXn;
T cXn = cos(Xn);
// T cXnp2 = cXn*cXn;
// T gXn = (1.0 - cXn)/Xnp2;
T DgXn_DXn = sXn/Xnp2 - 2.0*(1.0 - cXn)/Xnp3;
T DDgXn_DXnDXn = cXn/Xnp2 - 4.0*sXn/Xnp3 + 6.0*(1.0 - cXn)/Xnp4;
T hXn = (Xn - sXn)/Xnp3;
T DhXn_DXn = (1.0 - cXn)/Xnp3 - 3.0*(Xn - sXn)/Xnp4;
T DDhXn_DXnDXn = 6.0/Xnp4 + sXn/Xnp3 + 6.0*cXn/Xnp4 - 12.0*sXn/Xnp5;
Vec3T Xb = X/Xn;
Mat3T DXb_DX = 1.0/Xn*(Mat3T::Identity(3, 3) - Xb*Xb.transpose());
Vec3T XsksqV = SO3T::hat(X)*SO3T::hat(X)*V;
Mat3T DXsksqV_DX = Fu(X, V);
Mat3T DDXsksqVA_DXDX = Fuu(X, V, A);
Mat3T Vsk = SO3T::hat(V);
T AtpXb = A.transpose()*Xb;
Eigen::Matrix<T, 1, 3> AtpDXb = A.transpose()*DXb_DX;
return Vsk*A*DgXn_DXn*Xb.transpose()
+ Vsk*AtpXb*DgXn_DXn
+ Vsk*X*AtpDXb*DgXn_DXn
+ Vsk*X*AtpXb*Xb.transpose()*DDgXn_DXnDXn
+ DDXsksqVA_DXDX*hXn
+ DXsksqV_DX*A*Xb.transpose()*DhXn_DXn
+ DXsksqV_DX*AtpXb*DhXn_DXn
+ XsksqV*AtpDXb*DhXn_DXn
+ XsksqV*AtpXb*Xb.transpose()*DDhXn_DXnDXn;
}
template <class T = double>
Eigen::Matrix<T, 3, 3> DDJrXVA_DXDV(const Eigen::Matrix<T, 3, 1> &X, const Eigen::Matrix<T, 3, 1> &V, const Eigen::Matrix<T, 3, 1> &A) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
T Xn = X.norm();
if(Xn < 1e-4)
return -0.5*SO3T::hat(A);
T Xnp2 = Xn*Xn;
T Xnp3 = Xnp2*Xn;
T Xnp4 = Xnp3*Xn;
// T Xnp5 = Xnp4*Xn;
T sXn = sin(Xn);
// T sXnp2 = sXn*sXn;
T cXn = cos(Xn);
// T cXnp2 = cXn*cXn;
T gXn = (1.0 - cXn)/Xnp2;
T DgXn_DXn = sXn/Xnp2 - 2.0*(1.0 - cXn)/Xnp3;
// T DDgXn_DXnDXn = cXn/Xnp2 - 4.0*sXn/Xnp3 + 6.0*(1.0 - cXn)/Xnp4;
T hXn = (Xn - sXn)/Xnp3;
T DhXn_DXn = (1.0 - cXn)/Xnp3 - 3.0*(Xn - sXn)/Xnp4;
// T DDhXn_DXnDXn = 6.0/Xnp4 + sXn/Xnp3 + 6.0*cXn/Xnp4 - 12*sXn/Xnp5;
Vec3T Xb = X/Xn;
// Mat3T DXb_DX = 1.0/Xn*(Mat3T::Identity(3, 3) - Xb*Xb.transpose());
Mat3T DXsksqV_DV = Fv(X, V);
Mat3T DDXsksqVA_DXDV = Fuv(X, V, A);
T AtpXb = A.transpose()*Xb;
return -SO3T::hat(A)*gXn - SO3T::hat(X)*DgXn_DXn*AtpXb + DDXsksqVA_DXDV*hXn + DXsksqV_DV*DhXn_DXn*AtpXb;
}
template <class T = double>
Eigen::Matrix<T, 3, 3> DJrInvXV_DX(const Eigen::Matrix<T, 3, 1> &X, const Eigen::Matrix<T, 3, 1> &V) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
T Xn = X.norm();
if(Xn < 1e-4)
return -0.5*SO3T::hat(V);
T Xnp2 = Xn*Xn;
T Xnp3 = Xnp2*Xn;
T sXn = sin(Xn);
T sXnp2 = sXn*sXn;
T cXn = cos(Xn);
// T cXnp2 = cXn*cXn;
T gXn = (1.0/Xnp2 - (1.0 + cXn)/(2.0*Xn*sXn));
T DgXn_DXn = -2.0/Xnp3 + (Xn*sXnp2 + (sXn + Xn*cXn)*(1.0 + cXn))/(2.0*Xnp2*sXnp2);
Vec3T Xb = X/Xn;
Vec3T XsksqV = SO3T::hat(X)*SO3T::hat(X)*V;
Mat3T DXsksqV_DX = Fu(X, V);
return -0.5*SO3T::hat(V) + DXsksqV_DX*gXn + XsksqV*DgXn_DXn*Xb.transpose();
}
template <class T = double>
Eigen::Matrix<T, 3, 3> DDJrInvXVA_DXDX(const Eigen::Matrix<T, 3, 1> &X, const Eigen::Matrix<T, 3, 1> &V, const Eigen::Matrix<T, 3, 1> &A) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
T Xn = X.norm();
if(Xn < 1e-4)
return Fuu(X, V, A)/12.0;
T Xnp2 = Xn*Xn;
T Xnp3 = Xnp2*Xn;
T Xnp4 = Xnp3*Xn;
// T Xnp5 = Xnp4*Xn;
T sXn = sin(Xn);
T sXnp2 = sXn*sXn;
// T s2Xn = sin(2.0*Xn);
T cXn = cos(Xn);
// T cXnp2 = cXn*cXn;
T c2Xn = cos(2.0*Xn);
T gXn = 1.0/Xnp2 - (1.0 + cXn)/(2.0*Xn*sXn);
T DgXn_DXn = -2.0/Xnp3 + (sXn + Xn)*(1.0 + cXn)/(2.0*Xnp2*sXnp2);
// T DDgXn_DXnDXn = 6.0/Xnp4 + (1.0 - c2Xn + Xnp2*cXn + 2.0*Xn*sXn + Xnp2)/(Xnp3*2.0*sXn*(cXn - 1.0));
T DDgXn_DXnDXn = 6.0/Xnp4 + sXn/(Xnp3*(cXn - 1.0)) + (Xn*cXn + 2.0*sXn + Xn)/(2.0*Xnp2*sXn*(cXn - 1.0));
Vec3T Xb = X/Xn;
Mat3T DXb_DX = 1.0/Xn*(Mat3T::Identity(3, 3) - Xb*Xb.transpose());
Vec3T XsksqV = SO3T::hat(X)*SO3T::hat(X)*V;
Mat3T DXsksqV_DX = Fu(X, V);
Mat3T DDXsksqVA_DXDX = Fuu(X, V, A);
// Mat3T Vsk = SO3T::hat(V);
T AtpXb = A.transpose()*Xb;
Eigen::Matrix<T, 1, 3> AtpDXb = A.transpose()*DXb_DX;
return DDXsksqVA_DXDX*gXn
+ DXsksqV_DX*A*Xb.transpose()*DgXn_DXn
+ DXsksqV_DX*AtpXb*DgXn_DXn
+ XsksqV*AtpDXb*DgXn_DXn
+ XsksqV*AtpXb*Xb.transpose()*DDgXn_DXnDXn;
}
template <class T = double>
Eigen::Matrix<T, 3, 3> DDJrInvXVA_DXDV(const Eigen::Matrix<T, 3, 1> &X, const Eigen::Matrix<T, 3, 1> &V, const Eigen::Matrix<T, 3, 1> &A) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
T Xn = X.norm();
if(Xn < 1e-4)
return 0.5*SO3T::hat(A);
T Xnp2 = Xn*Xn;
T Xnp3 = Xnp2*Xn;
// T Xnp4 = Xnp3*Xn;
// T Xnp5 = Xnp4*Xn;
T sXn = sin(Xn);
T sXnp2 = sXn*sXn;
// T s2Xn = sin(2*Xn);
T cXn = cos(Xn);
// T cXnp2 = cXn*cXn;
// T c2Xn = cos(2*Xn);
T gXn = (1.0/Xnp2 - (1.0 + cXn)/(2.0*Xn*sXn));
T DgXn_DXn = -2.0/Xnp3 + (Xn*sXnp2 + (sXn + Xn*cXn)*(1.0 + cXn))/(2.0*Xnp2*sXnp2);
// T DDgXn_DXnDXn = (Xn + 6.0*s2Xn - 12.0*sXn - Xn*c2Xn + Xnp3*cXn + 2.0*Xnp2*sXn + Xnp3)/(Xnp4*(s2Xn - 2.0*sXn));
Vec3T Xb = X/Xn;
// Mat3T DXb_DX = 1.0/Xn*(Mat3T::Identity(3, 3) - Xb*Xb.transpose());
Mat3T DXsksqV_DV = Fv(X, V);
// Mat3T DXsksqV_DX = Fu(X, V);
Mat3T DDXsksqVA_DXDV = Fuv(X, V, A);
T AtpXb = A.transpose()*Xb;
return 0.5*SO3T::hat(A) + DDXsksqVA_DXDV*gXn + DXsksqV_DV*DgXn_DXn*AtpXb;
}
template <class T = double>
void ComputeXtAndJacobians(const GPState<T> &Xa,
const GPState<T> &Xb,
GPState<T> &Xt,
vector<vector<Eigen::Matrix<T, 3, 3>>> &DXt_DXa,
vector<vector<Eigen::Matrix<T, 3, 3>>> &DXt_DXb,
Eigen::Matrix<T, 9, 1> &gammaa_,
Eigen::Matrix<T, 9, 1> &gammab_,
Eigen::Matrix<T, 9, 1> &gammat_,
bool debug = false
) const
{
using SO3T = Sophus::SO3<T>;
using Vec3T = Eigen::Matrix<T, 3, 1>;
using Vec6T = Eigen::Matrix<T, 6, 1>;
using Vec9T = Eigen::Matrix<T, 9, 1>;
using Mat3T = Eigen::Matrix<T, 3, 3>;
// Map the variables of the state
double tau = Xt.t;
SO3T &Rt = Xt.R;
Vec3T &Ot = Xt.O;
Vec3T &St = Xt.S;
Vec3T &Pt = Xt.P;
Vec3T &Vt = Xt.V;
Vec3T &At = Xt.A;
// Calculate the the mixer matrixes
Matrix<T, Dynamic, Dynamic> LAM_ROSt = LAMDA(tau, SigGa).cast<T>();
Matrix<T, Dynamic, Dynamic> PSI_ROSt = PSI(tau, SigGa).cast<T>();
Matrix<T, Dynamic, Dynamic> LAM_PVAt = LAMDA(tau, SigNu).cast<T>();
Matrix<T, Dynamic, Dynamic> PSI_PVAt = PSI(tau, SigNu).cast<T>();
// Find the relative rotation
SO3T Rab = Xa.R.inverse()*Xb.R;
// Calculate the SO3 knots in relative form
Vec3T Thead0 = Vec3T::Zero();
Vec3T Thead1 = Xa.O;
Vec3T Thead2 = Xa.S;
Vec3T Theb = Rab.log();
Mat3T JrInvTheb = JrInv(Theb);
Mat3T HpTheb_ThebOb = DJrInvXV_DX(Theb, Xb.O);
Vec3T Thebd0 = Theb;
Vec3T Thebd1 = JrInvTheb*Xb.O;
Vec3T Thebd2 = JrInvTheb*Xb.S + HpTheb_ThebOb*Thebd1;
// Put them in vector form
Vec9T gammaa; gammaa << Thead0, Thead1, Thead2;
Vec9T gammab; gammab << Thebd0, Thebd1, Thebd2;
// Calculate the knot euclid states and put them in vector form
Vec9T pvaa; pvaa << Xa.P, Xa.V, Xa.A;
Vec9T pvab; pvab << Xb.P, Xb.V, Xb.A;
// Mix the knots to get the interpolated states
Vec9T gammat = LAM_ROSt*gammaa + PSI_ROSt*gammab;
Vec9T pvat = LAM_PVAt*pvaa + PSI_PVAt*pvab;
// Retrive the interpolated SO3 in relative form
Vec3T Thetd0 = gammat.block(0, 0, 3, 1);
Vec3T Thetd1 = gammat.block(3, 0, 3, 1);
Vec3T Thetd2 = gammat.block(6, 0, 3, 1);
Mat3T JrThet = Jr(Thetd0);
SO3T ExpThet = SO3T::exp(Thetd0);
Mat3T HThet_ThetThetd1 = DJrXV_DX(Thetd0, Thetd1);
// Assign the interpolated state
Rt = Xa.R*ExpThet;
Ot = JrThet*Thetd1;
St = JrThet*Thetd2 + HThet_ThetThetd1*Thetd1;
Pt = pvat.block(0, 0, 3, 1);
Vt = pvat.block(3, 0, 3, 1);
At = pvat.block(6, 0, 3, 1);
// Calculate the Jacobian
DXt_DXa = vector<vector<Mat3T>>(6, vector<Mat3T>(6, Mat3T::Zero()));
DXt_DXb = vector<vector<Mat3T>>(6, vector<Mat3T>(6, Mat3T::Zero()));
// Local index for the states in the state vector
const int RIDX = 0;
const int OIDX = 1;
const int SIDX = 2;
const int PIDX = 3;
const int VIDX = 4;
const int AIDX = 5;
// Some reusable matrices
SO3T ExpThetInv = ExpThet.inverse();
Mat3T HpTheb_ThebSb = DJrInvXV_DX(Theb, Xb.S);
Mat3T LpThebTheb_ThebObThebd1 = DDJrInvXVA_DXDX(Theb, Xb.O, Thebd1);
Mat3T LpThebOb_ThebObThebd1 = DDJrInvXVA_DXDV(Theb, Xb.O, Thebd1);
Mat3T HThet_ThetThetd2 = DJrXV_DX(Thetd0, Thetd2);
Mat3T LThetThet_ThetThetd1Thetd1 = DDJrXVA_DXDX(Thetd0, Thetd1, Thetd1);
Mat3T LThetThetd1_ThetThetd1Thetd1 = DDJrXVA_DXDV(Thetd0, Thetd1, Thetd1);
// Jacobians from L1 to L0
Mat3T JThead1Oa = Mat3T::Identity(); Mat3T JThead2Sa = Mat3T::Identity();
Mat3T JThebd0Ra = -JrInvTheb*Rab.inverse().matrix();
Mat3T &JThebd0Rb = JrInvTheb;
Mat3T JThebd1Ra = HpTheb_ThebOb*JThebd0Ra;
Mat3T JThebd1Rb = HpTheb_ThebOb*JThebd0Rb;
Mat3T &JThebd1Ob = JrInvTheb;
Mat3T JThebd2Ra = HpTheb_ThebSb*JThebd0Ra + HpTheb_ThebOb*JThebd1Ra + LpThebTheb_ThebObThebd1*JThebd0Ra;
Mat3T JThebd2Rb = HpTheb_ThebSb*JThebd0Rb + HpTheb_ThebOb*JThebd1Rb + LpThebTheb_ThebObThebd1*JThebd0Rb;
Mat3T JThebd2Ob = LpThebOb_ThebObThebd1 + HpTheb_ThebOb*JThebd1Ob;
Mat3T &JThebd2Sb = JrInvTheb;
// Jacobians from L2 to L1
Mat3T JThetd0Thead0 = LAM_ROSt.block(0, 0, 3, 3); Mat3T JThetd0Thead1 = LAM_ROSt.block(0, 3, 3, 3); Mat3T JThetd0Thead2 = LAM_ROSt.block(0, 6, 3, 3);
Mat3T JThetd1Thead0 = LAM_ROSt.block(3, 0, 3, 3); Mat3T JThetd1Thead1 = LAM_ROSt.block(3, 3, 3, 3); Mat3T JThetd1Thead2 = LAM_ROSt.block(3, 6, 3, 3);
Mat3T JThetd2Thead0 = LAM_ROSt.block(6, 0, 3, 3); Mat3T JThetd2Thead1 = LAM_ROSt.block(6, 3, 3, 3); Mat3T JThetd2Thead2 = LAM_ROSt.block(6, 6, 3, 3);
Mat3T JThetd0Thebd0 = PSI_ROSt.block(0, 0, 3, 3); Mat3T JThetd0Thebd1 = PSI_ROSt.block(0, 3, 3, 3); Mat3T JThetd0Thebd2 = PSI_ROSt.block(0, 6, 3, 3);
Mat3T JThetd1Thebd0 = PSI_ROSt.block(3, 0, 3, 3); Mat3T JThetd1Thebd1 = PSI_ROSt.block(3, 3, 3, 3); Mat3T JThetd1Thebd2 = PSI_ROSt.block(3, 6, 3, 3);
Mat3T JThetd2Thebd0 = PSI_ROSt.block(6, 0, 3, 3); Mat3T JThetd2Thebd1 = PSI_ROSt.block(6, 3, 3, 3); Mat3T JThetd2Thebd2 = PSI_ROSt.block(6, 6, 3, 3);
// Jacobians from L2 to L0
Mat3T JThetd0Ra = JThetd0Thebd0*JThebd0Ra + JThetd0Thebd1*JThebd1Ra + JThetd0Thebd2*JThebd2Ra;
Mat3T JThetd0Rb = JThetd0Thebd0*JThebd0Rb + JThetd0Thebd1*JThebd1Rb + JThetd0Thebd2*JThebd2Rb;
Mat3T JThetd0Oa = JThetd0Thead1*JThead1Oa;
Mat3T JThetd0Ob = JThetd0Thebd1*JThebd1Ob + JThetd0Thebd2*JThebd2Ob;
Mat3T JThetd0Sa = JThetd0Thead2*JThead2Sa;
Mat3T JThetd0Sb = JThetd0Thebd2*JThebd2Sb;
Mat3T JThetd1Ra = JThetd1Thebd0*JThebd0Ra + JThetd1Thebd1*JThebd1Ra + JThetd1Thebd2*JThebd2Ra;
Mat3T JThetd1Rb = JThetd1Thebd0*JThebd0Rb + JThetd1Thebd1*JThebd1Rb + JThetd1Thebd2*JThebd2Rb;
Mat3T JThetd1Oa = JThetd1Thead1*JThead1Oa;
Mat3T JThetd1Ob = JThetd1Thebd1*JThebd1Ob + JThetd1Thebd2*JThebd2Ob;
Mat3T JThetd1Sa = JThetd1Thead2*JThead2Sa;
Mat3T JThetd1Sb = JThetd1Thebd2*JThebd2Sb;
Mat3T JThetd2Ra = JThetd2Thebd0*JThebd0Ra + JThetd2Thebd1*JThebd1Ra + JThetd2Thebd2*JThebd2Ra;
Mat3T JThetd2Rb = JThetd2Thebd0*JThebd0Rb + JThetd2Thebd1*JThebd1Rb + JThetd2Thebd2*JThebd2Rb;
Mat3T JThetd2Oa = JThetd2Thead1*JThead1Oa;
Mat3T JThetd2Ob = JThetd2Thebd1*JThebd1Ob + JThetd2Thebd2*JThebd2Ob;
Mat3T JThetd2Sa = JThetd2Thead2*JThead2Sa;
Mat3T JThetd2Sb = JThetd2Thebd2*JThebd2Sb;
// Jacobians from L3 to L2
Mat3T &JRtThetd0 = JrThet;
Mat3T &JOtThetd0 = HThet_ThetThetd1;
Mat3T &JOtThetd1 = JrThet;
Mat3T JStThetd0 = HThet_ThetThetd2 + LThetThet_ThetThetd1Thetd1;
Mat3T JStThetd1 = LThetThetd1_ThetThetd1Thetd1 + HThet_ThetThetd1;
Mat3T &JStThetd2 = JrThet;
// DRt_DRa
DXt_DXa[RIDX][RIDX] = ExpThetInv.matrix() + JRtThetd0*JThetd0Ra;
// DRt_DOa
DXt_DXa[RIDX][OIDX] = JRtThetd0*JThetd0Oa;
// DRt_DSa
DXt_DXa[RIDX][SIDX] = JRtThetd0*JThetd0Sa;
// DRt_DPa DRt_DVa DRt_DAa are all zeros
// DOt_Ra
DXt_DXa[OIDX][RIDX] = JOtThetd0*JThetd0Ra + JOtThetd1*JThetd1Ra;
// DOt_Oa
DXt_DXa[OIDX][OIDX] = JOtThetd0*JThetd0Oa + JOtThetd1*JThetd1Oa;
// DOt_Sa
DXt_DXa[OIDX][SIDX] = JOtThetd0*JThetd0Sa + JOtThetd1*JThetd1Sa;
// DOt_DPa DOt_DVa DOt_DAa are all zeros
// DSt_Ra
DXt_DXa[SIDX][RIDX] = JStThetd0*JThetd0Ra + JStThetd1*JThetd1Ra + JStThetd2*JThetd2Ra;
// DSt_Oa
DXt_DXa[SIDX][OIDX] = JStThetd0*JThetd0Oa + JStThetd1*JThetd1Oa + JStThetd2*JThetd2Oa;
// DSt_Sa
DXt_DXa[SIDX][SIDX] = JStThetd0*JThetd0Sa + JStThetd1*JThetd1Sa + JStThetd2*JThetd2Sa;
// DSt_DPa DSt_DVa DSt_DAa are all zeros
// DRt_DRb
DXt_DXb[RIDX][RIDX] = JRtThetd0*JThetd0Rb;
// DRt_DOb
DXt_DXb[RIDX][OIDX] = JRtThetd0*JThetd0Ob;
// DRt_DSb
DXt_DXb[RIDX][SIDX] = JRtThetd0*JThetd0Sb;
// DRt_DPb DRt_DVb DRt_DAb are all zeros
// DOt_Rb
DXt_DXb[OIDX][RIDX] = JOtThetd0*JThetd0Rb + JOtThetd1*JThetd1Rb;
// DOt_Ob
DXt_DXb[OIDX][OIDX] = JOtThetd0*JThetd0Ob + JOtThetd1*JThetd1Ob;
// DOt_Sb
DXt_DXb[OIDX][SIDX] = JOtThetd0*JThetd0Sb + JOtThetd1*JThetd1Sb;
// DOt_DPb DOt_DVb DOt_DAb are all zeros
// DSt_Rb
DXt_DXb[SIDX][RIDX] = JStThetd0*JThetd0Rb + JStThetd1*JThetd1Rb + JStThetd2*JThetd2Rb;
// DSt_Ob
DXt_DXb[SIDX][OIDX] = JStThetd0*JThetd0Ob + JStThetd1*JThetd1Ob + JStThetd2*JThetd2Ob;
// DSt_Sb
DXt_DXb[SIDX][SIDX] = JStThetd0*JThetd0Sb + JStThetd1*JThetd1Sb + JStThetd2*JThetd2Sb;
// DSt_DPb DSt_DVb DSt_DAb are all zeros
// Extract the blocks of R3 states
Mat3T LAM_PVA11 = LAM_PVAt.block(0, 0, 3, 3); Mat3T LAM_PVA12 = LAM_PVAt.block(0, 3, 3, 3); Mat3T LAM_PVA13 = LAM_PVAt.block(0, 6, 3, 3);
Mat3T LAM_PVA21 = LAM_PVAt.block(3, 0, 3, 3); Mat3T LAM_PVA22 = LAM_PVAt.block(3, 3, 3, 3); Mat3T LAM_PVA23 = LAM_PVAt.block(3, 6, 3, 3);
Mat3T LAM_PVA31 = LAM_PVAt.block(6, 0, 3, 3); Mat3T LAM_PVA32 = LAM_PVAt.block(6, 3, 3, 3); Mat3T LAM_PVA33 = LAM_PVAt.block(6, 6, 3, 3);
Mat3T PSI_PVA11 = PSI_PVAt.block(0, 0, 3, 3); Mat3T PSI_PVA12 = PSI_PVAt.block(0, 3, 3, 3); Mat3T PSI_PVA13 = PSI_PVAt.block(0, 6, 3, 3);
Mat3T PSI_PVA21 = PSI_PVAt.block(3, 0, 3, 3); Mat3T PSI_PVA22 = PSI_PVAt.block(3, 3, 3, 3); Mat3T PSI_PVA23 = PSI_PVAt.block(3, 6, 3, 3);
Mat3T PSI_PVA31 = PSI_PVAt.block(6, 0, 3, 3); Mat3T PSI_PVA32 = PSI_PVAt.block(6, 3, 3, 3); Mat3T PSI_PVA33 = PSI_PVAt.block(6, 6, 3, 3);
// DPt_DPa
DXt_DXa[PIDX][PIDX] = LAM_PVA11;
// DPt_DVa
DXt_DXa[PIDX][VIDX] = LAM_PVA12;
// DPt_DAa
DXt_DXa[PIDX][AIDX] = LAM_PVA13;
// DVt_DPa
DXt_DXa[VIDX][PIDX] = LAM_PVA21;
// DVt_DVa
DXt_DXa[VIDX][VIDX] = LAM_PVA22;
// DVt_DAa
DXt_DXa[VIDX][AIDX] = LAM_PVA23;
// DAt_DPa
DXt_DXa[AIDX][PIDX] = LAM_PVA31;
// DAt_DVa
DXt_DXa[AIDX][VIDX] = LAM_PVA32;
// DAt_DAa
DXt_DXa[AIDX][AIDX] = LAM_PVA33;
// DPt_DPb
DXt_DXb[PIDX][PIDX] = PSI_PVA11;
// DRt_DPb
DXt_DXb[PIDX][VIDX] = PSI_PVA12;
// DRt_DAb
DXt_DXb[PIDX][AIDX] = PSI_PVA13;
// DVt_DPb
DXt_DXb[VIDX][PIDX] = PSI_PVA21;
// DVt_DVb
DXt_DXb[VIDX][VIDX] = PSI_PVA22;
// DVt_DAb
DXt_DXb[VIDX][AIDX] = PSI_PVA23;
// DAt_DPb
DXt_DXb[AIDX][PIDX] = PSI_PVA31;
// DAt_DVb
DXt_DXb[AIDX][VIDX] = PSI_PVA32;
// DAt_DAb
DXt_DXb[AIDX][AIDX] = PSI_PVA33;
gammaa_ = gammaa;
gammab_ = gammab;
gammat_ = gammat;
}
GPMixer &operator=(const GPMixer &other)
{
this->dt = other.dt;
this->SigGa = other.SigGa;
this->SigNu = other.SigNu;
}
};
// Define the shared pointer
typedef std::shared_ptr<GPMixer> GPMixerPtr;
/* #endregion Utility for propagation and interpolation matrices, elementary jacobians dXt/dXk, J_r, H_r, Hprime_r.. */
/* #region Managing control points: cration, extension, queries, ... ------------------------------------------------*/
class GaussianProcess
{
using CovM = Eigen::Matrix<double, STATE_DIM, STATE_DIM>;
private:
// The invalid covariance
const CovM CovMZero = CovM::Zero();
// Start time
double t0 = 0;
// Knot length
double dt = 0.0;
// Mixer
GPMixerPtr gpm;
// Set to true to maintain a covariance of each state
bool keepCov = false;
template <typename T>
using aligned_deque = std::deque<T, Eigen::aligned_allocator<T>>;
// Covariance
aligned_deque<CovM> C;
// State vector
aligned_deque<SO3d> R;
aligned_deque<Vec3> O;
aligned_deque<Vec3> S;
aligned_deque<Vec3> P;
aligned_deque<Vec3> V;
aligned_deque<Vec3> A;
public:
// Destructor
~GaussianProcess(){};
// Constructor
GaussianProcess(double dt_, Mat3 SigGa_, Mat3 SigNu_, bool keepCov_=false)
: dt(dt_), gpm(GPMixerPtr(new GPMixer(dt_, SigGa_, SigNu_))), keepCov(keepCov_) {};
Mat3 getSigGa() const { return gpm->getSigGa(); }
Mat3 getSigNu() const { return gpm->getSigNu(); }
bool getKeepCov() const {return keepCov;}
GPMixerPtr getGPMixerPtr()
{
return gpm;
}
double getMinTime() const
{
return t0;
}
double getMaxTime() const
{
return t0 + max(0, int(R.size()) - 1)*dt;
}
int getNumKnots() const
{
return int(R.size());
}
double getKnotTime(int kidx) const
{
return t0 + kidx*dt;
}
double getDt() const
{
return dt;
}
bool TimeInInterval(double t, double eps=0.0) const
{
return (t >= getMinTime() + eps && t < getMaxTime() - eps);
}
pair<int, double> computeTimeIndex(double t) const
{
int u = int((t - t0)/dt);
double s = double(t - t0)/dt - u;
return make_pair(u, s);
}
GPState<double> getStateAt(double t) const
{
// Find the index of the interval to find interpolation
auto us = computeTimeIndex(t);