This is the mail archive of the gsl-discuss@sourceware.org mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

alternate multimin api


Hello,

I would like to suggest supplementing the multidimensional minimization API with
a lower-level layer of access, that could at the same time support a
re-implementation of the existing API.  Although not as bulletproof as I'd
expect GSL code to be, the following brief header and sample program demonstrate
what I have in mind.

    typedef struct pointgrad_t
    {
      gsl_vector * x;
      double y;
      gsl_vector * dydx;
    } 
    pointgrad_t;

    typedef struct minsug_t
    {
      pointgrad_t best;
      pointgrad_t test;
      size_t n;

      int giveup;
      int want_y;
      int want_dydx;

      void * _minimizer_state;
    }
    minsug_t;

    minsug_t * minalgo_alloc(size_t s);
    void       minalgo_free(minsug_t * );
    void       minalgo_suggest(minsug_t *);
    void       minalgo_report(minsug_t *);

    void minimize_some_specific_fn()
    {
        minsug_t * m = minalgo_alloc(5);

        while (! m->giveup )
        {
            minalgo_suggest(m);
            if (m->want_y)
            {
                ... calculate m->test.y from m->test.x;
            }
            if (m->want_dydx)
            {
                ... calculate m->text.dydx
            }
            minalgo_report(m);
        }
    }

I think this API is an improvement on the current API for a few reasons:
- Since f(x,y), df(x,dx), and fdf(x,y,dx) routines are so tightly coupled, it
  seems natural to put their implementations together.
- It also incurs fewer function calls (although function calls are pretty fast). 
- It puts fewer constraints on the way the user implements his/her functions.
- If he/she wants to create a special structure for storing the parameters for
  his/her function, and write separate f(x), df() and fdf() routines with a certain
  declaration, and a void state pointer... he or she may still do so.
- In particular, the existing routines can be implemented using this API.
- This API suggests (and I plan to guarantee) that the buffers storing x, and
  dxdy vectors will not change from one minization iteration to the next.

Unfortunately, this API cannot be implemented in terms of the existing multimin
API.  What do the list readers think of refactoring the existing multimin
algorithms to export this API, and of re-implementing the existing API to use
this one?  I volunteer to do it under the supervisation of one of the
maintainers.

-- 
James Bergstra
http://www-etud.iro.umontreal.ca/~bergstrj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]