octave-maintainers
[Top][All Lists]
Advanced

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

Re: bfgsmin iterations


From: Levente Torok
Subject: Re: bfgsmin iterations
Date: Wed, 13 May 2009 20:59:51 +0200
User-agent: KMail/1.11.2 (Linux/2.6.27-11-generic; KDE/4.2.2; i686; ; )

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


On Wednesday 13 May 2009, you wrote:
> Hi Levente,
> I agree that it seems to be doing some unnecessary calls. One
> possibility is that the duplicate calls occur when there is a switch
> in the step size  algorithm from Newton to bisection. You might want
> to run this with maximum verbosity to see what's going on. If I find
> some time I'll try to look at this, but it might take me a while to
> get to. I think that a little review by a C++ literate person might
> greatly benefit __bfgsmin.cc. I'm strictly an amateur, and
> __bfgsmin.cc was the code I learned with.
> Regards, Michael
> 
> On Wed, May 13, 2009 at 10:27 AM, Levente Torok <address@hidden> wrote:
> > Dear Michael Creel,
> >
> > I used your bfgsmin implementation and I found that it evaluates the
> > objective function unnessessarily many times.
> > I have recorded the points at which my function was evaluated
> >
> > Please find the enclosed png file. x axis - iteration, y - value of my 1 
> > dimensional obj.func parameter.
> > And this is the array in which I recorded the location of the evaluations
> > z=[
> >   3.00000000000000e+02
> >    6.00000000000000e+02
> >    1.00000000000000e-01
> >    4.50000000000000e+02
> >    4.50000000000000e+02
> >    1.50000000000000e+02
> >    1.00000000000000e-01
> >    1.00000000000000e-01
> >    2.25000000000000e+02
> > ...
> >
> > As I see it usually calles the obj.func two times with exactly the same 
> > argument.
> > I'd like to know it if is normal and if so, isn't there an easy way of 
> > doing a caching
> > instead of double calling.
> >
> > Levente
> >
> > --
> > Blogger of http://fapuma.blogspot.com
> >
> >
> 


-- 
Blogger of http://fapuma.blogspot.com



reply via email to

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