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 is smaller near the poles, but will still have an equal probability of as the area element near the equator. Here
is the latitude and
the longitude. The radius of the Earth is
. 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 to
and
to
to be proportional to the area, i.e.,
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 and
such that
. We’d also like
and
to be normalized over the relevant ranges. With some guesswork, we get
Now, is the probability distribution function of a uniform distribution, so generating values for it is easy on a computer. As for
which is non-uniform, we make use of the Inverse transform sampling method. In short, if
is the cumulative distribution function for
, then random values for this probability distribution can be generated by first generating a value
that is picked from a uniform distribution that ranges from 0 to 1, and then finding
. The resulting value follows probability distribution
. The rationale can be derived through some calculus and from the basic definitions of probability related functions. The function
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…
