fmin error surface

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

fmin error surface

mdekauwe
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

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
Reply | Threaded
Open this post in threaded view
|

Re: [SciPy-user] fmin error surface

Sebastian Berg
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


_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: [SciPy-user] fmin error surface

mdekauwe
Hi,

thanks that is exactly what I want thanks for that will need to do a bit of reading as I can't quite work out how that works ha ha!

Much appreciated,

Martin

Sebastian Berg wrote
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


_______________________________________________
SciPy-User mailing list
SciPy-User@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user