Comments (3)
Thanks. I'll take a look then.
from lbfgspp.
Here's a simple MWE that gives fx = inf
while the initial value is feasible (f(x0) != inf
): https://gist.github.com/mad-s/c097680d0c083c1df3a5c5d6e71c0856
from lbfgspp.
This has been fixed, but note that your code to compute the gradient needs to be modified. These two lines lack two multipliers a1
and a2
:
grad += -mu/c1 * Vector2d(-3*a1*pow(a1*x(0)+b1, 2), 1);
grad += -mu/c2 * Vector2d(-3*a2*pow(a2*x(0)+b2, 2), 1);
The example itself is a bit ill-conditioned, so to get the global optimum you need a better initial value, for example (0.0, 10.0)
. You also need to increase max_linesearch
whenever it is necessary. Below is a working example modified from yours:
#include <Eigen/Core>
#include <iostream>
#include <LBFGS.h>
using namespace std;
using namespace LBFGSpp;
using Eigen::Vector2d;
using Eigen::VectorXd;
int main() {
LBFGSParam<double> param;
param.max_iterations = 100;
param.max_linesearch = 30;
LBFGSSolver<double> solver(param);
auto fun = [] (const VectorXd &x, VectorXd &grad) -> double {
double mu = 0.0001;
double fx = x(1);//sqrt(x(1));
double a1 = 2;
double b1 = 0;
double a2 = -1;
double b2 = 1;
// c_i >= 0
double c1 = x(1) - pow(a1*x(0)+b1, 3);
double c2 = x(1) - pow(a2*x(0)+b2, 3);
double c3 = x(1);
fx += c1 > 0 ? -mu*log(c1) : std::numeric_limits<double>::infinity();
fx += c2 > 0 ? -mu*log(c2) : std::numeric_limits<double>::infinity();
fx += c3 > 0 ? -mu*log(c3) : std::numeric_limits<double>::infinity();
grad = Vector2d(0., 1/* / sqrt(x(1))*/);
grad += -mu/c1 * Vector2d(-3*a1*pow(a1*x(0)+b1, 2), 1);
grad += -mu/c2 * Vector2d(-3*a2*pow(a2*x(0)+b2, 2), 1);
grad += -mu/c3 * Vector2d(0.,1.);
return fx;
};
VectorXd x = Vector2d(0., 10.);
double fx;
solver.minimize(fun, x, fx);
cout << "fx = " << fx << endl;
cout << "x = " << x << endl;
}
Output is
fx = 0.29831
x = 0.333296
0.296496
from lbfgspp.
Related Issues (20)
- Bounded LBFGS (box) doesn't work well HOT 1
- LBFGS Breaks on this trivial case HOT 2
- Comparison with Pythons scipy.optimize lbfgsb HOT 6
- Several ways to crash LBFGS++ HOT 8
- Examples hang on Linux/ppc64le HOT 1
- LineSearchNocedalWright - NaN in Step 2 (Zooming) HOT 1
- How to create a functor for LBFGSpp given objective function and its gradient HOT 2
- compare with some optimization tools? HOT 2
- The optimization returns 6 precision numbers HOT 2
- Division by zero in BFGSMat.h (apply_Hv(...)) HOT 2
- More Thuente line search can find proper step HOT 10
- Line Search failed using LBFGS for optimisation of chemical structures HOT 12
- Why the stop criteria is like Gradient Norm< epsilon_relative * x.norm() HOT 9
- `dg_hi` set but never used warning in LBFGSpp/LineSearchNocedalWright.h ? HOT 1
- Some compiler warnings. HOT 1
- How about support auto-diff for computing the gradient
- linesearch fails
- Is there an issue with your cauchy points finding step? HOT 5
- Vcpkg support HOT 1
- return covariance of estimated parameters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lbfgspp.