the jsomers.net blog.

Perfunctory Offers

What do you do when you want the last piece of bread? Do you just take it? Or do you offer it to the table?

You offer it. Everybody knows the score: they know that you want the last piece, and that you’re only offering it to everyone else to be polite. So they’re going to decline, and you’re going to end up with the bread.

Why not be more direct? Because then you’d be skipping a ritual that gives everyone a chance to demonstrate how cooperative they are. Rituals like that are important.

Of course, making the offer opens you up to someone accepting it. That’s the price you pay for coming off as polite and cooperative; what you’ve done, effectively, is to wager the bread to earn a bit of social credit.

Nine times out of ten you’ll win—you’ll look good and keep your baguette—but occasionally you’ll lose the bread. You should be prepared for that.

The odds of pulling off a successful perfunctory offer are usually worse than in this bread situation. The reason is that the bread situation happens so often, and is so well-understood, that people rarely deviate from the script: offer, refuse, eat. Whereas in other cases—like when you offer a friend a ride but don’t want him to accept—the game isn’t so clear; your friend might suspect that your offer is just for show, but he can’t be sure. And free rides are attractive. So he’s more likely to accept.

The good news is that you get paid for taking on this extra risk. Offering your friend a ride is a bigger deal than offering your last piece of bread to the table, which means you stand to earn more social credit.

The stakes are higher for the other guy, too. He also earns points by turning down your empty offers; we saw that in the bread situation. It’s because turning down an empty offer (a) lets you off the hook, which is a nice and cooperative move for him to make, and (b) demonstrates his ability to detect empty offers in the first place, which feeds his reputation as a skilled coordinator.

That, then, is the arithmetic of perfunctory offers: you balance the cost of giving up some X against the points you’d earn for seeming generous, while he weighs the value of receiving X against the points he’d earn for skillfully detecting—and then abiding—your true intentions.

The other green planet

Here’s a simple argument for the existence of extraterrestrial life: there are hundreds of billions of galaxies that each have hundreds of billions of stars. Our sun may be special in many ways, but it can’t be that special.

I used to be deeply unsure about the prospects for life elsewhere in our universe. I used to think that stories of aliens and exoplanets were thrilling but basically pathetic fantasies. Then, not too long ago, I read about the Hubble Deep Field, realized that the specks of light in that image are galaxies, went on to read that there are in the neighborhood of 10^22 stars in the observable universe, and immediately concluded that it is tremendously, profoundly stupid to think that we’re alone.

That seems to be the minority opinion. Ask someone at random whether they think there are aliens. If they don’t say “no,” they will at least be agnostic, and more likely dubious. Virtually nobody will confidently argue for their existence, and most of those that do will do so for the wrong reasons.

The biggest problem seems to be with the numbers. Ten billion sounds about as enormous, to the lay man, as ten sextillion, even though it’s a full thirteen orders of magnitude smaller. So the argument above loses a lot of its force just because people aren’t as impressed by “10^22″ as they ought to be.

It doesn’t help that we’re wired with a first-person view of the world, a view which has the effect of making each of us feel like the center of the universe. That feeling is probably single-handedly responsible for thousands of years of scientific false starts: the idea that the Sun revolves around the Earth, that our solar system is at the center of the galaxy, that humans were created beside and above the other animals, etc. It took an incredible amount of discipline to abandon this inborn self-centeredness and embrace a simple truth: that in the grand scheme of things, we aren’t all that special. [1]

The question I have, then, is what it would take for the mass of mankind to begin believing, with near certainty, that there is extraterrestrial life. And what would be the effect of such a widespread belief?

One scenario that’s been beaten to death is direct contact with an alien race. This is tremendously interesting, but for my purposes it goes too far. So how about this: suppose that in the year 2012, instead of the world ending, our scientists discovered a green exoplanet, i.e., a planet outside our solar system covered in chlorophyll. What would happen?

While some people would no doubt hail it as the greatest discovery in the history of mankind, and triumphantly proclaim the abundance of extraterrestrial life, my guess is that there would be a lot of resistance. People would demand more evidence and, just as they have in the global warming debate, cast doubt on the mere existence of a scientific consensus. For a long time they’d attack the credibility of the data, the instruments used to collect it, the scientists involved in analyzing it, and the press engaged in its popularization.

Let us suppose, though, that after enough debating and demanding and re-appraising, the existence of plant life on this exoplanet became about as credible and common a belief as the theory of evolution, that is, it became taken for granted by the educated mainstream. What then?

I think something pretty cool would happen. I think that being a kid growing up in “the era of the other green planet” would be a bit like growing up in Europe in the early 14th century, just when Marco Polo’s tales of a strange and wonderful far-off land were gaining traction among the public. [2] Your imagination would be forced to radically and irrevocably expand: what you once took to be the only way of being would be made small in its proper context, and you’d see our flora and our fauna and all our human apparatus—the courts and garbage men and roads and police and clothing and markets and so on—as so many accidents of history, some more evitable than others, each further fixing Earth’s minor place in a vast uncountable sea of possible worlds.

Which is to say that credible evidence of an alien planet, one too far away to examine directly, would force us all, first, to think of Earth as a world rather than the world, and second, to imagine what all the other worlds out there might be like, starting with the one scientists know for sure exists.

I think that qualifies as a paradigm shift. It would have all sorts of consequences:

  1. The academic’s trick of adopting “a Martian’s eye view” might go mainstream. What better way to kick off a discussion of money, say, than to ask students to “imagine there was an intelligent species on the other green planet. What would they say about you trading a piece of paper for a chocolate bar? Which parts of our economic system would seem strange to them, and which might make sense?”

  2. Students who study abroad have this somewhat irritating tendency, when they get back, to sing the praises of all things “there” at the expense of all things “here” (“The trains are really so much better in Japan,” or, “Americans can’t make a decent cup of coffee,” etc.). But that kind of doubt about one’s home—that critical eye—is no doubt useful. And certainly something of that sort would happen if more of us took extraterrestrial life seriously: we might be a little more ambivalent about ourselves, and a little more humble.

  3. Science fiction writers have always been painting pictures of other worlds full of strange landscapes and life-forms and customs. But that kind of creative imaginative activity could belong to everybody, once it became natural—rather than nerdy—to think about exoplanets.

  4. It’s natural to the point of being a cliché to occasionally look up on a clear night and marvel, and to ask yourself whether someone else, somewhere around the globe, is marveling with you. Or to find yourself in the grip of sadness and be comforted by the thought that perhaps millions of other people are crying at the very same time. How much richer would those moments be if you considered also the experience of every other sentient sensitive being in the ‘verse?

If nothing else I get a thrill out of imagining our dark cosmos teeming with colorful life. But I insist that this isn’t wishful thinking. In fact, I think it’s the conservative position, and that to think we’re alone is not just sad but crazy.

Notes

[1] See Carl Sagan’s “Pale Blue Dot” for a wonderful articulation of this theme.

[2] The Marco Polo analogy is due to my mother, who introduced it in a brief but entertaining conversation about aliens on the porch of our cottage overlooking Lac Echo.

The Hofstadterian Mood

For the last few months I’ve been feeling very uncreative. I try to sit down to write every day, but lately these sessions have ended prematurely, after ten or twenty minutes scouring what feels like an empty brain. I peruse my notes, but even there, it seems like I’ve been doing a lot more consuming than thinking. I’ve been bereft of ideas, of that feeling of teeming, the wonderful elastic looseness that accompanies a bustling inquisitive mind.

And then I started reading Hofstadter again. I first fell in love with him when I picked up Godel, Escher, Bach: An Eternal Golden Braid (GEB) in my sophomore year at Michigan, on the implicit recommendation of a friend who had it lying on his dorm room floor. That book rebuilt me: I came out of it with a thousand new interests, a new vocabulary, a massively expanded conceptual toolkit, a more playful attitude, and a remarkable feeling of clarity, like the mental equivalent of a cleansed palette. If you haven’t read it yet, you must.

Just a few weeks ago, I dove into his Le Ton Beau de Marot: In Praise of the Music of Language, a tome ostensibly “about” translation which of course turns out to be nothing short of an annotated, illustrated garden path through the totality of Hofstadter’s mind. Taking Clément Marot’s short poem “A une demoiselle malade” as its kernel, it unfolds a story of language, of Hofstadter’s personal life, of puzzles and puns and palindromes, of frames and templates and analogical structures, of “recursion, computation, reduction, holism, meaning, ‘jootsing’ (Jumping Out Of The System), ‘strange loops,’ and much, much more”—all presented with the usual “family of elaborate (and lovingly elaborated) analogies”, “structural puns”, and in general a feeling of childish delight that makes reading any of his books an incomparable joy. [1]

Enough gushing. The point is, after just one or two sittings with Le Ton Beau, I’ve been re-invigorated. And I think I know why.

Hofstadter’s writing—all of it—is littered with little anecdotes about sets of afternoons here and there where he dives into some intellectual adventure: translating a Stanislaw Lem story from Polish to English, pointing camcorders at televisions to investigate recursion, training himself to speak backwards (he calls it “Hsilgne”), etc. It’s hard not to be inspired by these informal experiments: what else can you do, after Hofstadter tells you that he wrote the preceding paragraph without using the letter “E”—he was making a point about the way constraints drive creativity—than to try it yourself? [2]

That’s why reading Hofstadter is so much fun, because he challenges you on every page. I said earlier, for example, that Le Ton Beau de Marot had Clément Marot’s short poem “A une demoiselle malade” as its “kernel”; what Hofstadter did was to ask a whole slew of his friends to translate that poem as best they could under certain constraints, mainly the requirement that they respect something of the original’s content, tone, and basic metric structure. When his friends began responding in spades, Hofstadter found the submissions so delightful, and the issues they raised—about languages, analogies, constraints, creativity, translation, and “transculturation”—so rich and interesting, that he decided to build an entire book around them. So Le Ton Beau‘s expository chapters are interleaved with small showcases of notable translation efforts, just as GEB‘s “regular” chapters were interposed between dialogues. The effect is wonderful and, again, it’s virtually impossible to go through without wanting to take a stab yourself. (Here’s mine.)

And that’s the trick. Hofstadter gradually ropes you in with his games and puzzles; he’s always demonstrating the very concepts he’s describing, always coaxing you to play along. In GEB, for instance, his dialogue, “Crab Canon”, about retrogressive palindromic structures in music, art, and biology, is itself palindromic: each speech is repeated twice, with the two halves of the dialogue mirror images of one another. The effect works because he specifically (and painstakingly) collected phrases with ambiguous meanings, like “Not at all!”—which can mean either “Definitely not!” or “No sweat!”—or “One has no frets”—which could either be about guitar strings or worries, depending on the context.

In Le Ton Beau, to take another example, one of the overriding themes is the relationship between form and content, and in particular on the way in which each influences and constrains the other. But rather than just talk about this problem, Hofstadter lives it, not just in little games like the “E”-less paragraph mentioned earlier—though there are plenty of those throughout—but in the construction of the book itself. From the introduction:

Above, I very casually remarked that I have enjoyed total control over page-breaks and such things; yet the truth of the matter would be far more accurately captured by turning the phrase around and saying that the page-breaks and word spacing and such things have enjoyed total control over me! By this, I mean that I have been forced to rewrite and rewrite and rewrite passages in order to make a page boundary come out exactly where I wanted it. It is not just by some happy accident, for instance, that the poems inside chapters are never, ever broken across page boundaries.

The amount of influence exerted on my text by concerns of purely visual esthetics is incalculable — and by “my text”, I don’t merely mean how I wound up phrasing my ideas, I mean the ideas themselves. Content has been determined by considerations of elegant form so often that I couldn’t begin to imagine it. Every single line of text, for instance, is characterized by its spacing — how wide the blanks between words are. I can clearly see the spacing as I type on my screen, and I rewrite and rewrite in order to make sure that no line is too tightly or too loosely spaced. In the course of such rewritings — here extracting a word, there using a shorter or a longer one, elsewhere inserting a word where none was — words and phrases that I would otherwise not have thought of pop to mind, suggesting ideas I would not have thought of, and those ideas suggest unexpected paragraphs, and those paragraphs are in turn linked to other ones, and so on…

It’s this feature—Hofstadter’s habit of taking fairly abstract concepts like “the battle between form and content” or “level-crossing feedback loops” and engaging them at every turn, in the selfsame sentences he uses to describe them—that most contributes, I think, to his ability to spark the reader’s creativity. Because the effect of his incessant demonstrations and illustrations is to gradually train you to think like him, to transform you into a little fledgling version of himself. Which is great, because as Dan Dennett puts it,

What Douglas Hofstadter is, quite simply, is a phenomenologist, a practicing phenomenologist, and he does it better than anybody else. Ever. For years he has been studying the processes of his own consciousness, relentlessly, unflinchingly, imaginatively, but undeludedly. [1]

That is, he’s a student of his own mind, a mind that is unstoppably inquisitive, and we benefit from his struggle to articulate its intricate workings, first because we’re exposed to his innumerable interests and second, because we too become students of those processes—analogy-making, constraint-satisfaction, conceptual slippage, etc.—that he uncovers as the basis of his creativity.

This first feature, the simple fact that his books cover a lot of ground and therefore activate in the reader all sorts of dormant swaths of brain, is probably best illustrated by a simple tour of GEB‘s wonderful annotated bibliography. Picking three starred entries basically at random, we find:

  1. Mikhail Bongard’s Pattern Recognition. Hofstadter remarks that “In his book, [Bongard] sets forth a magnificent collection of 100 ‘Bongard problems’ (as I call them)-puzzles for a pattern recognizer (human or machine) to test its wits on. They are invaluably stimulating for anyone who is interested in the nature of intelligence.” His enthusiastic recommendation led me to this webpage, an index of 280 Bongard problems, including 56 from Hofstadter himself. Solving these is not only a fun way to chew on difficult questions regarding cognition and AI, but also an excuse to kill four or five afternoons!

  2. The proceedings of a conference on Communication with Extraterrestial Intelligence. I found this in the New York Public Library and was so blown away by the one chapter I had time to read that I immediately bought it. The conference was broken into distinct sessions organized, roughly, by terms in the Drake equation, which is used to estimate the number of intelligent alien civilizations in our galaxy. So each session is this wonderful discussion among top scientists—a few Nobelists, guys like Freeman Dyson, Carl Sagan, Francis Drake, etc.—trying to home in on a reasonable estimate for a given term, say, L, the length of time an average intelligent civilization lasts, sometimes defending their hunches with sophisticated technical arguments and sometimes with nothing more than hand-wavy intuitions. It’s an absolutely fascinating read, not only because the question of extraterrestrial life itself is so fertile, but also because we get to see such talented scientists at work.

  3. Howard Bergerson’s Palindromes and Anagrams, a strange little book that boasts perhaps the world’s most complete collection of top-notch palindromes and anagrams (duh), along with several chapters discussing the art of anagrammatical-palindromic thinking, and diversions into other forms of wordplay, like “vocabularyclept poetry”, in which writers are challenged to craft a poem using the complete set of words from another poem that they haven’t seen before (interesting questions there include, How much will this new poem resemble the old one? and Do the two poets connect their (shared) words into phrases in the same way? and How much of a poem’s DNA is contained just in the words it uses, ignoring their placement and order?) Fun, fun, fun.

Three books chosen from more than one hundred, and all of them rich enough to set off about two weeks of intellectual exploration; I could easily write at length about each, with any feeling I used to have of “an empty mind” replaced by a sense of overflowing activity.

I think Hofstadter’s books range so broadly—that is, they touch on so much of the world—because he wants to drive home two points: first, that so much of the world is connected, and second, that analogy-making—the process of seeing an X as a Y—is the crux of thought, and creative thought in particular.

The following is from a section entitled Creativity and Randomness from page 673 of GEB:

Just as science is permeated with “conceptual revolutions” on all levels at all times, so the thinking of individuals is shot through and through with creative acts. They are not just on the highest plane; they are everywhere. Most of them are small and have been made a million times before—but they are close cousins to the most highly creative and new acts. Computer programs today do not yet seem to produce many small creations. Most of what they do is quite “mechanical” still. That just testifies to the fact that they are not close to simulating the way we think—but they are getting closer.

Perhaps what differentiates highly creative ideas from ordinary ones is some combined sense of beauty, simplicity, and harmony. In fact, I have a favorite “meta-analogy”, in which I liken analogies to chords. The idea is simple: superficially similar ideas are often not deeply related; and deeply related ideas are often superficially disparate. The analogy to chords is natural: physically close notes are harmonically distant (e.g., E-F-G); and harmonically close notes are physically distant (e.g., G-E-B). Ideas that share a conceptual skeleton resonate in a sort of conceptual analogue to harmony; these harmonious “idea-chords” are often widely separated, as measured on an imaginary “keyboard of concepts”. Of course, it doesn’t suffice to reach wide and plunk down any old way—you may hit a seventh or a ninth! Perhaps the present analogy is like a ninth-chord-wide but dissonant.

With that in mind, it becomes somewhat natural to think of Hofstadter’s project, or at least the bulk of his popular writing, as a kind of futzing around on this “keyboard of concepts”, looking for harmonies, trying to cull disparate ideas that really are deeply related. Along the way, he has no doubt become an expert in letting concepts “slip”, that is, in perceiving apparently unrelated phenomena as being “fundamentally ‘the same’ at a deeper, more abstract level”. [3] And it’s by watching him do this, by reading and engaging him in the act of analogy-making, that we gradually slip into the same slippable state.

Here’s one of my favorite examples from Le Ton Beau so far, on pages 40-41:

Over the years, I suppose largely because of my fanatical obsession with acquiring native-style accents in various languages, I gradually abstracted and generalized the notion of “foreign accent”. My exploration was rooted in languages and so the first abstractions that I made of it were naturally still language-based, but others soon transcended language.

For example, after I had been studying Chinese for a while, I realized with shame that my clumsily-drawn characters must have a very foreign-looking “visual accent” to them. In the course of trying to get rid of this “accent”, I started to wonder if there was such a thing as a “Japanese accent” in Chinese calligraphy, given that both languages revere the same set of characters and have calligraphic traditions stretching back thousands of years. [. . .]

Moving away from the realm of language, consider baseball, which has spread from America to other parts of the world, where it is played with equal enthusiasm. Do Cubans and Japanese, for instance, have “foreign accents” when they play baseball? Does a lifelong chess player have a “chess accent” in playing Go for the first time? Do I have an “Algol accent” when I write computer programs in Lisp (Algol having been my first computer language)? In the 1950′s and 1960′s, many physicists decided to move over into the exciting new field of molecular biology. Did they all have a recognizable “physics accent” in their various approaches to the problems of this alien discipline? Do Americans have an American accent when they drive in Europe? Do Europeans have European accents when they drive in America? Is it possible to recognize an Italian driver on a German Autobahn, or vice versa (not cheating by using license plates or car makes)?

What is a “French accent” in music? Certainly in the classical genres, Ravel, Debussy, Fauré, Poulenc, and Satie epitomize this notion, but what about someone like Hector Berlioz, who to me sounds more German that French? And what about César Franck, who, although Belgian, can sound just as French as any of them? I even know a piano-trio movement by Russian composer Alexander Scriabin that sound as “French” as anything I can think of. But what is this elusive French musical accent?

The feeling I get after reading stuff like this… that’s the “Hofstadterian mood”. It’s the feeling of having my brain rebooted, or maybe overclocked: I shed my simple-mindedness, I learn how to think analogically again, connectedly, using questions like Hofstadter’s “What is a ‘French accent’ in music?” to slip from one idea into another, stringing concepts together into one of those long-distance harmonic “idea-chords” that blend into the unmistakable euphonious thrum of a fertile mind at work.

Notes

[1] From “Hofstadter’s Quest: A Tale of Cognitive Pursuit“, Ch. 14 of Daniel Dennett’s Brainchildren: Essays on Designing Minds.

[2] Here’s one attempt—look Ma, no “E”s!—using the preceding paragraph as a model:

His writing—all of it—is swarming with accounts of brainy larks, or whimsical dips into rich tracts of thought: translating a Stanislaw story from Polish to Anglo-Saxon, pointing a photo-gizmo at its own TV output to study spiral loops, training to talk backwards, and so on. It’s hard not to act on such findings: what can you do, upon noticing that his last paragraph is missing our script’s most copious symbol—that paragraph was making a point about constraints—but try it too?

[3] From James B. Marshall PhD dissertation, Metacat: A Self-Watching Cognitive Architecture for Analogy-Making and High-Level Perception

Exploring the complexity of driving directions

When I was planning my first long drive from school in Ann Arbor back home to New Jersey, I remember looking up directions on Google Maps and noticing, as in the results here, that it really doesn’t take a lot of steps — or driving maneuvers — to get what seems to be a pretty long way across the country. In fact it only requires seventeen turns using the route Google gives, and even that number is inflated (those “keep left” and “keep right” steps are helpful, maybe, but not necessary).

Just for fun, I tried comparing that 500+ mile trip to one a fraction of its size, something closer to ten miles. You can see such a route here.

Remarkably, at only 2% of the distance, this short hop from one small town in New Jersey to another requires just fifteen steps, or only two fewer than the hefty road trip to Michigan.

I began to wonder: what’s the relationship between the length of a road trip and the complexity of the route? Do most trips, long or short, require roughly the same number of steps? How many steps are there in the most complex route in the country? What’s the distribution of step counts for every possible route in the contiguous United States?

These questions turn out to be tractable, thanks in large part to Google’s Directions API, which gives lowly developers like me access to their full suite of mapping, geolocation, and pathfinding algorithms, huge stores of data, and fast servers that can deliver tens of thousands of query results to a single client computer in a matter of minutes.

Before we dive into methods and results, though, let’s lay out exactly what we’re looking for:

  1. We want a histogram of step counts for some representative sample of routes within the US. This will give us a really good sense of how complex a typical road trip might be.

  2. We’d like to find the most complex route in the country, i.e., a pair of points such that the driving directions between them, given by Google, include a larger number of steps than for any other pair in the contiguous US. It’s extremely unlikely that we’ll find the monster route, but at least we’d like a ballpark estimate of its step count — is it 35, 500, 90, 180?

  3. We want a plot of route distance against route complexity. What will the plot look like? Is complexity a linear function of distance? Is there a direct or inverse relationship? Will there be any pattern at all?

  4. It would be pretty cool to find a “coefficient of friction” for regions in America, that is, a numerical estimate of how hard it is to drive through a particular region based on how many steps there are, on average, in a route passing through it. We could use this information to create a “heat map” of the entire US, with individual counties or zip codes shaded by friction. Such a map would help us figure out which states have the thorniest roads, or where the most straightforward routes are, or which cities are the hardest to get out of.

To get started, then, I went looking for a random sample of points. One way to do that would be to draw a box inscribed within the continental US and simply generate random lat-longs within that box. The trouble with that method, I thought, was that it could easily drop you in barren or ridiculous places like deserts or lakes; I wanted to focus on plausible real-life trips from one population center to another.

So I went looking for a data set, and before long, found one: the “MaxMind World Cities with Population” file, a 33 MB free download with more than enough data to get things rolling: after eliminating non-U.S. cities (a simple grep did the trick, since the text is nicely structured), I was left with 141,989 points covering nearly every corner of the country.

I hacked together a tiny Rails project (RoR being my hammer-that-makes-everything-look-like-a-nail at the moment) to (a) load the cities and lat-longs into some structured form, (b) drop that data into an HTML page hooked up to the JavaScript Google Directions API, and (c) write the results back to a database. All of the relevant code, along with a SQLite3 database with the structured cities data and results, is available at this github project page.

Perhaps the most important snippet, which I’ll excerpt below, is the code that actually samples points and talks to Google:

var map;
var directionDisplay;
var directionsService;
var stepDisplay;
var markerArray = [];
var step_counts = [];
var step_summaries = [];

function initialize() {
  // Instantiate a directions service.
  directionsService = new google.maps.DirectionsService();
}

function calcRoute(start, end) {
  // Retrieve the start and end locations and create
  // a DirectionsRequest using DRIVING directions.
  var city_start = [start[2], start[3]].join(", ");
  var city_end = [end[2], end[3]].join(", ");
  var latlong_start = [start[0], start[1]].join(",");
  var latlong_end = [end[0], end[1]].join(",");
  var request = {
      origin: latlong_start,
      destination: latlong_end,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
  };

  // Route the directions and pass the response to a
  // function to count the number of returned steps.
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var step_ct = countSteps(response);
      step_counts.push(step_ct);
      step_summaries.push([step_ct, city_start, city_end])
    } else {
      console.warn("Couldn't count steps for this route.");
    }
  });
}

function countSteps(directionResult) {
    var myRoute = directionResult.routes[0].legs[0];
    return myRoute.steps.length;
}

function getAndExecutePairs(n) {
    $.get("/directions/get_pairs", {n: n},
        function(ret) {
            pairs = ret;
            console.log(n + " lat/long pairs downloaded successfully.");
            execute(pairs);
        }
    )
}

function execute(pairs) {
    for (i = 0; i < pairs.length; i++) {
        pair = pairs[i];
        start = pair[0];
        end = pair[1];
        calcRoute(start, end);
    }
}

It’s all pretty straightforward. The process is kicked off by the getAndExecutePairs() function, which just hits the Rails server for n pairs of cities. This is the code it calls:

def get_pairs
    n = params[:n].to_i
    cities = City.find(:all, :limit => n * 2, :order => "random()");
    lat_longs = cities.collect {|c| [c.latitude, c.longitude, c.city, c.state]}
    pairs = Hash[*lat_longs].to_a
    render :json => pairs
end

And that’s it. With just ~100 or so lines of code, I was able to get a decent grip on the first three of the four questions posed above. In particular:

1. What’s the distribution of step counts for every possible route in the contiguous United States?

The answer, based on a random sample of some 2,000 points (and confirmed later by 8,000 more trials), is that you have a sort of right-skewed distribution centered at 20-30 steps and tailing out near 60.

2. How many steps are there in the most complex route in the country?

This is a lot less definitive, but the answer I got was 69 steps, in a route from Ponderose Pine, NM to Wildwood, MN. A friend suggested something like the following approach for finding more complicated routes:

Suppose you’re getting “good” (i.e., stepful) routes between points A and B. Draw a box around each of A and B and “wiggle” your start points within that box. If wiggling in one direction removes steps, try wiggling in another direction; or if it’s not direction that matters, but rather something tricky like “being within a development or behind a river,” maybe you could just select points within the box randomly and assign scores to different areas (sort of like a game of Battleship). That way you slowly optimize promising routes until you end up with truly high numbers.

One potential pitfall of this approach is that there could be discontinuities — A to B could take an unremarkable 35 steps, but (A + ε) to B could take 70 steps — in which case you might not choose the right starting points to begin with. But this would probably only happen if there was something like a maze next to a normal neighborhood.

3. What’s the relationship between trip distance and route complexity?

The graph above plots route distance (measured as the surface distance between the two lat-long pairs) against step counts. Aside from a few outliers, you’ll notice that a really wide range of step counts is covered by a relatively narrow range of distances: that is, most of the variation in step counts is accounted for in trips less than a few hundred miles; and at the margin, an extra mile buys you very little in terms of route complexity.

Perhaps the most interesting points are those short routes with a large number of steps. See, for example, the 69-step route called out above (just over 1,000 miles), or the 67-step route from South Lyndeborough, NH to Hartley, GA (875 miles).

(You’ll notice a few routes with more than 70 steps — these can be safely ignored, since they either originate from or end up in Alaska (oops!)).

4. Can you generate a “heat map” that shades regions by their “coefficient of friction,” i.e., a numerical estimate of how hard it is to drive through a particular region based on how many steps there are, on average, in a route passing through it?

This is left as an exercise for the reader, as is the task of finding even longer routes (here’s a 75-stepper) and the more general underlying problem of understanding which features — of cities and roads and geography — are implicated in route complexity.

Sundries

One way to appreciate good acting is to try to imagine some of your favorite lines written rather than spoken. Try to clear your mind of the actor’s specific performance. Focus on the words themselves, on the way they look on a page. Now do you see the distance between the screenplay and the speech? Isn’t it remarkable, the work that goes into enlivening those lines?

* * *

I have a mug here next to my keyboard that’s full of water. But I’ve been drinking it just like people in those Folgers commercials drink coffee: the way I go to pick it up; the way I hold it, with two hands; the way I hold it up to my nose, and close my eyes, and inhale appreciatively before I take a small sip; etc. If you were watching me from across the room you’d be convinced that I was drinking coffee, not water, just based on the way I’m moving.

Now the remarkable thing is that because of those movements, I get some of the pleasure, drinking water, that I would be getting if it really were coffee. That is, the movements themselves — the rituals — are enough to trick my brain into thinking the water is sort of rich and warm and fulfilling. How strange.

* * *

Not bothering about those guys at the bar who are being rude and rambunctious, or those cackling girls on the bus, is not just about dissociating to calm your nerves. It’s not just about ignoring them or putting them out of your mind. It’s about actively trying to appreciate their fun on their terms, and being heartened, or cheered up, or at the very least not repulsed by what you discover in their minds.

But imaginative empathy only goes so far, you say. “What about the vociferous leader of a hate group? I can’t understand how someone could get that way.” Can’t you? Work to imagine it! What did you learn?