loss_function.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, Clearpath Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
35 
36 #include <cmath>
37 #include <limits>
38 
39 
40 namespace ceres
41 {
42 
43 void DCSLoss::Evaluate(double s, double rho[3]) const
44 {
45  if (s > a_)
46  {
47  // Outlier region
48  const double inv = 1.0 / (a_ + s);
49  const double scale = 2.0 * a_ * inv;
50 
51  rho[0] = a_ * (3.0 * s - a_) * inv;
52  rho[1] = scale * scale;
53  rho[2] = -2.0 * inv * rho[1];
54  }
55  else
56  {
57  // Inlier region
58  rho[0] = s;
59  rho[1] = 1.0;
60  rho[2] = 0.0;
61  }
62 }
63 
64 void FairLoss::Evaluate(double s, double rho[3]) const
65 {
66  const double r = std::sqrt(s);
67  const double ra = r / a_;
68  const double sum = 1.0 + ra;
69 
70  rho[0] = 2.0 * b_ * (ra - std::log(sum));
71  rho[1] = 1.0 / sum;
72  rho[2] = r == 0.0 ? std::numeric_limits<double>::lowest() : -0.5 / (a_ * r * sum * sum);
73 }
74 
75 void GemanMcClureLoss::Evaluate(double s, double rho[3]) const
76 {
77  const double sum = b_ + s;
78  const double inv = 1.0 / sum;
79  const double scale = b_ * inv;
80 
81  rho[0] = s * scale;
82  rho[1] = scale * scale;
83  rho[2] = -2.0 * inv * rho[1];
84 }
85 
86 void WelschLoss::Evaluate(double s, double rho[3]) const
87 {
88  const double exp = std::exp(s * c_);
89 
90  rho[0] = b_ * (1 - exp);
91  rho[1] = exp;
92  rho[2] = c_ * exp;
93 }
94 
95 } // namespace ceres
ceres::GemanMcClureLoss::b_
const double b_
Definition: loss_function.h:216
ceres::WelschLoss::b_
const double b_
Definition: loss_function.h:239
s
XmlRpcServer s
ceres::WelschLoss::c_
const double c_
Definition: loss_function.h:240
ceres::WelschLoss::Evaluate
void Evaluate(double, double *) const override
Definition: loss_function.cpp:86
ceres::FairLoss::a_
const double a_
Definition: loss_function.h:168
ceres::GemanMcClureLoss::Evaluate
void Evaluate(double, double *) const override
Definition: loss_function.cpp:75
ceres::DCSLoss::a_
const double a_
Definition: loss_function.h:144
ceres
ceres::DCSLoss::Evaluate
void Evaluate(double, double *rho) const override
Definition: loss_function.cpp:43
loss_function.h
ceres::FairLoss::Evaluate
void Evaluate(double, double *) const override
Definition: loss_function.cpp:64
ceres::FairLoss::b_
const double b_
Definition: loss_function.h:169


fuse_loss
Author(s): Enrique Fernandez , Stephen Williams
autogenerated on Thu Apr 24 2025 02:19:00