[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: constrained_min




Glenn Newnham <gnewnham@ses.curtin.edu.au> writes:

> I'm using constrained_min to find model parameter values which minimise
> the difference between modelled and measured data. The measured data is
> contained in various ascii files.
> 
> At present my program opens the ascii file within the function to be
> minimised. this slows processing because the file is opened and closed
> every time constrained_min tries a new parameter set.
> 
> Is there a way to read in these variables in the main program and make
> them global or to pass them to the function within the constrained_min
> command?

First suggestion: this is indeed a place for common blocks.  It's
ugly, but that's because constrained_min doesn't provide a way for you
to get auxiliary data into your function (ie, by using _EXTRA, or a
private parameter).

At command line:
common mydata, x, y, err
read_data, x, y, err

In function:
function doodad, p
  common mydata, x, y, err
  ;  .. compute function value ...
  return, f
end

However, I have a second suggestion: You sound like you may doing
least squares curve fitting.  This is really a quite specialized
application which is accomplished by CURVEFIT (IDL library) and MPFIT
(available from my web page).  If you need to satisfy simple bounding
constraints, then MPFIT is probably a good choice for you.  Not only
is it a quite robust algorithm, but it also allows you to set
parameter constraints.  It may be as simple as:

fit_params = mpfitfun('DOODAD', x, y, err, start_params)

and can be customized from there.

I've recently updated another program TNMIN, available from the same
web page.  This function does more sophisticated function minimization
and also allows you to pass private data such as data values using the
FUNCTARGS keyword.  It's overkill for curve fitting though.

Good luck,
Craig
Web page: http://cow.physics.wisc.edu/~craigm/idl/idl.html
  (under Fitting and Tutorial)


-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------