[SciPy-dev] Trouble with optimize.fmin_ncg

dmitrey openopt@ukr....
Tue Jul 24 15:23:26 CDT 2007


I still have no idea...
I checked small example (below), it works ok

I don't know, maybe I did something wrong, but I removed 
/site-packages/scipy, re-installed the package from 
http://packages.ubuntu.com/feisty/python/python-scipy (ver 0.5.2), and 
your problem still makes my CPU hanging on.

can anyone who didn't update scipy from svn during last 10-11 days run 
Nils example?

Regards, D.

 >>> f = lambda x: ((x-arange(len(x)))**2).sum()
 >>> fprime = lambda x: 2*(x-arange(len(x)))
 >>> r = optimize.fmin_ncg(f, [10]*50, fprime)
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 2
         Function evaluations: 3
         Gradient evaluations: 4
         Hessian evaluations: 0
 >>> r
array([  0.,   1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.,
        11.,  12.,  13.,  14.,  15.,  16.,  17.,  18.,  19.,  20.,  21.,
        22.,  23.,  24.,  25.,  26.,  27.,  28.,  29.,  30.,  31.,  32.,
        33.,  34.,  35.,  36.,  37.,  38.,  39.,  40.,  41.,  42.,  43.,
        44.,  45.,  46.,  47.,  48.,  49.])




Nils Wagner wrote:
> On Tue, 24 Jul 2007 18:33:51 +0300
>   dmitrey <openopt@ukr.net> wrote:
>   
>> Nils, are you sure that troubles raised after last svn 
>> changes?
>>     
>
> Well, I believe it is less than 3 month ago that
> ncg worked as expected.
>
>   
>> All my changes are in func _cubicmin from optimize.py
>> but when I placed a breakpoint there, the hanging cycle 
>> didn't reached 
>> the one.
>> Can't you do the same trick?
>> scipy/optimize/optimize.py
>> line 309,
>>    d1 = empty((2,2))
>>
>> I have found the hanging cycle (optimize.py, line 1030,
>> while numpy.add.reduce(abs(ri)) > termcond: )
>> but numpy.add.reduce(abs(ri)) is constantly growing 
>> here.
>>
>> maybe you had changed x0 and now it's too far from 
>> x_opt?
>>
>>     
> Even if I start with a vector near x_opt ncg hangs.
>
> Nils
>
>   
>> btw if 2nd derivatives are not supplied, then other 
>> cycle is hanging:
>> line 1013:
>>    while (numpy.add.reduce(abs(update)) > xtol) and (k < 
>> maxiter):
>> I don't know howto fix the problem.
>> Please inform me about the breakpoint.
>>
>> BTW your func seems to be very suspicious to me
>> def R(v):
>>    rq = dot(v.T,A*v)/dot(v.T,B*v)
>>    res = (A*v-rq*B*v)/linalg.norm(B*v)
>>    data.append(linalg.norm(res))
>>    return rq      
>>
>> are you sure that the func(v)=dot(v.T,A*v)/dot(v.T,B*v) 
>> is convex?
>> I'm not.
>> So using 2nd derivatives (or their approximating by 
>> fmin_ncg  (if user 
>> didn't provide that ones) , in line 1033:
>>                    Ap = 
>> approx_fhess_p(xk,psupi,fprime,epsilon)
>> )
>> will handle non-convex funcs much more bad than 1-st 
>> order do.
>>
>> HTH, D.
>>
>>
>>     
>  
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-dev
>
>
>
>   



More information about the Scipy-dev mailing list