lqsuares module



Hi,

Robert Dodier wrote:
> On 5/20/07, Jussi Eloranta <Jussi.Eloranta at csun.edu> wrote:
> Jussi, thanks for your message. Looking over lsquares.mac,
> I believe it can be simplified quite a lot. Some things come to mind.
> (1) Preserving the calls to solve and mnewton isn't important.
> At the time lsquares was written, Maxima didn't have any better
> way of solving minimization problems, now there is lbfgs.
> (There are also specialized methods for least squares problems,
> but Maxima doesn't include any of those yet.)

Yes, I noticed. Since I have never programmed anything in maxima, took 
me a while to figure out how things work...
This, of course, also implies that you should really double check what I 
have done ;-) I wanted to keep everything in such way
that it retains backwards compatibility (hence mnewton et al. are there 
and default return is just the function).

And yes, it would be nice to have a special method for linear least 
squares (and simple extensions, line exp, etc., which can be converted
into linear least squares problems). This would give error estimates for 
the parameters as well (which you can't get from the non-linear
generic case). For example, the grace program has a decent collection 
and one could find good pointers there how to do things.
I could try to do something here but it will still take me some time 
before I am sufficiently comfortable with maxima programming...

> (2) I don't like putting print messages into the body of a function.
> In various interesting scenarios, there is no one at the console.
> Also, once the messages go by, they are lost (you don't see them
> again by displaying the return value again.)

Yes, the prints should be eliminated (or one should be able to enable 
iteration progress by special request).

> (3) Other functions for solving equations return just a list
> like [x = ..., y = ..., z = ...] (and not an equation with those
> values substituted). I believe lsquares should do likewise.
>

I think that it would be good to have the function as a first element 
(with the optimal parameters substituted in) because that would
make plotting the result so much easier. If you just get the variables, 
you have to re-eval the
function with the parameters. I seem to recall that mathematica gives 
the results this way.
This might make sense for lbfgs too as it could return the function 
value at the minimum as the
first element. This might not seem such a big issue for maxima gurus but 
people who just use it
occasionally would find this much easier.

> Solving least squares problems is an important application,
> so we should fix up lsquares. Thanks for bringing this to our
> attention. I'll put it on my to-do list.
Yes. I have just started to convert everything I use in teaching to 
maxima (from mathematica). I want my students to be able to do work
at home without having to pay $$$$$ for licenses and I want to be able 
to modify/fix the source code, if necessary.

Anyway, keep up the good work. It is really great that some people have 
put their time to write maxima!

Jussi Eloranta
Department of chemistry and biochemistry
Cal State Northridge