esa / pagmo2

A C++ platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model.
https://esa.github.io/pagmo2/
GNU General Public License v3.0
808 stars 160 forks source link

Help!! Need Help with Gradient calculation. #497

Closed A5troB0y closed 2 years ago

A5troB0y commented 2 years ago

Hi, i am new to optimization and pagmo, i am struggling with gradient calculation for IPOPT algorithm. As pagmo documentation doesn't have any examples it would help if someone could share some example codes with gradient functions.

bluescarni commented 2 years ago

@A5troB0y in order to provide a gradient, an optimisation problem must implement the gradient() member function as specified in the C++ docs:

https://esa.github.io/pagmo2/docs/cpp/problem.html#_CPPv4NK5pagmo7problem8gradientERK13vector_double

See here a concrete example for the Rosenbrock problem:

https://github.com/esa/pagmo2/blob/1fb2448cda6851f70076a947c84584a68d0b5187/src/problems/rosenbrock.cpp

A5troB0y commented 2 years ago

@bluescarni Hi, can you share some examples with estimate_gradient, estimate_gradient_h the above example doesn't have those functions implemented.

A5troB0y commented 2 years ago

Gradient Calculation :

vector_double gradient(const vector_double &dv) const
    {
        return estimate_gradient([this](const vector_double &x) {return this->fitness(x);},dv);
    }