Skip to content

Commit d441025

Browse files
authored
Merge pull request #382 from LouiseMsn/log-barrier-fix
Fix for LogResidualCost
2 parents 510c037 + 56809be commit d441025

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed the missing minus signs in the `LogResidualCost` (https://github.com/Simple-Robotics/aligator/pull/382)
13+
1014
## [0.17.1] - 2025-12-01
1115

1216
## [0.17.0] - 2025-11-21

include/aligator/modelling/costs/log-residual-cost.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@
55
#include "./composite-costs.hpp"
66

77
namespace aligator {
8-
9-
/// @brief Log-barrier of an underlying cost function.
8+
/**
9+
* @brief Log-barrier of an underlying cost function.
10+
*
11+
* @details Defined as :
12+
* \f[
13+
* c(x,u) = -w\ln(r(x,u))
14+
* \f]
15+
*
16+
* where :
17+
* -\f(\ c(x,u) \f) is the resulting cost
18+
* -\f(\ r(x,u) \f) is the input function
19+
* -\f(\ w \f) is the input scale
20+
*
21+
*/
1022
template <typename Scalar> struct LogResidualCostTpl : CostAbstractTpl<Scalar> {
1123
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar);
1224
using CostDataAbstract = CostDataAbstractTpl<Scalar>;

include/aligator/modelling/costs/log-residual-cost.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void LogResidualCostTpl<Scalar>::evaluate(const ConstVectorRef &x,
3838
Data &d = static_cast<Data &>(data);
3939
residual_->evaluate(x, u, *d.residual_data);
4040
d.value_ =
41-
barrier_weights_.dot(d.residual_data->value_.array().log().matrix());
41+
-barrier_weights_.dot(d.residual_data->value_.array().log().matrix());
4242
}
4343

4444
template <typename Scalar>
@@ -54,7 +54,7 @@ void LogResidualCostTpl<Scalar>::computeGradients(
5454
const int nrows = residual_->nr;
5555
for (int i = 0; i < nrows; i++) {
5656
auto g_i = J.row(i);
57-
d.grad_.noalias() += barrier_weights_(i) * g_i / v(i);
57+
d.grad_.noalias() += -barrier_weights_(i) * g_i / v(i);
5858
}
5959
}
6060

@@ -72,7 +72,7 @@ void LogResidualCostTpl<Scalar>::computeHessians(const ConstVectorRef &,
7272
for (int i = 0; i < nrows; i++) {
7373
auto g_i = J.row(i); // row vector
7474
d.hess_.noalias() +=
75-
barrier_weights_(i) * (g_i.transpose() * g_i) / (v(i) * v(i));
75+
-barrier_weights_(i) * (g_i.transpose() * g_i) / (v(i) * v(i));
7676
}
7777
}
7878
} // namespace aligator

0 commit comments

Comments
 (0)