[SciPy-user] Convergence behaviour of iterative solvers

Nils Wagner nwagner at iam.uni-stuttgart.de
Fri Jan 19 11:12:32 CST 2007


On Fri, 19 Jan 2007 17:38:36 +0100
  "Ed Schofield" <edschofield at gmail.com> wrote:
> On 1/19/07, Nils Wagner <nwagner at iam.uni-stuttgart.de> 
>wrote:
>>
>> Matthew Brett wrote:
>> > On 1/19/07, Giovanni Samaey 
>><Giovanni.Samaey at cs.kuleuven.be> wrote:
>> >
>> >> I needed this as well and I altered the GMRES 
>>function in scipy's
>> linalg
>> >> file as follows:
>> >>
>> >> I added an input parameter prnt and
>> >> added at line 618 the following lines
>> >>
>> >> if prnt:
>> >>     print "#GMRES: ", nbiter,resid
>> >>
>> >
>> > Or maybe an observer function of some sort for more 
>>flexibility:
>> >
>> > def show_convergence(nbiter, resid):
>> >    print "#GMRES: ", nbiter,resid
>> >
>> > def solver(...., observer_func = None)
>> > ...
>> > if observer_func:
>> >    observer_func(nbiter, resid)
>> >
>> > sort of thing.
>> >
>> > Matthew
>> > _______________________________________________
>> > SciPy-user mailing list
>> > SciPy-user at scipy.org
>> > http://projects.scipy.org/mailman/listinfo/scipy-user
>> >
>> Whatever will be implemented in the future it would be a 
>>nice enhancement.
>>
>> +1 for a monitoring function.
>>
>> I can file a ticket if needed.
> 
> 
> A few months ago I added a callback argument to various 
>nonlinear solvers in
> optimize.py. We might as well aim for the same syntax 
>for the linear
> solvers. It should be easy to do...
> 
> -- Ed
  

So how can I use this functionality within the following
script
from scipy import *

def func(x):
     return 0.5*dot(x,dot(A,x))-dot(x,b)

def callback(x):
     return linalg.norm(dot(A,x)-b)

n = 10
x0 = zeros(n,float)
A = random.rand(n,n)+diag(4*ones(n))
A = 0.5*(A+A.T)
b = random.rand(n)

x = optimize.fmin_cg(func,x0)

Nils



More information about the SciPy-user mailing list