[Gsll-devel] simulated-annealing

Liam Healy lhealy at common-lisp.net
Sat Apr 10 21:45:53 UTC 2010


On Wed, Mar 31, 2010 at 8:07 PM, James Wright <james at chumsley.org> wrote:
> Hi,
>
> I've run into a couple of problems trying to get
> simulated-annealing-examples to run; they both have to do with the
> sample generic function.
>
> The first problem is that trivial-example-step calls sample with
> 'uniform as an argument instead of :uniform.  I've attached a patch to
> fix this (although a patch is probably overkill since it's such a
> trivial fix).

Thanks for the patch, applied.  Git patches are never overkill,
it's really easy to apply them!

>
> The second problem is trickier, and I don't quite know what to do
> about it.  Basically, only the mpointer of the random-number-generator
> that is passed to simulated-annealing is passed through to
> simulated-annealing-int, which means that only the mpointer is passed
> to trivial-example-step.  This results in an error when
> trivial-example-step tries to call sample on the passed-in mpointer,
> because sample only has methods defined for random-number-generators.
>
> I tried changing sa-step-function to wrap the mpointer in a
> random-number-generator before passing it through to the
> user-step-function, but that seems to cause memory problems (I think
> the wrappers free the underlying random number generator too many
> times when they get garbage-collected).
>
> Has this sort of problem been fixed elsewhere in the codebase?  If
> not, does anyone have any ideas about how to fix this?

Kind of.  The problem is trying force-fit the C model of the world
into the Lisp world.  Basically, the only purpose of passing the
pointer to the GSL routines is so that it can pass it back to your
routine.  We have better ways of communicating information in lisp.
What I did for all the other solve-minimize-fit routines where there
is a "params" argument is to pass a null pointer for the params,
because you can define your function in the appropriate lexical
environment where all your parameters are bound; there's no need to
put them into a C vector and pass them to GSL so that it can pass them
back to you.

So what I've done now in this case is define a local special
cl-generator, and bound it in simulated-annealing.  Then in the step
function, simply declare cl-generator special and use it, meanwhile
ignoring the first argument passed in to the function, which will be
the mpointer.  It's not pretty but it should work (I've tested the
example and it seems to work).

As regards the simulated-annealing in general, I think my
implementation is the weakest of anything in GSLL, so I'm happy to get
any suggestions for improvements, non-trivial examples, etc.

>
> Thanks,
>      James
>

Thank you.

Liam




More information about the gsll-devel mailing list