The installation went smoothly for me. Don’t be surprised if your hard-drive is busy for a about half an hour after you first boot up; that’s Leopard’s Spotlight search program indexing your hard drive.

I want to focus on some of the new features for developers, particularly the upgrade of the Objective-C programming language to version 2.0, and the upgrade of the XCode integrated development environment to version 3.0.

Objective-C is an object-oriented version of C, dating from the early 1980’s, which is a strict super-set of C; that means ordinary C programs will compile successfully under an Objective-C compiler. That makes Objective-C sound a lot like C++, but I like Objective-C a lot more than C++. C++ takes a “Swiss army chainsaw” approach, throwing many new features into the language, while Objective-C is much more minimalist, basically extending the language just to support objects with a Smalltalk-like syntax. Objective-C is also much more dynamic than C++; much more is decided at run-time rather than compile-time. Because of that, it feels a lot closer to programming with a nice scripting language like Python or Ruby. Here’s an excellent introduction to the Objective-C language by Apple; it’s a surprisingly literate piece of technical documentation.

Objective-C is almost never used by itself, instead you use it in conjunction with a set of extensive libraries (the Cocoa libraries on Mac OS X or the GNUstep libraries on Linux or Windows). Cocoa and GNUstep derive from the NeXTStep and OpenStep libraries developed by the NeXT Computer company in the 1980’s and 1990’s. They add both fundamental features (e.g. string handling features, hash tables, that type of thing) and GUI-creation features. These libraries have been under development for 20 years, so they are extraordinarily mature. And since Apple uses Cocoa and Objective-C to develop all of its applications, including Mac OS X itself, it is clear that if you want to develop desktop applications for the Macintosh, you need to learn about them.

I actually believe that using Objective-C and GNUstep is also a very reasonable choice on Linux (or Windows), for those types of applications where you would otherwise use C++, but few people actually make that choice. In fact, I have found that GNUstep and Cocoa are compatible enough that one can pretty easily maintain code that works on all platforms if you need that.

Apple provides a very nice integrated development environment called XCode for free with Mac OS X. If you have not upgraded to Leopard, you’ll be limited to XCode 2.5, while Leopard gives you XCode 3.0. One of the nicest parts of XCode is the “Interface Builder,” which lets you build GUI’s using a GUI instead of by writing code.

With Leopard, Objective-C is being upgraded to version 2.0. Perhaps the most important new feature included is garbage collection. It’s an opt-in system, so legacy code will still work, and you can turn it off if you like allocating and releasing memory yourself, but for new code, most developers will obviously be very happy to have it. This removes one of the major warts of the Objective-C language.

To learn more about building desktop applications for Mac OS X, I highly recommend “Cocoa Programming for Mac OS X” 2nd edition, by Aaron Hillegass. I only wish that there was a third edition that covered the new features of XCode, Objective-C and Cocoa that have appeared in Tiger and Leopard. (UPDATE: Apparently, a 3rd edition is scheduled for Spring 2008.)

If you’re interested in programming Macintosh applications, but prefer to use Ruby, Python, or Haskell instead of Objective-C, you should know about RubyCocoa, PyObjC, and HOC, which let you call the Cocoa libraries from those languages. These tools are very nice, (I’ve actually only used PyObjC personally) but you’ll still need to have some familiarity with Objective-C to understand them.

“Structure and Interpretation of Classical Mechanics,” (SICM) by Gerald Jay Sussman and Jack Wisdom, with Meinhard Mayer, is a fascinating book, revisiting classical mechanics from the point of view that everything must be computationally explicit. I already mentioned the book in a previous post.

The book is available online, and all the software is freely available on-line as well. The software is written in Scheme, and a very extensive library called “scmutils” was developed to support computations in classical mechanics, including implementations of many symbolic and numerical algorithms.

I think that many scientists and programmers could find the “scmutils” library to be generally useful, even if they are not particularly interested in classical mechanics. If you are using the GNU/Linux operating system, there’s no problem in getting the library working. However, if you want to use it on Mac OS X (or Windows), the instructions leave the impression that it’s not possible, and Googling turned up some useful information, but no complete instructions, and also some people that seemed to be at a loss about how to do it.

Well, it is possible to get MIT-Scheme with the scmutils library running on Mac OS X (and you can probably modify my instructions to make it work on Windows too):

I already wrote about Gallager’s LDPC error-correcting codes, but I didn’t explain very much about how they work, aside from pointing you to some good references. I want to use this post to say a little about their decoders, which use the belief propagation algorithm, and also to make you aware of some freely available LDPC software, in case you want to study or simulate these codes.

The decoders typically work by message-passing (although decoders based on linear programming have also been studied). One represents the codes using a “Tanner graph,” that looks like the figure shown below, which is actually a Tanner graph for the famous Hamming code.

The circles in the Tanner graph represent the bits that are transmitted. For this Hamming code, only 7 bits are transmitted in a block, but more practical codes will have hundreds or thousands of bits in a block.

The squares with a “+” inside of them represent the parity check constraints. Each parity check constraint enforces that the bits that it is connected to must sum to 0 modulo 2, or equivalently the sum of the bits is even. For example, in the code above, there are three parity check constraints, and the first parity check constraint forces the first, second, third, plus fifth bit to sum to an even number. Even in codes with large number of bits, each check will only be connected to a small number of bits; that’s what makes the codes “low density.”

The plain squares represent the information from the channel about each bit. For example, if a binary symmetric channel with a flip probability of f was used, and the first bit was received as a 0, the first square would be a function that said that the first bit had a probability of 1-f of being a 0, and a probability of f of being a 1.

The belief propagation decoders for LDPC codes (there are actually various variants) work by passing messages back and forth between the bit nodes and the parity check nodes in the factor graph. The bit nodes start by sending their beliefs about what values they have to their neighboring check nodes. I.e., a message would say something like “bit 1 believes it has a 90% chance of being a 0, and a 10% chance of being a 1.”

The check nodes look at their incoming messages, and send out appropriate messages in response. For example, if a check node is connected to four bits, and the first three bits think that they are a 0, a 0, and a 1, respectively, the fourth bit will get a message to be a 1 (so that the sum will be even), with a probability that depends on how strongly the three other bits believe that they have those values.

When the bits get messages back from the check nodes, they update their beliefs appropriately and iterate. Eventually, if we’re lucky, the bits have beliefs which are consistent (when they are thresholded to their most likely value) with all the parity checks, and the decoder can output a codeword. Again, you should check out the references in my previous post about LDPC codes for more mathematical details about the algorithms.

If you want to implement LDPC codes, you might want to use the PyCodes package developed by Dr. Emin Martinian while he was at Mitsubishi Electric Research Labs (MERL). PyCodes is written in C, and linked into Python, so you can call it within Python as an ordinary module, but it still runs very fast.

Emin began writing PyCodes when he was my intern, and continued when he became a full-time employee at MERL. It’s very well-written code that I use a lot; Emin was a professional software developer before he was a graduate student, and the software is professional-quality. PyCodes is free for non-commercial use; see the license for more details.

Scientific collaboration is really difficult when you cannot talk directly with the person you’re working with. This has long made collaboration with distant colleagues cumbersome, to say the least. Fortunately, we live in the 21st century, and video conferencing technology now exists that is simple to set up, and works extremely well.

For the last few months, I have been using Apple’s video iChat software, and I can recommend it highly. It seems to have two major applications: connecting family members, and enabling business video meetings.

I have been video-conferencing with my colleague Stark Draper since he went to the University of Wisconsin earlier this summer. Video conferencing reliably works much better than phone conversations, and nearly as well as face-to-face meetings. It might seem surprising that it should be that big an improvement over phone conversations, but in fact human beings are very visual creatures, and a lot of information is conveyed by expressions and gestures. When you talk to somebody via video conference, they really seem like they’re with you in the same room.

If both you and your colleague have a recent Apple notebook or iMac with iSight camera built in, setting up iChat will be very easy; it just takes a couple minutes in all. You’ll need to sign up for a free trial .Mac account, which lets you use iChat (if you already have some other instant messaging account, like a Jabber account, you can also use that). The free trial lasts for 60 days after which you need to pay $100 if you want the full benefits of a .Mac account, but even if you don’t pay anything, you will still be able to continue to use your account for iChat. Since I wasn’t very interested in the other benefits of .Mac, that’s precisely what I did.

iChat uses the H.264 codec, which gives a very nice sharp image, although occasional video compression artifacts are noticeable (they’re interesting if you’ve worked on video compression, like me). There is also a very slight delay, which is noticeable, but not too bad. Actually setting up the video connection is trivial; it’s just a matter of knowing your partner’s .Mac account.

Other software like Skype exists for those of you with Windows or Linux. I don’t have any experience with video-conferencing with these services. If you do have such experience, and especially if you can compare with iChat, I’d be interested in your comments. Perhaps the main advantage for the Macs is just the fact that the camera is already built in.

Here’s a video that shows Steve Jobs demoing the new version of iChat that will be released with Leopard, the new version of Mac OS X coming out this month. It will give you a good idea of what a video chat is like; you might think that the reality is not so nice, but that’s essentially the quality I get with my video-conferences with Stark.

The upgrades for Leopard actually seem pretty minor to me; it will be nice to be able to share .pdf documents or presentations, but you can already basically do that by emailing the files. And I’m not too excited about the ability to distort my image or use weird back-drops. Originally, there was supposed to be a useful new feature in iChat for Leopard which enabled you to share your desk-top with your video partner, but it’s not clear whether that feature has been moved to another part of Leopard, delayed, or dropped altogether. We’ll soon find out. UPDATE: It looks like the desktop-sharing feature exists after all, which is excellent news, especially for people wanting to help out their computer-challenged friends and relations. However both sides of the chat will need to have Leopard for this to work.

If you’re interested in learning more about the game of Go, whether you’re an absolute beginner or already know something about the game, a good starting point is “Sensei’s Library”, a huge wiki (it currently contains 15722 pages) all about Go. There are many ways to explore the wiki, and tons of interesting topics to explore.

There are are many nice English language books on Go. I will just recommend, if you are a beginner, the excellent five volume “Learn to Play Go Series” by Janice Kim and Jeong Soo-hyun. (If you already know the rules and have played a couple games, you probably want to begin with volume 2).

Go-playing programs, unlike Chess programs, are no match for even moderately strong human amateurs, but for beginners or weak players like myself, they can provide an interesting challenge. I very much like the free Goban Go GUI for Mac OS X, which includes GNU Go, which is one of the best Go-playing programs. Goban also serves as a client for online Go servers and lets you replay Go games in the .sgf format.

When I tell my friends about this blog, they often want to know more about how it’s constructed. So I thought I’d talk a bit about the wordpress.com software that I use, and some tips I can pass on after seven weeks of using it.

First of all, it’s important to distinguish between wordpress.org and wordpress.com. WordPress.org is an open-source project for the wordpress blogging software; you can download it, and then set it up on your own web-server (it typically costs $7/month to set things up with a web-hosting company) and you’ll have full control over everything in your blog. WordPress.com is an easier alternative; they’ll host your web-site for you for free, but you don’t get absolutely complete control over what you can do. You can learn more details about the differences here.

I chose to use wordpress.com, because their features were basically what I wanted, but I wanted to use my own domain name (nerdwisdom.com) instead of the default nerdwisdom.wordpress.com. That extra feature costs $15/year; for that price, wordpress.com pays for your registration and handles redirection transparently. I recommend this option, because it means that if you ever want to change the way you do things later (e.g. switch to wordpress.org or some other service, which is not so hard because wordpress.com lets you “export” you entire blog as an XML file) you won’t have to change the url for your blog.

A nice bonus that happened when I paid for this option was that wordpress.com walked me through the process of setting up a Google Apps account for nerdwisdom.com. This is quite nice; I actively use Google’s Page Creator application, and there are other useful features and applications including Gmail accounts with the nerdwisdom.com domain.

Building your blog on wordpress.com is done through a web browser; you won’t need to download anything, and you can work on multiple computers with multiple operating systems. I recommend that you use the Firefox browser, it is better supported than the others. You write up your posts using an editor that can display either a WYSIWYG interface or your HTML code; it’s pretty easy to use if you have any experience with HTML, and I’d guess it’s not too bad even without any such experience. WordPress.com comes with a whole lot of different “themes” for changing the look of your blog, but I’m pretty happy with the default theme.

You can buy some “upgrades” with wordpress.com that give you some more control over your stylesheet and let you store more than 50 MB of data. At the rate I’m going, I’ll need to spend $20/year for the extra storage once I’ve done this for a couple years.

There are a few important restrictions with wordpress.com. Probably the most important is that you may not run advertisements (wordpress.com says this may change in the future). If you want to run ads you probably want to either use Google’s blogger.com service or wordpress.org or maybe typepad.com. You can also run advertisements on wordpress.com (and get other benefits) if you are a “VIP” blog, but to get that service you need to pay $300/month and have in the neighborhood of 15,000+ page-views/day, which is a lot.

I experimented just a little with blogger.com, and it seemed quite clunky to me in comparison with wordpress.com, but maybe that was just because I was already used to wordpress.com. My impression from what I have read is that wordpress.com is the more powerful system. I don’t have any experience with typepad.com at all. Apparently, blogger.com and typepad.com were the first entries into this field, but wordpress.com has now surpassed typepad.com in popularity, and is the second most used blogging software, and gaining on blogger.com.

Another restriction of wordpress.com is that it will not host Javascript widgets or Java applets. I wanted to put up a Java applet for my post on simulating the Ising model in NetLogo, so I put it on a page hosted by Google Pages instead, and just linked to the page.

One nice feature of wordpress.com is that they will put your posts on their front page if they think that they are high quality. I have no idea what algorithm they’re using to make that decision, but my posts are showing up pretty often, which drives some extra traffic my way. Speaking of traffic, you can access pages which give you a lot of information about how much traffic you’re getting and where it’s coming from.

Another nice thing about wordpress.com is their FAQs and forums. I use the FAQs a lot; nearly every time I have had a question, it’s been answered there.

Now a couple of tips for people already using wordpress.com. I found that Windows and Mac OS X browsers were using different fonts for my pages (the Mac OS X fonts were smaller than I liked), but you can fix this by using the HTML code “<font size=”2”> …. </font> in all your posts. I am also a big fan of the text widgets that let you put all sorts of things in your side-bars, because you can include HTML code.

You should also make sure to turn off the very annoying Snap preview feature, which is on by default.

If you’re interested, it’s easy as pie to set up an account and give it a whirl. I’m happy with the choice I made.

“Artificial Intelligence: A Modern Approach,” by Stuart Russell (professor of computer science at UC Berkeley) and Peter Norvig (head of research at Google) is the best-known and most-used textbook about artificial intelligence, and for good reason; it’s a great book! The first edition of this book was my guide to the field when I was switching over from physics research to computer science.

I feel almost embarrassed to recommend it, because I suspect nearly everybody interested in AI already knows about it. So I’m going to tell you about a couple related resources that are maybe not as well-known.

First, there is the online code repository to the algorithms in the book, in Java, Python, and Lisp. Many of the algorithms are useful beyond AI, so you may find for example that the search or optimization algorithm that you are interested in has already been written for you. I personally have used the Python code, and it’s really model code from which you can learn good programming style.

In my previous post about simulating the Ising model with the Metropolis algorithm in NetLogo, I said that I would return and and give a walk-through of the amazingly succint NetLogo code. Actually, I’m not going to do that; NetLogo code is sufficiently readable, and the documentation is sufficiently comprehensive, that there’s no real point.

Instead I want to discuss to what extent NetLogo can be considered a “real” programming language, suitable for work beyond its roots in education. The short answer is that it looks to me like quite a competitive language, which will make a particularly excellent choice for many scientific applications.

NetLogo is optimized for simulations of agents moving in a two-dimensional space. The moving agents are called “turtles” but you can think of them as objects endowed with a lot of built-in methods. It’s quite possible to use the turtles in the same way as objects in other object-based languages (although only a limited form of inheritance is available). For example, a turtle can contain other turtles as variables, and you can create new classes (called “breeds”) of turtles. The other basic objects, with many built-in methods, are the “patches” which tile the 2-d space, the “links” that you can set up between turtles, and the “observer.”

There are an impressive number of built-in primitive procedures, especially for anything that relates to simulations. You can also do all the basic things that you would expect a language to do: open and write to files, process strings, work with lists, etc.

The ability to quickly and easily build a GUI that will work on all platforms is very attractive. I have some experience building GUI’s for Mac OS X, using Cocoa and/or the Python bridge PyObjC (which is another worthwhile approach and something that I’ll post about at some point), and I can say that to build essentially the same simulation with the same GUI in NetLogo takes easily less than half as much work and code. It is also nice that it is so easy to construct applets and movies.

The syntax is similar to Lisp, but without parentheses, and with a great deal of syntactic sugar to make it look as close to English as possible. It is absolutely an optimal first language for the beginning programmer. My son was amazed that “everything worked, and when it didn’t I could understand the error messages.” He’s not really used to that from his experiences with other languages.

I looked for things that are missing. At first I thought hash tables weren’t there, but those are actually available through an extension. One thing that really is missing is the ability to treat a function as a value. You also can’t define your own special forms or macros, so I suppose that it’s not really Lisp. NetLogo also does not have, aside from in its core area of simulation, much in the way of libraries, but there is the ability to extend the language by writing functions using Java.

It’s easy to learn; but don’t neglect to look at the code examples section of the models library (you’ll need to download NetLogo first). You’ll see how easy it is to do things that take a lot more work in most languages.

I’ve already posted about NetLogo, but I want to return to it, because I’ve been very impressed with how ridiculously easy it is to construct sophisticated simulations of interesting models with it. My son Adam has been having a lot of fun with it, and he is able in the space of an hour or two, to create simulations of interesting models of his own devising, complete with easy-to-use GUI’s.

To illustrate how easy it is to build models, I’m going to use a familiar model that comes in the NetLogo library: the Ising Model of ferromagnetism on a square lattice, simulated using the Metropolis algorithm. (I simplified the code very slightly for clarity.)

In this model, there are spins at each node of a square lattice, that can point “up” or “down.” Spins like to have their neighbors point in the same direction. To compute the energy of a configuration of spins, we look at all pairs of neighboring spins, and add an energy of -1 if the two spins point in the same direction, and an energy of +1 if the two spins point in opposite directions. Boltzmann’s law tells us that each configuration should have a probability proportional to the exp(-Energy[configuration] / T), where T is the temperature.

The Metropolis algorithm is an algorithm for dynamically generating configurations of the model with the correct probability. One starts at some configuration, and picks a spin at random, and considers flipping it. If flipping it would reduce the energy or leave the energy unchanged, one makes the flip. Otherwise, one flips the spin anyways with a probability of exp(-Ediff/T), where Ediff is the amount that the energy will be increased by making the flip. Then pick another spin at random and continue.

It is not immediately obvious that the Metropolis algorithm generates configurations with probability given by Boltzmann’s Law, but one can prove that it does. The Metropolis algorithm is not the most efficient algorithm for generating samples from the correct probability distribution; much more efficient algorithms from that point of view are discussed in Werner Krauth’s book, which I previously reviewed.

There are many things to say about the Ising Model, but first let’s look at the NetLogo code for this model. It’s extremely short; the code (including the code controlling the GUI) is about the same length as the copyright notice that I’m appending because I only made small modifications to Uri Wilensky‘s code:

In a future post (Edit: it’s here), I’ll step through this code and show you how it works (you do also need to click on a few buttons to set up the GUI). For now, though, I want to show you what an applet running this code looks like, and make some more comments about the Ising model that are best illustrated by running the applet. So please (assuming you have Java installed; and if you’re on Mac OS X Leopard, use Safari, there’s some problem when using Firefox) CONTINUE HERE.

For certain genres of computer games, such as grand strategy games, the music can make a huge difference in the experience. One of the reasons that Civilization IV has been such a great hit is its wonderful music, particularly composer Christopher Tin‘s beautiful menu track “Baba Yetu” and opening track “Coronation.”

This music has attracted considerable notice; the picture above, taken from Tin’s website, is of the National Symphony Orchestra and the Washington Master Chorale performing “Baba Yetu” at the Kennedy Center. Tin makes “Baba Yetu” and “Coronation” (actually remixed versions slightly different from the computer game versions) available for download at his samples page, along with other samples of his work. (To download, just right-click and “save link” instead of left-clicking.) If you’re curious, the lyrics for “Baba Yetu” are actually a version of the Lord’s Prayer in Swahili.

My son Adam really enjoys playing the historical grand strategy games produced by Paradox Entertainment (Europa Universalis II, Victoria, Crusader Kings, and right now especially Europa Universalis III.) These games also have excellent music, but there are some tracks that he prefers more than others, and the music sometimes gets too repetitive in Europa Universalis III because there’s not as many tracks as he’d like. Adam also told me would play Crusader Kings mostly for its excellent music, and he would read the “Civilopedia” in Civ IV because it would let him listen to “Baba Yetu.”

Well, to give him a little more control, we made a playlist in iTunes, and put in only the tracks he likes from the games we own, and now he’s completely set. He just turns off the game music and uses his iTunes playlist instead. Speaking of iTunes on Windows, this is a funny quote from Apple’s CEO Steve Jobs a couple months back:

And speaking of running Windows on an Intel iMac using Bootcamp, which is what we do to run Windows-only games, this is a very funny link, but it’s not really accurate. Honestly our iMac running Windows (we actually run Windows XP instead of Vista because it runs games better, and is more stable) is easily the fastest and most stable Windows machine I’ve ever seen, probably largely because it’s missing all the bloat that normally comes on a PC (and because I’m very careful about what gets installed on it.) Walt Mossberg from the Wall Street Journal also reports that an iMac running Vista is the best Vista machine he’s seen.