[SciPy-dev] iterative callback function signature
Nathan Bell
wnbell at gmail.com
Tue May 20 16:52:36 EDT 2008
On Mon, May 19, 2008 at 4:41 PM, Neilen Marais <nmarais at sun.ac.za> wrote:
>
> if callback is not None and iter_ > olditer:
> callback(x)
>
> I'm a bit uneducated about the meaning of all the iterative variables,
> but is there a way I can obtain the residual from x here? Otherwise,
> would it not make sense to allow more complicated callback functions?
>
Neilen, since you know A and b when you call the iterative solve you
can compute residuals like so:
A = ..... #some matrix
b = ..... # some rhs
residuals = []
def callback(x):
residuals.append(norm(b - A*x))
x,info = cg(A, b, callback=callback)
# residuals now contains ||b-A*x|| at each iteration
--
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/
More information about the SciPy-Dev
mailing list