[SciPy-User] [SciPy-user] fmin error surface
Sebastian Berg
sebastian at sipsolutions.net
Thu Jan 20 17:29:25 EST 2011
Hello,
On Thu, 2011-01-20 at 14:07 -0800, mdekauwe wrote:
> Hi,
>
> Apologises I will use the incorrect technical terminology here...
>
> So I was playing around with the scipy simplex (fmin) and I didn't seem to
> be able to see any option to return the value evaluated by whichever cost
> function you choose. I see you can return all the minimised iterations, but
> I quite like plotting (x, y) minimised value against cost to visualise the
> error surface. The only way I can see you can do it is by editing
> optimize.py and adding
>
I think you should probably just add that to your own function that you
call, as thats rather simple. There is not much need in adding it to the
fmin itself. If you like to put it on and off easily, or like the option
of just adding it quickly to an existing program, maybe write yourself a
decorator, ie:
def store_cost(func):
x_list = []
cost_list = []
def new_func(x, *args):
x_list.append(x.copy())
e = func(x, *args)
cost_list.append(e)
return e
new_func.x = x_list
new_func.cost = cost_list
return new_func
@store_cost
def func(x):
return (x - 10)**2
fmin(func, [0])
print func.x
print func.cost
Some neat python foo for you ;)
Regards,
Sebastian
> if retall:
> allvecs = [sim[0]]
> cost = [fsim[0]]
>
> if retall:
> allvecs.append(sim[0])
> cost.append(fsim[0])
>
> if full_output:
> retlist = x, fval, iterations, fcalls[0], warnflag
> if retall:
> retlist += (allvecs, cost)
>
> I think it would be a useful thing to have returned? Or perhaps not?
>
> thanks,
>
> Martin
More information about the SciPy-User
mailing list