Python Forum
how to specify options or tickle python to output points swept by the optimization?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to specify options or tickle python to output points swept by the optimization?
#1
I need the list of points (x,y) python uses to reach the minimum. But the best I can find at the moment is to output the x coordinates of the list of points as shown below

>>>[xopt, fopt, iter, funcalls, warnflag, allvecs] = optimize.fmin(eng,[-1],disp=True,retall=True,full_output=True)

>>> print(xopt)
[8.8817842e-16]

>>> for items in allvecs:
... print(items)
...
[-1.]
[-0.9]
[-0.7]
[-0.3]
[0.1]
[-0.1]
[8.8817842e-16]

Is there a different optimization function which might output both x and y coordinate of the optimization path? If not, then would it be feasible to tickle the source code of scipy to achieve this feature?
Reply
#2
Use callback parameter, something like this:

values_storage = list()
def my_callback(x):
    values_storage.append(eng(x))
    
 ... = optimize.fmin(eng,[-1],disp=True,retall=True,full_output=True, callback=my_callback)

for a, b in zip(allvecs, values_storage):
    print(a, b)
Reply
#3
Thank you, scidam! Although not fully understand how callback works, I get your point requesting an extra function evaluation at given x instead of receiving it directly from fmin. Since my function evaluation can be expensive, I wonder whether there is a more straightforward way to get f(x) directly from the optimization procedure.
Reply
#4
(Aug-02-2019, 05:56 AM)bsmile Wrote: Since my function evaluation can be expensive, I wonder whether there is a more straightforward way to get f(x) directly from the optimization procedure.
I don't think it is possible without intervention to the source code of fmin. Usually, optimization algorithms do a lot of function calculations at different points, so one additional calculation in the callback should not significantly impact on total time required for minimum finding.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Project Structure for Modularity and Reusability with Multiple Entry Points b19wh33l5 0 100 Yesterday, 12:21 PM
Last Post: b19wh33l5
  Performance options for sys.stdout.writelines dgrunwal 11 3,139 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  Budget optimization in python ronjeremiah 0 1,721 May-16-2021, 01:18 PM
Last Post: ronjeremiah
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,655 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Determine number of all the immediately adjacent points in python zackk 1 1,871 Feb-06-2021, 09:23 AM
Last Post: zackk
  How can I scroll over my data points when creating plots in Python? (I'm using Spyder moose 0 1,612 Nov-02-2020, 07:18 AM
Last Post: moose
  Can argparse support undocumented options? pjfarley3 3 2,210 Aug-14-2020, 06:13 AM
Last Post: pjfarley3
  Help with options raiden 1 1,931 Aug-30-2019, 12:57 AM
Last Post: scidam
  Options for retaining persistent data? hunnimonstr 4 2,968 Feb-14-2018, 07:49 PM
Last Post: hunnimonstr
  Display options - screen tcpip 2 2,842 Feb-06-2018, 02:41 PM
Last Post: tcpip

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020