Skip to content

Commit 1a2cf5d

Browse files
committed
Minor changes in LBFGS
1 parent 2717f58 commit 1a2cf5d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

uno/ingredients/hessian_models/quasi_newton/LBFGSHessian.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Copyright (c) 2025 Charlie Vanaret
22
// Licensed under the MIT license. See LICENSE file in the project directory for details.
33

4-
#include <stdexcept>
54
#include "LBFGSHessian.hpp"
6-
7-
#include <model/Model.hpp>
8-
95
#include "linear_algebra/LAPACK.hpp"
6+
#include "linear_algebra/SymmetricMatrix.hpp"
7+
#include "model/Model.hpp"
108
#include "optimization/Iterate.hpp"
119
#include "symbolic/Range.hpp"
1210

@@ -31,26 +29,28 @@ namespace uno {
3129
this->update_memory(model, current_iterate, trial_iterate);
3230
}
3331

34-
void LBFGSHessian::evaluate_hessian(Statistics& /*statistics*/, const Model& /*model*/, const Vector<double>& /*primal_variables*/,
35-
double /*objective_multiplier*/, const Vector<double>& /*constraint_multipliers*/, SymmetricMatrix<size_t, double>& /*hessian*/) {
32+
void LBFGSHessian::evaluate_hessian(Statistics& /*statistics*/, const Model& model, const Vector<double>& /*primal_variables*/,
33+
double /*objective_multiplier*/, const Vector<double>& /*constraint_multipliers*/, SymmetricMatrix<size_t, double>& hessian) {
3634
if (this->hessian_recomputation_required) {
3735
this->recompute_hessian_representation();
3836
this->hessian_recomputation_required = false;
3937
}
4038

41-
// TODO
42-
throw std::runtime_error("LBFGSHessian::evaluate_hessian not implemented");
39+
for (size_t variable_index: Range(model.number_variables)) {
40+
hessian.insert(1., variable_index, variable_index);
41+
hessian.finalize_column(variable_index);
42+
}
4343
}
4444

45-
void LBFGSHessian::compute_hessian_vector_product(const Model& /*model*/, const Vector<double>& vector, double /*objective_multiplier*/,
45+
void LBFGSHessian::compute_hessian_vector_product(const Model& model, const Vector<double>& vector, double /*objective_multiplier*/,
4646
const Vector<double>& /*constraint_multipliers*/, Vector<double>& result) {
4747
if (this->hessian_recomputation_required) {
4848
this->recompute_hessian_representation();
4949
this->hessian_recomputation_required = false;
5050
}
5151

5252
// for the moment, pretend we have an identity Hessian TODO
53-
for (size_t variable_index: Range(vector.size())) {
53+
for (size_t variable_index: Range(model.number_variables)) {
5454
result[variable_index] = vector[variable_index];
5555
}
5656
}

0 commit comments

Comments
 (0)