Skip to content

Commit 5b58dcb

Browse files
committed
Minor changes
1 parent 0b6d026 commit 5b58dcb

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

uno/ingredients/hessian_models/quasi_newton/LBFGSHessian.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "optimization/OptimizationProblem.hpp"
1010
#include "symbolic/Expression.hpp"
1111
#include "symbolic/Range.hpp"
12+
#include "symbolic/VectorView.hpp"
1213
#include "tools/Logger.hpp"
1314
#include "tools/Statistics.hpp"
1415

@@ -57,7 +58,7 @@ namespace uno {
5758
}
5859

5960
void LBFGSHessian::notify_accepted_iterate(Iterate& current_iterate, Iterate& trial_iterate) {
60-
this->update_memory(current_iterate, trial_iterate);
61+
this->update_limited_memory(current_iterate, trial_iterate);
6162
// TODO set "|BFGS|"
6263
}
6364

@@ -74,6 +75,7 @@ namespace uno {
7475
throw std::runtime_error("The L-BFGS Hessian model was initialized with a different objective multiplier");
7576
}
7677

78+
// update_limited_memory() has updated the limited memory. A recomputation of the Hessian representation may be required
7779
if (this->hessian_recomputation_required) {
7880
this->recompute_hessian_representation();
7981
this->hessian_recomputation_required = false;
@@ -107,7 +109,7 @@ namespace uno {
107109

108110
// protected member functions
109111

110-
void LBFGSHessian::update_memory(Iterate& current_iterate, Iterate& trial_iterate) {
112+
void LBFGSHessian::update_limited_memory(Iterate& current_iterate, Iterate& trial_iterate) {
111113
DEBUG << "\n*** Updating the BFGS memory\n";
112114
// update the matrices S, Y and D
113115
// TODO check that the S entry isn't too small
@@ -116,9 +118,8 @@ namespace uno {
116118
this->update_D_matrix();
117119
DEBUG << "> S: " << this->S_matrix;
118120
DEBUG << "> Y: " << this->Y_matrix;
119-
DEBUG << "> D: "; print_vector(DEBUG, this->D_matrix);
121+
DEBUG << "> diag(D): "; print_vector(DEBUG, this->D_matrix);
120122

121-
// this->current_available_slot lives in [0, this->memory_size)
122123
// check that the latest D entry s^T y is > 0
123124
if (0. < this->D_matrix[this->current_memory_slot]) {
124125
DEBUG << "Adding vector to L-BFGS memory at slot " << this->current_memory_slot << '\n';
@@ -132,24 +133,22 @@ namespace uno {
132133
}
133134

134135
void LBFGSHessian::update_S_matrix(const Iterate& current_iterate, const Iterate& trial_iterate) {
135-
this->S_matrix.column(this->current_memory_slot) = trial_iterate.primals - current_iterate.primals;
136+
this->S_matrix.column(this->current_memory_slot) = view(trial_iterate.primals, 0, this->model.number_variables) -
137+
view(current_iterate.primals, 0, this->model.number_variables);
136138
}
137-
139+
138140
// fill the Y matrix: y = \nabla L(x_k, y_k, z_k) - \nabla L(x_{k-1}, y_k, z_k)
139141
void LBFGSHessian::update_Y_matrix(Iterate& current_iterate, Iterate& trial_iterate) {
140142
// evaluate Lagrangian gradients at the current and trial iterates, both with the trial multipliers
141-
current_iterate.evaluate_objective_gradient(this->model);
143+
// TODO preallocate
142144
std::vector<double> current_jacobian_values(this->model.number_jacobian_nonzeros());
143-
this->model.evaluate_constraint_jacobian(current_iterate.primals, current_jacobian_values.data());
144-
trial_iterate.evaluate_objective_gradient(this->model);
145145
std::vector<double> trial_jacobian_values(this->model.number_jacobian_nonzeros());
146+
current_iterate.evaluate_objective_gradient(this->model);
147+
trial_iterate.evaluate_objective_gradient(this->model);
148+
this->model.evaluate_constraint_jacobian(current_iterate.primals, current_jacobian_values.data());
146149
this->model.evaluate_constraint_jacobian(trial_iterate.primals, trial_jacobian_values.data());
147-
// TODO preallocate
148150
LagrangianGradient<double> current_split_lagrangian_gradient(this->model.number_variables);
149151
LagrangianGradient<double> trial_split_lagrangian_gradient(this->model.number_variables);
150-
const OptimizationProblem problem{this->model};
151-
//problem.evaluate_lagrangian_gradient(current_split_lagrangian_gradient, current_iterate, trial_iterate.multipliers);
152-
//problem.evaluate_lagrangian_gradient(trial_split_lagrangian_gradient, trial_iterate, trial_iterate.multipliers);
153152
const auto current_lagrangian_gradient = this->fixed_objective_multiplier * current_split_lagrangian_gradient.objective_contribution
154153
+ current_split_lagrangian_gradient.constraints_contribution;
155154
const auto trial_lagrangian_gradient = this->fixed_objective_multiplier * trial_split_lagrangian_gradient.objective_contribution

uno/ingredients/hessian_models/quasi_newton/LBFGSHessian.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace uno {
5454
DenseMatrix<double> Hessian_approximation;
5555
double initial_identity_multiple{1.}; // referred to as delta in Numerical optimization
5656

57-
void update_memory(Iterate& current_iterate, Iterate& trial_iterate);
57+
void update_limited_memory(Iterate& current_iterate, Iterate& trial_iterate);
5858
void update_S_matrix(const Iterate& current_iterate, const Iterate& trial_iterate);
5959
void update_Y_matrix(Iterate& current_iterate, Iterate& trial_iterate);
6060
void update_D_matrix();

0 commit comments

Comments
 (0)