Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eltoder committed Nov 18, 2024
1 parent 6f5cdcc commit 760fb25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
6 changes: 6 additions & 0 deletions ql/math/optimization/levenbergmarquardt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ namespace QuantLib {
*/
[[deprecated("Don't use this method; inspect the result of minimize instead")]]
virtual Integer getInfo() const { return info_; }

[[deprecated("Don't use this method; it is private")]]
void fcn(int m, int n, Real* x, Real* fvec, int*) { fcn(m, n, x, fvec); }

[[deprecated("Don't use this method; it is private")]]
void jacFcn(int m, int n, Real* x, Real* fjac, int*) { jacFcn(m, n, x, fjac); }
private:
void fcn(int m, int n, Real* x, Real* fvec);
void jacFcn(int m, int n, Real* x, Real* fjac);
Expand Down
30 changes: 18 additions & 12 deletions ql/termstructures/globalbootstrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,21 @@ template <class Curve> void GlobalBootstrap<Curve>::calculate() const {
// setup cost function
class TargetFunction : public CostFunction {
public:
TargetFunction(const Size firstHelper,
const Size numberHelpers,
std::function<Array()> additionalErrors,
// NOTE: TargetFunction retains passed pointers, so they must point to objects
// that outlive the function. We use pointers instead of const refs to avoid
// accidental binding to temporaries.
TargetFunction(Size firstHelper,
Size numberHelpers,
const std::function<Array()>* additionalErrors,
Curve* ts,
std::vector<Real> lowerBounds,
std::vector<Real> upperBounds)
const std::vector<Real>* lowerBounds,
const std::vector<Real>* upperBounds)
: firstHelper_(firstHelper), numberHelpers_(numberHelpers),
additionalErrors_(std::move(additionalErrors)), ts_(ts),
lowerBounds_(std::move(lowerBounds)), upperBounds_(std::move(upperBounds)) {}
additionalErrors_(*additionalErrors), ts_(ts),
lowerBounds_(*lowerBounds), upperBounds_(*upperBounds) {
QL_REQUIRE(additionalErrors != nullptr, "null additionalErrors");
QL_REQUIRE(lowerBounds != nullptr && upperBounds != nullptr, "null bounds");
}

Real transformDirect(const Real x, const Size i) const {
return (std::atan(x) + M_PI_2) / M_PI * (upperBounds_[i] - lowerBounds_[i]) + lowerBounds_[i];
Expand Down Expand Up @@ -294,12 +300,12 @@ template <class Curve> void GlobalBootstrap<Curve>::calculate() const {

private:
Size firstHelper_, numberHelpers_;
std::function<Array()> additionalErrors_;
Curve *ts_;
const std::vector<Real> lowerBounds_, upperBounds_;
const std::function<Array()>& additionalErrors_;
Curve* ts_;
const std::vector<Real> &lowerBounds_, &upperBounds_;
};
TargetFunction cost(firstHelper_, numberHelpers_, additionalErrors_, ts_,
std::move(lowerBounds), std::move(upperBounds));
TargetFunction cost(firstHelper_, numberHelpers_, &additionalErrors_, ts_,
&lowerBounds, &upperBounds);

// setup guess
Array guess(numberBounds);
Expand Down

0 comments on commit 760fb25

Please sign in to comment.