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
  argparser not showing all options bigal 1 229 May-22-2024, 02:54 AM
Last Post: deanhystad
  Python Project Structure for Modularity and Reusability with Multiple Entry Points b19wh33l5 0 277 Apr-24-2024, 12:21 PM
Last Post: b19wh33l5
  Budget optimization in python ronjeremiah 0 1,767 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,763 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Determine number of all the immediately adjacent points in python zackk 1 1,943 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,656 Nov-02-2020, 07:18 AM
Last Post: moose
  Help with options raiden 1 1,996 Aug-30-2019, 12:57 AM
Last Post: scidam
  Display options - screen tcpip 2 2,924 Feb-06-2018, 02:41 PM
Last Post: tcpip
  python pip - V points to old version of python metalray 5 6,468 Nov-06-2017, 03:42 PM
Last Post: metalray
  Return options Kongurinn 1 3,362 Sep-28-2017, 03:02 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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