# [SciPy-user] minimization returns values never used in residuum function

Carlos Scheidegger cscheid@sci.utah....
Tue Aug 28 17:09:45 CDT 2007

```I would bet that if you move those prints so that they're before the changes,
you're going to see the values beyond the boundaries. fmin_bfgs has no way to
know you're optimizing within the periodic boundaries.

-carlos

> Dear list,
>
> I've defined a residuum function based on angles which is cyclic. I'm adding
> pi for values smaller zero and taking the module for values larger pi:
>
> <snip>
> def res(self, event, x=None, y=None, z=None,
>             zenith=None, azimuth=None, energy=None, level=10):
>
>         if zenith < 0:
>             zenith += math.pi
>         zenith = zenith % math.pi
>         print 'zen: %f' % zenith
>
>         if azimuth < 0:
>             azimuth += math.pi * 2
>         azimuth = azimuth % (math.pi * 2)
>         print 'az: %f' % azimuth
> </snip>
>
> The minimizer (I was using leastsq and fmin_bfgs for now) returns negative
> values and values beyond the boundaries, though it never calls the residuum
> function with these values. Here's the output when calling the minimization:
> .... fmin_bfgs example.......
> zen: 0.634435
> az: 1.198491
> zen: 0.641435
> az: 1.198491
> zen: 0.634435
> az: 1.205491
> zen: 0.634435
> az: 1.198491
> Result: array([ 57.18310254,   7.48167597])
>
> ....... leastsq example ...........
> zen: 3.116993
> az: 0.359548
> zen: 3.116993
> az: 0.359548
> zen: 3.116993
> az: 0.359548
> Result: array([-0.02459993,  0.35954834])
>
> Where in the result the numbers are zenith and azimuth, respectively.
>
> Can someone explain what's going on?
>
> Thanks, Bernhard
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

```