# [Tutor] leastsquares.py

mdcooper mdcooper at uvic.ca
Thu Dec 30 22:20:02 CET 2004

```Hi Pierre,

you are correct - the methods that simply refuse negative results will not be
sufficient.

The code I have so far is attached as *.py files.

Thanks,

Matt

Be aware that I have adusted _lsq2.py so that it can be shown to the world -
it still contains a basic outline of what should be done but it may not look
too efficient.

>===== Original Message From Pierre Barbier de Reuille
<pierre.barbier at cirad.fr> =====
>Alan Gauld a écrit :
>>>I am trying to use a least squares method (the one written by Konrad
>>
>> Hinsen),
>>
>>>but I do not want the method to be able to generate negative values.
>>
>> Is there
>>
>>>a way to stop least squares programs from doing so?
>>
>>
>> def _leastSquare():
>>     # do the thing that might generate negatives
>>
>> def leastSquare():
>>     firstTry = _leastSquare()
>>     if firstTry < 0:
>>       return leastSquare() #  try again
>>     else:
>>       return firstTry
>>
>> Primitive but it works. If you want more a efficient/elegant solution
>> show us what you have...
>
>How is this suppose to work ? Most of the least square algorithm find
>the nearest local minimum of the distance function. So, if you call many
>times the least square function without changing the initial values it
>will do absolutely nothing ! Or what do you suppose for your least
>square method ?
>
>>
>> Alan G.
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>--
>Pierre Barbier de Reuille
>
>INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
>Botanique et Bio-informatique de l'Architecture des Plantes
>TA40/PSII, Boulevard de la Lironde
>34398 MONTPELLIER CEDEX 5, France
>
>tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
A non-text attachment was scrubbed...
Name: _lsq2.py
Type: application/octet-stream
Size: 2052 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20041230/03292787/_lsq2-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LeastSquares.py
Type: application/octet-stream
Size: 4139 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20041230/03292787/LeastSquares-0001.obj
```