Giter Club home page Giter Club logo

Comments (2)

PatWie avatar PatWie commented on June 13, 2024

Hi,
nice catch! Is it possible for you to create a pull request such that YOU get the credit for these changes?

from cppnumericalsolvers.

spinicist avatar spinicist commented on June 13, 2024

If you can create a patch and pull request I'd be happy to merge it.

Thanks.

On 1 Oct 2016, at 17:46, Connelly Barnes [email protected] wrote:

The example in the current README does not compile, due to:

The solver (BfgsSolver) should take as a template argument the problem class, not double.
The Vector helper has been removed from meta.
This is frustrating to new users of the library.

Fixed example code:

#include
#include "cppoptlib/meta.h"
#include "cppoptlib/problem.h"
#include "cppoptlib/solver/bfgssolver.h"

using namespace cppoptlib;
using Eigen::VectorXd;

class Rosenbrock : public Problem {
public:
using typename cppoptlib::Problem::Scalar;
using typename cppoptlib::Problem::TVector;

double value(const TVector &x) {
    const double t1 = (1 - x[0]);
    const double t2 = (x[1] - x[0] * x[0]);
    return   t1 * t1 + 100 * t2 * t2;
}
void gradient(const TVector &x, TVector &grad) {
    grad[0]  = -2 * (1 - x[0]) + 200 * (x[1] - x[0] * x[0]) * (-2 * x[0]);
    grad[1]  = 200 * (x[1] - x[0] * x[0]);
}

};

int main(int argc, char const *argv[]) {
Rosenbrock f;
BfgsSolver solver;
VectorXd x(2); x << -1, 2;
solver.minimize(f, x);
std::cout << "argmin " << x.transpose() << std::endl;
std::cout << "f in argmin " << f(x) << std::endl;
return 0;
}

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #60, or mute the thread https://github.com/notifications/unsubscribe-auth/AKie-EO5lONW2dMoiDFw2hmoxULFJt5-ks5qvo5kgaJpZM4KLzMc.

from cppnumericalsolvers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.