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
becomes
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:
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: