multivariate_distribution_traits.hpp
Go to the documentation of this file.
1 // Copyright 2024 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BELUGA_RANDOM_MULTIVARIATE_DISTRIBUTION_TRAITS_HPP
16 #define BELUGA_RANDOM_MULTIVARIATE_DISTRIBUTION_TRAITS_HPP
17 
18 #include <Eigen/Core>
19 #include <sophus/se2.hpp>
20 #include <sophus/se3.hpp>
21 #include <sophus/so3.hpp>
22 
28 namespace beluga {
29 
31 template <class T, class Enable = void>
33 
35 template <class T>
36 struct multivariate_distribution_traits<T, std::enable_if_t<std::is_base_of_v<Eigen::EigenBase<T>, T>>> {
37  static_assert(T::ColsAtCompileTime == 1 || T::RowsAtCompileTime == 1, "T should be a column or row vector");
38 
40  static constexpr int matrix_size = T::ColsAtCompileTime > T::RowsAtCompileTime //
41  ? T::ColsAtCompileTime
42  : T::RowsAtCompileTime;
43 
45  using scalar_type = typename T::Scalar;
46 
48  using result_type = typename T::PlainMatrix;
49 
51  using vector_type = typename T::PlainMatrix;
52 
54  using covariance_type = typename Eigen::Matrix<scalar_type, matrix_size, matrix_size>;
55 
57  [[nodiscard]] static constexpr vector_type to_vector(const result_type& t) { return t; }
58 
60  [[nodiscard]] static constexpr result_type from_vector(const vector_type& v) { return v; }
61 };
62 
64 template <class T>
65 struct multivariate_distribution_traits<T, std::enable_if_t<std::is_base_of_v<Sophus::SO2Base<T>, T>>> {
67  using scalar_type = typename T::Scalar;
68 
71 
73  using vector_type = typename Eigen::Matrix<scalar_type, 1, 1>;
74 
76  using covariance_type = typename Eigen::Matrix<scalar_type, 1, 1>;
77 
79  [[nodiscard]] static constexpr vector_type to_vector(const result_type& t) { return vector_type{t.log()}; }
80 
82  [[nodiscard]] static constexpr result_type from_vector(const vector_type& v) {
83  return Sophus::SO2<scalar_type>::exp(v.x());
84  }
85 };
86 
88 template <class T>
89 struct multivariate_distribution_traits<T, std::enable_if_t<std::is_base_of_v<Sophus::SE2Base<T>, T>>> {
91  using scalar_type = typename T::Scalar;
92 
95 
97  using vector_type = typename Eigen::Matrix<scalar_type, 3, 1>;
98 
100  using covariance_type = typename Eigen::Matrix<scalar_type, 3, 3>;
101 
103  [[nodiscard]] static constexpr vector_type to_vector(const result_type& t) {
104  vector_type v;
105  v << t.translation(), t.so2().log();
106  return v;
107  }
108 
110  [[nodiscard]] static constexpr result_type from_vector(const vector_type& v) {
111  return {Sophus::SO2<scalar_type>::exp(v.z()), v.head(2)};
112  }
113 };
114 
116 template <class T>
117 struct multivariate_distribution_traits<T, std::enable_if_t<std::is_base_of_v<Sophus::SO3Base<T>, T>>> {
119  using scalar_type = typename T::Scalar;
120 
123 
125  using vector_type = typename Eigen::Matrix<scalar_type, 3, 1>;
126 
128  using covariance_type = typename Eigen::Matrix<scalar_type, 3, 3>;
129 
131  [[nodiscard]] static constexpr vector_type to_vector(const result_type& t) { return t.log(); }
132 
134  [[nodiscard]] static constexpr result_type from_vector(const vector_type& v) {
135  // Projecting a Gaussian through the exponential map is not exactly correct.
136  // Rotations in Lie groups don't have infinite support, making the term 'normal' distribution incorrect.
137  // This approach follows the SO2/SE2 method, facing similar issues in 3D.
138  // For small covariances, the resulting rotations in SO3 approximate a normal distribution.
140  }
141 };
142 
144 template <class T>
145 struct multivariate_distribution_traits<T, std::enable_if_t<std::is_base_of_v<Sophus::SE3Base<T>, T>>> {
147  using scalar_type = typename T::Scalar;
148 
151 
153  using vector_type = typename Eigen::Matrix<scalar_type, 6, 1>;
154 
156  using covariance_type = typename Eigen::Matrix<scalar_type, 6, 6>;
157 
159  [[nodiscard]] static constexpr vector_type to_vector(const result_type& t) {
160  vector_type v;
161  v << t.translation(), t.so3().log();
162  return v;
163  }
164 
166  [[nodiscard]] static constexpr result_type from_vector(const vector_type& v) {
167  // Projecting a Gaussian through the exponential map is not exactly correct.
168  // Rotations in Lie groups don't have infinite support, making the term 'normal' distribution incorrect.
169  // This approach follows the SO2/SE2 method, facing similar issues in 3D.
170  // For small covariances, the resulting rotations in SO3 approximate a normal distribution.
171  return result_type{Sophus::SO3<scalar_type>::exp(v.tail(3)), v.head(3)};
172  }
173 };
174 
175 } // namespace beluga
176 
177 #endif
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Eigen::EigenBase< T >, T > > >::scalar_type
typename T::Scalar scalar_type
The scalar type.
Definition: multivariate_distribution_traits.hpp:45
Sophus::SE3::so3
SOPHUS_FUNC SO3Member & so3()
Sophus::SO2
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO3Base< T >, T > > >::vector_type
typename Eigen::Matrix< scalar_type, 3, 1 > vector_type
The vector type.
Definition: multivariate_distribution_traits.hpp:125
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO2Base< T >, T > > >::vector_type
typename Eigen::Matrix< scalar_type, 1, 1 > vector_type
The vector type.
Definition: multivariate_distribution_traits.hpp:73
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE3Base< T >, T > > >::scalar_type
typename T::Scalar scalar_type
The scalar type.
Definition: multivariate_distribution_traits.hpp:147
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE3Base< T >, T > > >::from_vector
static constexpr result_type from_vector(const vector_type &v)
Convert from vector to result representation.
Definition: multivariate_distribution_traits.hpp:166
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO3Base< T >, T > > >::to_vector
static constexpr vector_type to_vector(const result_type &t)
Convert from result to vector representation.
Definition: multivariate_distribution_traits.hpp:131
Sophus::SO3
so3.hpp
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE2Base< T >, T > > >::vector_type
typename Eigen::Matrix< scalar_type, 3, 1 > vector_type
The vector type.
Definition: multivariate_distribution_traits.hpp:97
Sophus::SO3::exp
static SOPHUS_FUNC SO3< Scalar > exp(Tangent const &omega)
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Eigen::EigenBase< T >, T > > >::covariance_type
typename Eigen::Matrix< scalar_type, matrix_size, matrix_size > covariance_type
The covariance matrix type.
Definition: multivariate_distribution_traits.hpp:54
Sophus::SO2::exp
static SOPHUS_FUNC SO2< Scalar > exp(Tangent const &theta)
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE3Base< T >, T > > >::covariance_type
typename Eigen::Matrix< scalar_type, 6, 6 > covariance_type
The covariance matrix type.
Definition: multivariate_distribution_traits.hpp:156
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Eigen::EigenBase< T >, T > > >::result_type
typename T::PlainMatrix result_type
The result type representation.
Definition: multivariate_distribution_traits.hpp:48
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE2Base< T >, T > > >::covariance_type
typename Eigen::Matrix< scalar_type, 3, 3 > covariance_type
The covariance matrix type.
Definition: multivariate_distribution_traits.hpp:100
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Eigen::EigenBase< T >, T > > >::from_vector
static constexpr result_type from_vector(const vector_type &v)
Convert from vector to result representation.
Definition: multivariate_distribution_traits.hpp:60
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO3Base< T >, T > > >::from_vector
static constexpr result_type from_vector(const vector_type &v)
Convert from vector to result representation.
Definition: multivariate_distribution_traits.hpp:134
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE2Base< T >, T > > >::scalar_type
typename T::Scalar scalar_type
The scalar type.
Definition: multivariate_distribution_traits.hpp:91
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO2Base< T >, T > > >::to_vector
static constexpr vector_type to_vector(const result_type &t)
Convert from result to vector representation.
Definition: multivariate_distribution_traits.hpp:79
Sophus::SE2::so2
SOPHUS_FUNC SO2Member & so2()
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE2Base< T >, T > > >::to_vector
static constexpr vector_type to_vector(const result_type &t)
Convert from result to vector representation.
Definition: multivariate_distribution_traits.hpp:103
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO3Base< T >, T > > >::covariance_type
typename Eigen::Matrix< scalar_type, 3, 3 > covariance_type
The covariance matrix type.
Definition: multivariate_distribution_traits.hpp:128
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO3Base< T >, T > > >::scalar_type
typename T::Scalar scalar_type
The scalar type.
Definition: multivariate_distribution_traits.hpp:119
se2.hpp
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE3Base< T >, T > > >::vector_type
typename Eigen::Matrix< scalar_type, 6, 1 > vector_type
The vector type.
Definition: multivariate_distribution_traits.hpp:153
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO2Base< T >, T > > >::scalar_type
typename T::Scalar scalar_type
The scalar type.
Definition: multivariate_distribution_traits.hpp:67
Sophus::SE2
Sophus::SE3::translation
SOPHUS_FUNC TranslationMember & translation()
Sophus::SE3
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO2Base< T >, T > > >::covariance_type
typename Eigen::Matrix< scalar_type, 1, 1 > covariance_type
The covariance matrix type.
Definition: multivariate_distribution_traits.hpp:76
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Eigen::EigenBase< T >, T > > >::to_vector
static constexpr vector_type to_vector(const result_type &t)
Convert from result to vector representation.
Definition: multivariate_distribution_traits.hpp:57
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SO2Base< T >, T > > >::from_vector
static constexpr result_type from_vector(const vector_type &v)
Convert from vector to result representation.
Definition: multivariate_distribution_traits.hpp:82
std
Definition: circular_array.hpp:529
Sophus::SE2::translation
SOPHUS_FUNC TranslationMember & translation()
beluga::multivariate_distribution_traits
Forward declaration of the multivariate_distribution_traits class template.
Definition: multivariate_distribution_traits.hpp:32
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE2Base< T >, T > > >::from_vector
static constexpr result_type from_vector(const vector_type &v)
Convert from vector to result representation.
Definition: multivariate_distribution_traits.hpp:110
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Sophus::SE3Base< T >, T > > >::to_vector
static constexpr vector_type to_vector(const result_type &t)
Convert from result to vector representation.
Definition: multivariate_distribution_traits.hpp:159
beluga::multivariate_distribution_traits< T, std::enable_if_t< std::is_base_of_v< Eigen::EigenBase< T >, T > > >::vector_type
typename T::PlainMatrix vector_type
The vector type.
Definition: multivariate_distribution_traits.hpp:51
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21
se3.hpp


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53