11-16-2022 11:35 AM
Hello, hello,
Say I have a function f(a,b). I'm looking for the 2 values of a and b within a certain range that will give the highest value for f.
I looked through the Advanced Analysis Library without finding anything (but sometimes the names aren't obvious). Any idea ?
Thanks
11-16-2022 12:36 PM
Well, this is a simple 2D optimization problem (independent of programming language) and it really depends how the f(a,b) surface looks like. Is it a simple smooth surface? Is it highly convoluted with many local maxima? Are a,b integers or floating point values?
11-20-2022 01:49 PM - edited 11-20-2022 01:53 PM
Why doesn't MaxMin2D work for you?
Well, of course, you need to evaluate it for a range of values first, and that may cause some issues as Altenbach suggested, but what other option do we have until the Wolfram symbolic solver is implemented into CVI 🙂
11-21-2022 03:26 AM
@ebalci: it's a function, not an array.
@altenbach: yes, it's a highly convoluted function, with discontinuities, so non derivable. I've tried 2 methods so far:
- Limited memory BFGS with a fake derivatives Df/Da=(f(a+D, b)-f(a,b))/D and Df/Db=(f(a, b+D)-f(a,b))/D but it fails immediately to converge.
- Nelder-Mead, it kinda works but converges to a wrong solution.
I'm gonna do some 2D or 3D plotting of my function to try and understand why, unless someone has other methods I can try.
11-21-2022 06:54 AM
The function also returns the indices that give the max/min value.
Isn't that enough? Or maybe I couldn't understand your question.
11-21-2022 12:50 PM
@ebalci wrote:
The function also returns the indices that give the max/min value.
Quantized to the chosen grid and the real solution could be completely elsewhere! 😄
For better accuracy, the NxM grid needs to be very fine. Your solution is also of O(N²) complexity and can get very expensive.
If the OP would attach the formula of the function and the the bounds for a and b, I could take a stab at it. 😄
11-22-2022 07:02 AM
Indeed, the function is very CPU intensive, so it's important to minimize the number of calls. I can't give the function because it is itself a Linear fit between a large dataset and a set of theoretical points. Only 2 parameters control this matching, hence the 2D function I want to minimize.
11-23-2022 04:24 AM
I've done some 2D and 3D plots of my function and it's pretty obvious that there are edge cases that are divergent, so I need to work on a better definition for now... Or even the best methods will be useless !
Anyway I've found a whole bunch of methods: Nelder-Mead, Powell, CG, BFGS, L-BFGS-B, Newton-CG, TNC, COBYLA, SLSQP, trust-constr, brute force, simulated/dual annealing... I'm just surprised not to see any in the Advanced Analysis Lib.