Coverage Control Library
Loading...
Searching...
No Matches
bivariate_normal_distribution.h
Go to the documentation of this file.
1/*
2 * This file is part of the CoverageControl library
3 *
4 * Author: Saurav Agarwal
5 * Contact: sauravag@seas.upenn.edu, agr.saurav1@gmail.com
6 * Repository: https://github.com/KumarRobotics/CoverageControl
7 *
8 * Copyright (c) 2024, Saurav Agarwal
9 *
10 * The CoverageControl library is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The CoverageControl library is distributed in the hope that it will be
16 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_BIVARIATE_NORMAL_DISTRIBUTION_H_
30#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_BIVARIATE_NORMAL_DISTRIBUTION_H_
31
32#include <cmath>
33
36
37namespace CoverageControl {
38
54 private:
55 Point2 mean_;
56 Point2 sigma_;
57 double rho_ = 0;
58 double scale_ = 1;
59 bool is_circular_ =
60 false;
62 public:
69 is_circular_ = true;
70 sigma_ = Point2{1, 1};
71 mean_ = Point2{0, 0};
72 rho_ = 0;
73 }
74
84 BivariateNormalDistribution(Point2 const &mean, double const &sigma,
85 double const scale = 1) {
86 is_circular_ = true;
87 sigma_ = Point2(sigma, sigma);
88 mean_ = mean;
89 rho_ = 0;
90 scale_ = scale;
91 }
92
103 BivariateNormalDistribution(Point2 const &mean, Point2 const &sigma,
104 double const rho, double const scale = 1) {
105 assert(rho_ < (1 - kEps));
106 if (rho_ > 0) {
107 is_circular_ = false;
108 rho_ = rho;
109 } else {
110 is_circular_ = true;
111 rho_ = 0;
112 }
113 sigma_ = sigma;
114 mean_ = mean;
115 scale_ = scale;
116 }
117
119 Point2 GetMean() const { return mean_; }
121 Point2 GetSigma() const { return sigma_; }
123 double GetRho() const { return rho_; }
125 double GetScale() const { return scale_; }
126
137 Point2 TransformPoint(Point2 const &in_point) const {
138 if (is_circular_) {
139 return Point2((in_point - mean_) / sigma_.x());
140 }
141 Point2 translated = in_point - mean_;
142 Point2 normalized(translated.x() / sigma_.x(), translated.y() / sigma_.y());
143 return Point2(
144 (normalized.x() - rho_ * normalized.y()) / (std::sqrt(1 - rho_ * rho_)),
145 normalized.y());
146 }
147
148 Point2f TransformPoint(Point2f const &in_point_f) const {
149 Point2f mean_f = mean_.cast<float>();
150 Point2f sigma_f = sigma_.cast<float>();
151 float rho_f = static_cast<float>(rho_);
152 if (is_circular_ or std::abs(rho_f) < kEpsf) {
153 return Point2f((in_point_f - mean_f) / sigma_f.x());
154 }
155 Point2f translated = in_point_f - mean_f;
156 Point2f normalized(translated.x() / sigma_f.x(),
157 translated.y() / sigma_f.y());
158 return Point2f(
159 (normalized.x() - rho_f * normalized.y()) / (sqrt(1 - rho_f * rho_f)),
160 normalized.y());
161 }
162
171 double IntegrateQuarterPlane(Point2 const &point) const {
172 Point2 transformed_point = TransformPoint(point);
173 return scale_ * std::erfc(transformed_point.x() * kOneBySqrt2) *
174 std::erfc(transformed_point.y() * kOneBySqrt2) / 4.;
175 }
176
177 float IntegrateQuarterPlane(Point2f const &point) const {
178 float scale_f = static_cast<float>(scale_);
179 Point2f transformed_point = TransformPoint(point);
180 return scale_f * std::erfc(transformed_point.x() * kOneBySqrt2f) *
181 std::erfc(transformed_point.y() * kOneBySqrt2f) / 4.f;
182 }
183};
184
185} /* namespace CoverageControl */
186#endif // CPPSRC_CORE_INCLUDE_COVERAGECONTROL_BIVARIATE_NORMAL_DISTRIBUTION_H_
double GetScale() const
Returns the scale of the distribution.
double GetRho() const
Returns the correlation coefficient of the distribution.
Point2 GetMean() const
Returns the mean of the distribution.
Point2f TransformPoint(Point2f const &in_point_f) const
Point2 GetSigma() const
Returns the standard deviation of the distribution.
Point2 TransformPoint(Point2 const &in_point) const
Transforms a point from general distribution to standard distribution.
BivariateNormalDistribution(Point2 const &mean, Point2 const &sigma, double const rho, double const scale=1)
Constructor for general distribution.
double IntegrateQuarterPlane(Point2 const &point) const
Integrates the distribution over a quarter plane The function integrates the distribution over a quar...
BivariateNormalDistribution(Point2 const &mean, double const &sigma, double const scale=1)
Constructor for standard distribution.
Constants for the CoverageControl library.
double const kEps
Definition constants.h:48
double const kOneBySqrt2
Definition constants.h:52
float const kOneBySqrt2f
Definition constants.h:53
float const kEpsf
Definition constants.h:49
Eigen::Vector2d Point2
Definition typedefs.h:44
Eigen::Vector2f Point2f
Definition typedefs.h:45
Namespace for the CoverageControl library.
Contains typedefs for the library.