1 #ifndef HOPS_ROSENBROCK_HPP
2 #define HOPS_ROSENBROCK_HPP
6 #include <unsupported/Eigen/MatrixFunctions>
46 typename MatrixType::Scalar scaleParameter;
48 long numberOfDimensions;
53 scaleParameter(scaleParameter),
54 shiftParameter(std::move(shiftParameter)) {
55 numberOfDimensions = this->shiftParameter.rows() * 2;
58 typename MatrixType::Scalar
60 if (x.rows() != numberOfDimensions) {
61 throw std::runtime_error(
"Input x has wrong number of rows.");
63 typename MatrixType::Scalar result = 0;
64 for (
long i = 0; i < shiftParameter.rows(); ++i) {
65 result += scaleParameter *
66 (100 * std::pow(std::pow(x(2 * i), 2) - x(2 * i + 1), 2) +
67 std::pow(x(2 * i) - shiftParameter(i), 2));
74 MatrixType observedFisherInformation(x.rows(), x.rows());
76 for (
long i = 0; i < shiftParameter.rows(); ++i) {
77 observedFisherInformation(2 * i, 2 * i) =
78 scaleParameter * (1200 * std::pow(x(2 * i), 2) - 400 * x(2 * i + 1) + 2);
79 observedFisherInformation(2 * i + 1, 2 * i) = scaleParameter * -400 * x(2 * i);
80 observedFisherInformation(2 * i, 2 * i + 1) = scaleParameter * -400 * x(2 * i);
81 observedFisherInformation(2 * i + 1, 2 * i + 1) = scaleParameter * 200;
84 return observedFisherInformation;
87 std::optional<VectorType>
90 for (
long i = 0; i < shiftParameter.rows(); ++i) {
91 gradient(2 * i) = scaleParameter * (4 * 100 * (x(2 * i + 1) - std::pow(x(2 * i), 2)) * (-2 * x(2 * i)) +
92 2 * (x(2 * i) - shiftParameter(i)));
94 gradient(2 * i + 1) = scaleParameter * 2 * 100 * (x(2 * i + 1) - std::pow(x(2 * i), 2));
99 std::optional<MatrixType>
103 double regularization = 1. / hessian.maxCoeff();
104 MatrixType expPositive = (regularization * hessian).exp();
105 MatrixType expNegative = (-regularization * hessian).exp();
106 hessian = (expPositive + expNegative) * hessian * (expPositive - expNegative).inverse();
112 #endif //HOPS_ROSENBROCK_HPP