You are currently browsing the monthly archive for April, 2008.

With 17 days of annual leave this year and a possibly sticky HR situation where I need to take them all by the end of the year, that was the natural question I asked. I’m at a loss here, but if random selection is the answer, you’ve probably seen them do it in the movies — spin a globe and jab at a spot, throw darts at a world map (daggers, arrows and bullets work too), … These methods aren’t quite random. People tend to jab at the portion of the globe facing them, so certain latitudes have a lower chance of getting chosen. As for throwing darts at a large world map, the map projection system causes some regions to have a non-uniform chances of getting chosen. Moreover, blindfolded dart throwers can have a certain bias on the spots they choose to aim. And, they always end up on land masses on their first tries despite the fact that 70% of the Earth’s surface is covered with water!

We’ll leave it to the random number generator on your PC! We can randomly generate latitude and longitude coordinates, then punch them into Google Map. Unfortunately there’s a slight complication. Random number generators built into most programming languages provide for two probability distributions — uniform and normal. If we’d generated the two geographical coordinates on uniform distributions, an area near the poles will tend have a higher chance of getting chosen compared to an equal area near the equator. That is because an area element r^2 \cos{\theta} d\theta d\phi is smaller near the poles, but will still have an equal probability of as the area element near the equator. Here \theta \in [-\frac{\pi}{2}, \frac{\pi}{2}] is the latitude and \phi \in [-\pi, \pi] the longitude. The radius of the Earth is r. We’re assuming the Earth is spherical.

(This section can be skipped by the math-phobic)

The way around this is to not have the latitudes and longitudes generated on uniform distributions. Let’s see what we really want…

We want the probability of choosing an area bounded by the latitude and longitude ranges \theta to \theta + d\theta and \phi to \phi + d \phi to be proportional to the area, i.e.,

P(\mbox{choose area }dA) = \int \int \frac{dA}{4\pi r^2} = \int\int \frac{r^2 \cos{\theta} d\theta d\phi}{4\pi r^2} = \int \int \frac{\cos{\theta}}{4\pi} d\theta d\phi

The term in the integral is the probability distribution function $p(\theta,\phi)$. But we’d like to generate random values for the latitude and longitude separately, since we’re generating them in a program. So we’d like to find probability distribution functions p_1 (\theta) and p_2(\phi) such that p(\theta,\phi) = p_1 (\theta)p_2 (\phi). We’d also like p_1 and p_2 to be normalized over the relevant ranges. With some guesswork, we get

p_1(\theta) = \frac{\cos{\theta}}{2}

p_2(\phi) = \frac{1}{2\pi}

Now, p_2 is the probability distribution function of a uniform distribution, so generating values for it is easy on a computer. As for p_1 which is non-uniform, we make use of the Inverse transform sampling method. In short, if F_1 is the cumulative distribution function for p_1, then random values for this probability distribution can be generated by first generating a value X that is picked from a uniform distribution that ranges from 0 to 1, and then finding F_1^{-1}(X). The resulting value follows probability distribution p_1. The rationale can be derived through some calculus and from the basic definitions of probability related functions. The function F_1^{-1}(x) = \arcsin{(2x-1)} in our case.

(continue here for the Python code)

Then I wrote a short Python code to generate my first ten travel suggestions. Most of them will naturally end up in the oceans. Results are appended below.

import random
import math

random.seed()

latradians = math.asin(2*random.random() -1)
longradians = random.uniform(-math.pi, math.pi)
latdegs = 180*latradians/math.pi
longdegs = 180*longradians/math.pi
if latdegs > 0:
latsign = 'N'
else:
latsign = 'S'

if longdegs > 0:
longsign = 'E'
else:
longsign = 'W'

print "Latitude: %(lat)0.4f %(NS)c" % {'lat': math.fabs(latdegs), "NS" : latsign}
print "Longitude: %(long)0.4f %(EW)c" % {'long': math.fabs(longdegs), "EW" : longsign}

Here’s what I got!

Indian Ocean off Indonesia
Latitude: 6.1519 S
Longitude: 88.0364 E

North Pacific Ocean north of Hawaii
Latitude: 30.4922 N
Longitude: 155.2186 W

South Atlantic Ocean west of the African continent
Latitude: 7.3661 S
Longitude: 6.5208 W

Sea north of Russia
Latitude: 73.5210 N
Longitude: 72.4081 E

Near Fuyang, China (land finally!)
Latitude: 33.0339 N
Longitude: 115.8606 E

Southern Chile (nearest city looks like Punta Arenas)
Latitude: 53.1839 S
Longitude: 73.2890 W

Sea off Kenya
Latitude: 3.9568 S
Longitude: 40.7945 E

North Pacific Ocean near Central America
Latitude: 5.2165 N
Longitude: 112.2900 W

South Pacific, near South America and Antarctica
Latitude: 62.1755 S
Longitude: 117.2731 W

Sea between Canada and Greenland
Latitude: 63.0687 N
Longitude: 60.2954 W

If one can be totally random, he should find himself in the ocean most of the time since about 70 percent of the Earth’s surface is cover by water, which is in agreement with the statistics observed here.

I’m not sure if my computer generated travel suggestions made it any easier to decide on a destination…

a

About

I blog from wordpress, but keep a mirror at thenoneventhorizon.blogspot.com. My gmail.com email username is the title of this blog excluding all spaces, hyphen, and the word "The". Hit Counter