[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-gsl] least-squares fitting or minimization with constrained pa

**From**: |
Max Belushkin |

**Subject**: |
Re: [Help-gsl] least-squares fitting or minimization with constrained parameters |

**Date**: |
Mon, 12 Dec 2005 14:51:14 +0100 |

**User-agent**: |
Thunderbird 1.5 (X11/20051025) |

The way I personally do it is as follows. Two examples given.

`Let's imagine we have two values (functions of the parameter vector) we
``want to constrain. F1(p) and F2(p). F1(p) must lie close to a value f1,
``and F2(p) must lie between f2_min and f2_max.
`

`We have a function chi_squared(p) we're minimizing. We change that to
``minimize_this (p) = chi_squared(p) + constrain (p), where
`
const double f1 = x.y;
const double f2_min = a.b;
const double f2_max = c.d;
double constrain (const gsl_vector* v) {
double val_f1 = F1(v);
double val_f2 = F2(v);
double strength_1=1.0,strength_2=100.0;
double ret=0;
ret+=pow(strength_1*(val_f1-f1),2)*exp(pow(strength_1*(val_f1-f1),2);
if (val_f2<f2_min)
ret+=pow(strength_2*(val_f2-f2_min),2)*exp(pow(strength_2*(val_f2-f2_min),2);
if (val_f2>f2_max)
ret+=pow(strength_2*(val_f2-f2_max),2)*exp(pow(strength_2*(val_f2-f2_max),2);
return ret;
};
Works fine for me so far...
Frank Küster wrote:

Hi,
I am wondering whether (and how) it is possible to use the least-squares
fitting, or alternatively minimization functions of gsl with constrained
parameters. What I mean with this is that I want to force the function
into the correct local minimum by supplying information which parameter
values are physically meaningful for these particular data, or which of
two degenerate minima I would like (to be able to compare different
fits). For example, if the function is the sum of two exponentials, I
would like to perform a least-squares fit to some data with the
constrain that the first of them has the shorter relaxation time.
Is this possible, and how would that be implemented?
TIA, Frank