patchGNU Octave - Patches: patch #8918, fgridsearch as a gridsearch...


patch #8918: fgridsearch as a gridsearch alternative to fminsearch

Submitted by:  Max Görner <maxg>
Submitted on:  Fri 26 Feb 2016 09:49:36 AM UTC  
Category: Core : new functionPriority: 5 - Normal
Status: NonePrivacy: Public
Assigned to: NoneOpen/Closed: Open

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 07 Jul 2016 05:31:52 AM UTC, comment #5:

Hi Kai,

I am not sure what you want to improve in Example III. The interval fminsearch function's focus is to find fval. If you are interested in the corresponding x values, you can find them with the interval fsolve function. Use optimset parameters on either function to improve accuracy.

I must agree that the function is not very useful as a generic tool, because it doesn't do much more than "min (f (meshgrid (...)))" would do. I would consider to use it in special cases where I know that my grid is good and not too big.

There is no bisection or heuristics of any kind, so all we have is a "brute force" attempt to traverse the grid.


Wed 01 Jun 2016 01:09:08 PM UTC, comment #4:

Please don't feel discouraged, but I really want to understand, what makes your function better than existing tools.

Looking at your examples, I don't like them, as they only reveal things I don't understand about your algorithm or need more documentation:

Example I - is in my opinion as elegant as writing the code of comment #1, and the results are only as good as choosing the grid.

Example II - has four equal minima on each edge of the grid! Here the code of comment #1 would even perform "better". This behavior of finding only one (and which one?) minimum must be clearly documented to be reliable.

Example III - My understanding of the example is a minimum near [-100 -100] with fval=-10. Maybe document this, it is tedious to find out.

Moreover I think this example just shows the feature of function handles and totally misleads, what fgridsearch should do.

fgridsearch does not (as I thought) search in this example for a minimum on the grid using fminsearch to help this. The returned params lies on the grid

but the function value for params is not the minimum!

It is just a point from the grid, that converged to the smallest local minimum MAYBE on the grid, as fminsearch embedded in @gh does not care about the given grid. In the following input, the starting point lies on the grid, but converges outside, and this is what fgridsearch would return without any warning for this example!

I think for global optimization the overloaded fminsearch for intervals
does a "better" job. I respects the boundaries and delivers rigorous inclusions. Using the interval package, I get:

Here I am sure to find the global minimum within these bounds. I added the package maintainer, maybe he can give a hint on how to improve Example III with his interval package.

Kai Torben Ohlhus <siko1056>
Project Member
Tue 31 May 2016 09:57:19 AM UTC, comment #3:

I improved the documentation a tiny bit. Most importantly, I added another example which demonstrates more clearly why I consider fgridsearch to be beneficial. I'll copy the example here for convenience:

I have to admit that this function only helps to hide loops, though.

If the new example makes the function interesting, I'll happily work on the other points.

(file #37315)

Max Görner <maxg>
Mon 14 Mar 2016 08:38:18 PM UTC, comment #2:

I want to address only the question about the need of this function now.

You're right when you note that the function in the example can be written as in your small listing. However, that's not the whole story. You can pass in any function taking any number of inputs and you'll get back the best value found by a gridsearch. Think of a complex model for which some meta parameters need to be found. This saves plenty of loops and can make more readable.

If this is considered interesting, I'll try to fix the other issues.

Max Görner <maxg>
Tue 08 Mar 2016 12:46:13 PM UTC, comment #1:

This function basically does something according to the following code:

Some points to consider:

1. This function is not MATLAB compatible. Is there a particular reason/scientific discipline, that needs this function and is not able to write code, like the small listing above?
2. The documentation is not very detailed, better document the input and output. See other Octave functions as guideline:

3. Does this function work for dimensions > 2?
4. How does this function perform for large scale problems?
5. I notice function crashes, without help for the user, for nonconforming input like

To sum up, I don't see the benefits of this function. If one needs to evaluate the whole optimization domain, like fgridsearch does, one will code something like in this post above. fminsearch addresses another use case, where only the optimum matters and from this point one can try to evaluate a local grid, to save lots of computational effort.

Kai Torben Ohlhus <siko1056>
Project Member
Fri 26 Feb 2016 09:49:36 AM UTC, original submission:

I wrote a small function performing a gridsearch on a function handle.

The benefit is mainly that one saves multiple nested loops, so code using this function gains readability. Furthermore, in an utopian future that function might be parallelised better than nested loops.

Another benefit is that one can get back all function evaluations, so an detailed analysis of the results can be done. This is not possible with fminsearch at the moment.

I would be glad for any criticism of that function. Furthermore I think that it would be a good alternative to have either in Octave itself or in the optim package.

Max Görner <maxg>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #37315:  fgridsearch.m added by maxg (3KiB - text/x-objective-c)
file #36470:  fgridsearch.m added by maxg (2KiB - d2l/unknowntype)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by lachlan (Updated the item)
  • -unavailable- added by siko1056
  • -unavailable- added by siko1056 (Posted a comment)
  • -unavailable- added by maxg (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 07 Jul 2016 02:06:34 AM UTClachlanCategoryNone=>Core : new function
    Wed 01 Jun 2016 01:09:24 PM UTCsiko1056Carbon-Copy-=>Added oheim
    Tue 31 May 2016 09:57:19 AM UTCmaxgAttached File-=>Added fgridsearch.m, #37315
    Fri 26 Feb 2016 09:49:36 AM UTCmaxgAttached File-=>Added fgridsearch.m, #36470

    Back to the top

    Powered by Savane 3.1-cleanup1