sparse_costs.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020, University of Edinburgh, University of Oxford
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 notice,
9 // 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 nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // 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 EXOTICA_CORE_TOOLS_SPARSE_COSTS_H_
31 #define EXOTICA_CORE_TOOLS_SPARSE_COSTS_H_
32 
34 #include <Eigen/Dense>
35 #include <vector>
36 
37 namespace exotica
38 {
39 inline double huber_cost(double x, double beta)
40 {
41  if (std::abs(x) < beta)
42  return 0.5 * x * x;
43  else
44  return beta * (std::abs(x) - 0.5 * beta);
45 }
46 
47 inline double huber_jacobian(double x, double beta)
48 {
49  if (std::abs(x) < beta)
50  return x;
51  if (x < 0)
52  return -beta;
53  return beta;
54 }
55 
56 inline double huber_hessian(double x, double beta)
57 {
58  if (std::abs(x) < beta)
59  return 1;
60  return 0;
61 }
62 
63 inline double smooth_l1_cost(double x, double beta)
64 {
65  if (std::abs(x) < beta)
66  return 0.5 * x * x / beta;
67  return std::abs(x) - 0.5 * beta;
68 }
69 
70 inline double smooth_l1_jacobian(double x, double beta)
71 {
72  if (std::abs(x) < beta)
73  return x / beta;
74  if (x < -beta)
75  return -1.0;
76  return 1.0;
77 }
78 
79 inline double smooth_l1_hessian(double x, double beta)
80 {
81  if (std::abs(x) < beta)
82  return 1.0 / beta;
83  return 0.0;
84 }
85 
86 inline double pseudo_huber_cost(double x, double beta)
87 {
88  return beta * beta * (std::sqrt(1 + std::pow(x / beta, 2)) - 1.0);
89 }
90 
91 inline double pseudo_huber_jacobian(double x, double beta)
92 {
93  return x / (std::sqrt(1.0 + x * x / (beta * beta)));
94 }
95 
96 inline double pseudo_huber_hessian(double x, double beta)
97 {
98  return std::pow(beta, 4) * std::sqrt(1.0 + x * x / (beta * beta)) / (std::pow(beta * beta + x * x, 2));
99 }
100 
101 } // namespace exotica
102 
103 #endif // EXOTICA_CORE_TOOLS_SPARSE_COSTS_H_
double huber_jacobian(double x, double beta)
Definition: sparse_costs.h:47
double smooth_l1_cost(double x, double beta)
Definition: sparse_costs.h:63
double pseudo_huber_jacobian(double x, double beta)
Definition: sparse_costs.h:91
double smooth_l1_hessian(double x, double beta)
Definition: sparse_costs.h:79
double smooth_l1_jacobian(double x, double beta)
Definition: sparse_costs.h:70
double huber_cost(double x, double beta)
Definition: sparse_costs.h:39
double pseudo_huber_cost(double x, double beta)
Definition: sparse_costs.h:86
double pseudo_huber_hessian(double x, double beta)
Definition: sparse_costs.h:96
double huber_hessian(double x, double beta)
Definition: sparse_costs.h:56


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:34:49