Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-linear Least Squares Optimization Library for C [closed]

I'm looking for a library in C that will do optimization of an objective function (preferrably Levenberg-Marquardt algorithm) and will support box constraints, linear inequality constraints and non-linear inequality constraints.

I've tried several libraries already, but none of them do employ the necessary constraint types for my application:

  • GNU GSL (does not support constraints at all)
  • cMPFIT (only supports box constraints)
  • levmar (does not support non-linear constraints at all)

I am currently exploring NLopt, but I'm not sure if I can achieve a least-squares approach with any of the supplied algorithms.

I find it hard to believe that there's not a single library supporting the full range of constraints in this problem, so I guess I did a mistake somewhere while googling.

I recently discovered I can call Matlab functions from C. While that would solve the problem quite easily, I don't want to have to call Matlab functions from C. It's not fast in my experience.

Any help will be greatly appreciated.

like image 824
alkar Avatar asked Jun 19 '11 15:06

alkar


People also ask

What is Matlab Lsqnonlin?

x = lsqnonlin( fun , x0 ) starts at the point x0 and finds a minimum of the sum of squares of the functions described in fun . The function fun should return a vector (or array) of values and not the sum of squares of the values. (The algorithm implicitly computes the sum of squares of the components of fun(x) .)

Which algorithm uses least square optimization?

Note that the Levenberg-Marquadt algorithm is often used to optimize least squares problems.

Is Least Squares an optimization problem?

Least squares (LS) optimiza- tion problems are those in which the objective (error) function is a quadratic function of the parameter(s) being optimized.

What is least square fitting method?

The least square method is the process of finding the best-fitting curve or line of best fit for a set of data points by reducing the sum of the squares of the offsets (residual part) of the points from the curve.


2 Answers

Some time ago I was researching the state of C/C++ least squares fitting libraries. I noted down a few links, including the ones you gave and also:

  • ALGLIB/optimization -- Lev-Mar with boundary constraints.

  • WNLIB/wnnlp -- a constrained non-linear optimization package in C (general optimization, not least squares). Constraints are handled by adding a penalty function.

I haven't used any of the libraries yet, but NLopt seems the most promising for me. It would be great if it had specialized interface and algorithms for (weighted) least-squares fitting.

BTW, does your note about Matlab mean that it has Lev-Mar with non-linear constraints?

like image 50
marcin Avatar answered Oct 04 '22 15:10

marcin


The approach I finally followed is the following:

  • I used NLopt for the optimization and the objective function was constructed to compute the squared error of the problem.

  • The algorithm that showed the most promising results was COBYLA (Local derivative-free optimization). It supports box constraints and non-linear constraints. The linear inequity constraints were introduced as non-linear constraints, which should be generally feasible.

Simple benchmarking shows that it does converge a little slower than a Lev-Mar approach, but speed is sacrificed due to the need for constraints.

like image 37
alkar Avatar answered Oct 04 '22 14:10

alkar