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

2005-12-17 Thread Brian Gough
Frank Küster writes:
 > 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?

Take a look at http://ool.sourceforge.net/ listed on the main GSL page
at gnu.org

-- 
Brian Gough

Network Theory Ltd,
Publishing the GSL Manual --- http://www.network-theory.co.uk/gsl/manual/


___
Help-gsl mailing list
Help-gsl@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gsl


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

2005-12-12 Thread Max Belushkin

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_f2f2_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




___
Help-gsl mailing list
Help-gsl@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gsl


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

2005-12-09 Thread Frank Küster
[EMAIL PROTECTED] wrote:

> Hi Frank,
> let me try to give you a general answer which has nothing to do with GSL
> library. The better, safest and probably faster way of introducing the
> kind of constraints you mention is through a re-parameterization of the
> problem. For instance, if you want to fit the sum of two exponentials
>
> a_1*exp{-b_1 t} + a_2 * exp{-b_2 t}
>
> with b_2>b_1>0 and a_1,a_2>0 rewrite the function as
>
> exp(-d_1^2 t+c_1) *(1.+exp(-d_2^2 t +c_2))

That sounds reasonable, however it has a practical disadvantage: I have
to change the fitted function and the parameter set every time I want to
try a new type of constraints.  I have not yet really thought about how
I would let the user set the fitted function at runtime (any hints
appreciated), but recompiling just to set a constraint would be
tedious... 

> Said that, some time ago I wrote a "wrapper" function around GSL
> minimization functions which implements BOUNDARIES constraints through
> change of variable approach. I use it for max-likelihood fitting and
> it seems to work. If you still need it, just ask.

I'd like to have a look at this, yes.  

Thank you, Frank
-- 
Frank Küster
Inst. f. Biochemie der Univ. Zürich
Debian Developer



___
Help-gsl mailing list
Help-gsl@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gsl


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

2005-12-09 Thread g1ul10
Hi Frank,
let me try to give you a general answer which has nothing to do with GSL
library. The better, safest and probably faster way of introducing the
kind of constraints you mention is through a re-parameterization of the
problem. For instance, if you want to fit the sum of two exponentials

a_1*exp{-b_1 t} + a_2 * exp{-b_2 t}

with b_2>b_1>0 and a_1,a_2>0 rewrite the function as

exp(-d_1^2 t+c_1) *(1.+exp(-d_2^2 t +c_2))

and fit c_1,c_2,d_1,d_2. When you have the fit, compute the old
variables as

a_1=exp(c_1)
a_2=a_1+exp(c_2)
b_1=d_1^2
b_2=d_1^2+d_2^2

and use the rules of propagation of errors to find the new error
bands.

Said that, some time ago I wrote a "wrapper" function around GSL
minimization functions which implements BOUNDARIES constraints through
change of variable approach. I use it for max-likelihood fitting and
it seems to work. If you still need it, just ask.

Hope this could help,
G.

On Fri, 09 Dec 2005 10:04:14 +0100
Frank Küster <[EMAIL PROTECTED]> 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
> -- 
> Frank Küster
> Inst. f. Biochemie der Univ. Zürich
> Debian Developer
> 
> 
> 
> ___
> Help-gsl mailing list
> Help-gsl@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gsl


-- 
Giulio Bottazzi PGP Key ID:BAB0A33F 

CAFiM  Center for the Analysis of Financial Markets
LEM  Laboratory of Economics and Management
Sant'Anna School for Advanced Studies, Pisa, Italy
Phone: (+39)-050-883365   Fax: (+39)-050-883344
email: [EMAIL PROTECTED]www.sssup.it/~bottazzi/


___
Help-gsl mailing list
Help-gsl@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gsl


[Help-gsl] least-squares fitting or minimization with constrained parameters

2005-12-09 Thread Frank Küster
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
-- 
Frank Küster
Inst. f. Biochemie der Univ. Zürich
Debian Developer



___
Help-gsl mailing list
Help-gsl@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gsl