nd.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, the mcl_3dl authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef MCL_3DL_ND_H
31 #define MCL_3DL_ND_H
32 
33 #define _USE_MATH_DEFINES
34 #include <cmath>
35 #include <Eigen/Core>
36 #include <Eigen/LU>
37 
38 namespace mcl_3dl
39 {
40 template <typename FLT_TYPE = float>
42 {
43 public:
44  explicit NormalLikelihood(const FLT_TYPE sigma)
45  {
46  a_ = 1.0 / sqrtf(2.0 * M_PI * sigma * sigma);
47  sq2_ = sigma * sigma * 2.0;
48  }
49  FLT_TYPE operator()(const FLT_TYPE x) const
50  {
51  return a_ * expf(-x * x / sq2_);
52  }
53 
54 protected:
55  FLT_TYPE a_;
56  FLT_TYPE sq2_;
57 };
58 
59 template <typename FLT_TYPE = float, size_t DIMENSION = 6>
61 {
62 public:
63  using Matrix = Eigen::Matrix<FLT_TYPE, DIMENSION, DIMENSION>;
64  using Vector = Eigen::Matrix<FLT_TYPE, DIMENSION, 1>;
65 
66  explicit NormalLikelihoodNd(const Matrix sigma)
67  {
68  a_ = 1.0 / (pow(2.0 * M_PI, 0.5 * DIMENSION) * sqrt(sigma.determinant()));
69  sigma_inv_ = sigma.inverse();
70  }
71  FLT_TYPE operator()(const Vector x) const
72  {
73  return a_ * expf(-0.5 * x.transpose() * sigma_inv_ * x);
74  }
75 
76 protected:
77  FLT_TYPE a_;
79 };
80 } // namespace mcl_3dl
81 
82 #endif // MCL_3DL_ND_H
FLT_TYPE operator()(const Vector x) const
Definition: nd.h:71
FLT_TYPE operator()(const FLT_TYPE x) const
Definition: nd.h:49
NormalLikelihoodNd(const Matrix sigma)
Definition: nd.h:66
NormalLikelihood(const FLT_TYPE sigma)
Definition: nd.h:44
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
Eigen::Matrix< FLT_TYPE, DIMENSION, DIMENSION > Matrix
Definition: nd.h:63
Eigen::Matrix< FLT_TYPE, DIMENSION, 1 > Vector
Definition: nd.h:64


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 8 2019 03:32:36