ev, subst, funmake, quote, apply ... argh!



On Dec 25, 2007 8:07 PM, dlakelan <dlakelan at street-artists.org> wrote:
> In my attempt to create a simulated annealing minimizer, I'm baffled by
> the following problem.
>
> Suppose I define a function which computes a figure of merit (rather
> than an expression, this is more of a computational function). An
> example, I want to minimize the max absolute error of my polynomial
> across a table of x,y values.
>
> xypairs := [[1,1],[2,3],[3,7],[5,4],[8,9]];
>
> err(a,b,c,d) := lmin(map(lambda([x,y],float(abs(a+b*x+c*x^2 - y))),
> xypairs)))

What you probably wanted to do here was

  err(a,b,c) := lmax(map(lambda([x,y],float(abs(a+b*x+c*x^2 - y))), xypairs)))

(d does not appear on the right and if you are looking for minimum
error then you can just set one error to zero).

In this case you should use linear programming to solve this problem.
Note that err>abs(expr) is equivalent err>expr, err>-expr:

(%i28) load(simplex)$
(%i29) err1(a,b,c) :=
  flatten(
    map(lambda([z],
               [float(e>a+b*z[1]+c*z[1]^2-z[2]),
                float(e>-a-b*z[1]-c*z[1]^2+z[2])]),
        xypairs))$
(%i30) err1(a,b,c)$
(%i31) minimize_lp(e, %);
(%o31) [2.11,[c=-.07000000000000003,b=1.17,a=2.01,e=2.11]]
(%i32) time(%o31);
(%o32) [0.04]

You will get better results faster.

HTH

-- 
Andrej