On Dec 25, 2007 2:07 PM, dlakelan <dlakelan at street-artists.org> wrote:
> Suppose I define a function which computes a figure of merit ...
> err(a,b,c,d) := lmin(map(lambda([x,y],float(abs(a+b*x+c*x^2 - y))),
> xypairs)))
>
> now I want to do something like this...
>
> minimize_sa(err(a,b,c,d) [a,b,c,d],[1,2,3,4]...)
>
> now for a regular function, err(a,b,c,d) will be evaluated BEFORE
> minimize_sa is called and therefore fail because err can't handle
> symbolic values in any useful way... so my inclination is to quote it...
>
> minimize_sa('err(a,b,c,d),....)
>
> however, when minimize_sa applies "subst" to this quoted expression it
> seems to evaluate to something like err(1,2,3,4) rather than actually
> calling the function err with those values. Even "ev" causes this
> behavior as far as I can tell. in other words, i think this is a "noun"
> form yes??
>
> If I pass "funmake(err,[a,b,c,d])" to the minimizer it seems to work,
> when I use "ev" within the minimizer code. but how should I handle this?
> In other words, what's the "right" way?
>
The simplest way to do this is
minimize_sa('(err(a,b,c,d)),...)
The potential problem with this is that any free variables in the quoted
expression will only be evaluated when you evaluate the expression, not when
you call minimize_sa. This is usually not a problem, but can be in some
cases; I wouldn't worry about it for now unless you want to do things like
multidimensional_minimze ( makelist( '(err(x,param)), param, [val1,
val2, val3] ) , ...)
There's a way to handle that, too (hint: use subst), but I won't complicate
this answer unless the case really comes up.
-s
-s