Wednesday, January 30, 2008

 

'Programming Collective Intelligence' in Common Lisp, Chapter 5 - Optimizations

Back from the holidays and plowing through the chapters again. The explanation for the various optimizations was good, but I had a hard time figuring out a more "Lisp-like" way of doing the code. Either there isn't, or I haven't quite reached Zen-like Lisp nirvana. I'm open to improvements, here's the code for the generic optimizations and the social network.

For these python translations I'm growing fond of the (incf cl) utilities. It includes macros to make list comprehensions in Lisp, so

sol=[random.randint(domain[i][0],domain[i][1])
for i in range(len(domain))]

becomes

(defun range-random (low high)
(+ low (random (1+ (- high low)))))
...
(let ((sol (assemble (range-random (car x) (cdr x)) (<- x domain))))

I know that one would be just as easy with mapcar, see incf-cl for better examples.

Here's a graph made from a simulated annealing optimization of the social network graph:

Comments:
Cool to see you back at posting things. It made me go back to the book as well -- thanks a lot for prodding me. :-)

I haven't had much time to work on this but will go on holidays tomorrow, so I better publish what little I have to let you know there are people out there who care.

I was going to try to more tightly couple a solution and its domain so one can check validity, create derivative solutions etc. without having to constantly hold on to the domain.

My attempt (written from scratch and thus quite empty) is at http://i-need-closure.pastebin.com/f212e697b
(apologies for stealing your title -- I thought it gave context to the posts).

For schedule.lisp (at http://i-need-closure.pastebin.com/f3a1a0a91) I started with your code and started making changes a) to fit my class and b) to use loop more making things more readable IMO. I am still not happy about schedule-cost -- the second loop should not have to decode the whole solution again; I should have collected the arrival and departure times in the first loop and should just iterate over that list in the second loop. But hey, it's a start...

BTW: All code untested so far as I wasn't far enough to actually test anything.

Thanks again and keep on posting!
 
Hallo,
Ich haben eben Eure Internetseite besucht und nutzen sogleich die Gelegenheit,euch auch einen Gruß aus Deutschland in Eurem Gästebuch zu hinterlassen. P.S. Kommt uns doch auch mal besuchen
Urlaub an der Ostsee
oder Nordsee

 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?