[SciPy-User] [SciPy-user] fmin_cg - using the same inverse calculation in func and fprime

gibbon Neale.Gibson at astro.ox.ac.uk
Tue Jul 19 06:39:44 EDT 2011


Thanks Oleksandr

That seems to have done the trick - I forgot lists/dictionaries passed to a
function were by reference and could be accessed without returning them.
I've decided to use a list instead as follows;

list = [K,]
p1 = fmin_cg(frime,p0,args=(list,),fprime=fprime)

and both func and fprime can now manipulate and store the matrix K. I don't
think the optimisation functions in general always evaluate the func and
then fprime (and the Hessian for ncg) in order, so a few messy if clauses
might be necessary to check if the inverse matrix has been updated for each
new parameter set.

Thanks again for your help.


sanGuziy wrote:
> 
> You could use the same dictionary in both functions and save the inverses
> to
> it.
> (a=>inv(a))
> --
> Oleksandr
> 
> 2011/7/18 gibbon <Neale.Gibson at astro.ox.ac.uk>
> 
>>
>> Hi all
>>
>> I'm looking some help in using fmin_cg to optimise a function. Basically
>> I
>> provide a function and its gradient as follows;
>>
>> > p1 = fmin_cg(func,p0,fprime=frime)
>>
>> and everything works fine. However, both func and fprime require the same
>> matrix inversion at each step (via cholesky factorization). As matrix
>> inversion is expensive, ideally I would like to calculate it only once
>> per
>> step, and use the matrix inverse calculated by func in the fprime
>> function
>> without having to repeat the calculation.
>>
>> Is this possible? ie to use the inverse calculated in func in the frime
>> function as well?
>>
>> Thanks for any help.
>> --
>> View this message in context:
>> http://old.nabble.com/fmin_cg---using-the-same-inverse-calculation-in-func-and-fprime-tp32085615p32085615.html
>> Sent from the Scipy-User mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
> 
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
> 
> 

-- 
View this message in context: http://old.nabble.com/fmin_cg---using-the-same-inverse-calculation-in-func-and-fprime-tp32085615p32089558.html
Sent from the Scipy-User mailing list archive at Nabble.com.




More information about the SciPy-User mailing list