octave-maintainers
[Top][All Lists]
Advanced

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

Re: bfgsmin iterations


From: Michael Creel
Subject: Re: bfgsmin iterations
Date: Thu, 14 May 2009 09:35:25 +0200

On Wed, May 13, 2009 at 8:59 PM, Levente Torok <address@hidden> wrote:
> Dear Michael / Przemek and all,
>
> Since fmins is relying on bfgsmin for pure theoretical reasons, I believe it
> is fairly crucial to have it implemented in a fast way.
> So I made the following modifications to it.
>
> ////////////////////////////
>
> // the compares two octave_values (thanks to jwe)
> bool isequal (const octave_value& a, const octave_value& b,
>           bool nans_compare_equal = false)
> {
>    octave_value_list args;
>
>    args(2) = b;
>    args(1) = a;
>    args(0) = nans_compare_equal;
>
>    octave_value_list tmp = feval ("__isequal__", args, 1);
>
>    // We expect __isequal__ to always return a single logical scalar.
>    return tmp(0).bool_value ();
> }
>
> // this is cache on feval to prevent the extra evaluation of the
> // objective function when subsequent calls with exactly the same arguments 
> would take place
>
> octave_value_list _feval( const std::string f, const octave_value_list f_args 
> )
> {
>    static octave_value_list f_args_prev;
>    static octave_value_list ret;
>
>    // check if ( f_args_prev == f_args )
>    bool same = true;
>    for( int i=0; i < f_args.length(); i++)
>    {
>        if (!isequal( f_args(i),f_args_prev(i)))
>        {
>            same = false;
>            break;
>        }
>    }
>    if (same)
>        return ret;
>
>    f_args_prev = f_args;
>    ret = feval( f, f_args );
>
>    return ret;
> }
> ///////////////////////////
> And replaced the "feval"-s with "_feval"-s.
> I submitted it into the SVN.
>
> Levente
>

These changes look reasonable to me, but I would also appreciate it if
you would carefully check that they actually work. Most importantly,
the algorithm is still as robust as it was? Of secondary importance to
me is verifying that this gives a speedup. The best solution to
duplicate calls would be to find out why they are occurring, and fix
that. This caching method is introducing new code that needs to be
evaluated EVERY time. Maybe the overhead of the new code is worse than
the occasional duplicate call. To check this, you could use the
bfgsmin_example.m script,

I am very glad that you are looking at the code. Thanks.

Regards, Michael



reply via email to

[Prev in Thread] Current Thread [Next in Thread]