tag:blogger.com,1999:blog-12983281.post-56704352381293609312008-01-30T08:19:00.000-08:002008-12-09T19:14:50.428-08:00'Programming Collective Intelligence' in Common Lisp, Chapter 5 - OptimizationsBack 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 <a href="http://blubparadox.googlepages.com/optimize.lisp">the generic optimizations</a> and <a href="http://blubparadox.googlepages.com/socialnetwork.lisp">the social network</a>.<br /><br />For these python translations I'm growing fond of the <a href="http://superadditive.com/projects/incf-cl/">(incf cl) utilities</a>. It includes macros to make list comprehensions in Lisp, so<br /><pre><code><br />sol=[random.randint(domain[i][0],domain[i][1])<br /> for i in range(len(domain))]<br /></code></pre><br />becomes<br /><pre><code><br />(defun range-random (low high)<br /> (+ low (random (1+ (- high low)))))<br />...<br />(let ((sol (assemble (range-random (car x) (cdr x)) (<- x domain)))) </code></pre><br />I know that one would be just as easy with mapcar, see incf-cl for better examples.<br /><br />Here's a graph made from a simulated annealing optimization of the social network graph:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_HdYrIZK4E04/R6CkfiCDFFI/AAAAAAAAADI/pGM6AANlla8/s1600-h/social.jpg"><img style="cursor: pointer;" src="http://4.bp.blogspot.com/_HdYrIZK4E04/R6CkfiCDFFI/AAAAAAAAADI/pGM6AANlla8/s400/social.jpg" alt="" id="BLOGGER_PHOTO_ID_5161306034584884306" border="0" /></a><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12983281-5670435238129360931?l=i-need-closures.blogspot.com'/></div>Richard Cookhttp://www.blogger.com/profile/11838741004941594394noreply@blogger.com1