Dear all,

I encountered bugs in COBYLA and BOBYQA. I think, I found the origin and
can provide two patches. An example code as well as two patches are
attached.

Cheers,

Klaus

Attachment: cobyla.patch
Description: Binary data

Attachment: bobyqa.patch
Description: Binary data

#include <iostream>
#include <vector>
#include <assert.h>
#include <nlopt.hpp>

using namespace std;

/*
 * f(x) = x*x
 * Minimum at x = 0 with f(x) = 0
 */
double myvfunc(const std::vector<double> &x, std::vector<double> &grad, void *my_func_data)
{
    assert ( grad.empty() );

    double f = 0;
    for (unsigned int i=0; i<x.size(); ++i) {
    	f += x.at(i)*x.at(i);
    }
    return f;
}


int main()
{
	int N = 2;
	std::vector<double> x(N);
	double minf;

	x.at(0) = 0.5;
	x.at(1) = -0.5;


	// Bug 1: COBYLA finds wrong minimum
	nlopt::opt opt(nlopt::LN_COBYLA, N);

	// Bug 2: BOBYQA fails
	//nlopt::opt opt(nlopt::LN_BOBYQA, N);

	opt.set_initial_step(x);
	opt.set_lower_bounds(-2);
	opt.set_upper_bounds(2);
	opt.set_min_objective(myvfunc, NULL);
	opt.set_xtol_rel(1e-4);
	nlopt::result result = opt.optimize(x, minf);

	cout << "Minimum value of f: " << minf;
	cout << " at x = [";
	for (int i=0; i<N; ++i) {
		cout << x.at(i) << " ";
	}
	cout << " ]" << endl;
}
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to